Commit 696edd9e authored by Varun Gupta's avatar Varun Gupta

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

MDEV-23438: Assertion `!field->is_null()' failed in my_decimal::my_decimal fails in ONLY_FULL_GROUP_BY mode

The issue here is query with aggregate function and non-aggregate field
in the SELECT LIST with ONLY_FULL_GROUP_BY was not disallowed.
In ONLY_FULL_GROUP_BY mode non-aggregate fields are only allowed inside an
aggregate functions or the non-aggregate fields are part of the GROUP BY clause.

In the query for the failing assert the non-aggregate field was inside
a WINDOW function and the window function was treated as an aggregate function
and so no error was thrown.

The fix would be to make sure to mark that a non-aggregate field is used inside a
window function and not an aggregate function and throw an error then.
parent c6686d2c
...@@ -3880,5 +3880,18 @@ a sum(a) bit_or(a) OVER (ORDER BY b) ...@@ -3880,5 +3880,18 @@ a sum(a) bit_or(a) OVER (ORDER BY b)
NULL NULL 0 NULL NULL 0
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-23438: Assertion `!field->is_null()' failed in my_decimal::my_decimal fails
# in ONLY_FULL_GROUP_BY mode
#
CREATE TABLE t1(a INT, b DECIMAL(10, 0) NOT NULL);
SET @save_sql_mode= @@sql_mode;
SET sql_mode='ONLY_FULL_GROUP_BY';
SELECT a, sum(a), bit_or(a) OVER (ORDER BY b) FROM t1;
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
SELECT sum(a), last_value(b) OVER () FROM t1;
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
SET sql_mode= @save_sql_mode;
DROP TABLE t1;
#
# End of 10.2 tests # End of 10.2 tests
# #
...@@ -2533,6 +2533,21 @@ SELECT a, bit_or(a) OVER (ORDER BY b) FROM t1; ...@@ -2533,6 +2533,21 @@ SELECT a, bit_or(a) OVER (ORDER BY b) FROM t1;
SELECT a, sum(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; DROP TABLE t1;
--echo #
--echo # MDEV-23438: Assertion `!field->is_null()' failed in my_decimal::my_decimal fails
--echo # in ONLY_FULL_GROUP_BY mode
--echo #
CREATE TABLE t1(a INT, b DECIMAL(10, 0) NOT NULL);
SET @save_sql_mode= @@sql_mode;
SET sql_mode='ONLY_FULL_GROUP_BY';
--error ER_MIX_OF_GROUP_FUNC_AND_FIELDS
SELECT a, sum(a), bit_or(a) OVER (ORDER BY b) FROM t1;
--error ER_MIX_OF_GROUP_FUNC_AND_FIELDS
SELECT sum(a), last_value(b) OVER () FROM t1;
SET sql_mode= @save_sql_mode;
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --echo #
...@@ -84,7 +84,9 @@ bool Item_sum::init_sum_func_check(THD *thd) ...@@ -84,7 +84,9 @@ bool Item_sum::init_sum_func_check(THD *thd)
/* Set a reference to the nesting set function if there is any */ /* Set a reference to the nesting set function if there is any */
in_sum_func= thd->lex->in_sum_func; in_sum_func= thd->lex->in_sum_func;
/* Save a pointer to object to be used in items for nested set functions */ /* Save a pointer to object to be used in items for nested set functions */
if (!window_func_sum_expr_flag)
thd->lex->in_sum_func= this; thd->lex->in_sum_func= this;
nest_level= thd->lex->current_select->nest_level; nest_level= thd->lex->current_select->nest_level;
ref_by= 0; ref_by= 0;
aggr_level= -1; aggr_level= -1;
......
...@@ -93,6 +93,12 @@ Item_window_func::fix_fields(THD *thd, Item **ref) ...@@ -93,6 +93,12 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
my_error(ER_NO_ORDER_LIST_IN_WINDOW_SPEC, MYF(0), window_func()->func_name()); my_error(ER_NO_ORDER_LIST_IN_WINDOW_SPEC, MYF(0), window_func()->func_name());
return true; return true;
} }
/*
Mark that Item_sum is used as a window function
*/
window_func()->mark_as_window_func_sum_expr();
/* /*
TODO: why the last parameter is 'ref' in this call? What if window_func TODO: why the last parameter is 'ref' in this call? What if window_func
decides to substitute itself for something else and does *ref=.... ? decides to substitute itself for something else and does *ref=.... ?
......
...@@ -10497,9 +10497,6 @@ window_func: ...@@ -10497,9 +10497,6 @@ window_func:
simple_window_func simple_window_func
| |
sum_expr sum_expr
{
((Item_sum *) $1)->mark_as_window_func_sum_expr();
}
; ;
simple_window_func: simple_window_func:
......
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