Bug #32268 | Indexed queries give bogus MIN and MAX results | ||
---|---|---|---|
Submitted: | 12 Nov 2007 8:13 | Modified: | 23 Jan 2008 16:25 |
Reporter: | William Grant | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 5.0.45, 5.1.22 | OS: | Linux (Ubuntu 7.10) |
Assigned to: | Georgi Kodinov | CPU Architecture: | Any |
[12 Nov 2007 8:13]
William Grant
[12 Nov 2007 9:05]
MySQL Verification Team
Thank you for this detailed bug report. I have reproduced the behavior as described. mysql> SELECT `key`, MIN(`value`), MAX(`value`) FROM breakage GROUP BY `key` ORDER BY `key` DESC; +-----+--------------+--------------+ | key | MIN(`value`) | MAX(`value`) | +-----+--------------+--------------+ | 3 | 9 | 9 | | 2 | 6 | 6 | | 1 | 3 | 3 | +-----+--------------+--------------+ 3 rows in set (0.01 sec) mysql> SELECT `key`, MIN(`value`), MAX(`value`), AVG(`value`) FROM breakage GROUP BY `key` ORDER BY `key` DESC; +-----+--------------+--------------+--------------+ | key | MIN(`value`) | MAX(`value`) | AVG(`value`) | +-----+--------------+--------------+--------------+ | 3 | 7 | 9 | 8 | | 2 | 4 | 6 | 5 | | 1 | 1 | 3 | 2 | +-----+--------------+--------------+--------------+ 3 rows in set (0.00 sec) mysql> alter table breakage drop index `break_it`; Query OK, 9 rows affected, 0 warnings (0.01 sec) Records: 9 Duplicates: 0 Warnings: 0 mysql> SELECT `key`, MIN(`value`), MAX(`value`) FROM breakage GROUP BY `key` ORDER BY `key` DESC; +-----+--------------+--------------+ | key | MIN(`value`) | MAX(`value`) | +-----+--------------+--------------+ | 3 | 7 | 9 | | 2 | 4 | 6 | | 1 | 1 | 3 | +-----+--------------+--------------+ 3 rows in set (0.00 sec)
[16 Nov 2007 15:33]
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/commits/37956 ChangeSet@1.2566, 2007-11-16 17:31:50+02:00, gkodinov@magare.gmz +3 -0 Bug #32268: Indexed queries give bogus MIN and MAX results Loose index scan does not work correctly on indexes in descending order. Fixed the bug by disabling loose index scan when sorting in descending order.ug #32268: Indexed queries give bogus MIN and MAX results Loose index scan does not work correctly on indexes in descending order. Fixed the bug by disabling loose index scan when sorting in descending order.
[20 Nov 2007 14:07]
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/commits/38136 ChangeSet@1.2566, 2007-11-20 16:07:24+02:00, gkodinov@magare.gmz +3 -0 Bug #32268: Indexed queries give bogus MIN and MAX results Loose index scan does the grouping so the temp table does not need to do it, even when sorting. Fixed by checking if the grouping is already done before doing sorting and grouping in a temp table and do only sorting.
[14 Dec 2007 8:14]
Bugs System
Pushed into 5.0.54
[14 Dec 2007 8:17]
Bugs System
Pushed into 5.1.23-rc
[14 Dec 2007 8:20]
Bugs System
Pushed into 6.0.5-alpha
[23 Jan 2008 16:25]
Paul DuBois
Noted in 5.0.54, 5.1.23, 6.0.5 changelogs. MIN() and MAX() could return incorrect results when an index was present if a loose index scan was used.