Commit 5eee8bbe authored by Igor Babaev's avatar Igor Babaev

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.
parent 21651541
...@@ -115,7 +115,7 @@ void Item_window_func::split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, ...@@ -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) 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); //curr->item_ptr->fix_fields(thd, curr->item);
Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE); 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) ...@@ -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) void Item_sum_rank::setup_window_func(THD *thd, Window_spec *window_spec)
{ {
/* TODO: move this into Item_window_func? */ /* 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); Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE);
orderby_fields.push_back(tmp); orderby_fields.push_back(tmp);
...@@ -139,7 +139,7 @@ void Item_sum_rank::setup_window_func(THD *thd, Window_spec *window_spec) ...@@ -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) void Item_sum_dense_rank::setup_window_func(THD *thd, Window_spec *window_spec)
{ {
/* TODO: consider moving this && Item_sum_rank's implementation */ /* 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); Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE);
orderby_fields.push_back(tmp); orderby_fields.push_back(tmp);
...@@ -198,7 +198,7 @@ bool Item_sum_percent_rank::add() ...@@ -198,7 +198,7 @@ bool Item_sum_percent_rank::add()
void Item_sum_percent_rank::setup_window_func(THD *thd, Window_spec *window_spec) void Item_sum_percent_rank::setup_window_func(THD *thd, Window_spec *window_spec)
{ {
/* TODO: move this into Item_window_func? */ /* 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); Cached_item *tmp= new_Cached_item(thd, curr->item[0], TRUE);
orderby_fields.push_back(tmp); orderby_fields.push_back(tmp);
......
...@@ -7837,10 +7837,16 @@ bool st_select_lex::add_window_def(THD *thd, ...@@ -7837,10 +7837,16 @@ bool st_select_lex::add_window_def(THD *thd,
SQL_I_List<ORDER> win_order_list, SQL_I_List<ORDER> win_order_list,
Window_frame *win_frame) 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, Window_def *win_def= new (thd->mem_root) Window_def(win_name,
win_ref, win_ref,
win_partition_list, win_part_list_ptr,
win_order_list, win_order_list_ptr,
win_frame); win_frame);
group_list= thd->lex->save_group_list; group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_list; order_list= thd->lex->save_order_list;
...@@ -7853,9 +7859,15 @@ bool st_select_lex::add_window_spec(THD *thd, ...@@ -7853,9 +7859,15 @@ bool st_select_lex::add_window_spec(THD *thd,
SQL_I_List<ORDER> win_order_list, SQL_I_List<ORDER> win_order_list,
Window_frame *win_frame) 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, Window_spec *win_spec= new (thd->mem_root) Window_spec(win_ref,
win_partition_list, win_part_list_ptr,
win_order_list, win_order_list_ptr,
win_frame); win_frame);
group_list= thd->lex->save_group_list; group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_list; order_list= thd->lex->save_order_list;
......
...@@ -25,13 +25,13 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it) ...@@ -25,13 +25,13 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it)
if (ref_name && if (ref_name &&
my_strcasecmp(system_charset_info, ref_name, win_spec_name) == 0) 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), my_error(ER_PARTITION_LIST_IN_REFERENCING_WINDOW_SPEC, MYF(0),
ref_name); ref_name);
return true; 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); my_error(ER_ORDER_LIST_IN_REFERENCING_WINDOW_SPEC, MYF(0), ref_name);
return true; return true;
...@@ -42,9 +42,9 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it) ...@@ -42,9 +42,9 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it)
return true; return true;
} }
referenced_win_spec= win_spec; referenced_win_spec= win_spec;
if (partition_list.elements == 0) if (partition_list->elements == 0)
partition_list= win_spec->partition_list; partition_list= win_spec->partition_list;
if (order_list.elements == 0) if (order_list->elements == 0)
order_list= win_spec->order_list; order_list= win_spec->order_list;
} }
} }
...@@ -109,9 +109,9 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, ...@@ -109,9 +109,9 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
bool hidden_group_fields; bool hidden_group_fields;
if (win_spec->check_window_names(itp) || if (win_spec->check_window_names(itp) ||
setup_group(thd, ref_pointer_array, tables, fields, all_fields, 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, 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 &&
win_spec->window_frame->check_frame_bounds())) win_spec->window_frame->check_frame_bounds()))
{ {
...@@ -1205,10 +1205,10 @@ bool compute_window_func_with_frames(Item_window_func *item_win, ...@@ -1205,10 +1205,10 @@ bool compute_window_func_with_frames(Item_window_func *item_win,
top_bound= get_frame_cursor(window_frame, true); top_bound= get_frame_cursor(window_frame, true);
bottom_bound= get_frame_cursor(window_frame, false); bottom_bound= get_frame_cursor(window_frame, false);
top_bound->init(thd, info, &item_win->window_spec->partition_list, top_bound->init(thd, info, item_win->window_spec->partition_list,
&item_win->window_spec->order_list); item_win->window_spec->order_list);
bottom_bound->init(thd, info, &item_win->window_spec->partition_list, bottom_bound->init(thd, info, item_win->window_spec->partition_list,
&item_win->window_spec->order_list); item_win->window_spec->order_list);
bool is_error= false; bool is_error= false;
longlong rownum= 0; longlong rownum= 0;
...@@ -1535,20 +1535,20 @@ bool JOIN::process_window_functions(List<Item> *curr_fields_list) ...@@ -1535,20 +1535,20 @@ bool JOIN::process_window_functions(List<Item> *curr_fields_list)
Connect the two lists for the duration of add_sorting_to_table() Connect the two lists for the duration of add_sorting_to_table()
call. call.
*/ */
DBUG_ASSERT(spec->partition_list.next[0] == NULL); DBUG_ASSERT(spec->partition_list->next[0] == NULL);
*(spec->partition_list.next)= spec->order_list.first; *(spec->partition_list->next)= spec->order_list->first;
/* /*
join_tab[top_join_tab_count].table is the temp. table where join join_tab[top_join_tab_count].table is the temp. table where join
output was stored. output was stored.
*/ */
add_sorting_to_table(&join_tab[top_join_tab_count], 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; join_tab[top_join_tab_count].used_for_window_func= true;
create_sort_index(this->thd, this, &join_tab[top_join_tab_count]); create_sort_index(this->thd, this, &join_tab[top_join_tab_count]);
/* Disconnect order_list from partition_list */ /* 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 Go through the sorted array and compute the window function
......
...@@ -88,17 +88,17 @@ class Window_spec : public Sql_alloc ...@@ -88,17 +88,17 @@ class Window_spec : public Sql_alloc
LEX_STRING *window_ref; 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_frame *window_frame;
Window_spec *referenced_win_spec; Window_spec *referenced_win_spec;
Window_spec(LEX_STRING *win_ref, Window_spec(LEX_STRING *win_ref,
SQL_I_List<ORDER> part_list, SQL_I_List<ORDER> *part_list,
SQL_I_List<ORDER> ord_list, SQL_I_List<ORDER> *ord_list,
Window_frame *win_frame) Window_frame *win_frame)
: window_ref(win_ref), partition_list(part_list), order_list(ord_list), : window_ref(win_ref), partition_list(part_list), order_list(ord_list),
window_frame(win_frame), referenced_win_spec(NULL) {} window_frame(win_frame), referenced_win_spec(NULL) {}
...@@ -107,7 +107,6 @@ class Window_spec : public Sql_alloc ...@@ -107,7 +107,6 @@ class Window_spec : public Sql_alloc
bool check_window_names(List_iterator_fast<Window_spec> &it); bool check_window_names(List_iterator_fast<Window_spec> &it);
char *window_reference() { return window_ref ? window_ref->str : NULL; } char *window_reference() { return window_ref ? window_ref->str : NULL; }
}; };
...@@ -119,8 +118,8 @@ class Window_def : public Window_spec ...@@ -119,8 +118,8 @@ class Window_def : public Window_spec
Window_def(LEX_STRING *win_name, Window_def(LEX_STRING *win_name,
LEX_STRING *win_ref, LEX_STRING *win_ref,
SQL_I_List<ORDER> part_list, SQL_I_List<ORDER> *part_list,
SQL_I_List<ORDER> ord_list, SQL_I_List<ORDER> *ord_list,
Window_frame *win_frame) Window_frame *win_frame)
: Window_spec(win_ref, part_list, ord_list, win_frame), : Window_spec(win_ref, part_list, ord_list, win_frame),
window_name(win_name) {} window_name(win_name) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment