diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2017-02-07 16:49:41 +0200 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2017-02-14 07:46:58 +0200 |
commit | 57341852b5b1e40b1f92e248d84f95de988022c0 (patch) | |
tree | 448800453edaae7503b31f91217089aa7c5be9af /sql/sql_window.cc | |
parent | f675eab7dc7f1eb4f4b61bfdd548d9e8052678a4 (diff) | |
download | mariadb-git-57341852b5b1e40b1f92e248d84f95de988022c0.tar.gz |
MDEV-11746: Wrong result upon using FIRST_VALUE with a window frame
Reimplement FIRST_VALUE to act as NTH_VALUE with 0 offset. The previous
implementation was flawed when the window frame would remove values.
Diffstat (limited to 'sql/sql_window.cc')
-rw-r--r-- | sql/sql_window.cc | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sql/sql_window.cc b/sql/sql_window.cc index e9e531714f6..668c6a41e08 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -2311,14 +2311,6 @@ void add_special_frame_cursors(THD *thd, Cursor_manager *cursor_manager, fc->add_sum_func(item_sum); cursor_manager->add_cursor(fc); break; - case Item_sum::FIRST_VALUE_FUNC: - fc= get_frame_cursor(thd, spec, true); - fc->set_no_action(); - cursor_manager->add_cursor(fc); - fc= new Frame_positional_cursor(*fc); - fc->add_sum_func(item_sum); - cursor_manager->add_cursor(fc); - break; case Item_sum::LAST_VALUE_FUNC: fc= get_frame_cursor(thd, spec, false); fc->add_sum_func(item_sum); @@ -2347,6 +2339,22 @@ void add_special_frame_cursors(THD *thd, Cursor_manager *cursor_manager, cursor_manager->add_cursor(fc); break; } + case Item_sum::FIRST_VALUE_FUNC: + { + Frame_cursor *bottom_bound= get_frame_cursor(thd, spec, false); + Frame_cursor *top_bound= get_frame_cursor(thd, spec, true); + cursor_manager->add_cursor(bottom_bound); + cursor_manager->add_cursor(top_bound); + DBUG_ASSERT(item_sum->fixed); + Item *offset_item= new (thd->mem_root) Item_int(thd, 0); + offset_item->fix_fields(thd, &offset_item); + fc= new Frame_positional_cursor(*top_bound, + *top_bound, *bottom_bound, + *offset_item, false); + fc->add_sum_func(item_sum); + cursor_manager->add_cursor(fc); + break; + } case Item_sum::NTH_VALUE_FUNC: { Frame_cursor *bottom_bound= get_frame_cursor(thd, spec, false); |