Commit 75965892 authored by Sergei Petrunia's avatar Sergei Petrunia

Get rid of Window_func_runner::first_run

We can call setup_partition_border_check() from
JOIN::make_aggr_tables_info(), provided that call is made after
appropriate set_items_ref_array() call.
parent cc59df65
......@@ -2334,6 +2334,14 @@ bool JOIN::make_aggr_tables_info()
curr_tab->fields= &tmp_fields_list1;
set_postjoin_aggr_write_func(curr_tab);
// psergey-todo: this is probably an incorrect place:
if (select_lex->window_funcs.elements)
{
curr_tab->window_funcs= new Window_funcs_computation;
if (curr_tab->window_funcs->setup(thd, &select_lex->window_funcs))
DBUG_RETURN(true);
}
tmp_table_param.func_count= 0;
tmp_table_param.field_count+= tmp_table_param.func_count;
if (sort_and_group || curr_tab->table->group)
......@@ -2698,14 +2706,6 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
tab->table= table;
table->reginfo.join_tab= tab;
// psergey-todo: this is probably an incorrect place:
if (select_lex->window_funcs.elements)
{
tab->window_funcs= new Window_funcs_computation;
if (tab->window_funcs->setup(thd, &select_lex->window_funcs))
goto err;
}
/* if group or order on first table, sort first */
if (group_list && simple_group)
{
......@@ -2749,6 +2749,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
order= NULL;
}
}
DBUG_RETURN(false);
err:
......
......@@ -1485,6 +1485,8 @@ bool Window_func_runner::setup(THD *thd)
spec->order_list->first);
filesort= new (thd->mem_root) Filesort(sort_order, HA_POS_ERROR, NULL);
win_func->setup_partition_border_check(thd);
Item_sum::Sumfunctype type= win_func->window_func()->sum_func();
switch (type)
{
......@@ -1521,7 +1523,6 @@ bool Window_func_runner::setup(THD *thd)
DBUG_ASSERT(0);
}
first_run= true;
return false;
}
......@@ -1533,29 +1534,6 @@ bool Window_func_runner::exec(JOIN *join)
{
THD *thd= join->thd;
/*
We have to call setup_partition_border_check here.
The reason is as follows:
When computing the value of sorting criteria from OVER (PARTITION ...
ORDER BY ...) clauses, we need to read temp.table fields.
This is achieved by ORDER::item being Item** object, which points into
ref_pointer_array.
Ref_pointer_array initially points to source table fields.
At execution phase, it is set to point to the temp.table fields.
We need to use items after this step is done.
TODO: an alternative is to use something that points into
ref_pointer_array, too. Something like wrap order->item in an Item_ref
object.
*/
if (first_run)
{
win_func->setup_partition_border_check(thd);
first_run= false;
}
if (create_sort_index(thd, join, &join->join_tab[join->top_join_tab_count],
filesort))
return true;
......
......@@ -159,7 +159,6 @@ class Window_func_runner : public Sql_alloc
/* The function to use for computation*/
window_compute_func_t compute_func;
bool first_run;
public:
Window_func_runner(Item_window_func *win_func_arg) :
win_func(win_func_arg)
......
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