From 08ba474174c6d8eb8668488110e3949cb82c50d7 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 13 Sep 2016 11:58:35 -0700 Subject: [PATCH] Fixed bug mdev-10783. Do not push conditions into materialized views/derived tables marked with the flag 'fill_me'. --- mysql-test/r/derived_cond_pushdown.result | 9 +++++++++ mysql-test/t/derived_cond_pushdown.test | 10 +++++++++- sql/sql_derived.cc | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/derived_cond_pushdown.result b/mysql-test/r/derived_cond_pushdown.result index 3b7eb58c14d..9401a035d55 100644 --- a/mysql-test/r/derived_cond_pushdown.result +++ b/mysql-test/r/derived_cond_pushdown.result @@ -7007,3 +7007,12 @@ WHERE f = 1; f 1 DROP TABLE t1; +# +# MDEV-10783: pushdown into constant view +# +CREATE TABLE t1 (i int) ENGINE=MyISAM; +CREATE VIEW v AS SELECT 5; +SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v ); +i +DROP VIEW v; +DROP TABLE t1; diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test index 7a85c53b5c8..cfd73bd145b 100644 --- a/mysql-test/t/derived_cond_pushdown.test +++ b/mysql-test/t/derived_cond_pushdown.test @@ -898,5 +898,13 @@ SELECT * WHERE f = 1; DROP TABLE t1; +--echo # +--echo # MDEV-10783: pushdown into constant view +--echo # - \ No newline at end of file +CREATE TABLE t1 (i int) ENGINE=MyISAM; +CREATE VIEW v AS SELECT 5; +SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v ); +DROP VIEW v; +DROP TABLE t1; + \ No newline at end of file diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index b0d505b8b38..a7435117e69 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -1144,6 +1144,10 @@ bool pushdown_cond_for_derived(THD *thd, Item *cond, TABLE_LIST *derived) if (!any_select_allows_cond_pushdown) return false; + /* Do not push conditions into constant derived */ + if (derived->fill_me) + return false; + /* Do not push conditions into recursive with tables */ if (derived->is_recursive_with_table()) return false;