diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2019-05-12 17:20:23 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2019-05-12 17:20:23 +0200 |
commit | c51f85f8823a845cd4a6aa1b2aa5af18484b2ab0 (patch) | |
tree | 65c45f6100c13dad90c33b86dc68be268139b0b8 /sql/sql_window.cc | |
parent | a89f199c64a1d2339de7c167ce64ec148061a4d3 (diff) | |
parent | 8ce702aa90c174566f4ac950e85cc7570bf9b647 (diff) | |
download | mariadb-git-c51f85f8823a845cd4a6aa1b2aa5af18484b2ab0.tar.gz |
Merge branch '10.2' into 10.3
Diffstat (limited to 'sql/sql_window.cc')
-rw-r--r-- | sql/sql_window.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 86c40b5f58f..487242933d4 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -2710,11 +2710,38 @@ bool save_window_function_values(List<Item_window_func>& window_functions, TABLE *tbl, uchar *rowid_buf) { List_iterator_fast<Item_window_func> iter(window_functions); + JOIN_TAB *join_tab= tbl->reginfo.join_tab; tbl->file->ha_rnd_pos(tbl->record[0], rowid_buf); store_record(tbl, record[1]); while (Item_window_func *item_win= iter++) item_win->save_in_field(item_win->result_field, true); + /* + In case we have window functions present, an extra step is required + to compute all the fields from the temporary table. + In case we have a compound expression such as: expr + expr, + where one of the terms has a window function inside it, only + after computing window function values we actually know the true + final result of the compounded expression. + + Go through all the func items and save their values once again in the + corresponding temp table fields. Do this for each row in the table. + + This needs to be done earlier because ORDER BY clause can also have + a window function, so we need to make sure all the fields of the temp.table + are updated before we do the filesort. So is best to update the other fields + that contain the window functions along with the computation of window + functions. + */ + + Item **func_ptr= join_tab->tmp_table_param->items_to_copy; + Item *func; + for (; (func = *func_ptr) ; func_ptr++) + { + if (func->with_window_func && func->type() != Item::WINDOW_FUNC_ITEM) + func->save_in_result_field(true); + } + int err= tbl->file->ha_update_row(tbl->record[1], tbl->record[0]); if (err && err != HA_ERR_RECORD_IS_THE_SAME) return true; |