diff options
-rw-r--r-- | sql/item_sum.cc | 7 | ||||
-rw-r--r-- | sql/item_sum.h | 5 | ||||
-rw-r--r-- | sql/sql_class.h | 5 | ||||
-rw-r--r-- | sql/sql_lex.cc | 8 | ||||
-rw-r--r-- | sql/sql_lex.h | 6 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 28 |
6 files changed, 42 insertions, 17 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 1f7a8a1c423..e194907fa06 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -3009,11 +3009,12 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)), Item_func_group_concat:: Item_func_group_concat(Name_resolution_context *context_arg, bool distinct_arg, List<Item> *select_list, - SQL_I_List<ORDER> *order_list, String *separator_arg) + const SQL_I_List<ORDER> &order_list, + String *separator_arg) :tmp_table_param(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), row_count(0), distinct(distinct_arg), @@ -3053,7 +3054,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 a0b54b0ec8a..edcdb5a4d1e 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1,7 +1,8 @@ #ifndef ITEM_SUM_INCLUDED #define ITEM_SUM_INCLUDED -/* 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 @@ -1402,7 +1403,7 @@ class Item_func_group_concat : public Item_sum public: Item_func_group_concat(Name_resolution_context *context_arg, bool is_distinct, List<Item> *is_select, - SQL_I_List<ORDER> *is_order, String *is_separator); + const SQL_I_List<ORDER> &is_order, String *is_separator); Item_func_group_concat(THD *thd, Item_func_group_concat *item); ~Item_func_group_concat(); diff --git a/sql/sql_class.h b/sql/sql_class.h index 99420ed0dd8..093758ce389 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3673,6 +3673,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 b013a4219f2..3c9e6955151 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2013, 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 @@ -2066,6 +2067,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 3be4c4111d4..e4fd6f42a48 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2013, 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 @@ -727,7 +728,7 @@ public: const char *type; /* type of select for EXPLAIN */ SQL_I_List<ORDER> order_list; /* ORDER clause */ - SQL_I_List<ORDER> *gorder_list; + SQL_I_List<ORDER> gorder_list; Item *select_limit, *offset_limit; /* LIMIT clause parameters */ // Arrays of pointers to top elements of all_fields list Item **ref_pointer_array; @@ -850,6 +851,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 dc4aadea33a..a1c0fdf08cb 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -8981,6 +8981,7 @@ sum_expr: if ($$ == NULL) MYSQL_YYABORT; $5->empty(); + sel->gorder_list.empty(); } ; @@ -9050,18 +9051,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<ORDER>(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: |