Skip to content

Commit

Permalink
ddl: fix drop multiple partitions with global index (#46908)
Browse files Browse the repository at this point in the history
close #46907
  • Loading branch information
L-maple authored Sep 18, 2023
1 parent 21db64f commit 8d11a2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2206,8 +2206,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

0 comments on commit 8d11a2f

Please sign in to comment.