Bug #15106 | EXPLAIN output differs for almost same query | ||
---|---|---|---|
Submitted: | 21 Nov 2005 19:32 | Modified: | 21 Dec 2005 10:44 |
Reporter: | Shane Bester (Platinum Quality Contributor) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.0.15, 5.0.17-bk | OS: | Linux (Linux, Windows) |
Assigned to: | Igor Babaev | CPU Architecture: | Any |
[21 Nov 2005 19:32]
Shane Bester
[22 Nov 2005 0:17]
Hartmut Holzgraefe
verified, i also get different result sets: mysql> SELECT * FROM t1 JOIN t2 ON t2.c1 = t1.c2 JOIN t3 ON t3.c1 = t2.c1 WHERE t1.c2 = '1'; +-----+----+-----+------------+------------+------+----+----+-----+----+----+-----+----+-----+----+ | c1 | c2 | c3 | c4 | c5 | c6 | c1 | c2 | c3 | c4 | c1 | c2 | c3 | c4 | c5 | +-----+----+-----+------------+------------+------+----+----+-----+----+----+-----+----+-----+----+ | Pv9 | Q | puZ | 1471135022 | 1997-06-10 | -20 | Q | D | 7oT | gw | Q | Rev | dn | NVn | lR | +-----+----+-----+------------+------------+------+----+----+-----+----+----+-----+----+-----+----+ 1 row in set (0.00 sec) mysql> SELECT * FROM t1 JOIN t2 ON t1.c2 = t2.c1 JOIN t3 ON t3.c1 = t2.c1 WHERE t1.c2 = '1'; Empty set (0.00 sec)
[24 Nov 2005 23:01]
Connor Harty
In regards to the comment above, the column used in the join would appear to be optimized away: SELECT t1.* FROM t1 JOIN t2 ON t2.c1 = t1.c2 JOIN t3 ON t3.c1 = t2.c1 where t1.c1 = 'PV9' and t1.c2='I feel ignored'; +-----+----+-----+------------+------------+------+ | c1 | c2 | c3 | c4 | c5 | c6 | +-----+----+-----+------------+------------+------+ | Pv9 | Q | puZ | 1471135022 | 1997-06-10 | -20 | +-----+----+-----+------------+------------+------+ While SELECT t1.* FROM t1 JOIN t2 ON t2.c1 = t1.c2 JOIN t3 ON t3.c1 = t2.c1 where t1.c1 = 'Not me' and t1.c2='Q'; yields: Empty set (0.00 sec) Another example: DROP TABLE IF EXISTS `a`; CREATE table a (key_a int4 not null, optimus varchar(32), PRIMARY KEY(key_a)); INSERT INTO a VALUES (0,''); INSERT INTO a VALUES (1,'i'); INSERT INTO a VALUES (2,'j'); INSERT INTO a VALUES (3,'k'); DROP TABLE IF EXISTS `aprime`; CREATE table aprime (key_a int4 not null, prime varchar(32), PRIMARY KEY(key_a)); INSERT INTO aprime VALUES (1,'r'); INSERT INTO aprime VALUES (2,'s'); INSERT INTO aprime VALUES (3,'t'); DROP TABLE IF EXISTS `b`; CREATE table b (key_a int4 not null, key_b int4 not null, foo varchar(32) , PRIMARY KEY(key_a,key_b)); INSERT INTO b VALUES (1,5,'x'); INSERT INTO b VALUES (1,6,'y'); INSERT INTO b VALUES (2,5,'xx'); INSERT INTO b VALUES (2,6,'yy'); INSERT INTO b VALUES (2,7,'zz'); INSERT INTO b VALUES (3,5,'xxx'); SELECT aprime.key_a,foo FROM a inner join aprime on a.key_a = aprime.key_a inner join b on a.key_a = b.key_a WHERE aprime.key_a = 2 and key_b=5; gives: +-------+------+ | key_a | foo | +-------+------+ | 1 | x | | 2 | xx | | 3 | xxx | +-------+------+ EXPLAIN: +----+-------------+--------+--------+---------------+---------+---------+-----------------------------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+--------+---------------+---------+---------+-----------------------------+------+--------------------------+ | 1 | SIMPLE | a | index | PRIMARY | PRIMARY | 4 | NULL | 4 | Using index | | 1 | SIMPLE | b | eq_ref | PRIMARY | PRIMARY | 8 | mysql_bugtest.a.key_a,const | 1 | | | 1 | SIMPLE | aprime | index | PRIMARY | PRIMARY | 4 | NULL | 3 | Using where; Using index | +----+-------------+--------+--------+---------------+---------+---------+-----------------------------+------+--------------------------+ while: SELECT aprime.key_a,foo FROM a inner join aprime on aprime.key_a = a.key_a inner join b on a.key_a = b.key_a WHERE aprime.key_a = 2 and key_b=5; gives: +-------+------+ | key_a | foo | +-------+------+ | 2 | xx | +-------+------+ EXPLAIN: +----+-------------+--------+-------+---------------+---------+---------+-------------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+-------+---------------+---------+---------+-------------+------+-------------+ | 1 | SIMPLE | a | const | PRIMARY | PRIMARY | 4 | const | 1 | Using index | | 1 | SIMPLE | aprime | const | PRIMARY | PRIMARY | 4 | const | 1 | Using index | | 1 | SIMPLE | b | const | PRIMARY | PRIMARY | 8 | const,const | 1 | | +----+-------------+--------+-------+---------------+---------+---------+-------------+------+-------------+
[26 Nov 2005 2:52]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/internals/32731
[12 Dec 2005 6:43]
Igor Babaev
ChangeSet 1.2012 05/11/25 18:51:44 igor@rurik.mysql.com +3 -0 Fixed bug #15106. A typo bug caused loss of a predicate of the form field=const in some cases. sql/item_cmpfunc.cc 1.186 05/11/25 18:51:39 igor@rurik.mysql.com +1 -1 Fixed bug #15106. A typo bug caused loss of a predicate of the form field=const in some cases. mysql-test/t/select.test 1.93 05/11/25 18:51:39 igor@rurik.mysql.com +45 -0 Added a test case for bug #15106. mysql-test/r/select.result 1.114 05/11/25 18:51:39 igor@rurik.mysql.com +46 -0 Added a test case for bug #15106. The fix will appear in 5.0.18.
[21 Dec 2005 10:44]
Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release. If necessary, you can access the source repository and build the latest available version, including the bugfix, yourself. More information about accessing the source trees is available at http://www.mysql.com/doc/en/Installing_source_tree.html Additional info: Documented in 5.0.18 changelog. Closed.