Skip to content

Commit

Permalink
MDEV-7949: Item_field::used_tables() takes 0.29% in OLTP RO
Browse files Browse the repository at this point in the history
small sixes of used_tables() usage
  • Loading branch information
sanja-byelkin committed Oct 29, 2015
1 parent 937aa7a commit fb4358f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
7 changes: 6 additions & 1 deletion sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,12 @@ class Item_result_field :public Item /* Item with result field */
~Item_result_field() {} /* Required with gcc 2.95 */
Field *get_tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
table_map used_tables() const { return true; }
/*
This implementation of used_tables() used by Item_avg_field and
Item_variance_field which work when only temporary table left, so theu
return table map of the temporary table.
*/
table_map used_tables() const { return 1; }
void set_result_field(Field *field) { result_field= field; }
bool is_result_field() { return true; }
void save_in_result_field(bool no_conversions)
Expand Down
8 changes: 4 additions & 4 deletions sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ class Item_func_sleep :public Item_int_func
const char *func_name() const { return "sleep"; }
table_map used_tables() const
{
return Item_int_func::used_tables() | RAND_TABLE_BIT;
return used_tables_cache | RAND_TABLE_BIT;
}
bool is_expensive() { return 1; }
longlong val_int();
Expand Down Expand Up @@ -1610,7 +1610,7 @@ class Item_func_get_lock :public Item_int_func
void fix_length_and_dec() { max_length=1; maybe_null=1;}
table_map used_tables() const
{
return Item_int_func::used_tables() | RAND_TABLE_BIT;
return used_tables_cache | RAND_TABLE_BIT;
}
bool const_item() const { return 0; }
bool is_expensive() { return 1; }
Expand All @@ -1630,7 +1630,7 @@ class Item_func_release_lock :public Item_int_func
void fix_length_and_dec() { max_length= 1; maybe_null= 1;}
table_map used_tables() const
{
return Item_int_func::used_tables() | RAND_TABLE_BIT;
return used_tables_cache | RAND_TABLE_BIT;
}
bool const_item() const { return 0; }
bool is_expensive() { return 1; }
Expand Down Expand Up @@ -1767,7 +1767,7 @@ class Item_func_set_user_var :public Item_func_user_var
}
table_map used_tables() const
{
return Item_func::used_tables() | RAND_TABLE_BIT;
return used_tables_cache | RAND_TABLE_BIT;
}
bool const_item() const { return 0; }
bool is_expensive() { return 1; }
Expand Down
5 changes: 3 additions & 2 deletions sql/item_subselect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5228,12 +5228,13 @@ double get_post_group_estimate(JOIN* join, double join_op_rows)
for (ORDER *order= join->group_list; order; order= order->next)
{
Item *item= order->item[0];
if (item->used_tables() & RAND_TABLE_BIT)
table_map item_used_tables= item->used_tables();
if (item_used_tables & RAND_TABLE_BIT)
{
/* Each join output record will be in its own group */
return join_op_rows;
}
tables_in_group_list|= item->used_tables();
tables_in_group_list|= item_used_tables;
}
tables_in_group_list &= ~PSEUDO_TABLE_BITS;

Expand Down
6 changes: 4 additions & 2 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7585,8 +7585,10 @@ Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field,
KEY_PART *key_part = param->key_parts;
KEY_PART *end = param->key_parts_end;
SEL_TREE *tree=0;
table_map value_used_tables= 0;
if (value &&
value->used_tables() & ~(param->prev_tables | param->read_tables))
(value_used_tables= value->used_tables()) &
~(param->prev_tables | param->read_tables))
DBUG_RETURN(0);
for (; key_part != end ; key_part++)
{
Expand All @@ -7595,7 +7597,7 @@ Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field,
SEL_ARG *sel_arg=0;
if (!tree && !(tree=new (param->thd->mem_root) SEL_TREE()))
DBUG_RETURN(0); // OOM
if (!value || !(value->used_tables() & ~param->read_tables))
if (!value || !(value_used_tables & ~param->read_tables))
{
/*
We need to restore the runtime mem_root of the thread in this
Expand Down
5 changes: 3 additions & 2 deletions sql/opt_subselect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,9 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
DBUG_RETURN(TRUE);
thd->lex->current_select=save_lex;

sj_nest->nested_join->sj_corr_tables= subq_pred->used_tables();
sj_nest->nested_join->sj_depends_on= subq_pred->used_tables() |
table_map subq_pred_used_tables= subq_pred->used_tables();
sj_nest->nested_join->sj_corr_tables= subq_pred_used_tables;
sj_nest->nested_join->sj_depends_on= subq_pred_used_tables |
subq_pred->left_expr->used_tables();
sj_nest->sj_on_expr= subq_lex->join->conds;

Expand Down
7 changes: 4 additions & 3 deletions sql/opt_sum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,13 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
if (!cond)
DBUG_RETURN(TRUE);
Field *field= field_part->field;
if (cond->used_tables() & OUTER_REF_TABLE_BIT)
table_map cond_used_tables= cond->used_tables();
if (cond_used_tables & OUTER_REF_TABLE_BIT)
{
DBUG_RETURN(FALSE);
}
if (!(cond->used_tables() & field->table->map) &&
MY_TEST(cond->used_tables() & ~PSEUDO_TABLE_BITS))
if (!(cond_used_tables & field->table->map) &&
MY_TEST(cond_used_tables & ~PSEUDO_TABLE_BITS))
{
/* Condition doesn't restrict the used table */
DBUG_RETURN(!cond->const_item());
Expand Down
21 changes: 13 additions & 8 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4530,8 +4530,9 @@ add_key_field(JOIN *join,
bool optimizable=0;
for (uint i=0; i<num_values; i++)
{
used_tables|=(value[i])->used_tables();
if (!((value[i])->used_tables() & (field->table->map | RAND_TABLE_BIT)))
table_map value_used_tables= (value[i])->used_tables();
used_tables|= value_used_tables;
if (!(value_used_tables & (field->table->map | RAND_TABLE_BIT)))
optimizable=1;
}
if (!optimizable)
Expand Down Expand Up @@ -14440,15 +14441,16 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
*/
if (table->on_expr)
{
table->dep_tables|= table->on_expr->used_tables();
table_map table_on_expr_used_tables= table->on_expr->used_tables();
table->dep_tables|= table_on_expr_used_tables;
if (table->embedding)
{
table->dep_tables&= ~table->embedding->nested_join->used_tables;
/*
Embedding table depends on tables used
in embedded on expressions.
*/
table->embedding->on_expr_dep_tables|= table->on_expr->used_tables();
table->embedding->on_expr_dep_tables|= table_on_expr_used_tables;
}
else
table->dep_tables&= ~table->get_map();
Expand Down Expand Up @@ -20160,10 +20162,13 @@ make_cond_after_sjm(THD *thd, Item *root_cond, Item *cond, table_map tables,
We assume that conditions that refer to only join prefix tables or
sjm_tables have already been checked.
*/
if (!inside_or_clause &&
(!(cond->used_tables() & ~tables) ||
!(cond->used_tables() & ~sjm_tables)))
return (COND*) 0; // Already checked
if (!inside_or_clause)
{
table_map cond_used_tables= cond->used_tables();
if((!(cond_used_tables & ~tables) ||
!(cond_used_tables & ~sjm_tables)))
return (COND*) 0; // Already checked
}

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

0 comments on commit fb4358f

Please sign in to comment.