Commit 087be9ba authored by unknown's avatar unknown

Fixed bug #19816.

This bug was introduced when the patch resolving the
performance problem 17164 was applied. As a result
of that modification the not_null_tables attributes
were calculated incorrectly for constant OR conditions.
This triggered invalid conversion of outer joins into
inner joins.


mysql-test/r/join_outer.result:
  Added a test case for bug #19816.
mysql-test/t/join_outer.test:
  Added a test case for bug #19816.
parent f1efd088
...@@ -1151,8 +1151,8 @@ EXPLAIN ...@@ -1151,8 +1151,8 @@ EXPLAIN
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
WHERE t1.name LIKE 'A%' OR FALSE; WHERE t1.name LIKE 'A%' OR FALSE;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY,name name 23 NULL 3 Using where; Using index 1 SIMPLE t2 index NULL fkey 5 NULL 5 Using index
1 SIMPLE t2 ref fkey fkey 5 test.t1.id 1 Using where; Using index 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.fkey 1 Using where
DROP TABLE t1,t2; DROP TABLE t1,t2;
DROP VIEW IF EXISTS v1,v2; DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2; DROP TABLE IF EXISTS t1,t2;
...@@ -1176,3 +1176,38 @@ a b ...@@ -1176,3 +1176,38 @@ a b
3 3 3 3
DROP VIEW v1,v2; DROP VIEW v1,v2;
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
INSERT INTO t1 VALUES (1), (2), (3), (4);
INSERT INTO t2 VALUES (2), (3);
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1);
a b
1 NULL
2 2
3 3
4 NULL
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1 OR 1);
a b
1 NULL
2 2
3 3
4 NULL
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (0 OR 1);
a b
1 NULL
2 2
3 3
4 NULL
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 2=2);
a b
1 NULL
2 2
3 3
4 NULL
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 1=0);
a b
1 NULL
2 2
3 3
4 NULL
DROP TABLE t1,t2;
...@@ -805,3 +805,21 @@ SELECT v1.a, v2. b ...@@ -805,3 +805,21 @@ SELECT v1.a, v2. b
DROP VIEW v1,v2; DROP VIEW v1,v2;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug 19816: LEFT OUTER JOIN with constant ORed predicates in WHERE clause
#
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
INSERT INTO t1 VALUES (1), (2), (3), (4);
INSERT INTO t2 VALUES (2), (3);
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1);
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1 OR 1);
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (0 OR 1);
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 2=2);
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 1=0);
DROP TABLE t1,t2;
...@@ -2570,7 +2570,9 @@ Item_cond::fix_fields(THD *thd, Item **ref) ...@@ -2570,7 +2570,9 @@ Item_cond::fix_fields(THD *thd, Item **ref)
(item= *li.ref())->check_cols(1)) (item= *li.ref())->check_cols(1))
return TRUE; /* purecov: inspected */ return TRUE; /* purecov: inspected */
used_tables_cache|= item->used_tables(); used_tables_cache|= item->used_tables();
if (!item->const_item()) if (item->const_item())
and_tables_cache= (table_map) 0;
else
{ {
tmp_table_map= item->not_null_tables(); tmp_table_map= item->not_null_tables();
not_null_tables_cache|= tmp_table_map; not_null_tables_cache|= tmp_table_map;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment