revision-id: a21374c84531ded0e947d7c8f1df7473a8bd7d86 (mariadb-10.2.23-75-ga21374c8453) parent(s): 1f1a61cfc41a01ffa65d568eebdc037a54b5c463 author: Galina Shalygina committer: Galina Shalygina timestamp: 2019-04-24 12:47:40 +0300 message: MDEV-19139: pushdown condition with Item_func_set_user_var The bug occurs because Item_func_set_user var is allowed to be pushed into materialized derived table/view. To fix it excl_dep_on_table() as added to Item_func_set_user_var class to prevent pushdown. --- mysql-test/r/derived_cond_pushdown.result | 49 +++++++++++++++++++++++++++++++ mysql-test/t/derived_cond_pushdown.test | 14 +++++++++ sql/item_func.h | 1 + 3 files changed, 64 insertions(+) diff --git a/mysql-test/r/derived_cond_pushdown.result b/mysql-test/r/derived_cond_pushdown.result index 00acdf241a6..d040aaf609d 100644 --- a/mysql-test/r/derived_cond_pushdown.result +++ b/mysql-test/r/derived_cond_pushdown.result @@ -10501,4 +10501,53 @@ a b max_d c 1 2 3 1 5 6 1 5 DROP TABLE t1,t2; +# +# MDEV-19139: pushdown condition with Item_func_set_user_var +# +CREATE TABLE t1 (a INT, b INT); +CREATE VIEW v1 AS SELECT a, MAX(b) FROM t1 GROUP BY a; +SELECT * FROM (SELECT 1 FROM v1 UNION (SELECT 1 FROM v1 WHERE @a := uuid())) dt; +1 +EXPLAIN FORMAT=JSON +SELECT * FROM (SELECT 1 FROM v1 UNION (SELECT 1 FROM v1 WHERE @a := uuid())) dt; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "<derived2>", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "materialized": { + "query_block": { + "union_result": { + "table_name": "<union2,3>", + "access_type": "ALL", + "query_specifications": [ + { + "query_block": { + "select_id": 2, + "table": { + "message": "no matching row in const table" + } + } + }, + { + "query_block": { + "select_id": 3, + "table": { + "message": "no matching row in const table" + } + } + } + ] + } + } + } + } + } +} +DROP TABLE t1; +DROP VIEW v1; # End of 10.2 tests diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test index 313d77d2332..8592b887966 100644 --- a/mysql-test/t/derived_cond_pushdown.test +++ b/mysql-test/t/derived_cond_pushdown.test @@ -2124,4 +2124,18 @@ WHERE t1.a=tab.c AND DROP TABLE t1,t2; +--echo # +--echo # MDEV-19139: pushdown condition with Item_func_set_user_var +--echo # + +CREATE TABLE t1 (a INT, b INT); +CREATE VIEW v1 AS SELECT a, MAX(b) FROM t1 GROUP BY a; + +SELECT * FROM (SELECT 1 FROM v1 UNION (SELECT 1 FROM v1 WHERE @a := uuid())) dt; +EXPLAIN FORMAT=JSON +SELECT * FROM (SELECT 1 FROM v1 UNION (SELECT 1 FROM v1 WHERE @a := uuid())) dt; + +DROP TABLE t1; +DROP VIEW v1; + --echo # End of 10.2 tests diff --git a/sql/item_func.h b/sql/item_func.h index 41eb019bd6b..1664f585d81 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1989,6 +1989,7 @@ class Item_func_set_user_var :public Item_func_user_var void cleanup(); Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return get_item_copy<Item_func_set_user_var>(thd, mem_root, this); } + bool excl_dep_on_table(table_map tab_map) { return false; } };