revision-id: b6e958edc5fb147fcfeb4a3837d14daacfa2c93e (mariadb-10.7.4-105-gb6e958e) parent(s): cea50896d2ea0d18924d92d62a7ec1607d55e509 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-30 19:42:27 -0800 message: MDEV-28958 Crash when checking whether condition can be pushed into view Do not set any flags in the items for constant subformulas TRUE/FALSE when checking pushability of a formula into a view. Occurrences of these subformulas can be ignored when checking pushability of the formula. At the same time the items used for these constants became immutable starting from version 10.7. Approved by Oleksandr Byelkin <sanja@mariadb.com> --- mysql-test/main/derived_cond_pushdown.result | 17 +++++++++++++++++ mysql-test/main/derived_cond_pushdown.test | 21 +++++++++++++++++++++ sql/item.h | 23 ++++++++++++++++------- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 5b0cc4a..b1fefd2 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -18186,3 +18186,20 @@ id select_type table type possible_keys key key_len ref rows Extra drop view v1; drop table t1; # End of 10.4 tests +# +# MDEV-28958: condition pushable into view after simplification +# contains constant TRUE/FALSE as subformula +# +create table t1 (c1 int); +insert into t1 values (3), (7), (1), (3), (1), (3); +create table t2 (c2 int); +insert into t2 values (3), (5), (7), (3); +create view v1 as select * from t1 group by c1; +create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2; +select * from v2 group by a,b having a=b or b > a+10; +a b +3 3 +7 7 +drop view v1,v2; +drop table t1,t2; +# End of 10.7 tests diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 39e8221..8fdc54d 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -3895,3 +3895,24 @@ drop view v1; drop table t1; --echo # End of 10.4 tests + +--echo # +--echo # MDEV-28958: condition pushable into view after simplification +--echo # contains constant TRUE/FALSE as subformula +--echo # + +create table t1 (c1 int); +insert into t1 values (3), (7), (1), (3), (1), (3); + +create table t2 (c2 int); +insert into t2 values (3), (5), (7), (3); + +create view v1 as select * from t1 group by c1; +create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2; + +select * from v2 group by a,b having a=b or b > a+10; + +drop view v1,v2; +drop table t1,t2; + +--echo # End of 10.7 tests diff --git a/sql/item.h b/sql/item.h index d197ebb..59d395a 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2681,18 +2681,27 @@ class Item :public Value_source, void register_in(THD *thd); bool depends_only_on(table_map view_map) - { return marker & MARKER_FULL_EXTRACTION; } - int get_extraction_flag() const - { return marker & MARKER_EXTRACTION_MASK; } + { return get_extraction_flag() & MARKER_FULL_EXTRACTION; } + int get_extraction_flag() const + { + if (basic_const_item()) + return MARKER_FULL_EXTRACTION; + else + return marker & MARKER_EXTRACTION_MASK; + } void set_extraction_flag(int16 flags) { - marker &= ~MARKER_EXTRACTION_MASK; - marker|= flags; + if (!basic_const_item()) + { + marker= marker & ~MARKER_EXTRACTION_MASK; + marker|= flags; + } } void clear_extraction_flag() { - marker &= ~MARKER_EXTRACTION_MASK; - } + if (!basic_const_item()) + marker= marker & ~MARKER_EXTRACTION_MASK; + } void check_pushable_cond(Pushdown_checker excl_dep_func, uchar *arg); bool pushable_cond_checker_for_derived(uchar *arg) {