Helper function that takes a list of window functions and writes their values in the current table record. */
| 2794 | their values in the current table record. |
| 2795 | */ |
| 2796 | static |
| 2797 | bool 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. |
no test coverage detected