List:Commits« Previous MessageNext Message »
From:kgeorge Date:November 17 2006 4:22pm
Subject:bk commit into 5.0 tree (gkodinov:1.2314) BUG#24156
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, 2006-11-17 17:21:55+02:00, gkodinov@stripped +3 -0
  Bug#24156: Loose index scan not used with CREATE TABLE ...SELECT and similar
             statements
  Trying loose index scan is currently enabled only for top level SELECT 
  statements.
  Extend loose index scan applicability by :
   - trying over the current subselect (lex->current_select) instead of 
     the whole query (lex->select_lex) : enables loose index scan for 
     sub-queries.
   - allowing non-select statements with SELECT parts (like, e.g. 
     CREATE TABLE .. SELECT ...) to use loose index scan.

  mysql-test/r/group_min_max.result@stripped, 2006-11-17 17:21:46+02:00, gkodinov@stripped
+63 -0
    Bug#24156: Loose index scan not used with CREATE TABLE ...SELECT and similar
               statements
     - test case

  mysql-test/t/group_min_max.test@stripped, 2006-11-17 17:21:47+02:00, gkodinov@stripped
+24 -0
    Bug#24156: Loose index scan not used with CREATE TABLE ...SELECT and similar
               statements
     - test case

  sql/opt_range.cc@stripped, 2006-11-17 17:21:48+02:00, gkodinov@stripped +3 -3
    Bug#24156: Loose index scan not used with CREATE TABLE ...SELECT and similar
               statements
     - loose index scan will be tried over the current subselect 
       (lex->current_select) instead of the whole query (lex->select_lex).
     - allow non-select statements with SELECT parts (like, e.g. 
       CREATE TABLE .. SELECT ...) to use loose index scan.

# 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:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B24156-5.0-opt

--- 1.231/sql/opt_range.cc	2006-10-24 23:31:06 +03:00
+++ 1.232/sql/opt_range.cc	2006-11-17 17:21:48 +02:00
@@ -7445,7 +7445,7 @@ static TRP_GROUP_MIN_MAX *
 get_best_group_min_max(PARAM *param, SEL_TREE *tree)
 {
   THD *thd= param->thd;
-  JOIN *join= thd->lex->select_lex.join;
+  JOIN *join= thd->lex->current_select->join;
   TABLE *table= param->table;
   bool have_min= FALSE;              /* TRUE if there is a MIN function. */
   bool have_max= FALSE;              /* TRUE if there is a MAX function. */
@@ -7466,7 +7466,7 @@ get_best_group_min_max(PARAM *param, SEL
   DBUG_ENTER("get_best_group_min_max");
 
   /* Perform few 'cheap' tests whether this access method is applicable. */
-  if (!join || (thd->lex->sql_command != SQLCOM_SELECT))
+  if (!join)
     DBUG_RETURN(NULL);        /* This is not a select statement. */
   if ((join->tables != 1) ||  /* The query must reference one table. */
       ((!join->group_list) && /* Neither GROUP BY nor a DISTINCT query. */
@@ -8316,7 +8316,7 @@ TRP_GROUP_MIN_MAX::make_quick(PARAM *par
   DBUG_ENTER("TRP_GROUP_MIN_MAX::make_quick");
 
   quick= new QUICK_GROUP_MIN_MAX_SELECT(param->table,
-                                        param->thd->lex->select_lex.join,
+                                       
param->thd->lex->current_select->join,
                                         have_min, have_max, min_max_arg_part,
                                         group_prefix_len, used_key_parts,
                                         index_info, index, read_cost, records,

--- 1.27/mysql-test/r/group_min_max.result	2006-10-19 03:24:29 +03:00
+++ 1.28/mysql-test/r/group_min_max.result	2006-11-17 17:21:46 +02:00
@@ -2162,3 +2162,66 @@ SELECT MIN(c) FROM t2 WHERE b = 2 and a 
 MIN(c)
 2
 DROP TABLE t1,t2;
+CREATE TABLE t1 (a INT, b INT, INDEX (a,b));
+INSERT INTO t1 (a, b) VALUES (1,1), (1,2), (1,3), (1,4), (1,5),
+(2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6);
+EXPLAIN SELECT max(b), a FROM t1 GROUP BY a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	NULL	a	5	NULL	8	Using index for group-by
+FLUSH STATUS;
+SELECT max(b), a FROM t1 GROUP BY a;
+max(b)	a
+5	1
+3	2
+1	3
+6	4
+SHOW STATUS LIKE 'handler_read%';
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	8
+Handler_read_next	0
+Handler_read_prev	0
+Handler_read_rnd	0
+Handler_read_rnd_next	0
+FLUSH STATUS;
+CREATE TABLE t2 SELECT max(b), a FROM t1 GROUP BY a;
+SHOW STATUS LIKE 'handler_read%';
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	8
+Handler_read_next	0
+Handler_read_prev	0
+Handler_read_rnd	0
+Handler_read_rnd_next	0
+FLUSH STATUS;
+SELECT * FROM (SELECT max(b), a FROM t1 GROUP BY a) b;
+max(b)	a
+5	1
+3	2
+1	3
+6	4
+SHOW STATUS LIKE 'handler_read%';
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	8
+Handler_read_next	0
+Handler_read_prev	0
+Handler_read_rnd	0
+Handler_read_rnd_next	5
+FLUSH STATUS;
+(SELECT max(b), a FROM t1 GROUP BY a) UNION 
+(SELECT max(b), a FROM t1 GROUP BY a);
+max(b)	a
+5	1
+3	2
+1	3
+6	4
+SHOW STATUS LIKE 'handler_read%';
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	16
+Handler_read_next	0
+Handler_read_prev	0
+Handler_read_rnd	0
+Handler_read_rnd_next	6
+DROP TABLE t1,t2;

--- 1.25/mysql-test/t/group_min_max.test	2006-10-19 03:24:30 +03:00
+++ 1.26/mysql-test/t/group_min_max.test	2006-11-17 17:21:47 +02:00
@@ -810,3 +810,27 @@ explain SELECT MIN(c) FROM t2 WHERE b = 
 SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
 
 DROP TABLE t1,t2;
+
+#
+# Bug#24156: Loose index scan not used with CREATE TABLE ...SELECT and similar statements
+#
+
+CREATE TABLE t1 (a INT, b INT, INDEX (a,b));
+INSERT INTO t1 (a, b) VALUES (1,1), (1,2), (1,3), (1,4), (1,5),
+       (2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6);
+EXPLAIN SELECT max(b), a FROM t1 GROUP BY a;
+FLUSH STATUS;
+SELECT max(b), a FROM t1 GROUP BY a;
+SHOW STATUS LIKE 'handler_read%';
+FLUSH STATUS;
+CREATE TABLE t2 SELECT max(b), a FROM t1 GROUP BY a;
+SHOW STATUS LIKE 'handler_read%';
+FLUSH STATUS;
+SELECT * FROM (SELECT max(b), a FROM t1 GROUP BY a) b;
+SHOW STATUS LIKE 'handler_read%';
+FLUSH STATUS;
+(SELECT max(b), a FROM t1 GROUP BY a) UNION 
+ (SELECT max(b), a FROM t1 GROUP BY a);
+SHOW STATUS LIKE 'handler_read%';
+
+DROP TABLE t1,t2;
Thread
bk commit into 5.0 tree (gkodinov:1.2314) BUG#24156kgeorge17 Nov