-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"math/rand" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/juju/errors" | ||
|
@@ -1811,3 +1812,34 @@ func (s *testDBSuite) TestCharacterSetInColumns(c *C) { | |
s.tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name != 'utf8'").Check(testkit.Rows("0")) | ||
s.tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name = 'utf8'").Check(testkit.Rows("2")) | ||
} | ||
|
||
func (s *testDBSuite) TestAddNotNullColumnWhileInsertOnDupUpdate(c *C) { | ||
tk1 := testkit.NewTestKit(c, s.store) | ||
tk1.MustExec("use " + s.schemaName) | ||
tk2 := testkit.NewTestKit(c, s.store) | ||
tk2.MustExec("use " + s.schemaName) | ||
closeCh := make(chan bool) | ||
wg := new(sync.WaitGroup) | ||
wg.Add(1) | ||
tk1.MustExec("create table nn (a int primary key, b int)") | ||
tk1.MustExec("insert nn values (1, 1)") | ||
var tk2Err error | ||
go func() { | ||
defer wg.Done() | ||
for { | ||
select { | ||
case <-closeCh: | ||
return | ||
default: | ||
} | ||
_, tk2Err = tk2.Exec("insert nn (a, b) values (1, 1) on duplicate key update a = 1, b = b + 1") | ||
if tk2Err != nil { | ||
return | ||
} | ||
} | ||
}() | ||
tk1.MustExec("alter table nn add column c int not null default 0") | ||
close(closeCh) | ||
wg.Wait() | ||
c.Assert(tk2Err, IsNil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check the result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not needed, the test fails every time before the fix. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
return v, nil | ||
} | ||
|
||
// DecodeRawRowData decodes raw row data to a datum row. | ||
// DecodeRawRowData decodes raw row data into a datum slice and a (columnID:columnValue) map. | ||
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) { | ||
v := make([]types.Datum, len(cols)) | ||
colTps := make(map[int64]*types.FieldType, len(cols)) | ||
for i, col := range cols { | ||
|
@@ -535,7 +534,7 @@ func DecodeRawRowData(ctx sessionctx.Context, meta *model.TableInfo, h int64, co | |
} | ||
rowMap, err := tablecodec.DecodeRow(value, colTps, ctx.GetSessionVars().GetTimeZone()) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
return nil, rowMap, errors.Trace(err) | ||
} | ||
defaultVals := make([]types.Datum, len(cols)) | ||
for i, col := range cols { | ||
|
@@ -552,10 +551,10 @@ func DecodeRawRowData(ctx sessionctx.Context, meta *model.TableInfo, h int64, co | |
} | ||
v[i], err = GetColDefaultValue(ctx, col, defaultVals) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
return nil, rowMap, errors.Trace(err) | ||
} | ||
} | ||
return v, nil | ||
return v, rowMap, nil | ||
} | ||
|
||
// Row implements table.Table Row 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.
Can we use ddl hooker to sleep a while in write-only stage, like runTestInSchemaState does?
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's not needed, the test fails every time before the fix.
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'll add the test in another pr.