summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-07-09 14:01:06 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-07-10 00:01:24 +0530
commit737c3025e9ed55855ee66806ad14e9e7e7852fa7 (patch)
tree1798ffb7d1a2229f28e32089b76286139ad2d32d /sql/sql_select.cc
parenta759f9af51b2093502d3a06c0150e9aa7fc21068 (diff)
downloadmariadb-git-737c3025e9ed55855ee66806ad14e9e7e7852fa7.tar.gz
MDEV-10120: Wrong result of UNION .. ORDER BY GROUP_CONCAT()
Reject queries that have aggregate functions with UNION as these are not allowed by standard.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 4cca2d67eb8..c33e554aaca 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -22709,10 +22709,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_union() &&
+ 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))
@@ -22723,6 +22726,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,