Skip to content

Commit c7a60de

Browse files
committed
Code cleanup
1 parent 39d3cdb commit c7a60de

File tree

4 files changed

+87
-96
lines changed

4 files changed

+87
-96
lines changed

sql/item_windowfunc.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,13 @@ class Item_window_func : public Item_func_or_sum
491491
: Item_func_or_sum(thd, (Item *) win_func),
492492
window_name(win_name), window_spec(NULL),
493493
force_return_blank(true),
494-
read_value_from_result_field(false) {}
494+
read_value_from_result_field(false) {}
495495

496496
Item_window_func(THD *thd, Item_sum *win_func, Window_spec *win_spec)
497497
: Item_func_or_sum(thd, (Item *) win_func),
498498
window_name(NULL), window_spec(win_spec),
499499
force_return_blank(true),
500-
read_value_from_result_field(false) {}
500+
read_value_from_result_field(false) {}
501501

502502
Item_sum *window_func() { return (Item_sum *) args[0]; }
503503

@@ -544,7 +544,8 @@ class Item_window_func : public Item_func_or_sum
544544
return ((Item_sum *) args[0])->field_type();
545545
}
546546
enum Item::Type type() const { return Item::WINDOW_FUNC_ITEM; }
547-
547+
548+
private:
548549
/*
549550
Window functions are very special functions, so val_() methods have
550551
special meaning for them:
@@ -584,11 +585,6 @@ class Item_window_func : public Item_func_or_sum
584585
read_value_from_result_field= true;
585586
}
586587

587-
void set_read_value_from_result_field()
588-
{
589-
read_value_from_result_field= true;
590-
}
591-
592588
double val_real()
593589
{
594590
double res;

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25898,7 +25898,7 @@ AGGR_OP::end_send()
2589825898

2589925899
// Update ref array
2590025900
join_tab->join->set_items_ref_array(*join_tab->ref_array);
25901-
join->process_window_functions(&join->fields_list); // location #2
25901+
join->process_window_functions(&join->select_lex->window_funcs);
2590225902
table->reginfo.lock_type= TL_UNLOCK;
2590325903

2590425904
bool in_first_read= true;

sql/sql_select.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ class JOIN :public Sql_alloc
14941494
int init_execution();
14951495
void exec();
14961496

1497-
bool process_window_functions(List<Item> *curr_fields_list);
1497+
bool process_window_functions(List<Item_window_func> *window_funcs);
14981498

14991499
void exec_inner();
15001500
bool prepare_result(List<Item> **columns_list);

sql/sql_window.cc

Lines changed: 81 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,102 +1579,97 @@ bool compute_two_pass_window_functions(Item_window_func *item_win,
15791579
true Error
15801580
*/
15811581

