diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-08-13 23:49:10 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-08-13 23:49:10 +0400 |
commit | c1599821a55ac4f59c5c799480a07913e1c26daa (patch) | |
tree | 0c064252ad3959fcd53b0f06a40b98d691fe070e /sql/item_windowfunc.cc | |
parent | 624dd71b9419555eca8baadc695e3376de72286f (diff) | |
parent | c4fd167d5a740f67ee5287a9b05b5383403b9ed0 (diff) | |
download | mariadb-git-c1599821a55ac4f59c5c799480a07913e1c26daa.tar.gz |
Merge remote-tracking branch 'origin/10.4' into 10.5
Diffstat (limited to 'sql/item_windowfunc.cc')
-rw-r--r-- | sql/item_windowfunc.cc | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 8eb4692b36e..f20d20c81d6 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -171,7 +171,8 @@ void Item_window_func::split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, bool Item_window_func::check_result_type_of_order_item() { - if (only_single_element_order_list()) + switch (window_func()->sum_func()) { + case Item_sum::PERCENTILE_CONT_FUNC: { Item_result rtype= window_spec->order_list->first->item[0]->cmp_type(); // TODO (varun) : support date type in percentile_cont function @@ -179,9 +180,29 @@ bool Item_window_func::check_result_type_of_order_item() rtype != DECIMAL_RESULT && rtype != TIME_RESULT) { my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name()); - return TRUE; + return true; + } + return false; + } + case Item_sum::PERCENTILE_DISC_FUNC: + { + Item *src_item= window_spec->order_list->first->item[0]; + Item_result rtype= src_item->cmp_type(); + // TODO-10.5: Fix MDEV-20280 PERCENTILE_DISC() rejects temporal and string input + if (rtype != REAL_RESULT && rtype != INT_RESULT && rtype != DECIMAL_RESULT) + { + my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name()); + return true; } - setting_handler_for_percentile_functions(rtype); + Item_sum_percentile_disc *func= + static_cast<Item_sum_percentile_disc*>(window_func()); + func->set_handler(src_item->type_handler()); + func->Type_std_attributes::set(src_item); + Type_std_attributes::set(src_item); + return false; + } + default: + break; } return FALSE; } @@ -331,39 +352,15 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; } - Type_std_attributes::set(args[0]); + for (uint i= 0; i < arg_count && !m_with_subquery; i++) m_with_subquery|= args[i]->with_subquery(); - Item *item2= args[0]->real_item(); - if (item2->type() == Item::FIELD_ITEM) - set_handler(item2->type_handler()); - else if (args[0]->cmp_type() == TIME_RESULT) - set_handler(item2->type_handler()); - else - set_handler_by_result_type(item2->result_type(), - max_length, collation.collation); + if (fix_length_and_dec()) + return true; - switch (result_type()) { - case INT_RESULT: - case DECIMAL_RESULT: - case STRING_RESULT: - break; - case REAL_RESULT: - max_length= float_length(decimals); - break; - case ROW_RESULT: - case TIME_RESULT: - DBUG_ASSERT(0); // XXX(cvicentiu) Should this never happen? - return TRUE; - }; setup_hybrid(thd, args[0]); - /* MIN/MAX can return NULL for empty set indepedent of the used column */ - maybe_null= 1; result_field=0; - null_value=1; - if (fix_length_and_dec()) - return TRUE; if (check_sum_func(thd, ref)) return TRUE; @@ -375,6 +372,14 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) return FALSE; } + +bool Item_sum_hybrid_simple::fix_length_and_dec() +{ + maybe_null= null_value= true; + return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this); +} + + bool Item_sum_hybrid_simple::add() { value->store(args[0]); |