From 462bca365ad3e8cda99b044bcf63d3ec5dc78bd9 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 4 May 2015 18:12:31 +0400 Subject: [PATCH] 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. --- sql/item.cc | 2 +- sql/item.h | 57 ++++++++++++++++++++++++++--------------------- sql/item_func.h | 2 ++ sql/sql_select.cc | 6 ++--- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index a1020e8ccfd..6e856856c16 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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), diff --git a/sql/item.h b/sql/item.h index 29114d5a440..a04322bb5f9 100644 --- a/sql/item.h +++ b/sql/item.h @@ -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 &list) :Item_args(list) { } bool walk(Item_processor processor, bool walk_subquery, uchar *arg) { @@ -3576,20 +3583,18 @@ public: 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 { diff --git a/sql/item_func.h b/sql/item_func.h index eff6b2f3e48..0d57c2b779b 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -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; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d0e0fae6612..c8ca0668556 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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;