CREATE TABLE t1 (id1 int, v1 int, PRIMARY KEY (id1), INDEX idx (v1)) ENGINE = INNODB; CREATE TABLE t2 (id2 int) ENGINE = INNODB; INSERT INTO t1(id1,v1) VALUES (1,11),(2,11),(3,12),(4,12); INSERT INTO t2(id2) VALUES (4); -- The select below will trigger the bug. Commenting it out makes the test -- case succeed SELECT 1 FROM t1 t11,t1 t12,t1 t13 WHERE 1=0; -- First select: should show 12, but does not select distinct v1 from t1 where id1 in (select id2 from t2); -- Second select: we just add a bogus constant column, and presto, it -- works as it should! select distinct v1,1 from t1 where id1 in (select id2 from t2);