diff --git a/sql/item_sum.cc b/sql/item_sum.cc index fd35ab027e1..fecf083e8ef 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2960,11 +2960,12 @@ int dump_leaf_key(uchar* key, element_count count __attribute__((unused)), Item_func_group_concat:: Item_func_group_concat(Name_resolution_context *context_arg, bool distinct_arg, List *select_list, - SQL_I_List *order_list, String *separator_arg) + const SQL_I_List &order_list, + String *separator_arg) :tmp_table_param(0), warning(0), separator(separator_arg), tree(0), unique_filter(NULL), table(0), order(0), context(context_arg), - arg_count_order(order_list ? order_list->elements : 0), + arg_count_order(order_list.elements), arg_count_field(select_list->elements), count_cut_values(0), distinct(distinct_arg), @@ -3004,7 +3005,7 @@ Item_func_group_concat(Name_resolution_context *context_arg, if (arg_count_order) { ORDER **order_ptr= order; - for (ORDER *order_item= order_list->first; + for (ORDER *order_item= order_list.first; order_item != NULL; order_item= order_item->next) { diff --git a/sql/item_sum.h b/sql/item_sum.h index 418899e61aa..6f8660e5491 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights + * reserved. 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 @@ -1222,7 +1223,7 @@ class Item_func_group_concat : public Item_sum public: Item_func_group_concat(Name_resolution_context *context_arg, bool is_distinct, List *is_select, - SQL_I_List *is_order, String *is_separator); + const SQL_I_List &is_order, String *is_separator); Item_func_group_concat(THD *thd, Item_func_group_concat *item); ~Item_func_group_concat(); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index f0a5d806d10..fad00ff0a17 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -2427,6 +2427,11 @@ inline bool add_order_to_list(THD *thd, Item *item, bool asc) return thd->lex->current_select->add_order_to_list(thd, item, asc); } +inline bool add_gorder_to_list(THD *thd, Item *item, bool asc) +{ + return thd->lex->current_select->add_gorder_to_list(thd, item, asc); +} + inline bool add_group_to_list(THD *thd, Item *item, bool asc) { return thd->lex->current_select->add_group_to_list(thd, item, asc); diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 78f0317b3fc..1305b608225 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2013 Oracle and/or its affiliates. All rights reserved. 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 @@ -1920,6 +1920,11 @@ bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc) } +bool st_select_lex::add_gorder_to_list(THD *thd, Item *item, bool asc) +{ + return add_to_list(thd, gorder_list, item, asc); +} + bool st_select_lex::add_item_to_list(THD *thd, Item *item) { DBUG_ENTER("st_select_lex::add_item_to_list"); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 0a054ced98a..2036707312a 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -628,7 +628,7 @@ public: const char *type; /* type of select for EXPLAIN */ SQL_I_List order_list; /* ORDER clause */ - SQL_I_List *gorder_list; + SQL_I_List gorder_list; Item *select_limit, *offset_limit; /* LIMIT clause parameters */ // Arrays of pointers to top elements of all_fields list Item **ref_pointer_array; @@ -763,6 +763,7 @@ public: bool add_group_to_list(THD *thd, Item *item, bool asc); bool add_ftfunc_to_list(Item_func_match *func); bool add_order_to_list(THD *thd, Item *item, bool asc); + bool add_gorder_to_list(THD *thd, Item *item, bool asc); TABLE_LIST* add_table_to_list(THD *thd, Table_ident *table, LEX_STRING *alias, ulong table_options, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 64a7dd10058..29516d34855 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -8334,6 +8334,7 @@ sum_expr: if ($$ == NULL) MYSQL_YYABORT; $5->empty(); + sel->gorder_list.empty(); } ; @@ -8403,18 +8404,27 @@ opt_gconcat_separator: opt_gorder_clause: /* empty */ + | ORDER_SYM BY { - Select->gorder_list = NULL; - } - | order_clause - { - SELECT_LEX *select= Select; - select->gorder_list= new (YYTHD->mem_root) - SQL_I_List(select->order_list); - if (select->gorder_list == NULL) + LEX *lex= Lex; + SELECT_LEX *sel= lex->current_select; + if (sel->linkage != GLOBAL_OPTIONS_TYPE && + sel->olap != UNSPECIFIED_OLAP_TYPE && + (sel->linkage != UNION_TYPE || sel->braces)) + { + my_error(ER_WRONG_USAGE, MYF(0), + "CUBE/ROLLUP", "ORDER BY"); MYSQL_YYABORT; - select->order_list.empty(); + } } + gorder_list; + ; + +gorder_list: + gorder_list ',' order_ident order_dir + { if (add_gorder_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; } + | order_ident order_dir + { if (add_gorder_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; } ; in_sum_expr: