MDEV-22463: Element_type &Bounds_checked_array<Item *>::operator[](size_t) [Element_type = Item *]: Assertion `n < m_size' failed.

Allocate space for fields inside the window function (arguments, PARTITION BY and ORDER BY clause)
in the ref pointer array. All fields inside the window function are part of the temporary
table that is required for the window function computation.
This commit is contained in:
Varun Gupta 2020-07-10 10:45:04 +05:30
parent 0994af43e5
commit b0df247db6
6 changed files with 81 additions and 5 deletions

View file

@ -3808,5 +3808,40 @@ MIN(d) OVER ()
1
DROP TABLE t1;
#
# MDEV-22463: Element_type &Bounds_checked_array<Item *>::operator[](size_t) [Element_type = Item *]:
# Assertion `n < m_size' failed
#
CREATE TABLE t1 (a INT, b INT, c INT, d INT, e INT, f INT, g int, h INT, i INT);
INSERT INTO t1 SELECT seq,seq,seq,seq, seq,seq,seq,seq,seq FROM seq_1_to_5;
SELECT ROW_NUMBER() OVER w2 FROM t1 WINDOW w2 AS (PARTITION BY -1,0,1,2,3,4,5,6);
ROW_NUMBER() OVER w2
1
2
3
4
5
SELECT a FROM t1 ORDER BY ROW_NUMBER() OVER (PARTITION BY -1,1,0,2,3,4,5,6,7,8);
a
1
2
3
4
5
SELECT a,b FROM t1 WINDOW w2 AS (PARTITION BY -1,1,0,2,3,4);
a b
1 1
2 2
3 3
4 4
5 5
SELECT ROW_NUMBER() OVER w2 FROM t1 WINDOW w2 AS (PARTITION BY -1,0,1,2,3,4,5,6);
ROW_NUMBER() OVER w2
1
2
3
4
5
DROP TABLE t1;
#
# End of 10.2 tests
#

View file

@ -1,6 +1,7 @@
#
# Window Functions Tests
#
--source include/have_sequence.inc
--disable_warnings
drop table if exists t1,t2;
@ -2481,6 +2482,21 @@ INSERT INTO t1 VALUES (1),(2);
SELECT MIN(d) OVER () FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-22463: Element_type &Bounds_checked_array<Item *>::operator[](size_t) [Element_type = Item *]:
--echo # Assertion `n < m_size' failed
--echo #
CREATE TABLE t1 (a INT, b INT, c INT, d INT, e INT, f INT, g int, h INT, i INT);
INSERT INTO t1 SELECT seq,seq,seq,seq, seq,seq,seq,seq,seq FROM seq_1_to_5;
SELECT ROW_NUMBER() OVER w2 FROM t1 WINDOW w2 AS (PARTITION BY -1,0,1,2,3,4,5,6);
--sorted_result
SELECT a FROM t1 ORDER BY ROW_NUMBER() OVER (PARTITION BY -1,1,0,2,3,4,5,6,7,8);
SELECT a,b FROM t1 WINDOW w2 AS (PARTITION BY -1,1,0,2,3,4);
SELECT ROW_NUMBER() OVER w2 FROM t1 WINDOW w2 AS (PARTITION BY -1,0,1,2,3,4,5,6);
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #

View file

@ -2140,6 +2140,7 @@ void st_select_lex::init_query()
n_sum_items= 0;
n_child_sum_items= 0;
hidden_bit_fields= 0;
fields_in_window_functions= 0;
subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0;
changed_elements= 0;
@ -2707,7 +2708,8 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
select_n_having_items +
select_n_where_fields +
order_group_num +
hidden_bit_fields) * 5;
hidden_bit_fields +
fields_in_window_functions) * 5;
if (!ref_pointer_array.is_null())
{
/*

View file

@ -871,6 +871,14 @@ public:
converted to a GROUP BY involving BIT fields.
*/
uint hidden_bit_fields;
/*
Number of fields used in the definition of all the windows functions.
This includes:
1) Fields in the arguments
2) Fields in the PARTITION BY clause
3) Fields in the ORDER BY clause
*/
uint fields_in_window_functions;
enum_parsing_place parsing_place; /* where we are parsing expression */
enum_parsing_place context_analysis_place; /* where we are in prepare */
bool with_sum_func; /* sum function indicator */
@ -1180,10 +1188,7 @@ public:
SQL_I_List<ORDER> win_order_list,
Window_frame *win_frame);
List<Item_window_func> window_funcs;
bool add_window_func(Item_window_func *win_func)
{
return window_funcs.push_back(win_func);
}
bool add_window_func(Item_window_func *win_func);
bool have_window_funcs() const { return (window_funcs.elements !=0); }

View file

@ -8556,6 +8556,11 @@ bool st_select_lex::add_window_def(THD *thd,
win_frame);
group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_list;
if (parsing_place != SELECT_LIST)
{
fields_in_window_functions+= win_part_list_ptr->elements +
win_order_list_ptr->elements;
}
return (win_def == NULL || window_specs.push_back(win_def));
}
@ -8577,6 +8582,11 @@ bool st_select_lex::add_window_spec(THD *thd,
win_frame);
group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_list;
if (parsing_place != SELECT_LIST)
{
fields_in_window_functions+= win_part_list_ptr->elements +
win_order_list_ptr->elements;
}
thd->lex->win_spec= win_spec;
return (win_spec == NULL || window_specs.push_back(win_spec));
}

View file

@ -2969,6 +2969,14 @@ Window_funcs_computation::save_explain_plan(MEM_ROOT *mem_root,
return xpl;
}
bool st_select_lex::add_window_func(Item_window_func *win_func)
{
if (parsing_place != SELECT_LIST)
fields_in_window_functions+= win_func->window_func()->argument_count();
return window_funcs.push_back(win_func);
}
/////////////////////////////////////////////////////////////////////////////
// Unneeded comments (will be removed when we develop a replacement for
// the feature that was attempted here