Skip to content

Commit fb4358f

Browse files
committed
MDEV-7949: Item_field::used_tables() takes 0.29% in OLTP RO
small sixes of used_tables() usage
1 parent 937aa7a commit fb4358f

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

sql/item.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,12 @@ class Item_result_field :public Item /* Item with result field */
22242224
~Item_result_field() {} /* Required with gcc 2.95 */
22252225
Field *get_tmp_table_field() { return result_field; }
22262226
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
2227-
table_map used_tables() const { return true; }
2227+
/*
2228+
This implementation of used_tables() used by Item_avg_field and
2229+
Item_variance_field which work when only temporary table left, so theu
2230+
return table map of the temporary table.
2231+
*/
2232+
table_map used_tables() const { return 1; }
22282233
void set_result_field(Field *field) { result_field= field; }
22292234
bool is_result_field() { return true; }
22302235
void save_in_result_field(bool no_conversions)

sql/item_func.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ class Item_func_sleep :public Item_int_func
13481348
const char *func_name() const { return "sleep"; }
13491349
table_map used_tables() const
13501350
{
1351-
return Item_int_func::used_tables() | RAND_TABLE_BIT;
1351+
return used_tables_cache | RAND_TABLE_BIT;
13521352
}
13531353
bool is_expensive() { return 1; }
13541354
longlong val_int();
@@ -1610,7 +1610,7 @@ class Item_func_get_lock :public Item_int_func
16101610
void fix_length_and_dec() { max_length=1; maybe_null=1;}
16111611
table_map used_tables() const
16121612
{
1613-
return Item_int_func::used_tables() | RAND_TABLE_BIT;
1613+
return used_tables_cache | RAND_TABLE_BIT;
16141614
}
16151615
bool const_item() const { return 0; }
16161616
bool is_expensive() { return 1; }
@@ -1630,7 +1630,7 @@ class Item_func_release_lock :public Item_int_func
16301630
void fix_length_and_dec() { max_length= 1; maybe_null= 1;}
16311631
table_map used_tables() const
16321632
{
1633-
return Item_int_func::used_tables() | RAND_TABLE_BIT;
1633+
return used_tables_cache | RAND_TABLE_BIT;
16341634
}
16351635
bool const_item() const { return 0; }
16361636
bool is_expensive() { return 1; }
@@ -1767,7 +1767,7 @@ class Item_func_set_user_var :public Item_func_user_var
17671767
}
17681768
table_map used_tables() const
17691769
{
1770-
return Item_func::used_tables() | RAND_TABLE_BIT;
1770+
return used_tables_cache | RAND_TABLE_BIT;
17711771
}
17721772
bool const_item() const { return 0; }
17731773
bool is_expensive() { return 1; }

sql/item_subselect.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5228,12 +5228,13 @@ double get_post_group_estimate(JOIN* join, double join_op_rows)
52285228
for (ORDER *order= join->group_list; order; order= order->next)
52295229
{
52305230
Item *item= order->item[0];
5231-
if (item->used_tables() & RAND_TABLE_BIT)
5231+
table_map item_used_tables= item->used_tables();
5232+
if (item_used_tables & RAND_TABLE_BIT)
52325233
{
52335234
/* Each join output record will be in its own group */
52345235
return join_op_rows;
52355236
}
5236-
tables_in_group_list|= item->used_tables();
5237+
tables_in_group_list|= item_used_tables;
52375238
}
52385239
tables_in_group_list &= ~PSEUDO_TABLE_BITS;
52395240

