DROP TABLE IF EXISTS `distinct_fail`; CREATE TABLE `distinct_fail` ( `a` int NOT NULL, `b` int NOT NULL, `c` int NOT NULL, `d` int NOT NULL, KEY `foo` (`c`,`d`,`a`,`b`), KEY `bar` (`c`,`a`,`b`,`d`) ) ENGINE=InnoDB; INSERT INTO `distinct_fail` VALUES (0,0,0,3), (0,0,0,4), (0,0,0,4), (0,0,0,5), (0,0,1,0), (0,0,1,0), (0,0,1,1), (0,0,1,1), (0,0,1,2), (0,0,1,3), (0,0,1,4), (0,0,1,5), (0,0,2,1), (0,0,2,2), (0,0,2,2), (0,0,2,3), (0,0,2,3), (0,0,2,4), (0,0,2,4), (0,0,3,0), (0,0,3,0), (0,0,3,1), (0,0,3,1), (0,0,3,1), (0,0,3,1), (0,0,3,3), (0,0,3,3), (0,0,3,3), (0,0,3,4), (0,0,3,4), (0,0,3,4), (0,0,3,4), (0,0,3,4), (0,0,3,5), (0,0,4,0), (0,0,4,0), (0,0,4,0), (0,0,4,1), (0,0,4,1), (0,0,4,3), (0,0,4,3), (0,0,4,3), (0,0,4,3), (0,0,4,3), (0,0,4,4), (0,0,4,4), (0,0,5,0), (0,0,5,0), (0,0,5,1), (0,0,5,3); analyze table distinct_fail; select 'This next query should return rows' as message; select c from distinct_fail where d=4; select 'If the bug exists this next query will be an empty set' as message; select distinct c from distinct_fail where d=4; select 'This is what the result should be' as message; select distinct c from distinct_fail where d=4 order by a;