Skip to content

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

Merged
qw4990 merged 9 commits intopingcap:masterfrom
qw4990:bugfix-decimal-div
Feb 7, 2020
Merged

expression: handle ErrTruncated when dividing decimals in non-data-change stmts#14438
qw4990 merged 9 commits intopingcap:masterfrom
qw4990:bugfix-decimal-div

Conversation

@qw4990
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

qw4990 commented Jan 10, 2020

/run-all-tests

Copy link
Copy Markdown
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