summaryrefslogtreecommitdiff
path: root/mysql-test/t/join_outer.test
diff options
context:
space:
mode:
authorunknown <timour@askmonty.org>2011-08-09 10:28:57 +0300
committerunknown <timour@askmonty.org>2011-08-09 10:28:57 +0300
commita6037394e3a33e6a8294ee0c573d623982a4535a (patch)
tree48259af53f94eb0f5940db579639b8718728d80b /mysql-test/t/join_outer.test
parentb7e9713ee3313415ba4ac7322405fef89befdfda (diff)
downloadmariadb-git-a6037394e3a33e6a8294ee0c573d623982a4535a.tar.gz
Fix bug lp:817384
This bug is a special case of lp:813447. Analysis: Constant optimization finds that the condition t2.a = 1 can be used to access the primary key of table 't2'. As a result both outer table t1,t2 are considered as constant when we reach the execution phase. At the same time, during constant optimization, the IN predicate is not evaluated because it is expensive. When execution of the outer query reaches do_select(), control flow enter the branch: if (join->table_count == join->const_tables) { ... } This branch checks only the WHERE and HAVING clauses, but doesn't check the ON clauses of the query. Since the IN predicate was not evaluated during optimization, it is not evaluated at all, thus execution doesn't detect that the ON clause is FALSE. Solution: Similar to the patch for bug lp:813447, exclude system tables from constant substitution based on unique key lookups if there is an expensive ON condition on the inner table.
Diffstat (limited to 'mysql-test/t/join_outer.test')
-rw-r--r--mysql-test/t/join_outer.test27
1 files changed, 27 insertions, 0 deletions
diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test
index 71a983bd569..253808c4eb7 100644
--- a/mysql-test/t/join_outer.test
+++ b/mysql-test/t/join_outer.test
@@ -1127,3 +1127,30 @@ SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
DROP TABLE t1,t2,t3;
+--echo #
+--echo # LP bug #817384 Wrong result with outer join + subquery in ON
+--echo # clause +unique key
+--echo #
+
+CREATE TABLE t1 ( c int NOT NULL , b char(1) NOT NULL ) ;
+INSERT INTO t1 VALUES (1,'b');
+
+CREATE TABLE t2 ( a int NOT NULL , b char(1) NOT NULL , PRIMARY KEY (a)) ;
+INSERT INTO t2 VALUES (1,'a');
+
+create table t3 (c1 char(1), c2 char(2));
+insert into t3 values ('c','d');
+insert into t3 values ('c','d');
+
+
+EXPLAIN SELECT t2.b
+FROM t1 LEFT JOIN t2 ON t1.c = t2.a AND ( t2.b , t1.b ) IN (SELECT * from t3);
+SELECT t2.b
+FROM t1 LEFT JOIN t2 ON t1.c = t2.a AND ( t2.b , t1.b ) IN (SELECT * from t3);
+
+EXPLAIN SELECT t2.b
+FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
+SELECT t2.b
+FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
+
+DROP TABLE t1,t2,t3;