Skip to content

Commit

Permalink
Fixed bug mdev-11315.
Browse files Browse the repository at this point in the history
There were no implementations for the virtual functions
exclusive_dependence_on_table_processor and
exclusive_dependence_on_table_processor. As a result
the procedure pushdown_cond_for_derived erroneously
detected some conditions with outer references as pushable
into materialized view / derived table.
  • Loading branch information
igorbabaev committed Nov 23, 2016
1 parent 779d416 commit f4d6f26
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 2 deletions.
114 changes: 114 additions & 0 deletions mysql-test/r/derived_cond_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -7262,3 +7262,117 @@ i
2
DROP VIEW v1;
DROP TABLE t1;
#
# MDEV-11315: condition with outer reference to mergeable derived
#
CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10,7,1),(11,0,2);
CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM;
INSERT INTO t2 VALUES
(1,4,'2008-09-27 00:34:58'),
(2,5,'2007-05-28 00:00:00'),
(3,6,'2009-07-25 09:21:20');
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
SELECT * FROM v1 AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
pk1 a b
10 7 1
11 0 2
EXPLAIN FORMAT=JSON
SELECT * FROM v1 AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 2,
"filtered": 100,
"attached_condition": "(<in_optimizer>(t1.b,<exists>(subquery#2)) or (t1.b = 100))"
},
"subqueries": [
{
"query_block": {
"select_id": 2,
"table": {
"table_name": "<derived4>",
"access_type": "index_subquery",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "4",
"used_key_parts": ["pk2"],
"ref": ["func"],
"rows": 2,
"filtered": 100,
"materialized": {
"query_block": {
"select_id": 4,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
}
]
}
}
SELECT * FROM ( SELECT * FROM t1 ) AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
pk1 a b
10 7 1
11 0 2
EXPLAIN FORMAT=JSON
SELECT * FROM ( SELECT * FROM t1 ) AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 2,
"filtered": 100,
"attached_condition": "(<in_optimizer>(t1.b,<exists>(subquery#3)) or (t1.b = 100))"
},
"subqueries": [
{
"query_block": {
"select_id": 3,
"table": {
"table_name": "<derived4>",
"access_type": "index_subquery",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "4",
"used_key_parts": ["pk2"],
"ref": ["func"],
"rows": 2,
"filtered": 100,
"materialized": {
"query_block": {
"select_id": 4,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
}
]
}
}
DROP VIEW v1,v2;
DROP TABLE t1,t2;
31 changes: 31 additions & 0 deletions mysql-test/t/derived_cond_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,34 @@ SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );

DROP VIEW v1;
DROP TABLE t1;

--echo #
--echo # MDEV-11315: condition with outer reference to mergeable derived
--echo #

CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10,7,1),(11,0,2);

CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM;
INSERT INTO t2 VALUES
(1,4,'2008-09-27 00:34:58'),
(2,5,'2007-05-28 00:00:00'),
(3,6,'2009-07-25 09:21:20');

CREATE VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;

SELECT * FROM v1 AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
EXPLAIN FORMAT=JSON
SELECT * FROM v1 AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;

SELECT * FROM ( SELECT * FROM t1 ) AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
EXPLAIN FORMAT=JSON
SELECT * FROM ( SELECT * FROM t1 ) AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;

DROP VIEW v1,v2;
DROP TABLE t1,t2;
8 changes: 6 additions & 2 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ class Item_field :public Item_ident
bool exclusive_dependence_on_table_processor(void *map);
bool exclusive_dependence_on_grouping_fields_processor(void *arg);
bool cleanup_excluding_outer_fields_processor(void *arg)
{ return depended_from ? 0 :cleanup_processor(arg); }
{ return depended_from ? 0 : cleanup_processor(arg); }

Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_field>(thd, mem_root, this); }
Expand Down Expand Up @@ -4278,7 +4278,11 @@ class Item_ref :public Item_ident
}
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_ref>(thd, mem_root, this); }
};
bool exclusive_dependence_on_table_processor(void *map)
{ return depended_from != NULL; }
bool exclusive_dependence_on_grouping_fields_processor(void *arg)
{ return depended_from != NULL; }
};


/*
Expand Down

0 comments on commit f4d6f26

Please sign in to comment.