diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2016-03-16 01:26:39 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2016-03-16 01:26:39 +0300 |
commit | 833304313d65f426323b10016616c3a6d951804b (patch) | |
tree | 474c8216cc46d33ff16f0c6a0aa12535191570ad /sql/item_windowfunc.h | |
parent | 21a0291c1de5553dbfc06447b8b81d3756adb843 (diff) | |
download | mariadb-git-833304313d65f426323b10016616c3a6d951804b.tar.gz |
Continuation of "Implemented a counter within Item_sum_sum" a few commits before
Query result had 0 where it should have had NULLs:
- Make Item_window_func::val* functions honor NULL-handling conventions:
1. set null_value to indicate whether we've returned a NULL value
2. val_str and val_decimal should return NULL pointer when they're
returning SQL NULL value.
Fix assertion failure when sending results to network.
- The assert was due to window func returing SQL NULL despite having
maybe_null=false
- Fixed by settting Item_window_func::maybe_null correctly in fix_fields
Diffstat (limited to 'sql/item_windowfunc.h')
-rw-r--r-- | sql/item_windowfunc.h | 80 |
1 files changed, 67 insertions, 13 deletions
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 5cb1e8aae32..e316c6d712a 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -481,37 +481,91 @@ public: double val_real() { + double res; if (force_return_blank) - return 0.0; - return read_value_from_result_field? result_field->val_real() : - window_func->val_real(); + { + res= 0.0; + null_value= false; + } + else if (read_value_from_result_field) + { + res= result_field->val_real(); + null_value= false; + } + else + { + res= window_func->val_real(); + null_value= window_func->null_value; + } } longlong val_int() { + longlong res; if (force_return_blank) - return 0; - return read_value_from_result_field? result_field->val_int() : - window_func->val_int(); + { + res= 0; + null_value= false; + } + else if (read_value_from_result_field) + { + res= result_field->val_int(); + null_value= result_field->is_null(); + } + else + { + res= window_func->val_int(); + null_value= window_func->null_value; + } + return res; } String* val_str(String* str) { + String *res; if (force_return_blank) - return str; - return read_value_from_result_field? result_field->val_str(str) : - window_func->val_str(str); + { + null_value= false; + str->length(0); + res= str; + } + else if (read_value_from_result_field) + { + if ((null_value= result_field->is_null())) + res= NULL; + else + res= result_field->val_str(str); + } + else + { + res= window_func->val_str(str); + null_value= window_func->null_value; + } + return res; } my_decimal* val_decimal(my_decimal* dec) - { + { + my_decimal *res; if (force_return_blank) { my_decimal_set_zero(dec); - return dec; + null_value= false; + res= dec; + } + else if (read_value_from_result_field) + { + if ((null_value= result_field->is_null())) + res= NULL; + else + res= result_field->val_decimal(dec); + } + else + { + res= result_field->val_decimal(dec); + null_value= window_func->null_value; } - return read_value_from_result_field? result_field->val_decimal(dec) : - window_func->val_decimal(dec); + return res; } void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, |