List:Commits« Previous MessageNext Message »
From:igor Date:January 19 2007 9:17am
Subject:bk commit into 5.0 tree (igor:1.2386) BUG#25219
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor 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-19 00:17:28-08:00, igor@stripped +4 -0
  Fixed bug #25219: crash for a query that contains an EXIST subquery with
  UNION over correlated and uncorrelated SELECTS.
  In such subqueries each uncorrelated SELECT should be considered as
  uncacheable. Otherwise join_free is called for it and in many cases
  it causes some problems.

  mysql-test/r/subselect.result@stripped, 2007-01-19 00:17:26-08:00, igor@stripped +33
-0
    Added a test case for bug #25219.

  mysql-test/t/subselect.test@stripped, 2007-01-19 00:17:26-08:00, igor@stripped +34 -0
    Added a test case for bug #25219.

  sql/mysql_priv.h@stripped, 2007-01-19 00:17:26-08:00, igor@stripped +4 -1
    Fixed bug #25219: crash for a query that contains an EXIST subquery with
    UNION over correlated and uncorrelated SELECTS.
    In such subqueries each uncorrelated SELECT should be considered as
    uncacheable. Otherwise join_free is called for it and in many cases
    it causes some problems. 
    Added a new flag UNCACHEABLE_UNITED for such SELECTs.

  sql/sql_lex.cc@stripped, 2007-01-19 00:17:26-08:00, igor@stripped +10 -2
    Fixed bug #25219: crash for a query that contains an EXIST subquery with
    UNION over correlated and uncorrelated SELECTS.
    In such subqueries each uncorrelated SELECT should be considered as
    uncacheable. Otherwise join_free is called for it and in many cases
    it causes some problems.
    Added a new flag UNCACHEABLE_UNITED for such SELECTs.

# 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:	igor
# Host:	olga.mysql.com
# Root:	/home/igor/dev-opt/mysql-5.0-opt-bug25219

--- 1.428/sql/mysql_priv.h	2007-01-19 00:17:34 -08:00
+++ 1.429/sql/mysql_priv.h	2007-01-19 00:17:34 -08:00
@@ -410,7 +410,10 @@
 #define UNCACHEABLE_EXPLAIN     8
 /* Don't evaluate subqueries in prepare even if they're not correlated */
 #define UNCACHEABLE_PREPARE    16
-/* Used to chack GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
+/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
+#define UNCACHEABLE_UNITED     32
+
+/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
 #define UNDEF_POS (-1)
 #ifdef EXTRA_DEBUG
 /*

--- 1.210/sql/sql_lex.cc	2007-01-19 00:17:34 -08:00
+++ 1.211/sql/sql_lex.cc	2007-01-19 00:17:34 -08:00
@@ -1371,9 +1371,17 @@
     if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
     {
       // Select is dependent of outer select
-      s->uncacheable|= UNCACHEABLE_DEPENDENT;
+      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
+                       UNCACHEABLE_DEPENDENT;
       SELECT_LEX_UNIT *munit= s->master_unit();
-      munit->uncacheable|= UNCACHEABLE_DEPENDENT;
+      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
+                       UNCACHEABLE_DEPENDENT;
+      for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
+      {
+        if (sl != s &&
+            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
+          sl->uncacheable|= UNCACHEABLE_UNITED;
+      }
     }
   is_correlated= TRUE;
   this->master_unit()->item->is_correlated= TRUE;

--- 1.167/mysql-test/r/subselect.result	2007-01-19 00:17:34 -08:00
+++ 1.168/mysql-test/r/subselect.result	2007-01-19 00:17:34 -08:00
@@ -3605,3 +3605,36 @@
 COUNT(*)
 3000
 DROP TABLE t1,t2;
+CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
+CREATE TABLE t2 (c int);
+INSERT INTO t1 VALUES ('aa', 1);
+INSERT INTO t2 VALUES (1);
+SELECT * FROM t1 
+WHERE EXISTS (SELECT c FROM t2 WHERE c=1
+UNION 
+SELECT c from t2 WHERE c=t1.c);
+id	c
+aa	1
+INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1);
+SELECT * FROM t1 
+WHERE EXISTS (SELECT c FROM t2 WHERE c=1
+UNION 
+SELECT c from t2 WHERE c=t1.c);
+id	c
+aa	1
+bb	2
+cc	3
+dd	1
+INSERT INTO t2 VALUES (2);
+CREATE TABLE t3 (c int);
+INSERT INTO t3 VALUES (1);
+SELECT * FROM t1 
+WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1
+UNION 
+SELECT c from t2 WHERE c=t1.c);
+id	c
+aa	1
+bb	2
+cc	3
+dd	1
+DROP TABLE t1,t2,t3;

--- 1.137/mysql-test/t/subselect.test	2007-01-19 00:17:34 -08:00
+++ 1.138/mysql-test/t/subselect.test	2007-01-19 00:17:34 -08:00
@@ -2508,3 +2508,37 @@
           FROM t1) t;
 
 DROP TABLE t1,t2;
+
+#
+# Bug #25219: EXIST subquery with UNION over a mix of
+#             correlated and uncorrelated selects
+#             
+
+CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
+CREATE TABLE t2 (c int);
+
+INSERT INTO t1 VALUES ('aa', 1);
+INSERT INTO t2 VALUES (1);
+
+SELECT * FROM t1 
+  WHERE EXISTS (SELECT c FROM t2 WHERE c=1
+                UNION 
+                SELECT c from t2 WHERE c=t1.c);
+
+INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1);
+
+SELECT * FROM t1 
+  WHERE EXISTS (SELECT c FROM t2 WHERE c=1
+                UNION 
+                SELECT c from t2 WHERE c=t1.c);
+
+INSERT INTO t2 VALUES (2);
+CREATE TABLE t3 (c int);
+INSERT INTO t3 VALUES (1);
+
+SELECT * FROM t1 
+  WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1
+                UNION 
+                SELECT c from t2 WHERE c=t1.c);
+
+DROP TABLE t1,t2,t3;
Thread
bk commit into 5.0 tree (igor:1.2386) BUG#25219igor19 Jan