1582-
bool JOIN::process_window_functions(List<Item> *curr_fields_list)
1582+
bool JOIN::process_window_functions(List<Item_window_func> *window_funcs)
15831583
{
1584-
List_iterator_fast<Item> it(*curr_fields_list);
1585-
Item *item;
1584+
List_iterator_fast<Item_window_func> it(*window_funcs);
1585+
Item_window_func *item_win;
15861586

1587+
while ((item_win= it++))
15871588
{
1588-
while ((item= it++))
1589-
{
1590-
if (item->type() == Item::WINDOW_FUNC_ITEM)
1591-
{
1592-
Item_window_func *item_win = (Item_window_func *) item;
1593-
item_win->set_phase_to_computation();
1594-
Window_spec *spec = item_win->window_spec;
1595-
/*
1596-
The sorting criteria should be
1597-
(spec->partition_list, spec->order_list)
1589+
item_win->set_phase_to_computation();
1590+
Window_spec *spec = item_win->window_spec;
1591+
/*
1592+
The sorting criteria should be
1593+
(spec->partition_list, spec->order_list)
15981594
1599-
Connect the two lists for the duration of add_sorting_to_table()
1600-
call.
1601-
*/
1602-
DBUG_ASSERT(spec->partition_list->next[0] == NULL);
1603-
*(spec->partition_list->next)= spec->order_list->first;
1595+
Connect the two lists for the duration of add_sorting_to_table()
1596+
call.
1597+
*/
1598+
DBUG_ASSERT(spec->partition_list->next[0] == NULL);
1599+
*(spec->partition_list->next)= spec->order_list->first;
1600+
1601+
/*
1602+
join_tab[top_join_tab_count].table is the temp. table where join
1603+
output was stored.
1604+
*/
1605+
// CAUTION: The sorting criteria list is not yet connected
1606+
add_sorting_to_table(&join_tab[top_join_tab_count],
1607+
spec->partition_list->first);
1608+
join_tab[top_join_tab_count].used_for_window_func= true;
1609+
1610+
create_sort_index(this->thd, this, &join_tab[top_join_tab_count]);
1611+
/* Disconnect order_list from partition_list */
1612+
*(spec->partition_list->next)= NULL;
16041613

1614+
/*
1615+
Go through the sorted array and compute the window function
1616+
*/
1617+
READ_RECORD info;
1618+
TABLE *tbl= join_tab[top_join_tab_count].table;
1619+
if (init_read_record(&info, thd, tbl, select, 0, 1, FALSE))
1620+
return true;
1621+
bool is_error= false;
1622+
1623+
item_win->setup_partition_border_check(thd);
1624+
1625+
Item_sum::Sumfunctype type= item_win->window_func()->sum_func();
1626+
switch (type) {
1627+
case Item_sum::ROW_NUMBER_FUNC:
1628+
case Item_sum::RANK_FUNC:
1629+
case Item_sum::DENSE_RANK_FUNC:
1630+
{
1631+
/*
1632+
One-pass window function computation, walk through the rows and
1633+
assign values.
1634+
*/
1635+
if (compute_window_func_values(item_win, tbl, &info))
1636+
is_error= true;
1637+
break;
1638+
}
1639+
case Item_sum::PERCENT_RANK_FUNC:
1640+
case Item_sum::CUME_DIST_FUNC:
1641+
{
1642+
if (compute_two_pass_window_functions(item_win, tbl, &info))
1643+
is_error= true;
1644+
break;
1645+
}
1646+
case Item_sum::COUNT_FUNC:
1647+
case Item_sum::SUM_BIT_FUNC:
1648+
case Item_sum::SUM_FUNC:
1649+
case Item_sum::AVG_FUNC:
1650+
{
16051651
/*
1606-
join_tab[top_join_tab_count].table is the temp. table where join
1607-
output was stored.
1608-
*/
1609-
add_sorting_to_table(&join_tab[top_join_tab_count],
1610-
spec->partition_list->first);
1611-
join_tab[top_join_tab_count].used_for_window_func= true;
1612-
1613-
create_sort_index(this->thd, this, &join_tab[top_join_tab_count]);
1614-
/* Disconnect order_list from partition_list */
1615-
*(spec->partition_list->next)= NULL;
1616-
1617-
/*
1618-
Go through the sorted array and compute the window function
1652+
Frame-aware window function computation. It does one pass, but
1653+
uses three cursors -frame_start, current_row, and frame_end.
16191654
*/
1620-
READ_RECORD info;
1621-
TABLE *tbl= join_tab[top_join_tab_count].table;
1622-
if (init_read_record(&info, thd, tbl, select, 0, 1, FALSE))
1623-
return true;
1624-
bool is_error= false;
1625-
1626-
item_win->setup_partition_border_check(thd);
1627-
1628-
Item_sum::Sumfunctype type= item_win->window_func()->sum_func();
1629-
switch (type) {
1630-
case Item_sum::ROW_NUMBER_FUNC:
1631-
case Item_sum::RANK_FUNC:
1632-
case Item_sum::DENSE_RANK_FUNC:
1633-
{
1634-
/*
1635-
One-pass window function computation, walk through the rows and
1636-
assign values.
1637-
*/
1638-
if (compute_window_func_values(item_win, tbl, &info))
1639-
is_error= true;
1640-
break;
1641-
}
1642-
case Item_sum::PERCENT_RANK_FUNC:
1643-
case Item_sum::CUME_DIST_FUNC:
1644-
{
1645-
if (compute_two_pass_window_functions(item_win, tbl, &info))
1646-
is_error= true;
1647-
break;
1648-
}
1649-
case Item_sum::COUNT_FUNC:
1650-
case Item_sum::SUM_BIT_FUNC:
1651-
case Item_sum::SUM_FUNC:
1652-
case Item_sum::AVG_FUNC:
1653-
{
1654-
/*
1655-
Frame-aware window function computation. It does one pass, but
1656-
uses three cursors -frame_start, current_row, and frame_end.
1657-
*/
1658-
if (compute_window_func_with_frames(item_win, tbl, &info))
1659-
is_error= true;
1660-
break;
1661-
}
1662-
default:
1663-
DBUG_ASSERT(0);
1664-
}
1655+
if (compute_window_func_with_frames(item_win, tbl, &info))
1656+
is_error= true;
1657+
break;
1658+
}
1659+
default:
1660+
DBUG_ASSERT(0);
1661+
}
16651662

1666-
item_win->set_phase_to_retrieval();
1667-
/* This calls filesort_free_buffers(): */
1668-
end_read_record(&info);
1663+
item_win->set_phase_to_retrieval();
1664+
/* This calls filesort_free_buffers(): */
1665+
end_read_record(&info);
16691666

1670-
delete join_tab[top_join_tab_count].filesort;
1671-
join_tab[top_join_tab_count].filesort= NULL;
1672-
free_io_cache(tbl);
1667+
delete join_tab[top_join_tab_count].filesort;
1668+
join_tab[top_join_tab_count].filesort= NULL;
1669+
free_io_cache(tbl);
16731670

1674-
if (is_error)
1675-
return true;
1676-
}
1677-
}
1671+
if (is_error)
1672+
return true;
16781673
}
16791674
return false;
16801675
}

0 commit comments

Comments
 (0)