Skip to content

Commit 30c9450

Browse files
committed
More comments
1 parent e64b57a commit 30c9450

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

sql/item_windowfunc.h

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
class Window_spec;
88

9+
/*
10+
ROW_NUMBER() OVER (...)
11+
12+
- This is a Window function (not just an aggregate)
13+
- It can be computed by doing one pass over select output, provided
14+
the output is sorted according to the window definition.
15+
*/
916

1017
class Item_sum_row_number: public Item_sum_int
1118
{
@@ -31,12 +38,28 @@ class Item_sum_row_number: public Item_sum_int
3138

3239
};
3340

41+
42+
/*
43+
RANK() OVER (...) Windowing function
44+
45+
- This is a Window function (not just an aggregate)
46+
- It can be computed by doing one pass over select output, provided
47+
the output is sorted according to the window definition.
48+
*/
49+
3450
class Item_sum_rank: public Item_sum_int
3551
{
3652
longlong rank;
37-
38-
void clear() {}
39-
bool add() { return false; }
53+
54+
/*TODO: implementation is currently missing */
55+
void clear()
56+
{
57+
// This is called on next partition
58+
}
59+
bool add()
60+
{
61+
return false;
62+
}
4063
void update_field() {}
4164

4265
public:
@@ -55,10 +78,20 @@ class Item_sum_rank: public Item_sum_int
5578

5679
};
5780

81+
82+
/*
83+
RANK() OVER (...) Windowing function
84+
85+
- This is a Window function (not just an aggregate)
86+
- It can be computed by doing one pass over select output, provided
87+
the output is sorted according to the window definition.
88+
*/
89+
5890
class Item_sum_dense_rank: public Item_sum_int
5991
{
6092
longlong dense_rank;
61-
93+
94+
/* TODO: implementation is missing */
6295
void clear() {}
6396
bool add() { return false; }
6497
void update_field() {}
@@ -164,7 +197,7 @@ class Item_window_func : public Item_result_field
164197
enum Item::Type type() const { return Item::WINDOW_FUNC_ITEM; }
165198

166199
/*
167-
TODO: Window functions are very special functions, so val_() methods have
200+
Window functions are very special functions, so val_() methods have
168201
special meaning for them:
169202
170203
- Phase#1: we run the join and put its result into temporary table. For
@@ -179,6 +212,7 @@ class Item_window_func : public Item_result_field
179212
- Phase#3: the temporary table is read and passed to query output.
180213
However, Item_window_func still remains in the select list, so
181214
item_windowfunc->val_int() will be called.
215+
During Phase#3, read_value_from_result_field= true.
182216
*/
183217
private:
184218
bool read_value_from_result_field;

sql/sql_window.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ bool JOIN::process_window_functions(List<Item> *curr_fields_list)
299299
*/
300300
item_win->advance_window();
301301

302-
/* Put the new value into temptable's field */
302+
/*
303+
Put the new value into temptable's field
304+
TODO: Should this use item_win->update_field() call?
305+
Regular aggegate function implementations seem to implement it.
306+
*/
303307
item_win->save_in_field(item_win->result_field, true);
304308
err= tbl->file->ha_update_row(tbl->record[1], tbl->record[0]);
305309
if (err && err != HA_ERR_RECORD_IS_THE_SAME)

0 commit comments

Comments
 (0)