diff options
author | Alexander Barkov <bar@mariadb.org> | 2015-05-05 01:09:47 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2015-05-05 01:09:47 +0400 |
commit | 2fe4d0e6cde260b772da5e0c3dbad4bd4ab5bee3 (patch) | |
tree | 7aaa5a724a0065463ced9d91031587e9f6da6141 | |
parent | 9090c3efcae0874219b990e73568e41e021a3352 (diff) | |
download | mariadb-git-2fe4d0e6cde260b772da5e0c3dbad4bd4ab5bee3.tar.gz |
MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step #3: Splitting the function check_equality() into a method in Item.
Implementing Item::check_equality() and Item_func_eq::check_equality().
Implement Item_func_eq::build_equal_items() in addition to
Item_func::build_equal_items() and moving the call for check_equality()
from Item_func::build_equal_items() to Item_func_eq::build_equal_items().
-rw-r--r-- | sql/item.h | 10 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 49 |
3 files changed, 38 insertions, 24 deletions
diff --git a/sql/item.h b/sql/item.h index a04322bb5f9..043605a6c7c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1133,6 +1133,16 @@ public: update_used_tables(); return this; } + /* + Checks whether the item is: + - a simple equality (field=field_item or field=constant_item), or + - a row equality + and form multiple equality predicates. + */ + virtual bool check_equality(THD *thd, COND_EQUAL *cond, List<Item> *eq_list) + { + return false; + } virtual void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields) {} /* Called for items that really have to be split */ diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index ae7bac0cac1..53f249d9def 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -562,6 +562,9 @@ public: cond_result eq_cmp_result() const { return COND_TRUE; } const char *func_name() const { return "="; } Item *negated_item(); + COND *build_equal_items(THD *thd, COND_EQUAL *inherited, + bool link_item_fields); + bool check_equality(THD *thd, COND_EQUAL *cond, List<Item> *eq_list); /* - If this equality is created from the subquery's IN-equality: number of the item it was created from, e.g. for diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c8ca0668556..95778f00bad 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12685,27 +12685,21 @@ static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row, or, if the procedure fails by a fatal error. */ -static bool check_equality(THD *thd, Item *item, COND_EQUAL *cond_equal, - List<Item> *eq_list) +bool Item_func_eq::check_equality(THD *thd, COND_EQUAL *cond_equal, + List<Item> *eq_list) { - if (item->type() == Item::FUNC_ITEM && - ((Item_func*) item)->functype() == Item_func::EQ_FUNC) - { - Item *left_item= ((Item_func*) item)->arguments()[0]; - Item *right_item= ((Item_func*) item)->arguments()[1]; + Item *left_item= arguments()[0]; + Item *right_item= arguments()[1]; - if (left_item->type() == Item::ROW_ITEM && - right_item->type() == Item::ROW_ITEM) - { - return check_row_equality(thd, - (Item_row *) left_item, - (Item_row *) right_item, - cond_equal, eq_list); - } - else - return check_simple_equality(left_item, right_item, item, cond_equal); - } - return FALSE; + if (left_item->type() == Item::ROW_ITEM && + right_item->type() == Item::ROW_ITEM) + { + return check_row_equality(thd, + (Item_row *) left_item, + (Item_row *) right_item, + cond_equal, eq_list); + } + return check_simple_equality(left_item, right_item, this, cond_equal); } @@ -12804,7 +12798,7 @@ COND *Item_cond_and::build_equal_items(THD *thd, structure here because it's restored before each re-execution of any prepared statement/stored procedure. */ - if (check_equality(thd, item, &cond_equal, &eq_list)) + if (item->check_equality(thd, &cond_equal, &eq_list)) li.remove(); } @@ -12893,9 +12887,9 @@ COND *Item_cond::build_equal_items(THD *thd, } -COND *Item_func::build_equal_items(THD *thd, - COND_EQUAL *inherited, - bool link_item_fields) +COND *Item_func_eq::build_equal_items(THD *thd, + COND_EQUAL *inherited, + bool link_item_fields) { COND_EQUAL cond_equal; cond_equal.upper_levels= inherited; @@ -12910,7 +12904,7 @@ COND *Item_func::build_equal_items(THD *thd, for WHERE a=b AND c=d AND (b=c OR d=5) b=c is replaced by =(a,b,c,d). */ - if (check_equality(thd, this, &cond_equal, &eq_list)) + if (Item_func_eq::check_equality(thd, &cond_equal, &eq_list)) { Item_equal *item_equal; int n= cond_equal.current_level.elements + eq_list.elements; @@ -12955,6 +12949,13 @@ COND *Item_func::build_equal_items(THD *thd, return and_cond; } } + return Item_func::build_equal_items(thd, inherited, link_item_fields); +} + + +COND *Item_func::build_equal_items(THD *thd, COND_EQUAL *inherited, + bool link_item_fields) +{ /* For each field reference in cond, not from equal item predicates, set a pointer to the multiple equality it belongs to (if there is any) |