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

expression: handle ErrTruncated when dividing decimals in non-data-change stmts #14438

Merged
merged 9 commits into from
Feb 7, 2020

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Jan 10, 2020

What problem does this PR solve?

Handle ErrTruncated when dividing decimals.
Before this PR:

mysql> select cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30));
ERROR 1265 (01000): Data truncated for column '%s' at row %d

After this PR:

mysql> select cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30));
+------------------------------------------------------------------------------------+
| cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30)) |
+------------------------------------------------------------------------------------+
|                                                   0.111111111111111111111111111111 |
+------------------------------------------------------------------------------------+

In MySQL:

mysql> select cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30));
+------------------------------------------------------------------------------------+
| cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30)) |
+------------------------------------------------------------------------------------+
|                                                   0.111111111111111111111111111111 |
+------------------------------------------------------------------------------------+

Check List

Tests

  • Unit test

@qw4990 qw4990 requested a review from a team as a code owner January 10, 2020 06:03
@ghost ghost requested review from SunRunAway and XuHuaiyu and removed request for a team January 10, 2020 06:03
@qw4990
Copy link
Contributor Author

qw4990 commented Jan 10, 2020

/run-all-tests

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

Please fix the test case.

@qw4990 qw4990 closed this Feb 5, 2020
@qw4990 qw4990 reopened this Feb 5, 2020
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

/run-all-tests

@qw4990 qw4990 changed the title expression: fix wrong fraction when dividing decimals in some cases expression: handle ErrTruncated when dividing decimals Feb 6, 2020
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

/rebuild

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

/run-all-tests

2 similar comments
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

/run-all-tests

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

/run-all-tests

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

/run-unit-test

@qw4990 qw4990 requested a review from wshwsh12 February 6, 2020 08:37
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

@SunRunAway @XuHuaiyu @wshwsh12 All CI problems have been resolved, PTAL~!

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Feb 6, 2020

MySQL works fine...

tidb> create table t(a int);
Query OK, 0 rows affected (0.01 sec)

tidb> insert into t values(cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30)));
ERROR 1292 (22007): Truncated incorrect DECIMAL value: '0.111111111111111111111111111111'

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 6, 2020

MySQL works fine...

tidb> create table t(a int);
Query OK, 0 rows affected (0.01 sec)

tidb> insert into t values(cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30)));
ERROR 1292 (22007): Truncated incorrect DECIMAL value: '0.111111111111111111111111111111'

What's the version of your MySQL? In my MySQL 8x, the result is below:

mysql> create table t (a int);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t values(cast(1 as decimal(60,30)) / cast(3 as decimal(60,30)) / cast(3 as decimal(60, 30)));
Query OK, 1 row affected (0.02 sec)

@XuHuaiyu XuHuaiyu changed the title expression: handle ErrTruncated when dividing decimals expression: handle ErrTruncated when dividing decimals in non-data-change stmts Feb 7, 2020
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

wshwsh12
wshwsh12 previously approved these changes Feb 7, 2020
Copy link
Contributor

@wshwsh12 wshwsh12 left a comment

Choose a reason for hiding this comment

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

LGTM

@wshwsh12 wshwsh12 added status/LGT2 Indicates that a PR has LGTM 2. status/can-merge Indicates a PR has been approved by a committer. labels Feb 7, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Feb 7, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Feb 7, 2020

@qw4990 merge failed.

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 7, 2020

/run-unit-test

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 7, 2020

/run-all-tests

@qw4990
Copy link
Contributor Author

qw4990 commented Feb 7, 2020

/run-all-tests

1 similar comment
@qw4990
Copy link
Contributor Author

qw4990 commented Feb 7, 2020

/run-all-tests

@qw4990 qw4990 merged commit 22fb77e into pingcap:master Feb 7, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Feb 7, 2020

cherry pick to release-3.0 failed

@sre-bot
Copy link
Contributor

sre-bot commented Apr 7, 2020

It seems that, not for sure, we failed to cherry-pick this commit to release-3.0. Please comment '/run-cherry-picker' to try to trigger the cherry-picker if we did fail to cherry-pick this commit before. @qw4990 PTAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants