types: fix delete error when convert string to float or int#10861
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10861 +/- ##
===========================================
Coverage 81.2876% 81.2876%
===========================================
Files 423 423
Lines 90133 90133
===========================================
Hits 73267 73267
Misses 11561 11561
Partials 5305 5305 |
47619a2 to
6e87e72
Compare
There was a problem hiding this comment.
This function is used in StrToUint, maybe not only delete statement?
There was a problem hiding this comment.
The condition statementContext.InDeleteStmt == true will keep it only work in delete statement.
And in delete statement, empty string can always convert to 0 without error and warning.(according to behaviour of mysql 5.x and 8.x ).
But in other statement like select, tidb is consistent with mysql(all with warning), so I restrict it in delete statement context.
There was a problem hiding this comment.
I suggest do not add more parameter for func testStrToFloat, considering 2 points:
- This new parameter
inDeleteStmtonly use in one test case - String is empty. We don't need to bring this parameter to other test case, which is this PR has done. - The test cases of
TestStrToIntandTestStrToUIntare missing. According to the Issue's description #10806, we actually need these test case.
In my view, we could add a new test function for the case of this issue
func testDeleteEmptyStringError(c *C) {
sc := new(stmtctx.StatementContext)
sc.InDeleteStmt = true
str := ""
expect := 0
val, err := StrToInt(sc, str)
c.Assert(err, IsNil)
c.Assert(val, Equals, int64(expect))
val1, err := StrToUint(sc, str)
c.Assert(err, IsNil)
c.Assert(val1, Equals, uint64(expect))
val2, err := StrToFloat(sc, str)
c.Assert(err, IsNil)
c.Assert(val2, Equals, float64(expect))
}and call the new test function in the end of func TestStrToNum
testStrToFloat(c, "-1e649", -math.MaxFloat64, true, ErrTruncatedWrongVal)
testStrToFloat(c, "-1e649", -math.MaxFloat64, false, nil)
+ // for issue #10806
+ testDeleteEmptyStringError(c)
}|
@Deardrops You are right, I have corrected unit test in this pr. |
|
LGTM |
|
@DQinYuan Sorry for the late review. Could you update the PR with the latest master branch and resolve the conflicts? |
What problem does this PR solve?
To fix the issue #10806
When delete from a varchar column only with empty string and a condition compare with a integer or float, tidb will return a "Data Truncated Error" and mysql(both 5.x and 8.x) will only return "Query OK, 0 rows affected (0.01 sec) "
What is changed and how it works?
Before:
After:
modify method
getValidFloatPrefixin types/convert.goWhen stmt context is "delete"(i.e. sc.InDeleteStmt is true) and string is empty,
getValidFloatPrefixdirectly return "0" and nil error.Check List
Tests