Skip to content

Commit

Permalink
ddl: fix add multi-indexes merge on partition tables (#52109)
Browse files Browse the repository at this point in the history
close #52080
  • Loading branch information
tangenta authored Mar 26, 2024
1 parent 8428e38 commit 094f4df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
7 changes: 5 additions & 2 deletions pkg/ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2277,8 +2277,11 @@ func getNextPartitionInfo(reorg *reorgInfo, t table.PartitionedTable, currPhysic

var startKey, endKey kv.Key
if reorg.mergingTmpIdx {
indexID := reorg.currElement.ID
startKey, endKey = tablecodec.GetTableIndexKeyRange(pid, tablecodec.TempIndexPrefix|indexID)
elements := reorg.elements
firstElemTempID := tablecodec.TempIndexPrefix | elements[0].ID
lastElemTempID := tablecodec.TempIndexPrefix | elements[len(elements)-1].ID
startKey = tablecodec.EncodeIndexSeekKey(pid, firstElemTempID, nil)
endKey = tablecodec.EncodeIndexSeekKey(pid, lastElemTempID, []byte{255})
} else {
currentVer, err := getValidCurrentVersion(reorg.d.store)
if err != nil {
Expand Down
35 changes: 20 additions & 15 deletions pkg/ddl/ingest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,26 @@ func TestMultiSchemaAddIndexMerge(t *testing.T) {
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")

tk.MustExec("create table t (a int, b int);")
tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3);")

first := true
var tk2Err error
ingest.MockExecAfterWriteRow = func() {
if !first {
return
for _, createTableSQL := range []string{
"create table t (a int, b int);",
"create table t (a int, b int) PARTITION BY HASH (`a`) PARTITIONS 4;",
} {
tk.MustExec("drop table if exists t;")
tk.MustExec(createTableSQL)
tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3);")

first := true
var tk2Err error
ingest.MockExecAfterWriteRow = func() {
if !first {
return
}
_, tk2Err = tk2.Exec("insert into t values (4, 4), (5, 5);")
first = false
}
_, tk2Err = tk2.Exec("insert into t values (4, 4);")
first = false
tk.MustExec("alter table t add index idx1(a), add index idx2(b);")
require.False(t, first)
require.NoError(t, tk2Err)
tk.MustExec("admin check table t;")
}

tk.MustExec("alter table t add index idx1(a), add index idx2(b);")
require.False(t, first)
require.NoError(t, tk2Err)
tk.MustExec("admin check table t;")
}

0 comments on commit 094f4df

Please sign in to comment.