sql/opt_range.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7585,8 +7585,10 @@ Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field,
75857585
KEY_PART *key_part = param->key_parts;
75867586
KEY_PART *end = param->key_parts_end;
75877587
SEL_TREE *tree=0;
7588+
table_map value_used_tables= 0;
75887589
if (value &&
7589-
value->used_tables() & ~(param->prev_tables | param->read_tables))
7590+
(value_used_tables= value->used_tables()) &
7591+
~(param->prev_tables | param->read_tables))
75907592
DBUG_RETURN(0);
75917593
for (; key_part != end ; key_part++)
75927594
{
@@ -7595,7 +7597,7 @@ Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field,
75957597
SEL_ARG *sel_arg=0;
75967598
if (!tree && !(tree=new (param->thd->mem_root) SEL_TREE()))
75977599
DBUG_RETURN(0); // OOM
7598-
if (!value || !(value->used_tables() & ~param->read_tables))
7600+
if (!value || !(value_used_tables & ~param->read_tables))
75997601
{
76007602
/*
76017603
We need to restore the runtime mem_root of the thread in this

sql/opt_subselect.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,9 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
15701570
DBUG_RETURN(TRUE);
15711571
thd->lex->current_select=save_lex;
15721572

1573-
sj_nest->nested_join->sj_corr_tables= subq_pred->used_tables();
1574-
sj_nest->nested_join->sj_depends_on= subq_pred->used_tables() |
1573+
table_map subq_pred_used_tables= subq_pred->used_tables();
1574+
sj_nest->nested_join->sj_corr_tables= subq_pred_used_tables;
1575+
sj_nest->nested_join->sj_depends_on= subq_pred_used_tables |
15751576
subq_pred->left_expr->used_tables();
15761577
sj_nest->sj_on_expr= subq_lex->join->conds;
15771578

sql/opt_sum.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,13 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
654654
if (!cond)
655655
DBUG_RETURN(TRUE);
656656
Field *field= field_part->field;
657-
if (cond->used_tables() & OUTER_REF_TABLE_BIT)
657+
table_map cond_used_tables= cond->used_tables();
658+
if (cond_used_tables & OUTER_REF_TABLE_BIT)
658659
{
659660
DBUG_RETURN(FALSE);
660661
}
661-
if (!(cond->used_tables() & field->table->map) &&
662-
MY_TEST(cond->used_tables() & ~PSEUDO_TABLE_BITS))
662+
if (!(cond_used_tables & field->table->map) &&
663+
MY_TEST(cond_used_tables & ~PSEUDO_TABLE_BITS))
663664
{
664665
/* Condition doesn't restrict the used table */
665666
DBUG_RETURN(!cond->const_item());

sql/sql_select.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4530,8 +4530,9 @@ add_key_field(JOIN *join,
45304530
bool optimizable=0;
45314531
for (uint i=0; i<num_values; i++)
45324532
{
4533-
used_tables|=(value[i])->used_tables();
4534-
if (!((value[i])->used_tables() & (field->table->map | RAND_TABLE_BIT)))
4533+
table_map value_used_tables= (value[i])->used_tables();
4534+
used_tables|= value_used_tables;
4535+
if (!(value_used_tables & (field->table->map | RAND_TABLE_BIT)))
45354536
optimizable=1;
45364537
}
45374538
if (!optimizable)
@@ -14440,15 +14441,16 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
1444014441
*/
1444114442
if (table->on_expr)
1444214443
{
14443-
table->dep_tables|= table->on_expr->used_tables();
14444+
table_map table_on_expr_used_tables= table->on_expr->used_tables();
14445+
table->dep_tables|= table_on_expr_used_tables;
1444414446
if (table->embedding)
1444514447
{
1444614448
table->dep_tables&= ~table->embedding->nested_join->used_tables;
1444714449
/*
1444814450
Embedding table depends on tables used
1444914451
in embedded on expressions.
1445014452
*/
14451-
table->embedding->on_expr_dep_tables|= table->on_expr->used_tables();
14453+
table->embedding->on_expr_dep_tables|= table_on_expr_used_tables;
1445214454
}
1445314455
else
1445414456
table->dep_tables&= ~table->get_map();
@@ -20160,10 +20162,13 @@ make_cond_after_sjm(THD *thd, Item *root_cond, Item *cond, table_map tables,
2016020162
We assume that conditions that refer to only join prefix tables or
2016120163
sjm_tables have already been checked.
2016220164
*/
20163-
if (!inside_or_clause &&
20164-
(!(cond->used_tables() & ~tables) ||
20165-
!(cond->used_tables() & ~sjm_tables)))
20166-
return (COND*) 0; // Already checked
20165+
if (!inside_or_clause)
20166+
{
20167+
table_map cond_used_tables= cond->used_tables();
20168+
if((!(cond_used_tables & ~tables) ||
20169+
!(cond_used_tables & ~sjm_tables)))
20170+
return (COND*) 0; // Already checked
20171+
}
2016720172

2016820173
/* AND/OR recursive descent */
2016920174
if (cond->type() == Item::COND_ITEM)

0 commit comments

Comments
 (0)