Commit 8dff1aa5 authored by Sergei Golubchik's avatar Sergei Golubchik

bug: move one_storage_engine checking loop

down to the point where all tables are already known
(and subqueries converted to joins, if needed)
parent c93ac0a1
...@@ -759,12 +759,6 @@ JOIN::prepare(Item ***rref_pointer_array, ...@@ -759,12 +759,6 @@ JOIN::prepare(Item ***rref_pointer_array,
TABLE_LIST *tbl; TABLE_LIST *tbl;
List_iterator_fast<TABLE_LIST> li(select_lex->leaf_tables); List_iterator_fast<TABLE_LIST> li(select_lex->leaf_tables);
/*
If all tables comes from the same storage engine, one_storage_engine will
be set to point to the handlerton of this engine.
*/
one_storage_engine= 0;
uint table_loop_count= 0;
while ((tbl= li++)) while ((tbl= li++))
{ {
/* /*
...@@ -776,17 +770,8 @@ JOIN::prepare(Item ***rref_pointer_array, ...@@ -776,17 +770,8 @@ JOIN::prepare(Item ***rref_pointer_array,
Note: this loop doesn't touch tables inside merged semi-joins, because Note: this loop doesn't touch tables inside merged semi-joins, because
subquery-to-semijoin conversion has not been done yet. This is intended. subquery-to-semijoin conversion has not been done yet. This is intended.
*/ */
if (tbl->table) if (mixed_implicit_grouping && tbl->table)
{
if (mixed_implicit_grouping)
tbl->table->maybe_null= 1; tbl->table->maybe_null= 1;
if (!table_loop_count++)
one_storage_engine= tbl->table->file->ht;
else if (one_storage_engine != tbl->table->file->ht)
one_storage_engine= 0;
}
else
one_storage_engine= 0;
} }
if ((wild_num && setup_wild(thd, tables_list, fields_list, &all_fields, if ((wild_num && setup_wild(thd, tables_list, fields_list, &all_fields,
...@@ -1914,11 +1899,24 @@ JOIN::optimize_inner() ...@@ -1914,11 +1899,24 @@ JOIN::optimize_inner()
group by handler to evaluate the group by group by handler to evaluate the group by
*/ */
if ((tmp_table_param.sum_func_count || group_list) && !procedure && if ((tmp_table_param.sum_func_count || group_list) && !procedure)
(one_storage_engine && one_storage_engine->create_group_by)) {
/*
At the moment we only support push down for queries where
all tables are in the same storage engine
*/
TABLE_LIST *tbl= tables_list;
handlerton *ht= tbl && tbl->table ? tbl->table->file->ht : 0;
for (tbl= tbl->next_local; ht && tbl; tbl= tbl->next_local)
{
if (!tbl->table || tbl->table->file->ht != ht)
ht= 0;
}
if (ht && ht->create_group_by)
{ {
/* Check if the storage engine can intercept the query */ /* Check if the storage engine can intercept the query */
group_by_handler *gbh= one_storage_engine->create_group_by(thd, &all_fields, group_by_handler *gbh= ht->create_group_by(thd, &all_fields,
tables_list, group_list, order, conds, having); tables_list, group_list, order, conds, having);
if (gbh) if (gbh)
{ {
...@@ -1936,8 +1934,8 @@ JOIN::optimize_inner() ...@@ -1936,8 +1934,8 @@ JOIN::optimize_inner()
tmp_table_param.hidden_field_count= (all_fields.elements - tmp_table_param.hidden_field_count= (all_fields.elements -
fields_list.elements); fields_list.elements);
if (!(exec_tmp_table1= if (!(exec_tmp_table1=
create_tmp_table(thd, &tmp_table_param, all_fields, create_tmp_table(thd, &tmp_table_param, all_fields, 0,
0, handler_flags & GROUP_BY_DISTINCT ? handler_flags & GROUP_BY_DISTINCT ?
0 : select_distinct, 1, 0 : select_distinct, 1,
select_options, HA_POS_ERROR, "", select_options, HA_POS_ERROR, "",
!need_tmp, !need_tmp,
...@@ -2002,6 +2000,7 @@ JOIN::optimize_inner() ...@@ -2002,6 +2000,7 @@ JOIN::optimize_inner()
DBUG_RETURN(thd->is_fatal_error); DBUG_RETURN(thd->is_fatal_error);
} }
} }
}
/* /*
The loose index scan access method guarantees that all grouping or The loose index scan access method guarantees that all grouping or
......
...@@ -1087,8 +1087,6 @@ public: ...@@ -1087,8 +1087,6 @@ public:
/* Finally picked QEP. This is result of join optimization */ /* Finally picked QEP. This is result of join optimization */
POSITION *best_positions; POSITION *best_positions;
/* points to a storage engine if all tables comes from the storage engine */
handlerton *one_storage_engine;
Pushdown_query *pushdown_query; Pushdown_query *pushdown_query;
JOIN_TAB *original_join_tab; JOIN_TAB *original_join_tab;
uint original_table_count; uint original_table_count;
...@@ -1391,7 +1389,6 @@ public: ...@@ -1391,7 +1389,6 @@ public:
group_optimized_away= 0; group_optimized_away= 0;
no_rows_in_result_called= 0; no_rows_in_result_called= 0;
positions= best_positions= 0; positions= best_positions= 0;
one_storage_engine= 0;
pushdown_query= 0; pushdown_query= 0;
original_join_tab= 0; original_join_tab= 0;
do_select_call_count= 0; do_select_call_count= 0;
......
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