Skip to content

Commit 39d3cdb

Browse files
committed
Encapsulate the switching between different return values in Item_window_func
1 parent 722f1b2 commit 39d3cdb

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

sql/item_windowfunc.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
112112
maybe_null= window_func()->maybe_null;
113113

114114
fixed= 1;
115-
force_return_blank= true;
116-
read_value_from_result_field= false;
115+
set_phase_to_initial();
117116
return false;
118117
}
119118

sql/item_windowfunc.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,28 +549,41 @@ class Item_window_func : public Item_func_or_sum
549549
Window functions are very special functions, so val_() methods have
550550
special meaning for them:
551551
552-
- Phase#1: we run the join and put its result into temporary table. For
553-
window functions, we write NULL (or some other) values as placeholders.
552+
- Phase#1, "Initial" we run the join and put its result into temporary
553+
table. For window functions, we write the default value (NULL?) as
554+
a placeholder.
554555
555-
- Phase#2: executor does the scan in {PARTITION, ORDER BY} order of this
556-
window function. It calls appropriate methods to inform the window
557-
function about rows entering/leaving the window.
558-
It calls window_func()->val_int() so that current window function value
556+
- Phase#2: "Computation": executor does the scan in {PARTITION, ORDER BY}
557+
order of this window function. It calls appropriate methods to inform
558+
the window function about rows entering/leaving the window.
559+
It calls window_func()->val_int() so that current window function value
559560
can be saved and stored in the temp.table.
560561
561-
- Phase#3: the temporary table is read and passed to query output.
562-
However, Item_window_func still remains in the select list, so
563-
item_windowfunc->val_int() will be called.
562+
- Phase#3: "Retrieval" the temporary table is read and passed to query
563+
output. However, Item_window_func still remains in the select list,
564+
so item_windowfunc->val_int() will be called.
564565
During Phase#3, read_value_from_result_field= true.
565566
*/
566-
public:
567-
// TODO: how to reset this for subquery re-execution??
568567
bool force_return_blank;
569-
private:
570-
571568
bool read_value_from_result_field;
572569

573570
public:
571+
void set_phase_to_initial()
572+
{
573+
force_return_blank= true;
574+
read_value_from_result_field= false;
575+
}
576+
void set_phase_to_computation()
577+
{
578+
force_return_blank= false;
579+
read_value_from_result_field= false;
580+
}
581+
void set_phase_to_retrieval()
582+
{
583+
force_return_blank= false;
584+
read_value_from_result_field= true;
585+
}
586+
574587
void set_read_value_from_result_field()
575588
{
576589
read_value_from_result_field= true;

sql/sql_window.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ bool JOIN::process_window_functions(List<Item> *curr_fields_list)
15901590
if (item->type() == Item::WINDOW_FUNC_ITEM)
15911591
{
15921592
Item_window_func *item_win = (Item_window_func *) item;
1593-
item_win->force_return_blank= false;
1593+
item_win->set_phase_to_computation();
15941594
Window_spec *spec = item_win->window_spec;
15951595
/*
15961596
The sorting criteria should be
@@ -1663,7 +1663,7 @@ bool JOIN::process_window_functions(List<Item> *curr_fields_list)
16631663
DBUG_ASSERT(0);
16641664
}
16651665

1666-
item_win->set_read_value_from_result_field();
1666+
item_win->set_phase_to_retrieval();
16671667
/* This calls filesort_free_buffers(): */
16681668
end_read_record(&info);
16691669

0 commit comments

Comments
 (0)