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

ddl: fix corrupted default value for bit type column (#18036) #20339

Merged
merged 8 commits into from
Nov 13, 2020

Conversation

ti-srebot
Copy link
Contributor

cherry-pick #18036 to release-3.0


What problem does this PR solve?

Issue Number: close #17641 close #17642

Problem Summary:

The ColumnInfo.OriginDefaultValue is corrupted when the column type is BIT. BIT type column values are stored as strings by JSON marshaling and read it by unmarshaling later. However, the data in a string can be changed in this case:

originBytes := []byte{25, 185}
originStr := string(originBytes)

mr, _ := json.Marshal(originStr)
var jsoned string
_ = json.Unmarshal(mr, &jsoned)

fmt.Printf("%v\n", []byte(originStr))
fmt.Printf("%v\n", []byte(jsoned))
[25 185]
[25 239 191 189]

If we store it as []byte, the problem disappeared. This is how DefaultValueBit works.

type ColumnInfo struct {
	// ...
	OriginDefaultValue    interface{} `json:"origin_default"`
	DefaultValue          interface{} `json:"default"`
	DefaultValueBit       []byte      `json:"default_bit"`
	// ...
}

The same problem exists in OriginDefaultValue. PR #12168 tried to restore the OriginDefaultValue from DefaultValueBit in the getter, but OriginDefaultValue is different from DefaultValue: OriginDefaultValue is used to skip the backfilling phase of AddColumn(). If a column's default value is modified by ALTER TABLE MODIFY COLUMN DEFAULT, they are not equal anymore(see the example in #17641).

What is changed and how it works?

This PR adds a field OriginDefaultValueBit to ColumnInfo, which borrows from DefaultValueBit to solve the problem completely.

Proposal: xxx

What's Changed:

How it Works:
If the column type is BIT, set/get the content with OriginDefaultValueBit.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

Release note

  • fix corrupted default value for bit type column.

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot added sig/sql-infra SIG: SQL Infra type/3.0-cherry-pick type/bugfix This PR fixes a bug. labels Oct 4, 2020
@ti-srebot ti-srebot added this to the 3.0.20 milestone Oct 4, 2020
@djshow832 djshow832 removed their request for review October 13, 2020 08:22
@tangenta tangenta added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Oct 14, 2020
@bb7133
Copy link
Member

bb7133 commented Nov 11, 2020

Please resolve the conflicts @tangenta

@bb7133
Copy link
Member

bb7133 commented Nov 11, 2020

/run-check_dev

@tangenta
Copy link
Contributor

Waiting for pingcap/parser#1090.

@bb7133
Copy link
Member

bb7133 commented Nov 13, 2020

/run-all-tests

@bb7133
Copy link
Member

bb7133 commented Nov 13, 2020

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 13, 2020
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

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 13, 2020
@zz-jason
Copy link
Member

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 13, 2020
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot merged commit 485833e into pingcap:release-3.0 Nov 13, 2020
@SunRunAway SunRunAway deleted the release-3.0-6342fa6a5068 branch December 21, 2020 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/sql-infra SIG: SQL Infra 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. type/3.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants