Bug #32933 | missing results with order by and limit in subquery in combination with indexes | ||
---|---|---|---|
Submitted: | 3 Dec 2007 15:13 | Modified: | 11 Jan 2008 17:04 |
Reporter: | Timo Boehme | Email Updates: | |
Status: | Can't repeat | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 5.0.52, 5.1.22-rc-community | OS: | Windows |
Assigned to: | Georgi Kodinov | CPU Architecture: | Any |
Tags: | INDEX, limit, order by, result, size, subquery |
[3 Dec 2007 15:13]
Timo Boehme
[3 Dec 2007 15:19]
Timo Boehme
DOS batch to create test case
Attachment: mysql-bug_subq_orderby_limit.bat (application/octet-stream, text), 834 bytes.
[3 Dec 2007 15:46]
Valeriy Kravchuk
Thank you for a bug report. Verified just as described. Indeed, after dropping index all the results are correct.
[21 Dec 2007 6:25]
Valeriy Kravchuk
Re-verified with 5.0.52 again. I've downloaded archive, got test table's .frm, .MYI and .MYD files from it, put them in test database's directory. Then: C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot test -P3308 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.0.52-enterprise-gpl-nt MySQL Enterprise Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show create table test\G *************************** 1. row *************************** Table: test Create Table: CREATE TABLE `test` ( `id` int(11) NOT NULL, `parent` int(11) default NULL, PRIMARY KEY (`id`), KEY `pIdx` (`parent`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 1 row in set (0.00 sec) mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=1 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id LIMIT 0,1); +----+ | id | +----+ | 4 | +----+ 1 row in set (0.47 sec) mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=1 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id DESC LIMIT 0,1); +-------+ | id | +-------+ | 10000 | +-------+ 1 row in set (0.09 sec) mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=2 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id LIMIT 0,1); +-------+ | id | +-------+ | 10001 | +-------+ 1 row in set (0.19 sec) mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=2 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id DESC LIMIT 0,1); Empty set (0.13 sec) mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=3 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id LIMIT 0,1); Empty set (0.30 sec) mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=3 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id DESC LIMIT 0,1); Empty set (0.31 sec) mysql> alter table test drop key `pIdx`; Query OK, 80000 rows affected (0.33 sec) Records: 80000 Duplicates: 0 Warnings: 0 mysql> SELECT c.id -> FROM test p, test c -> WHERE p.id=3 AND c.id=(SELECT c2.id FROM test c2 WHERE c2.parent=p.id ORD ER BY c2.id DESC LIMIT 0,1); +-------+ | id | +-------+ | 80000 | +-------+ 1 row in set (0.00 sec) So, exactly the same bug as described initially is easily repeatable on 5.0.52 also.
[11 Jan 2008 17:04]
Georgi Kodinov
I've tried both 5.0-BK and 5.1-BK on Windows and Linux FC8. The both don't exhibit the described problem. Can you please retry with the latest BK versions ? And if they still exhibit the problem for you please reopen the bug. The versions reported are "5.0.56-debug-log" and "5.1.23-rc-debug-log".