join_outer.result, join_outer.test:
Added a test case for bug #5896. sql_select.cc: Fixed the problem of ignoring on expressions depending only on outer table when outer table either contains 1 row or is guaranteed to return only 1 row (bug #5896). sql/sql_select.cc: Fixed the problem of ignoring on expressions depending only on outer tables when outer tables either contained 1 row or is guaranteed to return not more than 1 row. (bug #5896). mysql-test/t/join_outer.test: Added a test case for bug #5896. mysql-test/r/join_outer.result: Added a test case for bug #5896.
This commit is contained in:
parent
2f9c7c0b09
commit
dc25de58e5
@ -1,4 +1,4 @@
|
||||
drop table if exists t1,t2,t3,t4,t5;
|
||||
drop table if exists t0,t1,t2,t3,t4,t5;
|
||||
CREATE TABLE t1 (
|
||||
grp int(11) default NULL,
|
||||
a bigint(20) unsigned default NULL,
|
||||
@ -745,3 +745,47 @@ player_id match_1_h * match_id home UUX
|
||||
7 4 * 1 2 2
|
||||
3 3 * 1 2 1
|
||||
drop table t1, t2;
|
||||
CREATE TABLE t0 (a0 int PRIMARY KEY);
|
||||
CREATE TABLE t1 (a1 int PRIMARY KEY);
|
||||
CREATE TABLE t2 (a2 int);
|
||||
CREATE TABLE t3 (a3 int);
|
||||
INSERT INTO t0 VALUES (1);
|
||||
INSERT INTO t1 VALUES (1);
|
||||
INSERT INTO t2 VALUES (1), (2);
|
||||
INSERT INTO t3 VALUES (1), (2);
|
||||
SELECT * FROM t1 LEFT JOIN t2 ON a1=0;
|
||||
a1 a2
|
||||
1 NULL
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON a1=0;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 system NULL NULL NULL NULL 1
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
||||
SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0;
|
||||
a1 a2 a3
|
||||
1 NULL NULL
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 system NULL NULL NULL NULL 1
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2
|
||||
SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1;
|
||||
a0 a1 a2 a3
|
||||
1 1 NULL NULL
|
||||
EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t0 system PRIMARY NULL NULL NULL 1
|
||||
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2
|
||||
INSERT INTO t0 VALUES (0);
|
||||
INSERT INTO t1 VALUES (0);
|
||||
SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1;
|
||||
a0 a1 a2 a3
|
||||
1 1 NULL NULL
|
||||
EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t0 const PRIMARY PRIMARY 4 const 1 Using index
|
||||
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2
|
||||
DROP TABLE t0,t1,t2,t3;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2,t3,t4,t5;
|
||||
drop table if exists t0,t1,t2,t3,t4,t5;
|
||||
--enable_warnings
|
||||
|
||||
CREATE TABLE t1 (
|
||||
@ -501,3 +501,28 @@ select s.*, '*', m.*, (s.match_1_h - m.home) UUX from
|
||||
order by UUX desc;
|
||||
|
||||
drop table t1, t2;
|
||||
|
||||
# Test for bug #5896
|
||||
|
||||
CREATE TABLE t0 (a0 int PRIMARY KEY);
|
||||
CREATE TABLE t1 (a1 int PRIMARY KEY);
|
||||
CREATE TABLE t2 (a2 int);
|
||||
CREATE TABLE t3 (a3 int);
|
||||
INSERT INTO t0 VALUES (1);
|
||||
INSERT INTO t1 VALUES (1);
|
||||
INSERT INTO t2 VALUES (1), (2);
|
||||
INSERT INTO t3 VALUES (1), (2);
|
||||
|
||||
SELECT * FROM t1 LEFT JOIN t2 ON a1=0;
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON a1=0;
|
||||
SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0;
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0;
|
||||
SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1;
|
||||
EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1;
|
||||
|
||||
INSERT INTO t0 VALUES (0);
|
||||
INSERT INTO t1 VALUES (0);
|
||||
SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1;
|
||||
EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1;
|
||||
|
||||
DROP TABLE t0,t1,t2,t3;
|
||||
|
@ -4895,6 +4895,28 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
|
||||
COND *const_cond=
|
||||
make_cond_for_table(cond,join->const_table_map,(table_map) 0);
|
||||
DBUG_EXECUTE("where",print_where(const_cond,"constants"););
|
||||
for (JOIN_TAB *tab= join->join_tab+join->const_tables;
|
||||
tab < join->join_tab+join->tables ; tab++)
|
||||
{
|
||||
if (tab->on_expr)
|
||||
{
|
||||
JOIN_TAB *cond_tab= tab->first_inner;
|
||||
COND *tmp= make_cond_for_table(tab->on_expr,
|
||||
join->const_table_map,
|
||||
(table_map) 0);
|
||||
if (!tmp)
|
||||
continue;
|
||||
tmp= new Item_func_trig_cond(tmp, &cond_tab->not_null_compl);
|
||||
if (!tmp)
|
||||
DBUG_RETURN(1);
|
||||
tmp->quick_fix_field();
|
||||
cond_tab->select_cond= !cond_tab->select_cond ? tmp :
|
||||
new Item_cond_and(cond_tab->select_cond,tmp);
|
||||
if (!cond_tab->select_cond)
|
||||
DBUG_RETURN(1);
|
||||
cond_tab->select_cond->quick_fix_field();
|
||||
}
|
||||
}
|
||||
if (const_cond && !const_cond->val_int())
|
||||
{
|
||||
DBUG_PRINT("info",("Found impossible WHERE condition"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user