From 691214ae30dc9ccbb03337075f2c73cdf0ee6929 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 16 Nov 2016 22:16:20 -0800 Subject: [PATCH] Fixed bug mdev-11103. The class Item_func_nop_all missed an implementation of the virtual method get_copy. As a result if the condition that can be pushed into into a materialized view / derived table contained an ANY subselect then the pushdown condition was built incorrectly. --- mysql-test/r/derived_cond_pushdown.result | 41 +++++++++++++++++++++++ mysql-test/t/derived_cond_pushdown.test | 16 +++++++++ sql/item_cmpfunc.h | 2 ++ 3 files changed, 59 insertions(+) diff --git a/mysql-test/r/derived_cond_pushdown.result b/mysql-test/r/derived_cond_pushdown.result index c9fb33213fb..98430509618 100644 --- a/mysql-test/r/derived_cond_pushdown.result +++ b/mysql-test/r/derived_cond_pushdown.result @@ -7221,3 +7221,44 @@ EXPLAIN } DROP VIEW v2; DROP TABLE t1,t2; +# +# MDEV-11103: pushdown condition with ANY subquery +# +CREATE TABLE t1 (i INT); +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +EXPLAIN FORMAT=JSON +SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 ); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "((v1.i <= 3))", + "materialized": { + "query_block": { + "select_id": 3, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "((t1.i <= 3))" + } + } + } + } + } +} +Warnings: +Note 1249 Select 2 was reduced during optimization +SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 ); +i +1 +2 +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test index 0717c1e47e4..1e498661975 100644 --- a/mysql-test/t/derived_cond_pushdown.test +++ b/mysql-test/t/derived_cond_pushdown.test @@ -1011,3 +1011,19 @@ SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL; DROP VIEW v2; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-11103: pushdown condition with ANY subquery +--echo # + +CREATE TABLE t1 (i INT); +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); + +EXPLAIN FORMAT=JSON +SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 ); + +SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 ); + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 6d432bd97f3..b0120dd6c63 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -649,6 +649,8 @@ public: longlong val_int(); const char *func_name() const { return ""; } Item *neg_transformer(THD *thd); + Item *get_copy(THD *thd, MEM_ROOT *mem_root) + { return get_item_copy(thd, mem_root, this); } };