MDEV-38670 Unary minus on empty string returns -0#4632
MDEV-38670 Unary minus on empty string returns -0#46323titoo wants to merge 1 commit intoMariaDB:10.6from
Conversation
gkodinov
left a comment
There was a problem hiding this comment.
This is a preliminary review.
Thank you for working on this!
You have pinpointed the problem correctly. But it needs more work to arrive at a complete solution, adequate testing and a solid commit message.
8bd49fe to
f1bf275
Compare
gkodinov
left a comment
There was a problem hiding this comment.
Thanks for willing to make this a good and well-rounded database feature. Some further review comments below.
|
Added classification and normalization criteria to the JIRA. |
|
i have edited Item *Item_float::neg(THD *thd) CREATE TABLE t_signed_zero (a DOUBLE); It prints -0 and 0 as distinct numbers while they are equal |
gkodinov
left a comment
There was a problem hiding this comment.
Thanks for working on this. One small nitpick item below.
Please wait for the final review.
sql/item_func.h
Outdated
| @@ -285,6 +285,12 @@ class Item_func :public Item_func_or_sum | |||
| print(&str, QT_NO_DATA_EXPANSION); | |||
| my_error(ER_DATA_OUT_OF_RANGE, MYF(0), type_name, str.c_ptr_safe()); | |||
| } | |||
| inline double normalize_signed_zero(double value) | |||
There was a problem hiding this comment.
Do you really need to define this twice? item_func.cc already includes item.h (indirectly, but still).
|
Forgot to mention: please re-base on 10.6. This is safe to do and is a bug fix. So let's please assign the proper target version. |
|
Wouldn't it be enough to fix it in dtoa? So that it wouldn't print |
Fixing this in dtoa would only hide the sign during printing. The problem is that the server internally treats -0 and +0 differently in some execution paths (e.g., grouping), even though they are numerically equal. |
We discussed this issue with the team and think that double values of 0.0 and -0.0 compare as equal. Your patch also relies on this fact by the way:
Can you please give examples when grouping or some other execution paths give wrong results? |
Normalize -0.0 to +0.0 in Item_func_neg::real_op() to match binary subtraction behavior. Add test case in type_newdecimal. add result for tests fix tests Revert whitespace changes in type_newdecimal.result Revert whitespace changes in type_newdecimal.test normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0 normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0 normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0 normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0 normalize -0.0 to 0.0 normalize -0.0 to 0.0 Revert unintended changes in item_func.h Revert unintended changes in item_func.h (10.6)
gkodinov
left a comment
There was a problem hiding this comment.
LGTM from a preliminary review standpoint. Please take the alternative approach discussion with the final reviewer (Alexander).
Thanks for the review! @abarkov — since this involves choosing the overall approach for handling signed zero, I followed approach 2 for consistency. |




Normalize -0.0 to +0.0 in Item_func_neg::real_op() to match binary subtraction behavior. Add a test case in type_newdecimal.