Good afternoon,
I have a web application which uses mysql cluster (2 data nodes and 2 mysql nodes, 5.1.56-ndb-7.1.13-cluster-gpl MySQL Cluster Server). It works fine. Last week it appeared that the mysql cluster became slower, likely due to data increase.
Today i looked at this problem and saw that my secondary indexes all have a Cardinality of NULL (0 in phpmyadmin).
A simple example
Create table:
===
CREATE TABLE `versions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`version` int(11) NOT NULL DEFAULT '0',
`subversion` int(11) NOT NULL DEFAULT '0',
`needupdate` varchar(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) /*!50100 TABLESPACE ts_tc STORAGE DISK */ ENGINE=ndbcluster AUTO_INCREMENT=16 DEFAULT CHARSET=latin1
===
The test data:
===
INSERT INTO `versions` (`id`, `version`, `subversion`, `needupdate`) VALUES
(12, 2, 1, '1'),
(13, 2, 2, '1'),
(14, 2, 3, '0');
===
Add index:
===
ALTER TABLE `versions` ADD INDEX ( `subversion` )
===
Show indexes:
===
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| versions | 0 | PRIMARY | 1 | id | A | 3 | NULL | NULL | | BTREE | |
| versions | 1 | subversion | 1 | subversion | A | NULL | NULL | NULL | | BTREE | |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
===
(the primary key has Cardinality 3, but the secondary index (on subversion) has NULL)
I did optimize and analyze table.
ndb_desc output:
===
ndb_desc -c localhost versions -d tcnew
-- versions --
Version: 117440521
Fragment type: 9
K Value: 6
Min load factor: 78
Max load factor: 80
Temporary table: no
Number of attributes: 4
Number of primary keys: 1
Length of frm data: 319
Row Checksum: 1
Row GCI: 1
SingleUserMode: 0
ForceVarPart: 1
FragmentCount: 2
TableStatus: Retrieved
-- Attributes --
id Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
version Int NOT NULL AT=FIXED ST=DISK DEFAULT 0
subversion Int NOT NULL AT=FIXED ST=MEMORY DEFAULT 0
needupdate Varchar(5;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=DISK DEFAULT "0"
-- Indexes --
PRIMARY KEY(id) - UniqueHashIndex
subversion(subversion) - OrderedIndex
PRIMARY(id) - OrderedIndex
NDBT_ProgramExit: 0 - OK
===
How can i fix this problem?
Kind regards,
TWan
I have a web application which uses mysql cluster (2 data nodes and 2 mysql nodes, 5.1.56-ndb-7.1.13-cluster-gpl MySQL Cluster Server). It works fine. Last week it appeared that the mysql cluster became slower, likely due to data increase.
Today i looked at this problem and saw that my secondary indexes all have a Cardinality of NULL (0 in phpmyadmin).
A simple example
Create table:
===
CREATE TABLE `versions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`version` int(11) NOT NULL DEFAULT '0',
`subversion` int(11) NOT NULL DEFAULT '0',
`needupdate` varchar(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) /*!50100 TABLESPACE ts_tc STORAGE DISK */ ENGINE=ndbcluster AUTO_INCREMENT=16 DEFAULT CHARSET=latin1
===
The test data:
===
INSERT INTO `versions` (`id`, `version`, `subversion`, `needupdate`) VALUES
(12, 2, 1, '1'),
(13, 2, 2, '1'),
(14, 2, 3, '0');
===
Add index:
===
ALTER TABLE `versions` ADD INDEX ( `subversion` )
===
Show indexes:
===
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| versions | 0 | PRIMARY | 1 | id | A | 3 | NULL | NULL | | BTREE | |
| versions | 1 | subversion | 1 | subversion | A | NULL | NULL | NULL | | BTREE | |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
===
(the primary key has Cardinality 3, but the secondary index (on subversion) has NULL)
I did optimize and analyze table.
ndb_desc output:
===
ndb_desc -c localhost versions -d tcnew
-- versions --
Version: 117440521
Fragment type: 9
K Value: 6
Min load factor: 78
Max load factor: 80
Temporary table: no
Number of attributes: 4
Number of primary keys: 1
Length of frm data: 319
Row Checksum: 1
Row GCI: 1
SingleUserMode: 0
ForceVarPart: 1
FragmentCount: 2
TableStatus: Retrieved
-- Attributes --
id Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
version Int NOT NULL AT=FIXED ST=DISK DEFAULT 0
subversion Int NOT NULL AT=FIXED ST=MEMORY DEFAULT 0
needupdate Varchar(5;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=DISK DEFAULT "0"
-- Indexes --
PRIMARY KEY(id) - UniqueHashIndex
subversion(subversion) - OrderedIndex
PRIMARY(id) - OrderedIndex
NDBT_ProgramExit: 0 - OK
===
How can i fix this problem?
Kind regards,
TWan