-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
server: Make float rounding compatible with mysql for types: float, float(m,n) and double(m,n) #22823
base: master
Are you sure you want to change the base?
Conversation
884eb04
to
28502e6
Compare
Closing this PR this since mysql 8.0.14 have deprecated double(m,n) and float(m,n). |
4345b5d
to
1db348e
Compare
I re-open this PR again since I found there are still float formatting issues even for the float type with default column width. |
ac416ed
to
d834d31
Compare
c0ee5b2
to
20d9ff6
Compare
3a21b68
to
5db5666
Compare
This resolve issue pingcap#22791: query result for float type is incompatible with previous version It seems like this broke in the fix for issue pingcap#21692. In mysql, e-format is only returned when used in the query, for example: select 1e15, will print 1e15 back. However, when stored in a table mysel will print it in decimal form. issue pingcap#21692 resolved this by checking for empty table. However, that fix applies for everything rather than only for e-format. And that caused the new issue pingcap#22791. This resolves both pingcap#22791 and pingcap#21692. It also resolve an issue where for a default width float column we do not round to the mysql default precision.
"0.111", | ||
3, | ||
64, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted this test because for a column of 3 decimals, the input is already rounded when we store it. So the result is correct in an integration test.
However the result from the function test will not be correct. Let me know if you want me to implement this in the output formatter too, even though its truncated on input.
Co-authored-by: djshow832 <[email protected]>
Hi @djshow832 , thank you for your comment. Do you or @AilinKid (who is also assinged to this PR) have anymore feedback on this MR? Thanks in advance to have a look! |
seems like you guys has no interest to resolve these bugs, so closing this PR instead. |
I'm so sorry for the late response to your PR cause my notification mechanism is broken recently. Even for now, the float problem is still one of the big compatibility problems on our list. I'm not sure whether your pull request can solve this problem, so let's review it first, and if you are interested you can add a more detailed design about your work. More again, thanks for your contribution. @johan-j |
thank you @AilinKid for showing interest in this pull request. I hope it can resolve the compatibility issues. I put quite some effort into making this PR. "and if you are interested you can add a more detailed design about your work." |
5. mysql.TypeFloat(m,n): return a rounded value rounded with (precision = 5) and formatted with (precision = n) | ||
|
||
Note: Custom float/double column width is deprecated in mysql 8.0.14. | ||
However for compatibility, we still try to make the output the same as mysql for these types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better add a mysql referrence link here, and could you descript the imcompatiable behavior with mysql here a little bit?
func appendFormatFloat(in []byte, fVal float64, bitSize int, colDecimal uint8, colLength uint32, isFromSelect bool) []byte { | ||
isCustomColumnWidth := false | ||
prec := types.UnspecifiedLength | ||
if colDecimal > 0 && colDecimal != mysql.NotFixedDec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if colDecimal > 0 && colDecimal != mysql.NotFixedDec { | |
if colDecimal > 0 && int(colDecimal) != mysql.NotFixedDec { |
case isEFormat: | ||
return formatFloatScientificNotation(in, fVal, prec, bitSize) | ||
case bitSize == 32 && isCustomColumnWidth: | ||
return strconv.AppendFloat(in, fVal, 'f', prec, bitSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's same as the default logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM, thx for your detailed work.
@johan-j: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What problem does this PR solve?
Issue Number: close #22791
Problem Summary:
What is changed and how it works?
What's Changed:
This resolve issue #22791: query result for float type is incompatible with previous version
When #21692 was resolved, it created a new problem reported in #22823 (float/double not displaying decimals)
This resolves issues: #22791, #21692, and a new issue with float I found while working on this (mentioned in comment on issue #22791)
Default width float issue:
For this case there was actually even a test case. But the test case expected
-34028236
as result, which ment it passed even though the value is to precis for mysql.Previously we relied on go's built in strconv.AppendFloat to both round and format. However after much effort I came up with the solution to treat rounding and formatting separately.
Instead now it works in 2 steps:
This also means that the documentation at: https://docs.pingcap.com/tidb/stable/mysql-compatibility#incompatibility-caused-by-deprecated-features
could mention that deprecated types are now compatible with mysql, even if its encouraged to migrate to Decimal. Many big companies still run older versions like 5.7 of mysql and have no plans to migrate. So keeping it compatible might still be important to get some companies to use TiDB.
The new output formatter supports the below scenarios (which is also the doc/comment in the code):
Check List
Tests
Release note
mysql8.0
.