Skip to content

Commit 2fe4d0e

Browse files
author
Alexander Barkov
committed
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().
1 parent 9090c3e commit 2fe4d0e

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

sql/item.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,16 @@ class Item: public Type_std_attributes
11331133
update_used_tables();
11341134
return this;
11351135
}
1136+
/*
1137+
Checks whether the item is:
1138+
- a simple equality (field=field_item or field=constant_item), or
1139+
- a row equality
1140+
and form multiple equality predicates.
1141+
*/
1142+
virtual bool check_equality(THD *thd, COND_EQUAL *cond, List<Item> *eq_list)
1143+
{
1144+
return false;
1145+
}
11361146
virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
11371147
List<Item> &fields) {}
11381148
/* Called for items that really have to be split */

sql/item_cmpfunc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ class Item_func_eq :public Item_bool_rowready_func2
562562
cond_result eq_cmp_result() const { return COND_TRUE; }
563563
const char *func_name() const { return "="; }
564564
Item *negated_item();
565+
COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
566+
bool link_item_fields);
567+
bool check_equality(THD *thd, COND_EQUAL *cond, List<Item> *eq_list);
565568
/*
566569
- If this equality is created from the subquery's IN-equality:
567570
number of the item it was created from, e.g. for

sql/sql_select.cc

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12685,27 +12685,21 @@ static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row,
1268512685
or, if the procedure fails by a fatal error.
1268612686
*/
1268712687

12688-
static bool check_equality(THD *thd, Item *item, COND_EQUAL *cond_equal,
12689-
List<Item> *eq_list)
12688+
bool Item_func_eq::check_equality(THD *thd, COND_EQUAL *cond_equal,
12689+
List<Item> *eq_list)
1269012690
{
12691-
if (item->type() == Item::FUNC_ITEM &&
12692-
((Item_func*) item)->functype() == Item_func::EQ_FUNC)
12693-
{
12694-
Item *left_item= ((Item_func*) item)->arguments()[0];
12695-
Item *right_item= ((Item_func*) item)->arguments()[1];
12691+
Item *left_item= arguments()[0];
12692+
Item *right_item= arguments()[1];
1269612693

12697-
if (left_item->type() == Item::ROW_ITEM &&
12698-
right_item->type() == Item::ROW_ITEM)
12699-
{
12700-
return check_row_equality(thd,
12701-
(Item_row *) left_item,
12702-
(Item_row *) right_item,
12703-
cond_equal, eq_list);
12704-
}
12705-
else
12706-
return check_simple_equality(left_item, right_item, item, cond_equal);
12707-
}
12708-
return FALSE;
12694+
if (left_item->type() == Item::ROW_ITEM &&
12695+
right_item->type() == Item::ROW_ITEM)
12696+
{
12697+
return check_row_equality(thd,
12698+
(Item_row *) left_item,
12699+
(Item_row *) right_item,
12700+
cond_equal, eq_list);
12701+
}
12702+
return check_simple_equality(left_item, right_item, this, cond_equal);
1270912703
}
1271012704

1271112705

@@ -12804,7 +12798,7 @@ COND *Item_cond_and::build_equal_items(THD *thd,
1280412798
structure here because it's restored before each
1280512799
re-execution of any prepared statement/stored procedure.
1280612800
*/
12807-
if (check_equality(thd, item, &cond_equal, &eq_list))
12801+
if (item->check_equality(thd, &cond_equal, &eq_list))
1280812802
li.remove();
1280912803
}
1281012804

@@ -12893,9 +12887,9 @@ COND *Item_cond::build_equal_items(THD *thd,
1289312887
}
1289412888

1289512889

12896-
COND *Item_func::build_equal_items(THD *thd,
12897-
COND_EQUAL *inherited,
12898-
bool link_item_fields)
12890+
COND *Item_func_eq::build_equal_items(THD *thd,
12891+
COND_EQUAL *inherited,
12892+
bool link_item_fields)
1289912893
{
1290012894
COND_EQUAL cond_equal;
1290112895
cond_equal.upper_levels= inherited;
@@ -12910,7 +12904,7 @@ COND *Item_func::build_equal_items(THD *thd,
1291012904
for WHERE a=b AND c=d AND (b=c OR d=5)
1291112905
b=c is replaced by =(a,b,c,d).
1291212906
*/
12913-
if (check_equality(thd, this, &cond_equal, &eq_list))
12907+
if (Item_func_eq::check_equality(thd, &cond_equal, &eq_list))
1291412908
{
1291512909
Item_equal *item_equal;
1291612910
int n= cond_equal.current_level.elements + eq_list.elements;
@@ -12955,6 +12949,13 @@ COND *Item_func::build_equal_items(THD *thd,
1295512949
return and_cond;
1295612950
}
1295712951
}
12952+
return Item_func::build_equal_items(thd, inherited, link_item_fields);
12953+
}
12954+
12955+
12956+
COND *Item_func::build_equal_items(THD *thd, COND_EQUAL *inherited,
12957+
bool link_item_fields)
12958+
{
1295812959
/*
1295912960
For each field reference in cond, not from equal item predicates,
1296012961
set a pointer to the multiple equality it belongs to (if there is any)

0 commit comments

Comments
 (0)