Commit c16c9e8e authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-11999.

This patch complements the patch for bug 11138.
Without this patch some table-less queries with window functions
could cause crashes due to a memory overwrite.
parent 2f00b73a
...@@ -2545,3 +2545,16 @@ row_number() over (partition by 2) ...@@ -2545,3 +2545,16 @@ row_number() over (partition by 2)
select row_number() over (partition by 4 order by 1+2); select row_number() over (partition by 4 order by 1+2);
row_number() over (partition by 4 order by 1+2) row_number() over (partition by 4 order by 1+2)
1 1
#
# MDEV-11999: execution of prepared statement for
# tableless query with window functions
#
prepare stmt from
"select row_number() over (partition by 4 order by 1+2)";
execute stmt;
row_number() over (partition by 4 order by 1+2)
1
execute stmt;
row_number() over (partition by 4 order by 1+2)
1
deallocate prepare stmt;
...@@ -1547,3 +1547,15 @@ select row_number() over (), sum(5) over (); ...@@ -1547,3 +1547,15 @@ select row_number() over (), sum(5) over ();
select row_number() over (order by 2); select row_number() over (order by 2);
select row_number() over (partition by 2); select row_number() over (partition by 2);
select row_number() over (partition by 4 order by 1+2); select row_number() over (partition by 4 order by 1+2);
--echo #
--echo # MDEV-11999: execution of prepared statement for
--echo # tableless query with window functions
--echo #
prepare stmt from
"select row_number() over (partition by 4 order by 1+2)";
execute stmt;
execute stmt;
deallocate prepare stmt;
...@@ -1439,15 +1439,6 @@ JOIN::optimize_inner() ...@@ -1439,15 +1439,6 @@ JOIN::optimize_inner()
{ {
DBUG_PRINT("info",("No tables")); DBUG_PRINT("info",("No tables"));
error= 0; error= 0;
if (select_lex->have_window_funcs())
{
if (!join_tab &&
!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB))))
DBUG_RETURN(1);
need_tmp= 1;
}
if (make_aggr_tables_info())
DBUG_RETURN(1);
goto setup_subq_exit; goto setup_subq_exit;
} }
error= -1; // Error is sent to client error= -1; // Error is sent to client
...@@ -2135,7 +2126,17 @@ JOIN::optimize_inner() ...@@ -2135,7 +2126,17 @@ JOIN::optimize_inner()
setup_subq_exit: setup_subq_exit:
/* Choose an execution strategy for this JOIN. */ /* Choose an execution strategy for this JOIN. */
if (!tables_list || !table_count) if (!tables_list || !table_count)
{
choose_tableless_subquery_plan(); choose_tableless_subquery_plan();
if (select_lex->have_window_funcs())
{
if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB))))
DBUG_RETURN(1);
need_tmp= 1;
}
if (make_aggr_tables_info())
DBUG_RETURN(1);
}
/* /*
Even with zero matching rows, subqueries in the HAVING clause may Even with zero matching rows, subqueries in the HAVING clause may
need to be evaluated if there are aggregate functions in the query. need to be evaluated if there are aggregate functions in the query.
...@@ -2778,8 +2779,9 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields, ...@@ -2778,8 +2779,9 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
tmp_table_param.using_outer_summary_function= tmp_table_param.using_outer_summary_function=
tab->tmp_table_param->using_outer_summary_function; tab->tmp_table_param->using_outer_summary_function;
tab->join= this; tab->join= this;
DBUG_ASSERT(tab > tab->join->join_tab || !top_join_tab_count); DBUG_ASSERT(tab > tab->join->join_tab || !tables_list);
(tab - 1)->next_select= sub_select_postjoin_aggr; if (tables_list)
(tab - 1)->next_select= sub_select_postjoin_aggr;
tab->aggr= new (thd->mem_root) AGGR_OP(tab); tab->aggr= new (thd->mem_root) AGGR_OP(tab);
if (!tab->aggr) if (!tab->aggr)
goto err; goto err;
......
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