Skip to content

Commit

Permalink
MDEV-32259 Test from win.test fails with statement memory protection
Browse files Browse the repository at this point in the history
The function setup_windows() called at the prepare phase of processing a
select builds a list of all window specifications used in the select. This list
is built on the statement memory and it must be done only once.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
  • Loading branch information
igorbabaev committed Sep 27, 2023
1 parent b0763f5 commit 4e25947
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions sql/sql_lex.cc
Expand Up @@ -2441,6 +2441,7 @@ void st_select_lex::init_query()
m_custom_agg_func_used= false;
window_specs.empty();
window_funcs.empty();
is_win_spec_list_built= false;
tvc= 0;
in_tvc= false;
versioned_tables= 0;
Expand Down
1 change: 1 addition & 0 deletions sql/sql_lex.h
Expand Up @@ -1530,6 +1530,7 @@ class st_select_lex: public st_select_lex_node
bool no_to_clones);

List<Window_spec> window_specs;
bool is_win_spec_list_built;
void prepare_add_window_spec(THD *thd);
bool add_window_def(THD *thd, LEX_CSTRING *win_name, LEX_CSTRING *win_ref,
SQL_I_List<ORDER> win_partition_list,
Expand Down
40 changes: 23 additions & 17 deletions sql/sql_window.cc
Expand Up @@ -207,27 +207,33 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
DBUG_ENTER("setup_windows");
List_iterator<Window_spec> it(win_specs);

/*
Move all unnamed specifications after the named ones.
We could have avoided it if we had built two separate lists for
named and unnamed specifications.
*/
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
uint i = 0;
uint elems= win_specs.elements;
while ((win_spec= it++) && i++ < elems)
if (!thd->lex->current_select->is_win_spec_list_built)
{
if (win_spec->name() == NULL)

/*
Move all unnamed specifications after the named ones.
We could have avoided it if we had built two separate lists for
named and unnamed specifications.
*/
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
uint i = 0;
uint elems= win_specs.elements;
while ((win_spec= it++) && i++ < elems)
{
it.remove();
win_specs.push_back(win_spec);
if (win_spec->name() == NULL)
{
it.remove();
win_specs.push_back(win_spec);
}
}
}
if (arena)
thd->restore_active_arena(arena, &backup);
if (arena)
thd->restore_active_arena(arena, &backup);

it.rewind();
it.rewind();

thd->lex->current_select->is_win_spec_list_built= true;
}

List_iterator_fast<Window_spec> itp(win_specs);

Expand Down

0 comments on commit 4e25947

Please sign in to comment.