Commit f4d6f26a authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-11315.

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.
parent 779d416a
......@@ -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;
......@@ -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;
......@@ -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); }
......@@ -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; }
};
/*
......
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