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 drop multiple partitions with global index #46908

Merged
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
3 changes: 2 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2190,8 +2190,9 @@ func (w *worker) updateReorgInfoForPartitions(t table.PartitionedTable, reorg *r
if i == len(partitionIDs)-1 {
return true, nil
}
pid = partitionIDs[i+1]
break
}
pid = partitionIDs[i+1]
}

currentVer, err := getValidCurrentVersion(reorg.d.store)
Expand Down
38 changes: 38 additions & 0 deletions ddl/tests/partition/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,44 @@ func TestDropPartitionWithGlobalIndex(t *testing.T) {
require.Equal(t, 2, cnt)
}

func TestDropMultiPartitionWithGlobalIndex(t *testing.T) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableGlobalIndex = true
})
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists test_global")
tk.MustExec(`create table test_global ( a int, b int, c int)
partition by range( a ) (
partition p1 values less than (10),
partition p2 values less than (20),
partition p3 values less than (30)
);`)
tt := external.GetTableByName(t, tk, "test", "test_global")
pid := tt.Meta().Partition.Definitions[1].ID

tk.MustExec("Alter Table test_global Add Unique Index idx_b (b);")
tk.MustExec("Alter Table test_global Add Unique Index idx_c (c);")
tk.MustExec(`INSERT INTO test_global VALUES (1, 1, 1), (2, 2, 2), (11, 3, 3), (12, 4, 4), (21, 21, 21), (29, 29, 29)`)

tk.MustExec("alter table test_global drop partition p1, p2;")
result := tk.MustQuery("select * from test_global;")
result.Sort().Check(testkit.Rows("21 21 21", "29 29 29"))

tt = external.GetTableByName(t, tk, "test", "test_global")
idxInfo := tt.Meta().FindIndexByName("idx_b")
require.NotNil(t, idxInfo)
cnt := checkGlobalIndexCleanUpDone(t, tk.Session(), tt.Meta(), idxInfo, pid)
require.Equal(t, 2, cnt)

idxInfo = tt.Meta().FindIndexByName("idx_c")
require.NotNil(t, idxInfo)
cnt = checkGlobalIndexCleanUpDone(t, tk.Session(), tt.Meta(), idxInfo, pid)
require.Equal(t, 2, cnt)
}

func TestGlobalIndexInsertInDropPartition(t *testing.T) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
Expand Down