-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Fix bit default value bug #7249
Fix bit default value bug #7249
Conversation
/run-all-tests |
@@ -66,6 +66,7 @@ type ColumnInfo struct { | |||
Offset int `json:"offset"` | |||
OriginDefaultValue interface{} `json:"origin_default"` | |||
DefaultValue interface{} `json:"default"` | |||
DefaultValueBit []byte `json:"default_bit"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use a uniform default value in cloumn info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.google.com/document/d/17REO2MQ5v_AFOBE9ovehZDGlrtvhjCy3S1p7F1HWaSc/edit
This document explains the reason to do this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to write down how to do it in the description of PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- What's the problem
- How to do it
- Is there any compatibility problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ciscoxll done. PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be incompatible when rolling update TiDB?
As follows case:
On new TiDB, we builds a "add column" job , then we handle the DDL job on Old TiDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zimulala No. It is compatible.
if old tidb to handle job that created by new tidb, old tidb will ignore the DefaultValueBit
.
I have done an experiment in this scene.
/run-all-tests |
/run-unit-test |
Should we modify coprocessor? |
…_default_value_bug
@shenli , currently we don't support pushdown the |
…_default_value_bug
model/model.go
Outdated
return nil | ||
} | ||
return types.ErrInvalidDefault.GenByArgs(c.Name) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this useless line.
/run-all-tests |
/run-unit-test |
LGTM |
…_default_value_bug
4b55313
to
619da40
Compare
model/model.go
Outdated
return nil | ||
} | ||
|
||
// GetDefaultValue gets the default value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we need to add more comments. I understand that GetDefaultValue
will return the default value of the column but I am more interested in the case handling logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetDefaultValue
just return the column's default value.
just use column.GetDefaultValue()
instead of column.DefaultValue
,
because the bit type default value will stored in DefaultValueBit
field.
…_default_value_bug
…_default_value_bug
…_default_value_bug
/run-all-tests |
model/model.go
Outdated
// bit type default value will store in DefaultValueBit for fix bit default value decode/encode bug. | ||
func (c *ColumnInfo) GetDefaultValue() interface{} { | ||
if c.Tp == mysql.TypeBit && c.DefaultValueBit != nil { | ||
return string(c.DefaultValueBit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use hack.String()
?
model/model.go
Outdated
func (c *ColumnInfo) SetDefaultValue(value interface{}) error { | ||
c.DefaultValue = value | ||
if c.Tp == mysql.TypeBit { | ||
if v, ok := value.(string); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more description here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reset LGTM, please address comment
// GetDefaultValue gets the default value of the column. | ||
// Default value use to stored in DefaultValue field, but now, | ||
// bit type default value will store in DefaultValueBit for fix bit default value decode/encode bug. | ||
func (c *ColumnInfo) GetDefaultValue() interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change all "c.DefaultValue" to "GetDefaultValue()"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ye~ I have already changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"if column.DefaultValue != nil" in column.go, the ColumnInfo
in column.go is not the ColumnInfo
in model.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to replace "c.DefaultValue = types.ZeroDatetimeStr" with "SetDefaultValue()" in ddl_api.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh...
ye...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
b809f35
to
16028de
Compare
/run-all-tests |
…_default_value_bug
16028de
to
5752ccb
Compare
/run-all-tests |
What have you changed? (mandatory)
add
DefaultValueBit
toColumnInfo
to store the bit default value.old -> new : Does not affect the old data.
new -> old : May have compatibility problem when the byte of default bit value >= 128. Because the old version always have the bug.
new:
rollback to old:
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
unit test
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
No
Does this PR affect tidb-ansible update? (mandatory)
No
Does this PR need to be added to the release notes? (mandatory)
No
Refer to a related PR or issue link (optional)
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)