Commit 07de9ab7 authored by unknown's avatar unknown

Few simple performance fixes found with sysbench oltp.lua and Oprofile:

 - Avoid needless load/stores in my_hash_sort_simple due to possible aliasing
 - Avoid expensive Join_plan_state constructor in choose_subquery_plan when no subquery
 - Avoid calling update_virtual_fields for every row when no virtual fields.
parent 9a041944
...@@ -589,7 +589,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -589,7 +589,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
{ {
if ((error= select->quick->get_next())) if ((error= select->quick->get_next()))
break; break;
if (!error) if (!error && sort_form->vfield)
update_virtual_fields(thd, sort_form); update_virtual_fields(thd, sort_form);
file->position(sort_form->record[0]); file->position(sort_form->record[0]);
DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE);); DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE););
...@@ -608,7 +608,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -608,7 +608,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
else else
{ {
error=file->ha_rnd_next(sort_form->record[0]); error=file->ha_rnd_next(sort_form->record[0]);
if (!error) if (!error && sort_form->vfield)
update_virtual_fields(thd, sort_form); update_virtual_fields(thd, sort_form);
if (!flag) if (!flag)
{ {
......
...@@ -4950,7 +4950,6 @@ bool setup_jtbm_semi_joins(JOIN *join, List<TABLE_LIST> *join_list, ...@@ -4950,7 +4950,6 @@ bool setup_jtbm_semi_joins(JOIN *join, List<TABLE_LIST> *join_list,
bool JOIN::choose_subquery_plan(table_map join_tables) bool JOIN::choose_subquery_plan(table_map join_tables)
{ {
Join_plan_state save_qep; /* The original QEP of the subquery. */
enum_reopt_result reopt_result= REOPT_NONE; enum_reopt_result reopt_result= REOPT_NONE;
Item_in_subselect *in_subs; Item_in_subselect *in_subs;
...@@ -4969,12 +4968,15 @@ bool JOIN::choose_subquery_plan(table_map join_tables) ...@@ -4969,12 +4968,15 @@ bool JOIN::choose_subquery_plan(table_map join_tables)
} }
else else
return false; return false;
/* A strategy must be chosen earlier. */ /* A strategy must be chosen earlier. */
DBUG_ASSERT(in_subs->has_strategy()); DBUG_ASSERT(in_subs->has_strategy());
DBUG_ASSERT(in_to_exists_where || in_to_exists_having); DBUG_ASSERT(in_to_exists_where || in_to_exists_having);
DBUG_ASSERT(!in_to_exists_where || in_to_exists_where->fixed); DBUG_ASSERT(!in_to_exists_where || in_to_exists_where->fixed);
DBUG_ASSERT(!in_to_exists_having || in_to_exists_having->fixed); DBUG_ASSERT(!in_to_exists_having || in_to_exists_having->fixed);
Join_plan_state save_qep; /* The original QEP of the subquery. */
/* /*
Compute and compare the costs of materialization and in-exists if both Compute and compare the costs of materialization and in-exists if both
strategies are possible and allowed by the user (checked during the prepare strategies are possible and allowed by the user (checked during the prepare
......
...@@ -344,7 +344,8 @@ static int rr_quick(READ_RECORD *info) ...@@ -344,7 +344,8 @@ static int rr_quick(READ_RECORD *info)
break; break;
} }
} }
update_virtual_fields(info->thd, info->table); if (info->table->vfield)
update_virtual_fields(info->thd, info->table);
return tmp; return tmp;
} }
......
...@@ -15828,7 +15828,8 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, ...@@ -15828,7 +15828,8 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
DBUG_RETURN(NESTED_LOOP_KILLED); /* purecov: inspected */ DBUG_RETURN(NESTED_LOOP_KILLED); /* purecov: inspected */
} }
update_virtual_fields(join->thd, join_tab->table); if (join_tab->table->vfield)
update_virtual_fields(join->thd, join_tab->table);
if (select_cond) if (select_cond)
{ {
......
...@@ -2466,30 +2466,35 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, ...@@ -2466,30 +2466,35 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
/* /*
Process virtual columns, if any. Process virtual columns, if any.
*/ */
if (!(vfield_ptr = (Field **) alloc_root(&outparam->mem_root, if (!share->vfields)
(uint) ((share->vfields+1)* outparam->vfield= NULL;
sizeof(Field*))))) else
goto err;
outparam->vfield= vfield_ptr;
for (field_ptr= outparam->field; *field_ptr; field_ptr++)
{ {
if ((*field_ptr)->vcol_info) if (!(vfield_ptr = (Field **) alloc_root(&outparam->mem_root,
(uint) ((share->vfields+1)*
sizeof(Field*)))))
goto err;
outparam->vfield= vfield_ptr;
for (field_ptr= outparam->field; *field_ptr; field_ptr++)
{ {
if (unpack_vcol_info_from_frm(thd, if ((*field_ptr)->vcol_info)
outparam,
*field_ptr,
&(*field_ptr)->vcol_info->expr_str,
&error_reported))
{ {
error= 4; // in case no error is reported if (unpack_vcol_info_from_frm(thd,
goto err; outparam,
*field_ptr,
&(*field_ptr)->vcol_info->expr_str,
&error_reported))
{
error= 4; // in case no error is reported
goto err;
}
*(vfield_ptr++)= *field_ptr;
} }
*(vfield_ptr++)= *field_ptr;
} }
*vfield_ptr= 0; // End marker
} }
*vfield_ptr= 0; // End marker
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
if (share->partition_info_str_len && outparam->file) if (share->partition_info_str_len && outparam->file)
......
...@@ -306,19 +306,24 @@ void my_hash_sort_simple(CHARSET_INFO *cs, ...@@ -306,19 +306,24 @@ void my_hash_sort_simple(CHARSET_INFO *cs,
{ {
register const uchar *sort_order=cs->sort_order; register const uchar *sort_order=cs->sort_order;
const uchar *end; const uchar *end;
ulong n1, n2;
/* /*
Remove end space. We have to do this to be able to compare Remove end space. We have to do this to be able to compare
'A ' and 'A' as identical 'A ' and 'A' as identical
*/ */
end= skip_trailing_space(key, len); end= skip_trailing_space(key, len);
n1= *nr1;
n2= *nr2;
for (; key < (uchar*) end ; key++) for (; key < (uchar*) end ; key++)
{ {
nr1[0]^=(ulong) ((((uint) nr1[0] & 63)+nr2[0]) * n1^=(ulong) ((((uint) n1 & 63)+n2) *
((uint) sort_order[(uint) *key])) + (nr1[0] << 8); ((uint) sort_order[(uint) *key])) + (n1 << 8);
nr2[0]+=3; n2+=3;
} }
*nr1= n1;
*nr2= n2;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment