-
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
types,executor: treat decimal truncate as warning in update #5801
types,executor: treat decimal truncate as warning in update #5801
Conversation
executor/write_test.go
Outdated
// A warning rather than data truncated error. | ||
tk.MustExec("update decimals set a = a + 1.23;") | ||
r = tk.MustQuery("select * from decimals") | ||
r.Check(testkit.Rows("202")) |
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.
add show warnings here
_, err := tk.Exec(`select * from sc where a > cast(1.1 as decimal); | ||
update sc set a = 4 where a > cast(1.1 as decimal)`) | ||
c.Check(terror.ErrorEqual(err, types.ErrTruncated), IsTrue) | ||
tk.MustExec("update sc set a = 4 where a > cast(1.1 as decimal)") |
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've tested that this behavior confirms to MySQL 5.6, 5.7...
The previous code is wrong.
/run-all-tests |
LGTM |
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.
LGTM
@@ -1087,8 +1087,9 @@ func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.Statem | |||
return nil, errors.Trace(err) | |||
} | |||
if !dec.IsZero() && frac > decimal && dec.Compare(&old) != 0 { | |||
if sc.InInsertStmt { | |||
if sc.InInsertStmt || sc.InUpdateOrDeleteStmt { |
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.
Do we need to add a test for delete
SQL?
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.
Delete behavior is different from MySQL:
mysql> select * from decimals;
+-----+
| a |
+-----+
| 201 |
+-----+
1 row in set (0.00 sec)
MySQL:
mysql> delete from decimals where a = cast(201.2 as decimal(20,0));
Query OK, 1 row affected (0.00 sec)
TiDB:
mysql> delete from decimals where a = cast(201.2 as decimal(20,0));
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+----------------+
| Level | Code | Message |
+---------+------+----------------+
| Warning | 1265 | Data Truncated |
+---------+------+----------------+
1 row in set (0.00 sec)
Although it's not the same behavior as MySQL, the result in this PR is more acceptable for delete statement than before.
@zimulala
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.
LGTM
Fix issue #5532
@coocood @zimulala @XuHuaiyu