summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-07-14 17:13:37 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-07-14 22:59:19 +0300
commit8a0944080c950349aaf7c81bc8f8c63b262f98eb (patch)
tree660faff324d2f66e57e2800155196739bf972dc1 /sql/sql_select.cc
parentf3f23b5c4bdc669ad0af4a1c79bd70c40ed9c594 (diff)
parent07e89bf7d15ba9e9a3b21d087c20d687446b2ff7 (diff)
downloadmariadb-git-8a0944080c950349aaf7c81bc8f8c63b262f98eb.tar.gz
Merge 10.2 into 10.3
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 9f5a406507c..b34e6f1fc2e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2009, 2019, MariaDB Corporation.
+ Copyright (c) 2009, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23565,10 +23565,13 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List<Item> &all_fields, ORDER *order,
bool from_window_spec)
{
+ SELECT_LEX *select = thd->lex->current_select;
enum_parsing_place context_analysis_place=
thd->lex->current_select->context_analysis_place;
thd->where="order clause";
- for (; order; order=order->next)
+ const bool for_union= select->master_unit()->is_unit_op() &&
+ select == select->master_unit()->fake_select_lex;
+ for (uint number = 1; order; order=order->next, number++)
{
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
all_fields, false, true, from_window_spec))
@@ -23579,6 +23582,18 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
return 1;
}
+
+ /*
+ UNION queries cannot be used with an aggregate function in
+ an ORDER BY clause
+ */
+
+ if (for_union && (*order->item)->with_sum_func)
+ {
+ my_error(ER_AGGREGATE_ORDER_FOR_UNION, MYF(0), number);
+ return 1;
+ }
+
if (from_window_spec && (*order->item)->with_sum_func &&
(*order->item)->type() != Item::SUM_FUNC_ITEM)
(*order->item)->split_sum_func(thd, ref_pointer_array,