Commit 0cb85479 authored by unknown's avatar unknown

join.result, select.result:

  Fixed bug #4976.
join_nested.result, join_nested.test:
  Added a test case for bug #4976.
sql_select.cc:
  Applied conversion from an outer join to an inner join 
  when the on expression does not depend on the outer table.
  It fixed bug #4976.


sql/sql_select.cc:
  Applied conversion from an outer join to an inner join 
  when the on expression does not depend on the outer table.
  It fixed bug #4976.
mysql-test/t/join_nested.test:
  Added a case test for bug #4976.
mysql-test/r/join_nested.result:
  Added a case test for bug #4976.
mysql-test/r/select.result:
  Fixed bug #4976.
mysql-test/r/join.result:
  Fixed bug #4976.
parent c63100de
...@@ -59,11 +59,9 @@ id count(t2.id) ...@@ -59,11 +59,9 @@ id count(t2.id)
107 1 107 1
select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null; select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
id id id id
NULL 75
explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null; explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
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 const PRIMARY NULL NULL NULL 1 Impossible ON condition 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where
explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0; explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0;
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 NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
......
...@@ -1208,3 +1208,22 @@ SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a; ...@@ -1208,3 +1208,22 @@ SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a;
a a a a a a
1 NULL NULL 1 NULL NULL
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
CREATE TABLE t1(a int, key (a));
CREATE TABLE t2(b int, key (b));
CREATE TABLE t3(c int, key (c));
INSERT INTO t1 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
INSERT INTO t2 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
INSERT INTO t3 VALUES (0), (1), (2), (3), (4), (5);
EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON c < 3 and b = c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 index c c 5 NULL 6 Using where; Using index
1 SIMPLE t2 ref b b 5 test.t3.c 2 Using where; Using index
1 SIMPLE t1 index NULL a 5 NULL 21 Using index
EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range b b 5 NULL 3 Using where; Using index
1 SIMPLE t3 ref c c 5 test.t2.b 2 Using where; Using index
1 SIMPLE t1 index NULL a 5 NULL 21 Using index
DROP TABLE t1,t2,t3;
...@@ -2181,10 +2181,10 @@ a a a ...@@ -2181,10 +2181,10 @@ a a a
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1; select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
a a a a a a
1 1 2 1 1 2
1 1 3
2 2 2 2 2 2
2 2 3
3 3 2 3 3 2
1 1 3
2 2 3
3 3 3 3 3 3
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1; select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a a a a
......
...@@ -727,3 +727,23 @@ DELETE FROM t2; ...@@ -727,3 +727,23 @@ DELETE FROM t2;
SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a; SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#on expression for a nested outer join does not depend on the outer table
#bug #4976
CREATE TABLE t1(a int, key (a));
CREATE TABLE t2(b int, key (b));
CREATE TABLE t3(c int, key (c));
INSERT INTO t1 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
INSERT INTO t2 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
INSERT INTO t3 VALUES (0), (1), (2), (3), (4), (5);
EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON c < 3 and b = c;
EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
DROP TABLE t1,t2,t3;
...@@ -6078,7 +6078,9 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top) ...@@ -6078,7 +6078,9 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
table->embedding->nested_join->not_null_tables|= not_null_tables; table->embedding->nested_join->not_null_tables|= not_null_tables;
} }
if (!table->outer_join || (used_tables & not_null_tables)) if (!table->outer_join || (used_tables & not_null_tables) ||
(table->outer_join &&
!(table->on_expr->used_tables() & ~used_tables)))
{ {
/* /*
For some of the inner tables there are conjunctive predicates For some of the inner tables there are conjunctive predicates
......
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