From 221ce9223da6c386c4b904cd7b79ef02e7845882 Mon Sep 17 00:00:00 2001 From: Ole John Aske Date: Mon, 7 Feb 2011 10:36:21 +0100 Subject: Fix for bug#59308: Incorrect result for SELECT DISTINCT ... ORDER BY DESC. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix bug#59110: Memory leak of QUICK_SELECT_I allocated memory. Includes Jørgen Lølands review comments. Root cause of these bugs are that test_if_skip_sort_order() decided to revert the 'skip_sort_order' descision (and use filesort) after the query plan has been updated to reflect a 'skip' of the sort order. This might happen in 'check_reverse_order:' if we have a select->quick which could not be made descending by appending a QUICK_SELECT_DESC. (). The original 'save_quick' was then restored after the QEP has been modified, which caused: - An incorrect 'precomputed_group_by= TRUE' may have been set, and not reverted, as part of the already modifified QEP (Bug#59308) - A 'select->quick' might have been created which we fail to delete (bug#59110). This fix is a refactorication of test_if_skip_sort_order() where all logic related to modification of QEP (controlled by argument 'bool no_changes'), is moved to the end of test_if_skip_sort_order(), and done after *all* 'test_if_skip' checks has been performed - including the 'check_reverse_order:' checks. The refactorication above contains now intentional changes to the logic which has been moved to the end of the function. Furthermore, a smaller part of the fix address the handling of the select->quick objects which may already exists when we call 'test_if_skip_sort_order()' (save_quick) -and new select->quick's created during test_if_skip_sort_order(): - Before new select->quick may be created by calling ::test_quick_select(), we set 'select->quick= 0' to avoid that ::test_quick_select() prematurely delete the save_quick's. (After this call we may have both a 'save_quick' and 'select->quick') - All returns from ::test_if_skip_sort_order() where we may have both a 'save_quick' and a 'select->quick' has been changed to goto's to the exit points 'skiped_sort_order:' or 'need_filesort:' where we decide which of the QUICK_SELECT's to keep, and delete the other. --- mysql-test/t/order_by.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'mysql-test/t/order_by.test') diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index a8a6ad00648..1064320b65c 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -1492,4 +1492,21 @@ LIMIT 2; DROP TABLE t1, t2; +--echo # +--echo # Bug #59110: Memory leak of QUICK_SELECT_I allocated memory +--echo # and +--echo # Bug #59308: Incorrect result for +--echo SELECT DISTINCT ... ORDER BY DESC +--echo +--echo # Use Valgrind to detect #59110! +--echo # + +CREATE TABLE t1 (a INT,KEY (a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); + +EXPLAIN SELECT DISTINCT a,1 FROM t1 WHERE a <> 1 ORDER BY a DESC; +SELECT DISTINCT a,1 FROM t1 WHERE a <> 1 ORDER BY a DESC; + +DROP TABLE t1; + --echo End of 5.1 tests -- cgit v1.2.1 From 4c1eb0c1719004b66187a166ddf0765cb481a927 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Wed, 30 Mar 2011 14:33:53 +0200 Subject: mtr: cleaned up some superfluos global warning suppressions --- mysql-test/t/order_by.test | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mysql-test/t/order_by.test') diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 1064320b65c..e310d960c97 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -846,8 +846,7 @@ set session max_sort_length= 2180; --error 1038 select * from t1 order by b; drop table t1; - - +call mtr.add_suppression("Out of sort memory; increase server sort buffer size"); --echo # --echo # Bug #39844: Query Crash Mysql Server 5.0.67 --echo # -- cgit v1.2.1