diff options
author | Igor Babaev <igor@askmonty.org> | 2016-03-16 00:50:14 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2016-03-16 00:50:14 -0700 |
commit | 5eee8bbe87dbf61c1606ad5e44d9c3a1bb55b3e5 (patch) | |
tree | f622ea9dc4646e3452224d152aa68c5ce7febc75 | |
parent | 21651541ce0b2cc0e777988f1e35040b4badfce1 (diff) | |
download | mariadb-git-5eee8bbe87dbf61c1606ad5e44d9c3a1bb55b3e5.tar.gz |
The class Window_spec now has pointers to the partition and order lists
of the type SQL_I_List<ORDER> rather then the objects of this type.
It allows to replace easily one instance of such a list for another.
Besides it will facilitate to compare two lists if they originate from the
same window specification.
In fact any direct assignment for objects of the type SQL_I_List<ORDER>
was not valid.
-rw-r--r-- | sql/item_windowfunc.cc | 8 | ||||
-rw-r--r-- | sql/sql_parse.cc | 20 | ||||
-rw-r--r-- | sql/sql_window.cc | 32 | ||||
-rw-r--r-- | sql/sql_window.h | 13 |
4 files changed, 42 insertions, 31 deletions
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 027b0bdf0a1..aa100ff3f90 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -115,7 +115,7 @@ void Item_window_func::split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, void Item_window_func::setup_partition_border_check(THD *thd) { - for (ORDER *curr= window_spec->partition_list.first; curr; curr=curr->next) + for (ORDER *curr= window_spec->partition_list->first; curr; curr=curr->next) { //curr->item_ptr->fix_fields(thd, curr->item); Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE); @@ -128,7 +128,7 @@ void Item_window_func::setup_partition_border_check(THD *thd) void Item_sum_rank::setup_window_func(THD *thd, Window_spec *window_spec) { /* TODO: move this into Item_window_func? */ - for (ORDER *curr= window_spec->order_list.first; curr; curr=curr->next) + for (ORDER *curr= window_spec->order_list->first; curr; curr=curr->next) { Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE); orderby_fields.push_back(tmp); @@ -139,7 +139,7 @@ void Item_sum_rank::setup_window_func(THD *thd, Window_spec *window_spec) void Item_sum_dense_rank::setup_window_func(THD *thd, Window_spec *window_spec) { /* TODO: consider moving this && Item_sum_rank's implementation */ - for (ORDER *curr= window_spec->order_list.first; curr; curr=curr->next) + for (ORDER *curr= window_spec->order_list->first; curr; curr=curr->next) { Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE); orderby_fields.push_back(tmp); @@ -198,7 +198,7 @@ bool Item_sum_percent_rank::add() void Item_sum_percent_rank::setup_window_func(THD *thd, Window_spec *window_spec) { /* TODO: move this into Item_window_func? */ - for (ORDER *curr= window_spec->order_list.first; curr; curr=curr->next) + for (ORDER *curr= window_spec->order_list->first; curr; curr=curr->next) { Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE); orderby_fields.push_back(tmp); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 6bd1c9b639b..8f73087979f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7837,10 +7837,16 @@ bool st_select_lex::add_window_def(THD *thd, SQL_I_List<ORDER> win_order_list, Window_frame *win_frame) { + SQL_I_List<ORDER> *win_part_list_ptr= + new (thd->mem_root) SQL_I_List<ORDER> (win_partition_list); + SQL_I_List<ORDER> *win_order_list_ptr= + new (thd->mem_root) SQL_I_List<ORDER> (win_order_list); + if (!(win_part_list_ptr && win_order_list_ptr)) + return true; Window_def *win_def= new (thd->mem_root) Window_def(win_name, win_ref, - win_partition_list, - win_order_list, + win_part_list_ptr, + win_order_list_ptr, win_frame); group_list= thd->lex->save_group_list; order_list= thd->lex->save_order_list; @@ -7853,9 +7859,15 @@ bool st_select_lex::add_window_spec(THD *thd, SQL_I_List<ORDER> win_order_list, Window_frame *win_frame) { + SQL_I_List<ORDER> *win_part_list_ptr= + new (thd->mem_root) SQL_I_List<ORDER> (win_partition_list); + SQL_I_List<ORDER> *win_order_list_ptr= + new (thd->mem_root) SQL_I_List<ORDER> (win_order_list); + if (!(win_part_list_ptr && win_order_list_ptr)) + return true; Window_spec *win_spec= new (thd->mem_root) Window_spec(win_ref, - win_partition_list, - win_order_list, + win_part_list_ptr, + win_order_list_ptr, win_frame); group_list= thd->lex->save_group_list; order_list= thd->lex->save_order_list; diff --git a/sql/sql_window.cc b/sql/sql_window.cc index efdb5aa91a0..8c9b77b9392 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -25,13 +25,13 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it) if (ref_name && my_strcasecmp(system_charset_info, ref_name, win_spec_name) == 0) { - if (partition_list.elements) + if (partition_list->elements) { my_error(ER_PARTITION_LIST_IN_REFERENCING_WINDOW_SPEC, MYF(0), ref_name); return true; } - if (win_spec->order_list.elements && order_list.elements) + if (win_spec->order_list->elements && order_list->elements) { my_error(ER_ORDER_LIST_IN_REFERENCING_WINDOW_SPEC, MYF(0), ref_name); return true; @@ -42,9 +42,9 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it) return true; } referenced_win_spec= win_spec; - if (partition_list.elements == 0) + if (partition_list->elements == 0) partition_list= win_spec->partition_list; - if (order_list.elements == 0) + if (order_list->elements == 0) order_list= win_spec->order_list; } } @@ -109,9 +109,9 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, bool hidden_group_fields; if (win_spec->check_window_names(itp) || setup_group(thd, ref_pointer_array, tables, fields, all_fields, - win_spec->partition_list.first, &hidden_group_fields) || + win_spec->partition_list->first, &hidden_group_fields) || setup_order(thd, ref_pointer_array, tables, fields, all_fields, - win_spec->order_list.first) || + win_spec->order_list->first) || (win_spec->window_frame && win_spec->window_frame->check_frame_bounds())) { @@ -1205,10 +1205,10 @@ bool compute_window_func_with_frames(Item_window_func *item_win, top_bound= get_frame_cursor(window_frame, true); bottom_bound= get_frame_cursor(window_frame, false); - top_bound->init(thd, info, &item_win->window_spec->partition_list, - &item_win->window_spec->order_list); - bottom_bound->init(thd, info, &item_win->window_spec->partition_list, - &item_win->window_spec->order_list); + top_bound->init(thd, info, item_win->window_spec->partition_list, + item_win->window_spec->order_list); + bottom_bound->init(thd, info, item_win->window_spec->partition_list, + item_win->window_spec->order_list); bool is_error= false; longlong rownum= 0; @@ -1535,22 +1535,22 @@ bool JOIN::process_window_functions(List<Item> *curr_fields_list) Connect the two lists for the duration of add_sorting_to_table() call. */ - DBUG_ASSERT(spec->partition_list.next[0] == NULL); - *(spec->partition_list.next)= spec->order_list.first; + DBUG_ASSERT(spec->partition_list->next[0] == NULL); + *(spec->partition_list->next)= spec->order_list->first; /* join_tab[top_join_tab_count].table is the temp. table where join output was stored. */ add_sorting_to_table(&join_tab[top_join_tab_count], - spec->partition_list.first); + spec->partition_list->first); join_tab[top_join_tab_count].used_for_window_func= true; create_sort_index(this->thd, this, &join_tab[top_join_tab_count]); /* Disconnect order_list from partition_list */ - *(spec->partition_list.next)= NULL; - - /* + *(spec->partition_list->next)= NULL; + + /* Go through the sorted array and compute the window function */ READ_RECORD info; diff --git a/sql/sql_window.h b/sql/sql_window.h index 555150248dc..18229eb04bc 100644 --- a/sql/sql_window.h +++ b/sql/sql_window.h @@ -88,17 +88,17 @@ class Window_spec : public Sql_alloc LEX_STRING *window_ref; - SQL_I_List<ORDER> partition_list; + SQL_I_List<ORDER> *partition_list; - SQL_I_List<ORDER> order_list; + SQL_I_List<ORDER> *order_list; Window_frame *window_frame; Window_spec *referenced_win_spec; Window_spec(LEX_STRING *win_ref, - SQL_I_List<ORDER> part_list, - SQL_I_List<ORDER> ord_list, + SQL_I_List<ORDER> *part_list, + SQL_I_List<ORDER> *ord_list, Window_frame *win_frame) : window_ref(win_ref), partition_list(part_list), order_list(ord_list), window_frame(win_frame), referenced_win_spec(NULL) {} @@ -107,7 +107,6 @@ class Window_spec : public Sql_alloc bool check_window_names(List_iterator_fast<Window_spec> &it); - char *window_reference() { return window_ref ? window_ref->str : NULL; } }; @@ -119,8 +118,8 @@ class Window_def : public Window_spec Window_def(LEX_STRING *win_name, LEX_STRING *win_ref, - SQL_I_List<ORDER> part_list, - SQL_I_List<ORDER> ord_list, + SQL_I_List<ORDER> *part_list, + SQL_I_List<ORDER> *ord_list, Window_frame *win_frame) : Window_spec(win_ref, part_list, ord_list, win_frame), window_name(win_name) {} |