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

planner, executor: fix tp.Flen size when union with castIntAsString #8442

Merged
merged 5 commits into from
Nov 27, 2018

Conversation

AndrewDi
Copy link
Contributor

@AndrewDi AndrewDi commented Nov 25, 2018

What problem does this PR solve?

fix #8231, fix tp.Flen size when union with castIntAsString

What is changed and how it works?

When execute func unionJoinFieldType(a, b *types.FieldType) *types.FieldType, if any union type is int and result.Flen is less than mysql.MaxIntWidth then set resultTp.Flen = mysql.MaxIntWidth

Check List

Tests

  • Unit test

This change is Reviewable

@sre-bot
Copy link
Contributor

sre-bot commented Nov 25, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@shenli shenli added contribution This PR is from a community contributor. sig/planner SIG: Planner type/bugfix This PR fixes a bug. labels Nov 25, 2018
@shenli
Copy link
Member

shenli commented Nov 25, 2018

@AndrewDi Thanks! Please fix the CI.

@AndrewDi
Copy link
Contributor Author

@shenli it seems like ci server can not download image.

Build-agent version 0.1.1073-1f69f340 (2018-11-20T18:07:03+0000)
Starting container golang:1.11
  image cache not found on this host, downloading golang:1.11

Error response from daemon: error parsing HTTP 404 response body: invalid character 'p' after top-level value: "404 page not found\n"

@zhouqiang-cl
Copy link
Contributor

/run-all-tests

@zhouqiang-cl
Copy link
Contributor

@AndrewDi I have rerun ci and env is ok. But it failed. PTAL

@XuHuaiyu XuHuaiyu changed the title Planner: fix tp.Flen size when union with castIntAsString planner, executor: fix tp.Flen size when union with castIntAsString Nov 26, 2018
@@ -659,6 +659,9 @@ func unionJoinFieldType(a, b *types.FieldType) *types.FieldType {
resultTp.Decimal = mathutil.Max(a.Decimal, b.Decimal)
// `Flen - Decimal` is the fraction before '.'
resultTp.Flen = mathutil.Max(a.Flen-a.Decimal, b.Flen-b.Decimal) + resultTp.Decimal
if (a.EvalType() == types.ETInt || b.EvalType() == types.ETInt) && resultTp.Flen < mysql.MaxIntWidth {
Copy link
Contributor

Choose a reason for hiding this comment

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

When resultTp is also EvalInt, the truncation would not happen. (Check TestIndexRangeElimininatedProjection)

We may need to check

resultTp.EvalType() != types.ETInt && (a.EvalType() == types.ETInt || b.EvalType() == types.ETInt) && resultTp.Flen < mysql.MaxIntWidth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good, check more strict.

@AndrewDi AndrewDi force-pushed the fix_union_issue_8231 branch from 89b815d to bf1bd1c Compare November 26, 2018 13:23
@AndrewDi
Copy link
Contributor Author

@AndrewDi I have rerun ci and env is ok. But it failed. PTAL

That's wired, I just update branch, and CI check successful.

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 the status/LGT1 Indicates that a PR has LGTM 1. label Nov 26, 2018
@zz-jason
Copy link
Member

@XuHuaiyu PTAL

@XuHuaiyu
Copy link
Contributor

/run-all-tests

@XuHuaiyu
Copy link
Contributor

/run-common-test
/run-integration-common-test
/run-sqllogic-test

tk.MustExec("drop table if exists t1")
tk.MustExec("CREATE TABLE t1 (uid int(1))")
tk.MustExec("INSERT INTO t1 SELECT 150")
tk.MustQuery("SELECT 'a' UNION SELECT uid FROM t1;").Check(testkit.Rows("a", "150"))
Copy link
Contributor

Choose a reason for hiding this comment

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

add order by for union,
since unionExec is executed parallelly.

@AndrewDi AndrewDi force-pushed the fix_union_issue_8231 branch from 8966283 to 3051695 Compare November 27, 2018 00:51
@XuHuaiyu
Copy link
Contributor

/run-common-test
/run-integration-common-test
/run-sqllogic-test

@XuHuaiyu
Copy link
Contributor

/run-common-test
/run-integration-common-test

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

@XuHuaiyu XuHuaiyu added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 27, 2018
@zz-jason zz-jason merged commit 487bb50 into pingcap:master Nov 27, 2018
@zz-jason
Copy link
Member

@AndrewDi Could you cherry-pick this commit to the release-2.1 and release-2.0 branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. sig/planner SIG: Planner 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.

result of union length is wrong
6 participants