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: fix type infer when wrap cast decimal as string #7451

Merged
merged 5 commits into from
Aug 21, 2018

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Aug 21, 2018

What problem does this PR solve?

MySQL [test]> create table ee(a decimal(11,8),b decimal(11,8));
Query OK, 0 rows affected (1.16 sec)

MySQL [test]> insert into ee values("114.57011441","38.04620115");
Query OK, 1 row affected (0.28 sec)

Before this PR:

MySQL [test]> select a,b,concat_ws(",",a,b) from ee;
+--------------+-------------+-------------------------+
| a            | b           | concat_ws(",",a,b)      |
+--------------+-------------+-------------------------+
| 114.57011441 | 38.04620115 | 114.5701144,38.04620115 |
+--------------+-------------+-------------------------+
1 row in set, 1 warning (0.00 sec)

After this PR:

MySQL [test]> select a,b,concat_ws(",",a,b) from ee;
+--------------+-------------+-------------------------+
| a            | b           | concat_ws(",",a,b)      |
+--------------+-------------+-------------------------+
| 114.57011441 | 38.04620115 | 114.57011441,38.04620115 |
+--------------+-------------+-------------------------+
1 row in set, 1 warning (0.00 sec)

What is changed and how it works?

When do type inferring for concat_ws, the argument will be wrapped a
CastAsString if the type of the arg is not type string. Especially when the
argument is of type decimal, the result length will be set to the length of the
decimal which do not take the decimal point and the negative sign into
consideration. During evaluation, the result of CastDecimalAsString will be
truncated to the wrong length, and cause the unexpected result of concat_ws.

Check List

Tests

  • Integration test

Code changes

  • Has exported function/method change

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

@XuHuaiyu XuHuaiyu added type/bugfix This PR fixes a bug. sig/execution SIG execution labels Aug 21, 2018
@XuHuaiyu XuHuaiyu added this to the 2.1 milestone Aug 21, 2018
@XuHuaiyu
Copy link
Contributor Author

/run-all-tests

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added status/LGT1 Indicates that a PR has LGTM 1. status/all tests passed labels Aug 21, 2018
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

@XuHuaiyu XuHuaiyu merged commit d9ea38b into pingcap:master Aug 21, 2018
@XuHuaiyu XuHuaiyu deleted the fix/concat_flen branch August 21, 2018 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants