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: do not set ParseToJSONFlag to a JSON column #8564

Merged
merged 7 commits into from
Dec 12, 2018

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Dec 4, 2018

What problem does this PR solve?

Do not set ParseToJSONFlag to a JSON column which can avoid the data race when another goroutine tries to read the column's flag.

What is changed and how it works?

ParseToJSONFlag is used to effect the behavior of castStringAsJSON.
If ParseToJSONFlag is set, we invoke json.ParseBinaryFromString(str) to parse this string to a JSON, where str must be a valid JSON-string (e.g. '"abc"').
Or, we use json.CreateBinary(str) to wrap this string as a JSON directly without check.

ParseToJSONFlag is introduced to resolve the compatibility of compare function and JSON-related function with MySQL.

e.g.:

json_unquote(str)    -- We use CreateBinary(str)
json_merge(str, str) -- We use ParseBinaryFromString(str)

For a JSON column, we do not need to set this flag for it.

Check List

Tests

  • No code

Code changes

  • Has exported function/method change

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch
    release-2.1 release-2.0

This change is Reviewable

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Dec 4, 2018

/run-all-tests

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Dec 4, 2018

PTAL @winoros @zz-jason

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

XuHuaiyu commented Dec 6, 2018

/run-common-test tidb-test=pr/676
/run-integration-common-test tidb-test=pr/676

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Dec 6, 2018

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

// Moreover, Column.RetType refers to the infoschema, if we modify
// it, data race may happen if another goroutine read from the
// infoschema at the same time.
if _, isColumn := args[i].(*Column); isColumn {
Copy link
Member

@zz-jason zz-jason Dec 6, 2018

Choose a reason for hiding this comment

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

Can we extract a common function to do it? There are a lot of duplicated code and comments.

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Dec 6, 2018

/run-common-test tidb-test=pr/676

@XuHuaiyu
Copy link
Contributor Author

/run-all-tests

@winoros winoros added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 12, 2018
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/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 12, 2018
@XuHuaiyu XuHuaiyu merged commit 63e7dac into pingcap:master Dec 12, 2018
@XuHuaiyu XuHuaiyu deleted the copy_jsonflag branch December 12, 2018 05:36
XuHuaiyu added a commit to XuHuaiyu/tidb that referenced this pull request Dec 12, 2018
XuHuaiyu added a commit to XuHuaiyu/tidb that referenced this pull request Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression 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.

3 participants