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

Function save_window_function_values

sql/sql_window.cc:2796–2838  ·  view source on GitHub ↗

Helper function that takes a list of window functions and writes their values in the current table record. */

Source from the content-addressed store, hash-verified

2794 their values in the current table record.
2795*/
2796static
2797bool save_window_function_values(List<Item_window_func>& window_functions,
2798 TABLE *tbl, uchar *rowid_buf)
2799{
2800 List_iterator_fast<Item_window_func> iter(window_functions);
2801 JOIN_TAB *join_tab= tbl->reginfo.join_tab;
2802 tbl->file->ha_rnd_pos(tbl->record[0], rowid_buf);
2803 store_record(tbl, record[1]);
2804 while (Item_window_func *item_win= iter++)
2805 item_win->save_in_field(item_win->result_field, true);
2806
2807 /*
2808 In case we have window functions present, an extra step is required
2809 to compute all the fields from the temporary table.
2810 In case we have a compound expression such as: expr + expr,
2811 where one of the terms has a window function inside it, only
2812 after computing window function values we actually know the true
2813 final result of the compounded expression.
2814
2815 Go through all the func items and save their values once again in the
2816 corresponding temp table fields. Do this for each row in the table.
2817
2818 This needs to be done earlier because ORDER BY clause can also have
2819 a window function, so we need to make sure all the fields of the temp.table
2820 are updated before we do the filesort. So is best to update the other fields
2821 that contain the window functions along with the computation of window
2822 functions.
2823 */
2824
2825 Item **func_ptr= join_tab->tmp_table_param->items_to_copy;
2826 Item *func;
2827 for (; (func = *func_ptr) ; func_ptr++)
2828 {
2829 if (func->with_window_func() && func->type() != Item::WINDOW_FUNC_ITEM)
2830 func->save_in_result_field(true);
2831 }
2832
2833 int err= tbl->file->ha_update_row(tbl->record[1], tbl->record[0]);
2834 if (err && err != HA_ERR_RECORD_IS_THE_SAME)
2835 return true;
2836
2837 return false;
2838}
2839
2840/*
2841 TODO(cvicentiu) update this comment to reflect the new execution.

Callers 1

compute_window_funcFunction · 0.85

Calls 6

ha_rnd_posMethod · 0.80
with_window_funcMethod · 0.80
ha_update_rowMethod · 0.80
save_in_fieldMethod · 0.45
typeMethod · 0.45
save_in_result_fieldMethod · 0.45

Tested by

no test coverage detected