List:Internals« Previous MessageNext Message »
From:eugene Date:October 10 2005 2:54pm
Subject:bk commit into 5.0 tree (evgen:1.2032) BUG#13327
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen 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
  1.2032 05/10/10 18:53:57 evgen@stripped +3 -0
  Fix bug#13327 check_equality() wasn't checking view's fields
  
  check_equality() finds equalities among field items. It checks input items
  to be Item_fields thus skipping view's fields, which are represented by
  Item_direct_view_ref. Because of this index wasn't applied in all cases
  it can be.
  
  To fix this problem check_equality() now takes real item of
  Item_direct_view_ref, except outer view refs (with depended_from set).

  mysql-test/t/view.test
    1.115 05/10/10 18:51:04 evgen@stripped +20 -0
    Test case for bug#13327 VIEW performs index scan

  mysql-test/r/view.result
    1.123 05/10/10 18:50:36 evgen@stripped +22 -0
    Test case for bug#13327 VIEW performs index scan

  sql/sql_select.cc
    1.377 05/10/10 18:50:03 evgen@stripped +15 -0
    Fix bug #13327 VIEW performs index scan
     For proper views fields handling check_equality() now takes real item from Item_direct_view_ref, with exception of outer view refs.

# 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:	evgen
# Host:	moonbone.local
# Root:	/work/13327-bug-5.0-mysql

--- 1.376/sql/sql_select.cc	2005-09-30 01:34:15 +04:00
+++ 1.377/sql/sql_select.cc	2005-10-10 18:50:03 +04:00
@@ -6254,6 +6254,21 @@
   {
     Item *left_item= ((Item_func*) item)->arguments()[0];
     Item *right_item= ((Item_func*) item)->arguments()[1];
+
+    if (left_item->type() == Item::REF_ITEM &&
+        ((Item_ref*)left_item)->ref_type() == Item_ref::VIEW_REF)
+    {
+      if (((Item_ref*)left_item)->depended_from)
+        return FALSE;
+      left_item= left_item->real_item();
+    }
+    if (right_item->type() == Item::REF_ITEM &&
+        ((Item_ref*)right_item)->ref_type() == Item_ref::VIEW_REF)
+    {
+      if (((Item_ref*)right_item)->depended_from)
+        return FALSE;
+      right_item= right_item->real_item();
+    }
     if (left_item->type() == Item::FIELD_ITEM &&
         right_item->type() == Item::FIELD_ITEM &&
         !((Item_field*)left_item)->depended_from &&

--- 1.122/mysql-test/r/view.result	2005-10-01 10:35:10 +04:00
+++ 1.123/mysql-test/r/view.result	2005-10-10 18:50:36 +04:00
@@ -2298,3 +2298,25 @@
 3
 DROP VIEW v1;
 DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT, INDEX(a,b));
+CREATE TABLE t2 LIKE t1;
+CREATE TABLE t3 (a INT);
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
+INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
+INSERT INTO t3 VALUES (1),(2),(3);
+CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b;
+CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a;
+EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a	a	5	const	1	Using where; Using index
+1	SIMPLE	t2	ref	a	a	10	const,test.t1.b	2	Using where; Using index
+EXPLAIN SELECT * FROM v1 WHERE a=1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ref	a	a	5	const	1	Using where; Using index
+1	PRIMARY	t2	ref	a	a	10	const,test.t1.b	2	Using where; Using index
+EXPLAIN SELECT * FROM v2 WHERE a=1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ref	a	a	5	const	1	Using where; Using index
+1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	Using where
+DROP VIEW v1,v2;
+DROP TABLE t1,t2,t3;

--- 1.114/mysql-test/t/view.test	2005-10-01 10:35:10 +04:00
+++ 1.115/mysql-test/t/view.test	2005-10-10 18:51:04 +04:00
@@ -2167,3 +2167,23 @@
 
 DROP VIEW v1;
 DROP TABLE t1;
+
+#
+# Bug #13327 view wasn't using index for const condition
+#
+
+CREATE TABLE t1 (a INT, b INT, INDEX(a,b));
+CREATE TABLE t2 LIKE t1;
+CREATE TABLE t3 (a INT);
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
+INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
+INSERT INTO t3 VALUES (1),(2),(3);
+CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b;
+CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a;
+EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1;
+EXPLAIN SELECT * FROM v1 WHERE a=1;
+EXPLAIN SELECT * FROM v2 WHERE a=1;
+DROP VIEW v1,v2;
+DROP TABLE t1,t2,t3;
+
+
Thread
bk commit into 5.0 tree (evgen:1.2032) BUG#13327eugene10 Oct