Description:
MySQL is not presented index statistics from NDB engine, and therefore cannot make good decisions when multiple possible indexes are available.
How to repeat:
create table t1 (id int not null auto_increment, c1 int, c2 int, c3 int, primary key (id), key (c1), key (c1,c2), key (c1,c2,c3)) engine = ndbcluster;
insert into t1 (c1,c2,c3) values (1,2,3),(7,8,9),(111,222,333),(4444,5555,6666);
;Fill table with anything.
insert into t1 (c1,c2,c3) select c1+c1,c2+c2,c3+c3 from t1;
explain select c1 from t1 where c1=1, c2=2 c3=3;
mysql> explain select c1 from t1 where c1=1 and c2=2 and c3=3;
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------------------+
| 1 | SIMPLE | t1 | ref | c1,c1_2,c1_3 | c1 | 5 | const | 10 | Using where with pushed condition |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------------------+
1 row in set (0.03 sec)
mysql> show indexes from t1;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| t1 | 0 | PRIMARY | 1 | id | A | 2080 | NULL | NULL | | BTREE | |
| t1 | 1 | c1 | 1 | c1 | A | 2080 | NULL | NULL | YES | BTREE | |
| t1 | 1 | c1_2 | 1 | c1 | A | NULL | NULL | NULL | YES | BTREE | |
| t1 | 1 | c1_2 | 2 | c2 | A | 2080 | NULL | NULL | YES | BTREE | |
| t1 | 1 | c1_3 | 1 | c1 | A | NULL | NULL | NULL | YES | BTREE | |
| t1 | 1 | c1_3 | 2 | c2 | A | NULL | NULL | NULL | YES | BTREE | |
| t1 | 1 | c1_3 | 3 | c3 | A | 2080 | NULL | NULL | YES | BTREE | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
Should use c1_3, or even c1_2 index instead of single column index c1.
Suggested fix:
Present index statistics to MySQL optimizer.