List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:January 24 2011 9:02am
Subject:bzr push into mysql-trunk branch (jorgen.loland:3543 to 3544) Bug#47853
View as plain text  
 3544 Jorgen Loland	2011-01-24
      BUG#47853: Implicitly grouped queries do not need to use 
                 temporary tables
      
      A query is implicitly grouped if it contains an aggregate 
      function but no GROUP BY clause. Implicitly grouped queries 
      return zero or one row, so ordering does not make sense. 
      
      This patch removes the order by clause during the prepare()
      stage of the optimizer when implicitly ordered queries are 
      detected.
     @ mysql-test/r/func_group.result
        Updated result file
     @ mysql-test/r/limit.result
        Updated result file
     @ mysql-test/r/subquery_nomat_nosj.result
        Updated result file
     @ mysql-test/r/subquery_none.result
        Updated result file
     @ sql/sql_select.cc
        Remove order by clause during prepare() if the query is implicitly grouped.

    modified:
      mysql-test/r/func_group.result
      mysql-test/r/limit.result
      mysql-test/r/subquery_nomat_nosj.result
      mysql-test/r/subquery_none.result
      sql/sql_select.cc
 3543 Anitha Gopi	2011-01-24
      Add more tests to daily run

    modified:
      mysql-test/collections/mysql-trunk.daily
=== modified file 'mysql-test/r/func_group.result'
--- a/mysql-test/r/func_group.result	2010-12-21 12:34:13 +0000
+++ b/mysql-test/r/func_group.result	2011-01-24 09:02:03 +0000
@@ -1507,7 +1507,7 @@ SELECT MAX(pk) as max, i
 FROM t1
 ORDER BY max;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using temporary
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
 
 # Only 11 is correct for collumn i in this result
 SELECT MAX(pk) as max, i

=== modified file 'mysql-test/r/limit.result'
--- a/mysql-test/r/limit.result	2008-10-15 21:34:51 +0000
+++ b/mysql-test/r/limit.result	2011-01-24 09:02:03 +0000
@@ -80,13 +80,13 @@ create table t1 (a int);
 insert into t1 values (1),(2),(3),(4),(5),(6),(7);
 explain select count(*) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where; Using temporary
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where
 select count(*) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
 c
 7
 explain select sum(a) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where; Using temporary
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where
 select sum(a) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
 c
 28

=== modified file 'mysql-test/r/subquery_nomat_nosj.result'
--- a/mysql-test/r/subquery_nomat_nosj.result	2011-01-18 11:42:09 +0000
+++ b/mysql-test/r/subquery_nomat_nosj.result	2011-01-24 09:02:03 +0000
@@ -5088,7 +5088,7 @@ SELECT 1 FROM t1
 WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3))
 ORDER BY count(*);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	PRIMARY	t1	index	NULL	a	5	NULL	2	Using index; Using temporary
+1	PRIMARY	t1	index	NULL	a	5	NULL	2	Using index
 2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
 3	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
 # should not crash the next statement

=== modified file 'mysql-test/r/subquery_none.result'
--- a/mysql-test/r/subquery_none.result	2011-01-18 11:42:09 +0000
+++ b/mysql-test/r/subquery_none.result	2011-01-24 09:02:03 +0000
@@ -5087,7 +5087,7 @@ SELECT 1 FROM t1
 WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3))
 ORDER BY count(*);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	PRIMARY	t1	index	NULL	a	5	NULL	2	Using index; Using temporary
+1	PRIMARY	t1	index	NULL	a	5	NULL	2	Using index
 2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
 3	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
 # should not crash the next statement

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-01-20 09:09:26 +0000
+++ b/sql/sql_select.cc	2011-01-24 09:02:03 +0000
@@ -749,7 +749,11 @@ JOIN::prepare(Item ***rref_pointer_array
   unit= unit_arg;
 
   if (tmp_table_param.sum_func_count && !group_list)
+  {
     implicit_grouping= TRUE;
+    // Result will contain zero or one row - ordering is meaningless
+    order= NULL;
+  }
 
 #ifdef RESTRICTED_GROUP
   if (implicit_grouping)

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (jorgen.loland:3543 to 3544) Bug#47853Jorgen Loland24 Jan