Commit 2f957915 authored by Michael Widenius's avatar Michael Widenius

Added item.real_type() for easy access to the underlaying types for Item_ref...

Added item.real_type() for easy access to the underlaying types for Item_ref and Item_cache_wrapper()
This allows us to simplify and speed up some tests and also remove get_cached_item()

sql/item.h:
  Added item.real_type()
  Removed get_cached_item()
sql/opt_range.cc:
  Simplify test
sql/sql_select.cc:
  Simplify test
sql/sql_show.cc:
  Simplify test
parent 139a2b64
......@@ -609,6 +609,12 @@ class Item {
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 @@ class Item {
bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs);
Item* set_expr_cache(THD *thd, List<Item*> &depends_on);
virtual Item *get_cached_item() { return NULL; }
};
......@@ -2437,6 +2442,8 @@ class Item_ref :public Item_ident
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 @@ class Item_cache_wrapper :public Item_result_field
const char *func_name() const { return "<expr_cache>"; }
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<Item*> &depends_on);
......
......@@ -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);
/*
......
......@@ -12055,9 +12055,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &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)
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment