1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Merge branch 'bb-10.2-mdev9543' of github.com:MariaDB/server into bb-10.2-mdev9543

This commit is contained in:
Sergei Petrunia
2016-03-28 22:19:55 +03:00
8 changed files with 194 additions and 17 deletions

View File

@ -2140,7 +2140,6 @@ bool JOIN::make_aggr_tables_info()
All optimization is done. Check if we can use the storage engines
group by handler to evaluate the group by
*/
group_by_handler *gbh= NULL;
if (tables_list && (tmp_table_param.sum_func_count || group_list) &&
!procedure)
{
@ -2339,14 +2338,6 @@ 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)
@ -2658,6 +2649,24 @@ bool JOIN::make_aggr_tables_info()
skip_sort_order= true;
}
}
/*
Window functions computation step should be attached to the last join_tab
that's doing aggregation.
The last join_tab reads the data from the temp. table. It also may do
- sorting
- duplicate value removal
Both of these operations are done after window function computation step.
*/
curr_tab= join_tab + top_join_tab_count + aggr_tables - 1;
if (select_lex->window_funcs.elements)
{
curr_tab->window_funcs_step= new Window_funcs_computation;
if (curr_tab->window_funcs_step->setup(thd, &select_lex->window_funcs,
curr_tab))
DBUG_RETURN(true);
}
fields= curr_fields_list;
// Reset before execution
set_items_ref_array(items0);
@ -19137,7 +19146,10 @@ bool test_if_use_dynamic_range_scan(JOIN_TAB *join_tab)
int join_init_read_record(JOIN_TAB *tab)
{
int error;
/*
Note: the query plan tree for the below operations is constructed in
save_agg_explain_data.
*/
if (tab->distinct && tab->remove_duplicates()) // Remove duplicates.
return 1;
if (tab->filesort && tab->sort_table()) // Sort table.
@ -24174,6 +24186,14 @@ void save_agg_explain_data(JOIN *join, Explain_select *xpl_sel)
node= new Explain_aggr_tmp_table;
node->child= prev_node;
if (join_tab->window_funcs_step)
{
prev_node=node;
node= new Explain_aggr_window_funcs;
node->child= prev_node;
}
/* The below matches execution in join_init_read_record() */
if (join_tab->distinct)
{
prev_node= node;
@ -25946,9 +25966,10 @@ AGGR_OP::end_send()
// Update ref array
join_tab->join->set_items_ref_array(*join_tab->ref_array);
if (join_tab->window_funcs)
if (join_tab->window_funcs_step)
{
join_tab->window_funcs->exec(join);
if (join_tab->window_funcs_step->exec(join))
return NESTED_LOOP_ERROR;
}
table->reginfo.lock_type= TL_UNLOCK;