diff --git a/sql/item.h b/sql/item.h index c16e1d89001..5c84d9f9598 100644 --- a/sql/item.h +++ b/sql/item.h @@ -609,6 +609,12 @@ public: virtual enum_field_types string_field_type() const; virtual enum_field_types field_type() const; virtual enum Type type() const =0; + /* + real_type() is the type of base item. This is same as type() for + most items, except Item_ref() and Item_cache_wrapper() where it + shows the type for the underlaying item. + */ + virtual enum Type real_type() const { return type(); } /* Return information about function monotonicity. See comment for @@ -1185,7 +1191,6 @@ public: bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs); Item* set_expr_cache(THD *thd, List &depends_on); - virtual Item *get_cached_item() { return NULL; } }; @@ -2437,6 +2442,8 @@ public: Item_ref(THD *thd, Item_ref *item) :Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {} enum Type type() const { return REF_ITEM; } + enum Type real_type() const { return ref ? (*ref)->type() : + REF_ITEM; } bool eq(const Item *item, bool binary_cmp) const { Item *it= ((Item *) item)->real_item(); @@ -2628,7 +2635,7 @@ public: const char *func_name() const { return ""; } enum Type type() const { return EXPR_CACHE_ITEM; } - virtual Item *get_cached_item() { return orig_item; } + enum Type real_type() const { return orig_item->type(); } bool set_cache(THD *thd, List &depends_on); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 24720e48861..91ac52f6246 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -11707,9 +11707,7 @@ check_group_min_max_predicates(COND *cond, Item_field *min_max_arg_item, the MIN/MAX argument field, and disallow the optimization only if this is so. */ - if (cond_type == Item::SUBSELECT_ITEM || - (cond->get_cached_item() && - cond->get_cached_item()->type() == Item::SUBSELECT_ITEM)) + if (cond->real_type() == Item::SUBSELECT_ITEM) DBUG_RETURN(FALSE); /* diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bc31fd62dfd..0fb062e37a3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12055,9 +12055,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, { if (item->used_tables() & OUTER_REF_TABLE_BIT) item->update_used_tables(); - if (type == Item::SUBSELECT_ITEM || - (item->get_cached_item() && - item->get_cached_item()->type() == Item::SUBSELECT_ITEM ) || + if ((item->real_type() == Item::SUBSELECT_ITEM) || (item->used_tables() & ~OUTER_REF_TABLE_BIT)) { /* @@ -17989,9 +17987,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, } } else if ((real_pos->type() == Item::FUNC_ITEM || - real_pos->type() == Item::SUBSELECT_ITEM || - (real_pos->get_cached_item() && - real_pos->get_cached_item()->type() == Item::SUBSELECT_ITEM) || + real_pos->real_type() == Item::SUBSELECT_ITEM || real_pos->type() == Item::CACHE_ITEM || real_pos->type() == Item::COND_ITEM) && !real_pos->with_sum_func) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 15db2d05dc2..833b695e4bf 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3003,10 +3003,7 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table) else if (item->type() == Item::REF_ITEM) return uses_only_table_name_fields(item->real_item(), table); - if ((item->type() == Item::SUBSELECT_ITEM || - (item->get_cached_item() && - item->get_cached_item()->type() == Item::SUBSELECT_ITEM)) - && !item->const_item()) + if (item->real_type() == Item::SUBSELECT_ITEM && !item->const_item()) return 0; return 1;