Skip to content

Commit

Permalink
MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alexander Barkov committed May 4, 2015
1 parent 53382ac commit 462bca3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion sql/item.cc
Expand Up @@ -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),
Expand Down
57 changes: 31 additions & 26 deletions sql/item.h
Expand Up @@ -2134,19 +2134,7 @@ class Item_result_field :public Item /* Item with 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
class Item_ident :public Item_result_field
{
protected:
/*
Expand Down Expand Up @@ -2336,6 +2324,25 @@ class Item_field :public Item_ident
{
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) { }
Expand Down Expand Up @@ -3459,7 +3466,7 @@ class Used_tables_and_const_cache
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() {}
Expand All @@ -3471,7 +3478,7 @@ class Item_func_or_sum: public Item_ident_or_func_or_sum, public Item_args
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)
{
Expand Down Expand Up @@ -3576,20 +3583,18 @@ class Item_ref :public Item_ident
table_map used_tables() const;
void update_used_tables();
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,
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.
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.
*/
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);
DBUG_ASSERT(real_type() != FIELD_ITEM);
return Item_ident::build_equal_items(thd, inherited, link_item_fields);
}
bool const_item() const
{
Expand Down
2 changes: 2 additions & 0 deletions sql/item_func.h
Expand Up @@ -131,6 +131,8 @@ class Item_func :public Item_func_or_sum, public Used_tables_and_const_cache
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; }
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_select.cc
Expand Up @@ -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_EQUAL *inherited,
bool link_item_fields)
COND *Item_func::build_equal_items(THD *thd,
COND_EQUAL *inherited,
bool link_item_fields)
{
COND_EQUAL cond_equal;
cond_equal.upper_levels= inherited;
Expand Down

0 comments on commit 462bca3

Please sign in to comment.