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

*: fix writing null value into not null column in write-only state. #6249

Merged
merged 4 commits into from
Apr 10, 2018

Conversation

coocood
Copy link
Member

@coocood coocood commented Apr 9, 2018

GetColDefaultValue returns null if the column is not public which cause writing null value into the not null column.

GetColDefaultValue returns null if the column is not public which cause writing null value into the not null column.
@coocood coocood added the type/bugfix This PR fixes a bug. label Apr 9, 2018
@coocood coocood changed the title *: fix update write-only not null column with null value. *: fix write null value into not null column in write-only state. Apr 9, 2018
@coocood coocood changed the title *: fix write null value into not null column in write-only state. *: fix writing null value into not null column in write-only state. Apr 9, 2018
@coocood
Copy link
Member Author

coocood commented Apr 9, 2018

/run-all-tests

tk1.MustExec("alter table nn add column c int not null default 0")
close(closeCh)
wg.Wait()
c.Assert(tk2Err, IsNil)
Copy link
Member

Choose a reason for hiding this comment

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

Should we check the result of select count(*) from nn where c is null; is zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not needed, the test fails every time before the fix.

}
}
}()
tk1.MustExec("alter table nn add column c int not null default 0")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use ddl hooker to sleep a while in write-only stage, like runTestInSchemaState does?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not needed, the test fails every time before the fix.

Copy link
Member

Choose a reason for hiding this comment

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

I'll add the test in another pr.

@coocood
Copy link
Member Author

coocood commented Apr 9, 2018

/run-all-tests

if err != nil {
return errors.Trace(err)
}
// Fill write-only columns with originDefaultValue if value is null.
for _, col := range cols {
if col.State != model.StatePublic && oldRow[col.Offset].IsNull() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check the null value is updated by other TiDBs?

// Fill write-only columns with originDefaultValue if value is null.
for _, col := range cols {
if col.State != model.StatePublic && oldRow[col.Offset].IsNull() {
oldRow[col.Offset], err = table.GetColOriginDefaultValue(e.ctx, col.ToInfo())
Copy link
Contributor

Choose a reason for hiding this comment

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

Cloud we put this logic to UpdateRecord in tables.go?

@coocood
Copy link
Member Author

coocood commented Apr 9, 2018

/run-all-tests

if err != nil {
return errors.Trace(err)
}
// Fill write-only columns with originDefaultValue if not found in oldValue is null.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add write-reorg to this comment?

@@ -515,8 +515,7 @@ func (t *Table) RowWithCols(ctx sessionctx.Context, h int64, cols []*table.Colum

// DecodeRawRowData decodes raw row data to a datum row.
func DecodeRawRowData(ctx sessionctx.Context, meta *model.TableInfo, h int64, cols []*table.Column,
value []byte) ([]types.Datum,
error) {
value []byte) ([]types.Datum, map[int64]types.Datum, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Add comment for the new return value.

@zimulala
Copy link
Contributor

zimulala commented Apr 9, 2018

LGTM

@shenli
Copy link
Member

shenli commented Apr 9, 2018

LGTM

@coocood coocood merged commit 2b2522b into pingcap:master Apr 10, 2018
@coocood coocood deleted the fix-add-not-null-column branch April 10, 2018 01:21
@@ -506,17 +506,16 @@ func (t *Table) RowWithCols(ctx sessionctx.Context, h int64, cols []*table.Colum
if err != nil {
return nil, errors.Trace(err)
}
v, err := DecodeRawRowData(ctx, t.Meta(), h, cols, value)
v, _, err := DecodeRawRowData(ctx, t.Meta(), h, cols, value)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to get the default value once again as we did in duplicate update?

jackysp added a commit to jackysp/tidb that referenced this pull request Apr 13, 2018
jackysp added a commit that referenced this pull request Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants