Commit c6686d2c authored by Varun Gupta's avatar Varun Gupta

MDEV-22702: Assertion `!field->is_null()' failed in my_decimal::my_decimal

With implicit grouping with window functions, we need to make sure that all the
fields inside the window functions are nullable as any non-aggregated field can
produce a NULL value.
parent 845e3c98
......@@ -3866,5 +3866,19 @@ NULL
DROP VIEW v1;
DROP TABLE t1,t2;
#
# MDEV-22702: Assertion `!field->is_null()' failed in my_decimal::my_decimal
#
CREATE TABLE t1(a INT, b DECIMAL(10, 0) NOT NULL);
SELECT a, bit_or(min(a)) OVER (ORDER BY b) FROM t1;
a bit_or(min(a)) OVER (ORDER BY b)
NULL 0
# No implicit grouping here
SELECT a, bit_or(a) OVER (ORDER BY b) FROM t1;
a bit_or(a) OVER (ORDER BY b)
SELECT a, sum(a), bit_or(a) OVER (ORDER BY b) FROM t1;
a sum(a) bit_or(a) OVER (ORDER BY b)
NULL NULL 0
DROP TABLE t1;
#
# End of 10.2 tests
#
......@@ -2522,6 +2522,17 @@ SELECT NTH_VALUE(i1, i1) OVER (PARTITION BY i1) FROM v1;
DROP VIEW v1;
DROP TABLE t1,t2;
--echo #
--echo # MDEV-22702: Assertion `!field->is_null()' failed in my_decimal::my_decimal
--echo #
CREATE TABLE t1(a INT, b DECIMAL(10, 0) NOT NULL);
SELECT a, bit_or(min(a)) OVER (ORDER BY b) FROM t1;
--echo # No implicit grouping here
SELECT a, bit_or(a) OVER (ORDER BY b) FROM t1;
SELECT a, sum(a), bit_or(a) OVER (ORDER BY b) FROM t1;
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -1191,6 +1191,8 @@ class st_select_lex: public st_select_lex_node
bool add_window_func(Item_window_func *win_func);
bool have_window_funcs() const { return (window_funcs.elements !=0); }
uint get_number_of_window_funcs() const
{ return window_funcs.elements; }
bool cond_pushdown_is_allowed() const
{ return !have_window_funcs() && !olap && !explicit_limit; }
......
......@@ -770,6 +770,31 @@ JOIN::prepare(TABLE_LIST *tables_init,
break;
}
}
/*
If the query has a window function with an aggregate function,
then we have a mix of elements with and without grouping.
Window function can be present in the SELECT LIST and the ORDER BY clause
so a separate check is made here (above we just iterate over the
SELECT LIST).
Window function is inherited from Item_sum class which means
each window function is registered as a sum item,
so a check needs to be any of the sum items are aggregate functions
or not.
Example:
(1) SELECT a, sum(a), row_number() OVER (ORDER BY b) :=> sum_items= 2
(2) SELECT a, sum(a) OVER (ORDER BY b) :=> sum_items= 1
In example (1) we have an aggregate function and a window function
In example (2) we have a window function (SUM function is used as
a window function here)
*/
if (select_lex->have_window_funcs() &&
select_lex->get_number_of_window_funcs() < select_lex->n_sum_items)
mixed_implicit_grouping= true;
}
table_count= select_lex->leaf_tables.elements;
......
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