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

parser, ddl: support decoding binary literal in set/enum #35822

Merged
merged 9 commits into from
Jun 30, 2022

Conversation

tangenta
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #31338

Problem Summary:

#31338 (comment):

This is because the binary literal like 0xD2BB in enum/set can only be decoded to utf8mb4. When the result is written back to the client, an error occurs because 0xD2BB cannot be encoded with gbk. Thus, the result is truncated.

What is changed and how it works?

After this PR, the enum/set values are saved by parser along with a flag, which is used to indicate that whether it is a binary literal:

// FieldType records field type information.
type FieldType struct {
        // ...
	// elems is the element list for enum and set type.
	elems            []string
	elemsIsBinaryLit []bool
}

In the stage of buildTableInfo, we decode column's FieldType.elems according to the column charset to UTF-8 values, and save it. Thus, the enum/set values are always valid UTF-8, nothing is truncated.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix the incorrect result of `SHOW CREATE TABLE` when specifying binary literals as enum/set values.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jun 29, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Defined2014
  • xhebox

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 submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 29, 2022
Copy link
Contributor

@Defined2014 Defined2014 left a comment

Choose a reason for hiding this comment

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

And seems some problems with ut

ddl/ddl_api.go Show resolved Hide resolved
parser/types/field_type.go Show resolved Hide resolved
for i, e := range elems {
trimmed := strings.TrimRight(e.Value, " ")
tp.SetElemWithIsBinaryLit(i, trimmed, e.IsBinaryLiteral)
fieldLen += len(trimmed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it is not len(tp.GetElem())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are the same string.

Copy link
Contributor

Choose a reason for hiding this comment

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

I knew. My point is that tp.GetElem() makes less assumption about what SetElemWithIsBinaryLit is doing. I won't insist on the change.

Copy link
Contributor Author

@tangenta tangenta Jun 30, 2022

Choose a reason for hiding this comment

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

Actually the fieldLen should not be calculated here because it may change after decoding. Let's remove it.

The one who changes SetElemWithIsBinaryLit should check all the usages.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 30, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Jun 30, 2022

@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 Jun 30, 2022
@tangenta
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 934ea38

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 30, 2022
@Defined2014
Copy link
Contributor

@tangenta Please update mysql-test

@xhebox
Copy link
Contributor

xhebox commented Jun 30, 2022

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 30, 2022
@tangenta
Copy link
Contributor Author

/run-mysql-test tidb-test=pr/1856

@tangenta
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 30, 2022
@ti-chi-bot ti-chi-bot merged commit c578d19 into pingcap:master Jun 30, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Jun 30, 2022

TiDB MergeCI notify

🔴 Bad News! New failing [2] after this pr merged.
These new failed integration tests seem to be caused by the current PR, please try to fix these new failed integration tests, thanks!

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-common-test 🟥 failed 2, success 9, total 11 33 min New failing
idc-jenkins-ci-tidb/common-test 🟥 failed 2, success 10, total 12 9 min 34 sec New failing
idc-jenkins-ci/integration-cdc-test 🟢 all 35 tests passed 31 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 8 min 24 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 6 min 25 sec Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 6 min 6 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 5 min 26 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 17 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 3 min 17 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

you06 added a commit to you06/tidb that referenced this pull request Jul 1, 2022
Signed-off-by: you06 <you1474600@gmail.com>

fix tests

Signed-off-by: you06 <you1474600@gmail.com>

fix test

Signed-off-by: you06 <you1474600@gmail.com>

update

Signed-off-by: you06 <you1474600@gmail.com>

update bazel

Signed-off-by: you06 <you1474600@gmail.com>

fix test

Signed-off-by: you06 <you1474600@gmail.com>

fix test

Signed-off-by: you06 <you1474600@gmail.com>

update

Signed-off-by: you06 <you1474600@gmail.com>

update client-go

Signed-off-by: you06 <you1474600@gmail.com>

update client-go

Signed-off-by: you06 <you1474600@gmail.com>

update grafana

Signed-off-by: you06 <you1474600@gmail.com>

update bazel

Signed-off-by: you06 <you1474600@gmail.com>

display by stack

Signed-off-by: you06 <you1474600@gmail.com>

set request source for ctx of

Signed-off-by: you06 <you1474600@gmail.com>

address comment

Signed-off-by: you06 <you1474600@gmail.com>

address comment

Signed-off-by: you06 <you1474600@gmail.com>

parser, ddl: support decoding binary literal in set/enum (pingcap#35822)

close pingcap#31338

executor: fix a nil point when @@tidb_enable_collect_execution_info is off and cop cache is on (pingcap#35839)

close pingcap#35829

ddl: support drop columns for multi-schema change (pingcap#35737)

ref pingcap#14766

planner: don't push down predicates over table dual (pingcap#35669)

close pingcap#35527

*: Remove some useless staleness code (pingcap#35849)

close pingcap#35848

ddl: fix potential wrong column definition when setting default value (pingcap#35845)

close pingcap#35846

*: add timeout for test cases (pingcap#35844)

ddl: remove `onDropColumns` and `onAddColumns` (pingcap#35862)

ref pingcap#14766

*: Fix Dockerfile (pingcap#35835)

close pingcap#35828

server: refactor TestConnExecutionTimeout (pingcap#35865)

close pingcap#35868

fix test

Signed-off-by: you06 <you1474600@gmail.com>

fix lint

Signed-off-by: you06 <you1474600@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The "show create table" command is incorrect, when "character_set_results = GBK" and it has illegal characters
5 participants