Bug #21418 | Correlated subqueries with UNIQUE columns used in WHERE clause are incorrect | ||
---|---|---|---|
Submitted: | 2 Aug 2006 15:04 | Modified: | 23 Aug 2006 14:36 |
Reporter: | Michael Peters | Email Updates: | |
Status: | Can't repeat | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 5.0.22/4.1;5.0;5.1BK | OS: | Linux (Linux (FC3)) |
Assigned to: | Igor Babaev | CPU Architecture: | Any |
Tags: | correlated, subquery, unique |
[2 Aug 2006 15:04]
Michael Peters
[2 Aug 2006 15:11]
Michael Peters
Running EXPLAIN on the query for both 4.1 and 5.0.22 gave the exact same results even though the results of the execution where different.
[2 Aug 2006 17:26]
MySQL Verification Team
Thank you for the bug report. Verified as described: mysql> SELECT t1.t1_id FROM t1 WHERE (SELECT COUNT(*) FROM t2 JOIN t3 ON(t2.t3_id = -> t3.t3_id) WHERE t3.foo = '1039' AND t1.t1_id = t2.t1_id) >= 1; Empty set (0.02 sec) mysql> alter table t3 drop key foo; Query OK, 2 rows affected (0.02 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> alter table t3 add index(foo); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> SELECT t1.t1_id FROM t1 WHERE (SELECT COUNT(*) FROM t2 JOIN t3 ON(t2.t3_id = -> t3.t3_id) WHERE t3.foo = '1039' AND t1.t1_id = t2.t1_id) >= 1; +-------+ | t1_id | +-------+ | 2 | +-------+ 1 row in set (0.00 sec
[23 Aug 2006 14:36]
Igor Babaev
I failed to repeat the problem with:mysql> SELECT VERSION(); +--------------+ | VERSION() | +--------------+ | 5.0.25-debug | +--------------+ mysql> SELECT t1.t1_id FROM t1 WHERE (SELECT COUNT(*) FROM t2 JOIN t3 ON(t2.t3_id = -> t3.t3_id) WHERE t3.foo = '1039' AND t1.t1_id = t2.t1_id) >= 1; +-------+ | t1_id | +-------+ | 2 | +-------+ 1 row in set (0.00 sec)