List:Commits« Previous MessageNext Message »
From:timour Date:August 23 2006 2:03pm
Subject:bk commit into 5.0 tree (timour:1.2245)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of timka. When timka 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, 2006-08-23 17:03:34+03:00, timour@stripped +3 -0
  Merge lamia.home:/home/timka/mysql/src/4.1-bug-21456
  into  lamia.home:/home/timka/mysql/src/5.0-bug-21456
  MERGE: 1.1616.2144.181

  mysql-test/r/distinct.result@stripped, 2006-08-23 17:03:32+03:00, timour@stripped +0 -11
    merge for BUG#21456
    MERGE: 1.27.1.7

  mysql-test/t/distinct.test@stripped, 2006-08-23 17:03:32+03:00, timour@stripped +11 -11
    merge for BUG#21456
    MERGE: 1.14.1.5

  sql/sql_select.cc@stripped, 2006-08-23 17:03:32+03:00, timour@stripped +0 -0
    merge for BUG#21456
    MERGE: 1.216.125.16

# 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:	timour
# Host:	lamia.home
# Root:	/home/timka/mysql/src/5.0-bug-21456/RESYNC

--- 1.439/sql/sql_select.cc	2006-08-23 17:03:38 +03:00
+++ 1.440/sql/sql_select.cc	2006-08-23 17:03:38 +03:00
@@ -812,6 +812,36 @@ JOIN::optimize()
     if (!order && org_order)
       skip_sort_order= 1;
   }
+  /*
+     Check if we can optimize away GROUP BY/DISTINCT.
+     We can do that if there are no aggregate functions and the
+     fields in DISTINCT clause (if present) and/or columns in GROUP BY
+     (if present) contain direct references to all key parts of
+     an unique index (in whatever order).
+     Note that the unique keys for DISTINCT and GROUP BY should not
+     be the same (as long as they are unique).
+
+     The FROM clause must contain a single non-constant table.
+  */
+  if (tables - const_tables == 1 && (group_list || select_distinct) &&
+      !tmp_table_param.sum_func_count)
+  {
+    if (group_list &&
+       list_contains_unique_index(join_tab[const_tables].table,
+                                 find_field_in_order_list,
+                                 (void *) group_list))
+    {
+      group_list= 0;
+      group= 0;
+    }
+    if (select_distinct &&
+       list_contains_unique_index(join_tab[const_tables].table,
+                                 find_field_in_item_list,
+                                 (void *) &fields_list))
+    {
+      select_distinct= 0;
+    }
+  }
   if (group_list || tmp_table_param.sum_func_count)
   {
     if (! hidden_group_fields && rollup.state == ROLLUP::STATE_NONE)
@@ -880,40 +910,6 @@ JOIN::optimize()
 			     &simple_group);
     if (old_group_list && !group_list)
       select_distinct= 0;
-  }
-  /*
-     Check if we can optimize away GROUP BY/DISTINCT.
-     We can do that if there are no aggregate functions and the
-     fields in DISTINCT clause (if present) and/or columns in GROUP BY
-     (if present) contain direct references to all key parts of
-     an unique index (in whatever order).
-     Note that the unique keys for DISTINCT and GROUP BY should not
-     be the same (as long as they are unique).
-
-     The FROM clause must contain a single non-constant table.
-  */
-  if (tables - const_tables == 1 && (group_list || select_distinct) &&
-      !tmp_table_param.sum_func_count &&
-      (!join_tab[const_tables].select ||
-       !join_tab[const_tables].select->quick ||
-       join_tab[const_tables].select->quick->get_type() != 
-       QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX))
-  {
-    if (group_list &&
-       list_contains_unique_index(join_tab[const_tables].table,
-                                 find_field_in_order_list,
-                                 (void *) group_list))
-    {
-      group_list= 0;
-      group= 0;
-    }
-    if (select_distinct &&
-       list_contains_unique_index(join_tab[const_tables].table,
-                                 find_field_in_item_list,
-                                 (void *) &fields_list))
-    {
-      select_distinct= 0;
-    }
   }
   if (!group_list && group)
   {

--- 1.24/mysql-test/t/distinct.test	2006-08-23 17:03:38 +03:00
+++ 1.25/mysql-test/t/distinct.test	2006-08-23 17:03:38 +03:00
@@ -385,6 +385,17 @@ insert into t1 values (1, "line number o
 select distinct id, IFNULL(dsc, '-') from t1;
 drop table t1;
 
+#
+# Bug 21456: SELECT DISTINCT(x) produces incorrect results when using order by
+#
+CREATE TABLE t1 (a int primary key, b int);
+
+INSERT INTO t1 (a,b) values (1,1), (2,3), (3,2);
+
+explain SELECT DISTINCT a, b FROM t1 ORDER BY b;
+SELECT DISTINCT a, b FROM t1 ORDER BY b;
+DROP TABLE t1;
+
 # End of 4.1 tests
 
 
Thread
bk commit into 5.0 tree (timour:1.2245)timour23 Aug