Commit c8141f53 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-7950 Item_func::type() takes 0.26% in OLTP RO

Step#2:

1. Removes the function build_equal_items_for_cond() and
   introduces a new method Item::build_equal_items() instead,
   with specific implementations in the following Items:

   Item  (the default implementation)
   Item_ident_or_func_or_sum
   Item_cond
   Item_cond_and

2. Adds a new abstract class Item_ident_or_func_or_sum,
   a common parent for Item_ident and Item_func_or_sum,
   as they have exactly the same build_equal_items().

3. Renames Item_cond_and::cond_equal to Item_cond_and::m_cond_equal,
   to avoid confusion between the member and local variables named
   "cond_equal".
parent 46816996
...@@ -734,7 +734,7 @@ Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg) ...@@ -734,7 +734,7 @@ Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg)
*/ */
Item_ident::Item_ident(THD *thd, Item_ident *item) Item_ident::Item_ident(THD *thd, Item_ident *item)
:Item_result_field(thd, item), :Item_ident_or_func_or_sum(thd, item),
orig_db_name(item->orig_db_name), orig_db_name(item->orig_db_name),
orig_table_name(item->orig_table_name), orig_table_name(item->orig_table_name),
orig_field_name(item->orig_field_name), orig_field_name(item->orig_field_name),
......
...@@ -1127,6 +1127,12 @@ class Item: public Type_std_attributes ...@@ -1127,6 +1127,12 @@ class Item: public Type_std_attributes
void print_item_w_name(String *, enum_query_type query_type); void print_item_w_name(String *, enum_query_type query_type);
void print_value(String *); void print_value(String *);
virtual void update_used_tables() {} virtual void update_used_tables() {}
virtual COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields)
{
update_used_tables();
return this;
}
virtual void split_sum_func(THD *thd, Item **ref_pointer_array, virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
List<Item> &fields) {} List<Item> &fields) {}
/* Called for items that really have to be split */ /* Called for items that really have to be split */
...@@ -2128,7 +2134,19 @@ class Item_result_field :public Item /* Item with result field */ ...@@ -2128,7 +2134,19 @@ class Item_result_field :public Item /* Item with result field */
}; };
class Item_ident :public Item_result_field class Item_ident_or_func_or_sum: public Item_result_field
{
public:
Item_ident_or_func_or_sum(): Item_result_field() { }
Item_ident_or_func_or_sum(THD *thd, Item_ident_or_func_or_sum *item)
:Item_result_field(thd, item)
{ }
COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields);
};
class Item_ident :public Item_ident_or_func_or_sum
{ {
protected: protected:
/* /*
...@@ -3441,25 +3459,20 @@ class Used_tables_and_const_cache ...@@ -3441,25 +3459,20 @@ class Used_tables_and_const_cache
An abstract class representing common features of An abstract class representing common features of
regular functions and aggregate functions. regular functions and aggregate functions.
*/ */
class Item_func_or_sum: public Item_result_field, public Item_args class Item_func_or_sum: public Item_ident_or_func_or_sum, public Item_args
{ {
public: public:
Item_func_or_sum() Item_func_or_sum() :Item_args() {}
:Item_result_field(), Item_args() {} Item_func_or_sum(Item *a) :Item_args(a) { }
Item_func_or_sum(Item *a) Item_func_or_sum(Item *a, Item *b) :Item_args(a, b) { }
:Item_result_field(), Item_args(a) { } Item_func_or_sum(Item *a, Item *b, Item *c) :Item_args(a, b, c) { }
Item_func_or_sum(Item *a, Item *b)
:Item_result_field(), Item_args(a, b) { }
Item_func_or_sum(Item *a, Item *b, Item *c)
:Item_result_field(), Item_args(a, b, c) { }
Item_func_or_sum(Item *a, Item *b, Item *c, Item *d) Item_func_or_sum(Item *a, Item *b, Item *c, Item *d)
:Item_result_field(), Item_args(a, b, c, d) { } :Item_args(a, b, c, d) { }
Item_func_or_sum(Item *a, Item *b, Item *c, Item *d, Item *e) Item_func_or_sum(Item *a, Item *b, Item *c, Item *d, Item *e)
:Item_result_field(), Item_args(a, b, c, d, e) { } :Item_args(a, b, c, d, e) { }
Item_func_or_sum(THD *thd, Item_func_or_sum *item) Item_func_or_sum(THD *thd, Item_func_or_sum *item)
:Item_result_field(thd, item), Item_args(thd, item) { } :Item_ident_or_func_or_sum(thd, item), Item_args(thd, item) { }
Item_func_or_sum(List<Item> &list) Item_func_or_sum(List<Item> &list) :Item_args(list) { }
:Item_result_field(), Item_args(list) { }
bool walk(Item_processor processor, bool walk_subquery, uchar *arg) bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
{ {
if (walk_args(processor, walk_subquery, arg)) if (walk_args(processor, walk_subquery, arg))
......
...@@ -1768,6 +1768,8 @@ class Item_cond :public Item_bool_func ...@@ -1768,6 +1768,8 @@ class Item_cond :public Item_bool_func
used_tables_and_const_cache_init(); used_tables_and_const_cache_init();
used_tables_and_const_cache_update_and_join(list); used_tables_and_const_cache_update_and_join(list);
} }
COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields);
virtual void print(String *str, enum_query_type query_type); virtual void print(String *str, enum_query_type query_type);
void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields); void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
friend int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, friend int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
...@@ -2078,9 +2080,9 @@ class Item_equal_fields_iterator_slow ...@@ -2078,9 +2080,9 @@ class Item_equal_fields_iterator_slow
class Item_cond_and :public Item_cond class Item_cond_and :public Item_cond
{ {
public: public:
COND_EQUAL cond_equal; /* contains list of Item_equal objects for COND_EQUAL m_cond_equal; /* contains list of Item_equal objects for
the current and level and reference the current and level and reference
to multiple equalities of upper and levels */ to multiple equalities of upper and levels */
Item_cond_and() :Item_cond() {} Item_cond_and() :Item_cond() {}
Item_cond_and(Item *i1,Item *i2) :Item_cond(i1,i2) {} Item_cond_and(Item *i1,Item *i2) :Item_cond(i1,i2) {}
Item_cond_and(THD *thd, Item_cond_and *item) :Item_cond(thd, item) {} Item_cond_and(THD *thd, Item_cond_and *item) :Item_cond(thd, item) {}
...@@ -2101,6 +2103,8 @@ class Item_cond_and :public Item_cond ...@@ -2101,6 +2103,8 @@ class Item_cond_and :public Item_cond
void mark_as_condition_AND_part(TABLE_LIST *embedding); void mark_as_condition_AND_part(TABLE_LIST *embedding);
virtual uint exists2in_reserved_items() { return list.elements; }; virtual uint exists2in_reserved_items() { return list.elements; };
bool walk_top_and(Item_processor processor, uchar *arg); bool walk_top_and(Item_processor processor, uchar *arg);
COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields);
}; };
inline bool is_cond_and(Item *item) inline bool is_cond_and(Item *item)
......
This diff is collapsed.
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