summaryrefslogtreecommitdiff
path: root/sql/sql_window.cc
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2017-02-07 17:16:20 +0200
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2017-02-14 07:46:58 +0200
commit5bf338435aae358b2661ce2dc04b5a70d3d0c783 (patch)
tree1cb1e81ff05c2380553cdc4ff3acc78c0eeb0c80 /sql/sql_window.cc
parent57341852b5b1e40b1f92e248d84f95de988022c0 (diff)
downloadmariadb-git-5bf338435aae358b2661ce2dc04b5a70d3d0c783.tar.gz
MDEV-11746: Wrong result upon using FIRST_VALUE with a window frame
The same approach is needed for LAST_VALUE, otherwise the LAST_VALUE sum functions are not cleared correctly. Now LAST_VALUE behaves as NTH_VALUE with 0 offset, only that the frame that it is examining is the bottom bound, not the top bound.
Diffstat (limited to 'sql/sql_window.cc')
-rw-r--r--sql/sql_window.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index 668c6a41e08..37095ad78ca 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -2311,11 +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::LAST_VALUE_FUNC:
- fc= get_frame_cursor(thd, spec, false);
- fc->add_sum_func(item_sum);
- cursor_manager->add_cursor(fc);
- break;
case Item_sum::LEAD_FUNC:
case Item_sum::LAG_FUNC:
{
@@ -2355,6 +2350,22 @@ void add_special_frame_cursors(THD *thd, Cursor_manager *cursor_manager,
cursor_manager->add_cursor(fc);
break;
}
+ case Item_sum::LAST_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(*bottom_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);