diff --git a/sql/item.cc b/sql/item.cc index 0de712f2944..f74ad94609a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7533,13 +7533,14 @@ Item *Item_field::update_value_transformer(THD *thd, uchar *select_arg) void Item::check_pushable_cond(Pushdown_checker checker, uchar *arg) { - clear_extraction_flag(); if (type() == Item::COND_ITEM) { bool and_cond= ((Item_cond*) this)->functype() == Item_func::COND_AND_FUNC; List_iterator li(*((Item_cond*) this)->argument_list()); uint count= 0; Item *item; + + clear_extraction_flag(); while ((item=li++)) { item->check_pushable_cond(checker, arg); @@ -7557,8 +7558,8 @@ void Item::check_pushable_cond(Pushdown_checker checker, uchar *arg) item->clear_extraction_flag(); } } - else if (!((this->*checker) (arg))) - set_extraction_flag(MARKER_NO_EXTRACTION); + else if (!basic_const_item()) + set_extraction_flag(!((this->*checker) (arg)) ? MARKER_NO_EXTRACTION : 0); } @@ -10925,11 +10926,9 @@ bool Item::cleanup_excluding_immutables_processor (void *arg) { if (!(get_extraction_flag() == MARKER_IMMUTABLE)) return cleanup_processor(arg); - else - { + if (!basic_const_item()) clear_extraction_flag(); - return false; - } + return false; } diff --git a/sql/item.h b/sql/item.h index ee8a1460f15..75aeb8fa1c8 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2673,7 +2673,7 @@ class Item :public Value_source, marker &= ~MARKER_EXTRACTION_MASK; marker|= flags; } - void clear_extraction_flag() + virtual void clear_extraction_flag() { marker &= ~MARKER_EXTRACTION_MASK; } @@ -4438,12 +4438,18 @@ class Item_bool_static :public Item_bool { public: Item_bool_static(const char *str_arg, longlong i): - Item_bool(str_arg, i) {}; + Item_bool(str_arg, i) + { + set_extraction_flag(MARKER_NO_EXTRACTION); + }; /* Don't mark static items as top level item */ virtual void top_level_item() override {} void set_join_tab_idx(uint8 join_tab_idx_arg) override { DBUG_ASSERT(0); } + virtual void clear_extraction_flag() override + { + } void cleanup() override {} }; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 9c0b12c6f8b..4b9efe4090f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -8807,7 +8807,7 @@ bool st_select_lex::collect_grouping_fields(THD *thd) /** @brief - For a condition check possibility of exraction a formula over grouping fields + For a condition check possibility of extraction a formula over grouping fields @param thd The thread handle @param cond The condition whose subformulas are to be analyzed @@ -8836,7 +8836,6 @@ st_select_lex::check_cond_extraction_for_grouping_fields(THD *thd, Item *cond) { if (cond->get_extraction_flag() == MARKER_NO_EXTRACTION) return; - cond->clear_extraction_flag(); if (cond->type() == Item::COND_ITEM) { Item_cond_and *and_cond= @@ -8848,6 +8847,8 @@ st_select_lex::check_cond_extraction_for_grouping_fields(THD *thd, Item *cond) uint count= 0; // to count items not containing MARKER_NO_EXTRACTION uint count_full= 0; // to count items with MARKER_FULL_EXTRACTION Item *item; + + cond->clear_extraction_flag(); while ((item=li++)) { check_cond_extraction_for_grouping_fields(thd, item); @@ -11046,7 +11047,8 @@ Item *remove_pushed_top_conjuncts_for_having(THD *thd, Item *cond) /* Nothing to extract */ if (cond->get_extraction_flag() == MARKER_NO_EXTRACTION) { - cond->clear_extraction_flag(); + if (!cond->basic_const_item()) + cond->clear_extraction_flag(); return cond; } /* cond can be pushed in WHERE entirely */