-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent date_sub/date_add with MySQL when the type of first argument is float #56339
Comments
/severity minor |
@gengliqi I'm not sure this is even a bug, since it is also converting between a base 2 binary 64 bit float, which is about 16 decimal digits max in significance. So extending it above 16 digits and then truncate or round when there is more than 16 digits does not make sense to me, since those numbers are already only interpreted instead of actually given by the user. I would say that it should see how many significant digits it can use and then set the FSP accordingly, including having just enough digits to convert back deterministically to a float64 again. For reference: An example from MySQL 8.0.32:
If you think it is still worth changing, I'm also proposing #56442 which also should handle this case :) |
@mjonss I understand your point. It really doesn't seem to make sense. But my point is just to keep TiDB consistent with TiKV and MySQL behavior. |
@gengliqi OK, then I see the issue to be fixed and don't mind fixing it. Maybe verify that TiDB internally handle it the same as TiKV/TiFlash/UniStore engines would be a good idea. |
Bug Report
For
cast_float_as_datetime
, TiDB converts the float to string first and then converts the string to datetime.For date_sub/date_add part, TiDB converts the integer part of the float to datetime first and then converts the frac part to fsp.
The bug is that TiDB forgets to round the frac part.
TiKV does the round for the frac part so the bug exists only in TiDB.(https://github.com/tikv/tikv/blob/c67e7c37786f9d153ede85a1c8daacebe2610688/components/tidb_query_datatype/src/codec/mysql/time/mod.rs#L786)
TiDB
MySQL
The text was updated successfully, but these errors were encountered: