Commit c86ffc23 authored by Sergey Petrunya's avatar Sergey Petrunya

BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90

- Correct handling of outer joins + DuplicateWeedout (docs pending)
parent ef2b4b14
......@@ -1685,4 +1685,34 @@ f10 f10 f11 f10
0 0 a 0
0 0 a 0
drop table t1,t2,t3,t4;
#
# BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
#
set @tmp803457=@@optimizer_switch;
set optimizer_switch='materialization=off';
CREATE TABLE t1 (f1 int, f2 int );
INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL);
CREATE TABLE t2 (f2 int, f3 int );
INSERT INTO t2 VALUES (NULL,NULL),(0,0);
CREATE TABLE t3 ( f1 int, f3 int );
INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0);
CREATE TABLE t4 ( f2 int);
INSERT INTO t4 VALUES (0),(NULL);
# The following uses Duplicate Weedout, and "End temporary" must not be
# in the middle of the inner side of an outer join:
explain
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Start temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where
1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join)
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3 ) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
f1 f2 f3 f3
2 0 0 0
4 0 0 0
4 0 0 0
0 NULL NULL NULL
DROP TABLE t1, t2, t3, t4;
set @tmp803457=@@optimizer_switch;
set optimizer_switch=@subselect_sj_tmp;
......@@ -1696,6 +1696,36 @@ f10 f10 f11 f10
0 0 a 0
0 0 a 0
drop table t1,t2,t3,t4;
#
# BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
#
set @tmp803457=@@optimizer_switch;
set optimizer_switch='materialization=off';
CREATE TABLE t1 (f1 int, f2 int );
INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL);
CREATE TABLE t2 (f2 int, f3 int );
INSERT INTO t2 VALUES (NULL,NULL),(0,0);
CREATE TABLE t3 ( f1 int, f3 int );
INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0);
CREATE TABLE t4 ( f2 int);
INSERT INTO t4 VALUES (0),(NULL);
# The following uses Duplicate Weedout, and "End temporary" must not be
# in the middle of the inner side of an outer join:
explain
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Start temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (incremental, BNL join)
1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3 ) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
f1 f2 f3 f3
2 0 0 0
4 0 0 0
4 0 0 0
0 NULL NULL NULL
DROP TABLE t1, t2, t3, t4;
set @tmp803457=@@optimizer_switch;
set optimizer_switch=@subselect_sj_tmp;
#
# BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
......
......@@ -1529,5 +1529,31 @@ WHERE t2.f10 IN (
drop table t1,t2,t3,t4;
--echo #
--echo # BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
--echo #
set @tmp803457=@@optimizer_switch;
set optimizer_switch='materialization=off';
CREATE TABLE t1 (f1 int, f2 int );
INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL);
CREATE TABLE t2 (f2 int, f3 int );
INSERT INTO t2 VALUES (NULL,NULL),(0,0);
CREATE TABLE t3 ( f1 int, f3 int );
INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0);
CREATE TABLE t4 ( f2 int);
INSERT INTO t4 VALUES (0),(NULL);
--echo # The following uses Duplicate Weedout, and "End temporary" must not be
--echo # in the middle of the inner side of an outer join:
explain
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3 ) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
DROP TABLE t1, t2, t3, t4;
set @tmp803457=@@optimizer_switch;
# The following command must be the last one the file
set optimizer_switch=@subselect_sj_tmp;
......@@ -2477,6 +2477,15 @@ void advance_sj_state(JOIN *join, table_map remaining_tables,
nest->nested_join->sj_depends_on |
nest->nested_join->sj_corr_tables;
}
if (pos->dupsweedout_tables)
{
/* we're in the process of constructing a DuplicateWeedout range */
TABLE_LIST *emb= new_join_tab->table->pos_in_table_list->embedding;
/* and we've entered an inner side of an outer join*/
if (emb && emb->on_expr)
pos->dupsweedout_tables |= emb->nested_join->used_tables;
}
if (pos->dupsweedout_tables &&
!(remaining_tables &
......
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