List:Commits« Previous MessageNext Message »
From:kgeorge Date:January 11 2007 3:23pm
Subject:bk commit into 5.1 tree (gkodinov:1.2384) BUG#16590
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 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-01-11 16:23:18+02:00, gkodinov@stripped +3 -0
  BUG#16590: Optimized does not do right "const" table pre-read
   st_table::const_key_parts member is used in determining if
   certain key has a prefix that is compared to constant(s) in
   the query predicates.
   If there's such prefix the index can be used to get the data
   from the remaining suffix columns in sorted order.
   However if a field is compared to another field from a "const"
   table the const_key_parts is not amended.
   This makes the optimizer unable to detect that the key can be 
   used and add an extra filesort.
   Fixed by updating the const_key_parts after reading in the "const"
   table.

  mysql-test/r/order_by.result@stripped, 2007-01-11 16:23:09+02:00, gkodinov@stripped +9 -0
    BUG#16590: Optimized does not do right "const" table pre-read
     - test case

  mysql-test/t/order_by.test@stripped, 2007-01-11 16:23:10+02:00, gkodinov@stripped +13 -0
    BUG#16590: Optimized does not do right "const" table pre-read
     - test case

  sql/sql_select.cc@stripped, 2007-01-11 16:23:11+02:00, gkodinov@stripped +13 -0
    BUG#16590: Optimized does not do right "const" table pre-read
     - fill up the const_key_parts structure

# 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/B16590-5.1-opt

--- 1.477/sql/sql_select.cc	2007-01-08 12:31:02 +02:00
+++ 1.478/sql/sql_select.cc	2007-01-11 16:23:11 +02:00
@@ -7712,6 +7712,19 @@ static void update_const_equal_items(CON
         key_map possible_keys= field->key_start;
         possible_keys.intersect(field->table->keys_in_use_for_query);
         stat[0].const_keys.merge(possible_keys);
+
+        /* update const_key_parts for determining the order by keys */
+        if (!possible_keys.is_clear_all())
+        {
+          TABLE *tab= field->table;
+          KEYUSE *use;
+          for (use= tab->reginfo.join_tab->keyuse; use && use->table ==
tab; 
+               use++)
+            if (possible_keys.is_set(use->key) && 
+                tab->key_info[use->key].key_part[use->keypart].field ==
+                field)
+              tab->const_key_parts[use->key]|= use->keypart_map;
+        }
       }
     }
   }

--- 1.59/mysql-test/r/order_by.result	2006-11-19 20:19:48 +02:00
+++ 1.60/mysql-test/r/order_by.result	2007-01-11 16:23:09 +02:00
@@ -918,3 +918,12 @@ NULL
 2
 3
 DROP TABLE t1,t2,t3,t4;
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), UNIQUE KEY b (b));
+INSERT INTO t1 VALUES (1,1),(2,2);
+CREATE TABLE t2 (a INT, b INT, KEY a (a,b));
+INSERT INTO t2 VALUES (1,1),(1,2),(2,1),(2,2);
+EXPLAIN SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	const	PRIMARY,b	b	5	const	1	
+1	SIMPLE	t2	ref	a	a	5	const	2	Using where; Using index
+DROP TABLE t1,t2;

--- 1.42/mysql-test/t/order_by.test	2006-11-19 20:25:00 +02:00
+++ 1.43/mysql-test/t/order_by.test	2007-01-11 16:23:10 +02:00
@@ -625,3 +625,16 @@ SELECT t2.b FROM t1 LEFT JOIN (t2, t3 LE
 ON (t1.a=t2.a AND t1.b=t3.b) order by t2.b;
 
 DROP TABLE t1,t2,t3,t4;
+
+#
+# BUG#16590: Optimized does not do right "const" table pre-read
+#
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), UNIQUE KEY b (b));
+INSERT INTO t1 VALUES (1,1),(2,2);
+
+CREATE TABLE t2 (a INT, b INT, KEY a (a,b));
+INSERT INTO t2 VALUES (1,1),(1,2),(2,1),(2,2);
+
+EXPLAIN SELECT 1 FROM t1,t2 WHERE t1.b=2 AND t1.a=t2.a ORDER BY t2.b;
+
+DROP TABLE t1,t2;
Thread
bk commit into 5.1 tree (gkodinov:1.2384) BUG#16590kgeorge11 Jan