Skip to content

Commit

Permalink
Fixed bug mdev-11102.
Browse files Browse the repository at this point in the history
Do not push conditions from where into materialized inner tables
of outer joins: this is not valid.
  • Loading branch information
igorbabaev committed Nov 16, 2016
1 parent ded4cd1 commit 1655160
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
54 changes: 54 additions & 0 deletions mysql-test/r/derived_cond_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -7167,3 +7167,57 @@ EXPLAIN
}
DROP VIEW v2,v3;
DROP TABLE t1,t2,t3;
#
# MDEV-11102: condition pushdown into materialized inner table
# of outer join is not applied as not being valid
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1),(2);
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL;
a b
0 NULL
SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
a b
0 NULL
EXPLAIN FORMAT=JSON
SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 2,
"filtered": 100
},
"table": {
"table_name": "<derived2>",
"access_type": "ref",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "5",
"used_key_parts": ["b"],
"ref": ["test.t1.a"],
"rows": 2,
"filtered": 100,
"attached_condition": "(trigcond(isnull(v2.b)) and trigcond(trigcond((t1.a is not null))))",
"materialized": {
"query_block": {
"select_id": 2,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 2,
"filtered": 100
}
}
}
}
}
}
DROP VIEW v2;
DROP TABLE t1,t2;
23 changes: 23 additions & 0 deletions mysql-test/t/derived_cond_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,26 @@ SELECT * FROM t1 WHERE a IN (

DROP VIEW v2,v3;
DROP TABLE t1,t2,t3;

--echo #
--echo # MDEV-11102: condition pushdown into materialized inner table
--echo # of outer join is not applied as not being valid
--echo #

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(2);

CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1),(2);

CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;

SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL;

SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;

EXPLAIN FORMAT=JSON
SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;

DROP VIEW v2;
DROP TABLE t1,t2;
7 changes: 6 additions & 1 deletion sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,12 @@ JOIN::optimize_inner()
List_iterator_fast<TABLE_LIST> li(select_lex->leaf_tables);
while ((tbl= li++))
{
if (tbl->is_materialized_derived())
/*
Do not push conditions from where into materialized inner tables
of outer joins: this is not valid.
*/
if (tbl->is_materialized_derived() &&
!tbl->is_inner_table_of_outer_join())
{
if (pushdown_cond_for_derived(thd, conds, tbl))
DBUG_RETURN(1);
Expand Down

0 comments on commit 1655160

Please sign in to comment.