Skip to content
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

Merged
merged 5 commits into from
Feb 8, 2018

Conversation

tiancaiamao
Copy link
Contributor

// 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"))
Copy link
Contributor

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)")
Copy link
Contributor Author

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.

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Feb 6, 2018

/run-all-tests

@coocood
Copy link
Member

coocood commented Feb 6, 2018

LGTM

XuHuaiyu
XuHuaiyu previously approved these changes Feb 6, 2018
Copy link
Contributor

@XuHuaiyu XuHuaiyu left a 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 {
Copy link
Contributor

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?

Copy link
Contributor Author

@tiancaiamao tiancaiamao Feb 6, 2018

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

@zimulala zimulala dismissed XuHuaiyu’s stale review February 6, 2018 11:03

need to address comments

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jackysp jackysp merged commit eaef520 into pingcap:master Feb 8, 2018
@tiancaiamao tiancaiamao deleted the decimal-truncate-as-warning branch February 8, 2018 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants