MCPcopy Create free account
hub / github.com/MariaDB/server / compute_window_func

Function compute_window_func

sql/sql_window.cc:2877–2977  ·  view source on GitHub ↗

TODO(cvicentiu) update this comment to reflect the new execution. Streamed window function computation with window frames. We make a single pass over the ordered temp.table, but we're using three cursors: - current row - the row that we're computing window func value for) - start_bound - the start of the frame - bottom_bound - the end of the frame All three cursors move toget

Source from the content-addressed store, hash-verified

2875
2876*/
2877bool compute_window_func(THD *thd,
2878 List<Item_window_func>& window_functions,
2879 List<Cursor_manager>& cursor_managers,
2880 TABLE *tbl,
2881 SORT_INFO *filesort_result)
2882{
2883 List_iterator_fast<Item_window_func> iter_win_funcs(window_functions);
2884 List_iterator_fast<Cursor_manager> iter_cursor_managers(cursor_managers);
2885 bool ret= false;
2886 uint err;
2887
2888 READ_RECORD info;
2889
2890 if (init_read_record(&info, current_thd, tbl, NULL/*select*/, filesort_result,
2891 0, 1, FALSE))
2892 return true;
2893
2894 Cursor_manager *cursor_manager;
2895 while ((cursor_manager= iter_cursor_managers++))
2896 cursor_manager->initialize_cursors(&info);
2897
2898 /* One partition tracker for each window function. */
2899 List<Group_bound_tracker> partition_trackers;
2900 Item_window_func *win_func;
2901 while ((win_func= iter_win_funcs++))
2902 {
2903 Group_bound_tracker *tracker= new Group_bound_tracker(thd,
2904 win_func->window_spec->partition_list);
2905 // TODO(cvicentiu) This should be removed and placed in constructor.
2906 tracker->init();
2907 partition_trackers.push_back(tracker);
2908 }
2909
2910 List_iterator_fast<Group_bound_tracker> iter_part_trackers(partition_trackers);
2911 ha_rows rownum= 0;
2912 uchar *rowid_buf= (uchar*) my_malloc(PSI_INSTRUMENT_ME, tbl->file->ref_length, MYF(0));
2913
2914 while (true)
2915 {
2916 if ((err= info.read_record()))
2917 break; // End of file.
2918
2919 /* Remember current row so that we can restore it before computing
2920 each window function. */
2921 tbl->file->position(tbl->record[0]);
2922 memcpy(rowid_buf, tbl->file->ref, tbl->file->ref_length);
2923
2924 iter_win_funcs.rewind();
2925 iter_part_trackers.rewind();
2926 iter_cursor_managers.rewind();
2927
2928 Group_bound_tracker *tracker;
2929 while ((win_func= iter_win_funcs++) &&
2930 (tracker= iter_part_trackers++) &&
2931 (cursor_manager= iter_cursor_managers++))
2932 {
2933 if (tracker->check_if_next_group() || (rownum == 0))
2934 {

Callers 1

execMethod · 0.85

Calls 15

init_read_recordFunction · 0.85
my_mallocFunction · 0.85
my_freeFunction · 0.85
end_read_recordFunction · 0.85
initialize_cursorsMethod · 0.80
read_recordMethod · 0.80
check_if_next_groupMethod · 0.80
window_funcMethod · 0.80
is_killedMethod · 0.80

Tested by

no test coverage detected