From 31f1541f1e367f6eb91f948c4e814bb6554e6b78 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 26 Jun 2017 03:53:27 +0530 Subject: [PATCH] Setting handler to have the return type as that of the element by which we are ordering the partition --- sql/item.h | 2 +- sql/item_windowfunc.cc | 5 +++++ sql/item_windowfunc.h | 12 ++++++++---- sql/sql_window.cc | 4 ++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/sql/item.h b/sql/item.h index 68d09577dcc..0e7582a9ac4 100644 --- a/sql/item.h +++ b/sql/item.h @@ -5386,7 +5386,7 @@ public: Cached_item_decimal(Item *item_par); bool cmp(void); int cmp_read_only(); - my_decimal get_value(){ return value;}; + my_decimal *get_value(){ return &value;}; void clear() { null_value= false; diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 50a8c5d82cd..5e77132ad38 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -210,6 +210,11 @@ void Item_sum_percentile_disc::setup_window_func(THD *thd, Window_spec *window_s setup_percentile_func(thd, window_spec->order_list); } +void Item_sum_percentile_disc::set_type_handler(Window_spec *window_spec) +{ + type_handler()->get_handler_by_cmp_type(window_spec->order_list->first->item[0]->result_type()); +} + bool Item_sum_dense_rank::add() { if (peer_tracker->check_if_next_group() || first_add) diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 6595012fabf..9087404ea3e 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -701,11 +701,13 @@ class Item_sum_ntile : public Item_sum_window_with_row_count ulong current_row_count_; }; -class Item_sum_percentile_disc : public Item_sum_cume_dist +class Item_sum_percentile_disc : public Item_sum_cume_dist, + public Type_handler_hybrid_field_type { public: Item_sum_percentile_disc(THD *thd, Item* arg) : Item_sum_cume_dist(thd, arg), - value(NULL), val_calculated(FALSE) {} + Type_handler_hybrid_field_type(&type_handler_longlong), + value(NULL), val_calculated(FALSE) {} double val_real() { @@ -715,7 +717,7 @@ public: return 0; } null_value= false; - return ((Cached_item_int*) value)->get_value(); + return ((Cached_item_real*) value)->get_value(); } longlong val_int() @@ -769,7 +771,9 @@ public: } void update_field() {} - const Type_handler *type_handler() const { return &type_handler_double; } + void set_type_handler(Window_spec *window_spec); + const Type_handler *type_handler() const + {return Type_handler_hybrid_field_type::type_handler();} void fix_length_and_dec() { diff --git a/sql/sql_window.cc b/sql/sql_window.cc index a4c558b52b6..dc8c66120ff 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -319,6 +319,10 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, while ((win_func_item= li++)) { win_func_item->update_used_tables(); + if (win_func_item->only_single_element_order_list()) + { + ((Item_sum_percentile_disc*)win_func_item)->set_type_handler(win_func_item->window_spec); + } } DBUG_RETURN(0);