diff options
-rw-r--r-- | mysql-test/r/win.result | 13 | ||||
-rw-r--r-- | mysql-test/t/win.test | 15 | ||||
-rw-r--r-- | sql/item_sum.cc | 4 | ||||
-rw-r--r-- | sql/item_windowfunc.cc | 6 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 3 |
5 files changed, 37 insertions, 4 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 018dba8ad50..394d9b852bb 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3880,5 +3880,18 @@ a sum(a) bit_or(a) OVER (ORDER BY b) NULL NULL 0 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 # diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 602fedad6ea..cda5499e749 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2534,5 +2534,20 @@ SELECT a, sum(a), bit_or(a) OVER (ORDER BY b) FROM 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 # End of 10.2 tests --echo # diff --git a/sql/item_sum.cc b/sql/item_sum.cc index e50822e71f2..9f68a89a7c8 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -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 */ in_sum_func= thd->lex->in_sum_func; /* Save a pointer to object to be used in items for nested set functions */ - thd->lex->in_sum_func= this; + if (!window_func_sum_expr_flag) + thd->lex->in_sum_func= this; + nest_level= thd->lex->current_select->nest_level; ref_by= 0; aggr_level= -1; diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index bb4a8a9f3af..1c97c4cb6d8 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -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()); 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 decides to substitute itself for something else and does *ref=.... ? diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 386c86cb3e2..ddff82ea4ba 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -10497,9 +10497,6 @@ window_func: simple_window_func | sum_expr - { - ((Item_sum *) $1)->mark_as_window_func_sum_expr(); - } ; simple_window_func: |