From: Date: April 6 2007 4:30pm Subject: bk commit into 5.0 tree (gkodinov:1.2435) BUG#27659 List-Archive: http://lists.mysql.com/commits/23987 X-Bug: 27659 Message-Id: <200704061430.l36EUEN0010311@magare.gmz> Below is the list of changes that have just been committed into a local 5.0 repository of kgeorge. When kgeorge does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-04-06 17:30:10+03:00, gkodinov@stripped +3 -0 Bug #27659: The optimizer transforms DISTINCT into a GROUP BY when possible. It does that by constructing the same structure (a list of ORDER instances) the parser makes when parsing GROUP BY. While doing that it also eliminates duplicates. But if a duplicate is found it doesn't advance the pointer to ref_pointer array, so the next (and subsequent) ORDER structures point to the wrong element in the SELECT list. Fixed by advancing the pointer in ref_pointer_array even in the case of a duplicate. mysql-test/r/distinct.result@stripped, 2007-04-06 17:30:07+03:00, gkodinov@stripped +14 -0 Bug #27659: test case mysql-test/t/distinct.test@stripped, 2007-04-06 17:30:08+03:00, gkodinov@stripped +13 -0 Bug #27659: test case sql/sql_select.cc@stripped, 2007-04-06 17:30:08+03:00, gkodinov@stripped +3 -0 Bug #27659: use correct ref_pointer_array element # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: gkodinov # Host: magare.gmz # Root: /home/kgeorge/mysql/work/B27659-5.0-opt --- 1.507/sql/sql_select.cc 2007-04-02 04:56:34 +03:00 +++ 1.508/sql/sql_select.cc 2007-04-06 17:30:08 +03:00 @@ -13541,7 +13541,10 @@ create_distinct_group(THD *thd, Item **r if ((*ord_iter->item)->eq(item, 1)) break; if (ord_iter) + { + ref_pointer_array++; continue; + } ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER)); if (!ord) --- 1.51/mysql-test/r/distinct.result 2007-01-31 10:18:13 +02:00 +++ 1.52/mysql-test/r/distinct.result 2007-04-06 17:30:07 +03:00 @@ -668,3 +668,17 @@ NULL 3 4 DROP TABLE t1; +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES(1,1),(1,2),(1,3); +SELECT DISTINCT a, b FROM t1; +a b +1 1 +1 2 +1 3 +SELECT DISTINCT a, a, b FROM t1; +a a b +1 1 1 +1 1 2 +1 1 3 +DROP TABLE t1; +End of 5.0 tests --- 1.30/mysql-test/t/distinct.test 2007-01-31 10:18:13 +02:00 +++ 1.31/mysql-test/t/distinct.test 2007-04-06 17:30:08 +03:00 @@ -540,3 +540,16 @@ EXPLAIN SELECT a FROM t1 GROUP BY a; SELECT a FROM t1 GROUP BY a; DROP TABLE t1; + +# +#Bug #27659: SELECT DISTINCT returns incorrect result set when field is +#repeated +# +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES(1,1),(1,2),(1,3); +SELECT DISTINCT a, b FROM t1; +SELECT DISTINCT a, a, b FROM t1; +DROP TABLE t1; + +--echo End of 5.0 tests