Details
Description
Taken from: http://bugs.mysql.com/bug.php?id=70038
test case:
--source include/have_innodb.inc CREATE TABLE tmp ( id int NOT NULL AUTO_INCREMENT, a int NOT NULL, b int NOT NULL, PRIMARY KEY (id), UNIQUE KEY ba (b, a) ) ENGINE=InnoDB; INSERT INTO tmp (a, b) VALUES(1,101),(1,102),(1,103),(1,104),(1,105),(1,106),(1,107),(1,108),(1,109),(1,110); SELECT COUNT(DISTINCT b) FROM tmp WHERE a = 1; DROP TABLE tmp;
Select returns 5, should be 10. Myisam works correctly.
I think the problem is because in function QUICK_GROUP_MIN_MAX_SELECT::get_next() call to file->ha_index_read_map() fetches next row when it shouldn't. Happens when index_next_different() is called with is_index_scan = true.
Gliffy Diagrams
Attachments
Issue Links
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
The only difference between the two test cases below is the presence of a PK. The test case with the PK produces wrong result, the other one works correctly:
– Wrong result
CREATE TABLE t1 (id int NOT NULL AUTO_INCREMENT, a char(3) NOT NULL, b char(3) NOT NULL,
PRIMARY KEY (id),
KEY ba (b, a)
) ENGINE=InnoDB;
INSERT INTO t1 (a, b) VALUES('777','101'),('777','102');
EXPLAIN EXTENDED
SELECT COUNT(DISTINCT b) FROM t1 WHERE a = '777';
-----
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------SELECT COUNT(DISTINCT b) FROM t1 WHERE a = '777';
-------------------
-------------------
-------------------
– Correct result
CREATE TABLE t2 (a char(3) NOT NULL, b char(3) NOT NULL,
KEY ba (b, a)) ENGINE=InnoDB;
INSERT INTO t2 (a, b) VALUES('777','101'),('777','102');
EXPLAIN EXTENDED
SELECT COUNT(DISTINCT b) FROM t2 WHERE a = '777';
-----
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------SELECT COUNT(DISTINCT b) FROM t2 WHERE a = '777';
-------------------
-------------------
-------------------