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)
*/
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_table_name(item->orig_table_name),
orig_field_name(item->orig_field_name),
......
......@@ -2134,19 +2134,7 @@ public:
};
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
class Item_ident :public Item_result_field
{
protected:
/*
......@@ -2336,6 +2324,25 @@ public:
{
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; }
void set_result_field(Field *field) {}
void save_in_result_field(bool no_conversions) { }
......@@ -3459,7 +3466,7 @@ public:
An abstract class representing common features of
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:
Item_func_or_sum() :Item_args() {}
......@@ -3471,7 +3478,7 @@ public:
Item_func_or_sum(Item *a, Item *b, Item *c, Item *d, Item *e)
:Item_args(a, b, c, d, e) { }
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) { }
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
{
......@@ -3579,17 +3586,15 @@ public:
bool link_item_fields)
{
/*
Item_ref cannot refer to Item_field when build_equal_items() is called,
because all "WHERE/HAVING field" are already replaced to
"WHERE/HAVING field<>0" by this time. See normalize_cond().
TODO: make sure with Igor and Sanja, perhaps the below expression
can be simplified just to a Item::build_equal_items() call.
*/
return real_type() == FIELD_ITEM ?
Item_ident_or_func_or_sum::build_equal_items(thd, inherited,
link_item_fields) :
Item::build_equal_items(thd, inherited,
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_ref referencing to Item_field are possible.
*/
DBUG_ASSERT(real_type() != FIELD_ITEM);
return Item_ident::build_equal_items(thd, inherited, link_item_fields);
}
bool const_item() const
{
......
......@@ -131,6 +131,8 @@ public:
used_tables_and_const_cache_init();
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;
virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
virtual bool have_rev_func() const { return 0; }
......
......@@ -12893,7 +12893,7 @@ 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,
bool link_item_fields)
{
......
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