Commit 462bca36 authored by Alexander Barkov's avatar Alexander Barkov

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

Step 2c:

After discussion with Igor, it appeared that Item_field and Item_ref
could not appear in this context in the old function build_equal_item_for_cond:

  else if (cond->type() == Item::FUNC_ITEM ||
           cond->real_item()->type() == Item::FIELD_ITEM)

The part of the condition checking for Item_field::FIELD_ITEM was a dead code.
- Moving implementation of Item_ident_or_func_or_sum::build_equal_items()
to Item_func::build_equal_items()
- Restoring deriving of Item_ident and Item_sum_or_func from Item_result_field.
  Removing Item_ident_or_func_or_sum.
parent 53382ac1
...@@ -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_ident_or_func_or_sum(thd, item), :Item_result_field(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),
......
...@@ -2134,19 +2134,7 @@ public: ...@@ -2134,19 +2134,7 @@ public:
}; };
class Item_ident_or_func_or_sum: public Item_result_field class Item_ident :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:
/* /*
...@@ -2336,6 +2324,25 @@ public: ...@@ -2336,6 +2324,25 @@ public:
{ {
update_table_bitmaps(); update_table_bitmaps();
} }
COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields)
{
/*
normilize_cond() replaced all conditions of type
WHERE/HAVING field
to:
WHERE/HAVING field<>0
By the time of a build_equal_items() call, all such conditions should
already be replaced. No Item_field are possible.
Note, some Item_field derivants are still possible.
Item_insert_value:
SELECT * FROM t1 WHERE VALUES(a);
Item_default_value:
SELECT * FROM t1 WHERE DEFAULT(a);
*/
DBUG_ASSERT(type() != FIELD_ITEM);
return Item_ident::build_equal_items(thd, inherited, link_item_fields);
}
bool is_result_field() { return false; } bool is_result_field() { return false; }
void set_result_field(Field *field) {} void set_result_field(Field *field) {}
void save_in_result_field(bool no_conversions) { } void save_in_result_field(bool no_conversions) { }
...@@ -3459,7 +3466,7 @@ public: ...@@ -3459,7 +3466,7 @@ public:
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_ident_or_func_or_sum, public Item_args class Item_func_or_sum: public Item_result_field, public Item_args
{ {
public: public:
Item_func_or_sum() :Item_args() {} Item_func_or_sum() :Item_args() {}
...@@ -3471,7 +3478,7 @@ public: ...@@ -3471,7 +3478,7 @@ public:
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_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_ident_or_func_or_sum(thd, item), Item_args(thd, item) { } :Item_result_field(thd, item), Item_args(thd, item) { }
Item_func_or_sum(List<Item> &list) :Item_args(list) { } Item_func_or_sum(List<Item> &list) :Item_args(list) { }
bool walk(Item_processor processor, bool walk_subquery, uchar *arg) bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
{ {
...@@ -3576,20 +3583,18 @@ public: ...@@ -3576,20 +3583,18 @@ public:
table_map used_tables() const; table_map used_tables() const;
void update_used_tables(); void update_used_tables();
COND *build_equal_items(THD *thd, COND_EQUAL *inherited, COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields) bool link_item_fields)
{ {
/* /*
Item_ref cannot refer to Item_field when build_equal_items() is called, normilize_cond() replaced all conditions of type
because all "WHERE/HAVING field" are already replaced to WHERE/HAVING field
"WHERE/HAVING field<>0" by this time. See normalize_cond(). to:
TODO: make sure with Igor and Sanja, perhaps the below expression WHERE/HAVING field<>0
can be simplified just to a Item::build_equal_items() call. By the time of a build_equal_items() call, all such conditions should
already be replaced. No Item_ref referencing to Item_field are possible.
*/ */
return real_type() == FIELD_ITEM ? DBUG_ASSERT(real_type() != FIELD_ITEM);
Item_ident_or_func_or_sum::build_equal_items(thd, inherited, return Item_ident::build_equal_items(thd, inherited, link_item_fields);
link_item_fields) :
Item::build_equal_items(thd, inherited,
link_item_fields);
} }
bool const_item() const bool const_item() const
{ {
......
...@@ -131,6 +131,8 @@ public: ...@@ -131,6 +131,8 @@ public:
used_tables_and_const_cache_init(); used_tables_and_const_cache_init();
used_tables_and_const_cache_update_and_join(arg_count, args); used_tables_and_const_cache_update_and_join(arg_count, args);
} }
COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
bool link_item_fields);
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; } virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
virtual bool have_rev_func() const { return 0; } virtual bool have_rev_func() const { return 0; }
......
...@@ -12893,9 +12893,9 @@ COND *Item_cond::build_equal_items(THD *thd, ...@@ -12893,9 +12893,9 @@ COND *Item_cond::build_equal_items(THD *thd,
} }
COND *Item_ident_or_func_or_sum::build_equal_items(THD *thd, COND *Item_func::build_equal_items(THD *thd,
COND_EQUAL *inherited, COND_EQUAL *inherited,
bool link_item_fields) bool link_item_fields)
{ {
COND_EQUAL cond_equal; COND_EQUAL cond_equal;
cond_equal.upper_levels= inherited; cond_equal.upper_levels= inherited;
......
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