From 9a5930bcdfc72f3b63569332205d8574a586247d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Tue, 20 Sep 2016 20:44:49 +0200 Subject: Implement first_value and last_value as window functions Currently the implementation doesn't support removal, thus the computation is performed by running over the window frame again. --- sql/item_windowfunc.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'sql/item_windowfunc.cc') diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index c8ea979900c..5a7ee522d44 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -219,3 +219,26 @@ void Item_sum_percent_rank::setup_window_func(THD *thd, Window_spec *window_spec peer_tracker->init(); clear(); } + +bool Item_sum_first_value::add() +{ + if (value_added) + return false; + + /* TODO(cvicentiu) This is done like this due to how Item_sum_hybrid works. + For this usecase we can actually get rid of arg_cache. arg_cache is just + for running a comparison function. */ + value_added= true; + arg_cache->cache_value(); + value->store(arg_cache); + null_value= arg_cache->null_value; + return false; +} + +bool Item_sum_last_value::add() +{ + arg_cache->cache_value(); + value->store(arg_cache); + null_value= arg_cache->null_value; + return false; +} -- cgit v1.2.1