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

partition: set AddRecordOpt.isUpdate = true when update partition records (#57590) #57622

Open
wants to merge 2 commits into
base: release-8.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/ddl/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,27 @@ func TestReorganizePartitionRollback(t *testing.T) {
// test then add index should success
tk.MustExec("alter table t1 add index idx_kc (k, c)")
}

func TestUpdateDuringAddColumn(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (c1 int, c2 int) partition by hash (c1) partitions 16")
tk.MustExec("insert t1 values (1, 1), (2, 2)")
tk.MustExec("create table t2 (c1 int, c2 int) partition by hash (c1) partitions 16")
tk.MustExec("insert t2 values (1, 3), (2, 5)")
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")

testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobUpdated", func(job *model.Job) {
if job.SchemaState == model.StateWriteOnly {
tk2.MustExec("update t1, t2 set t1.c1 = 8, t2.c2 = 10 where t1.c2 = t2.c1")
tk2.MustQuery("select * from t1").Sort().Check(testkit.Rows("8 1", "8 2"))
tk2.MustQuery("select * from t2").Sort().Check(testkit.Rows("1 10", "2 10"))
}
})

tk.MustExec("alter table t1 add column c3 bigint default 9")

tk.MustQuery("select * from t1").Sort().Check(testkit.Rows("8 1 9", "8 2 9"))
}
2 changes: 1 addition & 1 deletion pkg/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (opt *UpdateRecordOpt) SkipWriteUntouchedIndices() bool {

// GetAddRecordOpt creates a AddRecordOpt.
func (opt *UpdateRecordOpt) GetAddRecordOpt() *AddRecordOpt {
return &AddRecordOpt{commonMutateOpt: opt.commonMutateOpt}
return &AddRecordOpt{commonMutateOpt: opt.commonMutateOpt, isUpdate: true}
}

// GetCreateIdxOpt creates a CreateIdxOpt.
Expand Down
4 changes: 2 additions & 2 deletions pkg/table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func TestOptions(t *testing.T) {
// NewUpdateRecordOpt without option
updateOpt := NewUpdateRecordOpt()
require.Equal(t, UpdateRecordOpt{}, *updateOpt)
require.Equal(t, AddRecordOpt{}, *(updateOpt.GetAddRecordOpt()))
require.Equal(t, AddRecordOpt{isUpdate: true}, *(updateOpt.GetAddRecordOpt()))
require.Equal(t, CreateIdxOpt{}, *(updateOpt.GetCreateIdxOpt()))
// NewUpdateRecordOpt with options
updateOpt = NewUpdateRecordOpt(WithCtx(ctx))
require.Equal(t, UpdateRecordOpt{commonMutateOpt: commonMutateOpt{ctx: ctx}}, *updateOpt)
require.Equal(t, AddRecordOpt{commonMutateOpt: commonMutateOpt{ctx: ctx}}, *(updateOpt.GetAddRecordOpt()))
require.Equal(t, AddRecordOpt{commonMutateOpt: commonMutateOpt{ctx: ctx}, isUpdate: true}, *(updateOpt.GetAddRecordOpt()))
require.Equal(t, CreateIdxOpt{commonMutateOpt: commonMutateOpt{ctx: ctx}}, *(updateOpt.GetCreateIdxOpt()))
// NewCreateIdxOpt without option
createIdxOpt := NewCreateIdxOpt()
Expand Down