Commit b0df247d authored by Varun Gupta's avatar Varun Gupta

MDEV-22463: Element_type &Bounds_checked_array<Item *>::operator[](size_t)...

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.
parent 0994af43
...@@ -3808,5 +3808,40 @@ MIN(d) OVER () ...@@ -3808,5 +3808,40 @@ MIN(d) OVER ()
1 1
DROP TABLE t1; 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 # End of 10.2 tests
# #
# #
# Window Functions Tests # Window Functions Tests
# #
--source include/have_sequence.inc
--disable_warnings --disable_warnings
drop table if exists t1,t2; drop table if exists t1,t2;
...@@ -2481,6 +2482,21 @@ INSERT INTO t1 VALUES (1),(2); ...@@ -2481,6 +2482,21 @@ INSERT INTO t1 VALUES (1),(2);
SELECT MIN(d) OVER () FROM t1; SELECT MIN(d) OVER () FROM t1;
DROP TABLE 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 #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --echo #
...@@ -2140,6 +2140,7 @@ void st_select_lex::init_query() ...@@ -2140,6 +2140,7 @@ void st_select_lex::init_query()
n_sum_items= 0; n_sum_items= 0;
n_child_sum_items= 0; n_child_sum_items= 0;
hidden_bit_fields= 0; hidden_bit_fields= 0;
fields_in_window_functions= 0;
subquery_in_having= explicit_limit= 0; subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0; is_item_list_lookup= 0;
changed_elements= 0; changed_elements= 0;
...@@ -2707,7 +2708,8 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num) ...@@ -2707,7 +2708,8 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
select_n_having_items + select_n_having_items +
select_n_where_fields + select_n_where_fields +
order_group_num + order_group_num +
hidden_bit_fields) * 5; hidden_bit_fields +
fields_in_window_functions) * 5;
if (!ref_pointer_array.is_null()) if (!ref_pointer_array.is_null())
{ {
/* /*
......
...@@ -871,6 +871,14 @@ class st_select_lex: public st_select_lex_node ...@@ -871,6 +871,14 @@ class st_select_lex: public st_select_lex_node
converted to a GROUP BY involving BIT fields. converted to a GROUP BY involving BIT fields.
*/ */
uint hidden_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 parsing_place; /* where we are parsing expression */
enum_parsing_place context_analysis_place; /* where we are in prepare */ enum_parsing_place context_analysis_place; /* where we are in prepare */
bool with_sum_func; /* sum function indicator */ bool with_sum_func; /* sum function indicator */
...@@ -1180,10 +1188,7 @@ class st_select_lex: public st_select_lex_node ...@@ -1180,10 +1188,7 @@ class st_select_lex: public st_select_lex_node
SQL_I_List<ORDER> win_order_list, SQL_I_List<ORDER> win_order_list,
Window_frame *win_frame); Window_frame *win_frame);
List<Item_window_func> window_funcs; List<Item_window_func> window_funcs;
bool add_window_func(Item_window_func *win_func) bool add_window_func(Item_window_func *win_func);
{
return window_funcs.push_back(win_func);
}
bool have_window_funcs() const { return (window_funcs.elements !=0); } bool have_window_funcs() const { return (window_funcs.elements !=0); }
......
...@@ -8556,6 +8556,11 @@ bool st_select_lex::add_window_def(THD *thd, ...@@ -8556,6 +8556,11 @@ bool st_select_lex::add_window_def(THD *thd,
win_frame); win_frame);
group_list= thd->lex->save_group_list; group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_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)); return (win_def == NULL || window_specs.push_back(win_def));
} }
...@@ -8577,6 +8582,11 @@ bool st_select_lex::add_window_spec(THD *thd, ...@@ -8577,6 +8582,11 @@ bool st_select_lex::add_window_spec(THD *thd,
win_frame); win_frame);
group_list= thd->lex->save_group_list; group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_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; thd->lex->win_spec= win_spec;
return (win_spec == NULL || window_specs.push_back(win_spec)); return (win_spec == NULL || window_specs.push_back(win_spec));
} }
......
...@@ -2969,6 +2969,14 @@ Window_funcs_computation::save_explain_plan(MEM_ROOT *mem_root, ...@@ -2969,6 +2969,14 @@ Window_funcs_computation::save_explain_plan(MEM_ROOT *mem_root,
return xpl; 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 // Unneeded comments (will be removed when we develop a replacement for
// the feature that was attempted here // the feature that was attempted here
......
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