MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:kgeorge Date:April 10 2007 1:55pm
Subject:bk commit into 5.0 tree (gkodinov:1.2435) BUG#27659
View as plain text  
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-10 16:55:48+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-10 16:55:47+03:00, gkodinov@stripped +14 -0
    Bug #27659: test case

  mysql-test/t/distinct.test@stripped, 2007-04-10 16:55:47+03:00, gkodinov@stripped +13 -0
    Bug #27659: test case

  sql/sql_select.cc@stripped, 2007-04-10 16:55:47+03:00, gkodinov@stripped +2 -3
    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-10 16:55:47 +03:00
@@ -13539,9 +13539,7 @@ create_distinct_group(THD *thd, Item **r
       ORDER *ord_iter;
       for (ord_iter= group; ord_iter; ord_iter= ord_iter->next)
         if ((*ord_iter->item)->eq(item, 1))
-          break;
-      if (ord_iter)
-        continue;
+          goto next_item;
       
       ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER));
       if (!ord)
@@ -13556,6 +13554,7 @@ create_distinct_group(THD *thd, Item **r
       *prev=ord;
       prev= &ord->next;
     }
+next_item:
     ref_pointer_array++;
   }
   *prev=0;

--- 1.51/mysql-test/r/distinct.result	2007-01-31 10:18:13 +02:00
+++ 1.52/mysql-test/r/distinct.result	2007-04-10 16:55:47 +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-10 16:55:47 +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
Thread
bk commit into 5.0 tree (gkodinov:1.2435) BUG#27659kgeorge10 Apr