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: fix the bug that wrong collation is used when try fast path for enum or set #23217

Merged
merged 8 commits into from
Mar 12, 2021

Conversation

wjhuang2016
Copy link
Member

Signed-off-by: wjhuang2016 huangwenjun1997@gmail.com

What problem does this PR solve?

Issue Number: close #23053

Problem Summary:
When comparing datum, we used the wrong collation.

		dVal, err := d.ConvertTo(stmtCtx, &col.FieldType)
		if err != nil {
			if terror.ErrorEqual(types.ErrOverflow, err) {
				return append(nvPairs, nameValuePair{colName: colName.Name.Name.L, value: d, param: param}), true
			}
			// Some scenarios cast to int with error, but we may use this value in point get.
			if !terror.ErrorEqual(types.ErrTruncatedWrongVal, err) {
				return nil, false
			}
		}
		cmp, err := d.CompareDatum(stmtCtx, &dval)

CompareDatum uses the d's collation, which is wrong.

What is changed and how it works?

d.CompareDatum(stmtCtx, &dval) =>
dVal.CompareDatum(stmtCtx, &d)

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Side effects

Release note

  • fix the bug that wrong collation is used when try fast path for enum or set

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
@wjhuang2016 wjhuang2016 requested review from a team as code owners March 9, 2021 11:30
@wjhuang2016 wjhuang2016 requested review from lzmhhh123 and removed request for a team March 9, 2021 11:30
@ti-chi-bot ti-chi-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 9, 2021
@wjhuang2016 wjhuang2016 added needs-cherry-pick-4.0 type/bugfix This PR fixes a bug. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 9, 2021
@ichn-hu ichn-hu mentioned this pull request Mar 9, 2021
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c set('A', 'B') collate utf8mb4_general_ci);")
tk.MustExec("insert into t values('a');")
tk.MustQuery("select c from t1 where c = 'a';").Check(testkit.Rows("A"))
Copy link
Contributor

@Reminiscent Reminiscent Mar 10, 2021

Choose a reason for hiding this comment

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

Here should be select c from t where c = 'a';(table t not the t1)

@qw4990 qw4990 self-requested a review March 10, 2021 02:54
Copy link
Contributor

@qw4990 qw4990 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 CI problem:

[2021-03-09T11:40:22.369Z] FAIL: integration_test.go:6242: testIntegrationSerialSuite.TestCollationBasic
``` @wjhuang2016 

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c set('A', 'B') collate utf8mb4_general_ci);")
tk.MustExec("insert into t values('a');")
tk.MustQuery("select c from t1 where c = 'a';").Check(testkit.Rows("A"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add more test queries like this comment.

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 11, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 12, 2021
Copy link
Contributor

@Reminiscent Reminiscent left a comment

Choose a reason for hiding this comment

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

/LGTM

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Reminiscent
  • qw4990

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 12, 2021
@Reminiscent
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 2d140c4

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2021
@ti-chi-bot ti-chi-bot merged commit 689a598 into pingcap:master Mar 12, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 12, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #23292

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 12, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0-rc in PR #23293

ti-chi-bot pushed a commit that referenced this pull request Mar 18, 2021
@wjhuang2016 wjhuang2016 deleted the fix_fast_enumset branch November 17, 2022 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression size/S Denotes a PR that changes 10-29 lines, ignoring generated files. 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.

wrong fast plan for set or enum
5 participants