@@ -1579,102 +1579,97 @@ bool compute_two_pass_window_functions(Item_window_func *item_win,
1579
1579
true Error
1580
1580
*/
1581
1581
1582
- bool JOIN::process_window_functions (List<Item > *curr_fields_list )
1582
+ bool JOIN::process_window_functions (List<Item_window_func > *window_funcs )
1583
1583
{
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 ;
1586
1586
1587
+ while ((item_win= it++))
1587
1588
{
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)
1598
1594
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 ;
1604
1613
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
+ {
1605
1651
/*
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.
1619
1654
*/
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
+ }
1665
1662
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);
1669
1666
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);
1673
1670
1674
- if (is_error)
1675
- return true ;
1676
- }
1677
- }
1671
+ if (is_error)
1672
+ return true ;
1678
1673
}
1679
1674
return false ;
1680
1675
}
0 commit comments