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

admin: support cleanup multi-valued index #40428

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion executor/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (e *CleanupIndexExec) getIdxColTypes() []*types.FieldType {
}
e.idxColFieldTypes = make([]*types.FieldType, 0, len(e.columns))
for _, col := range e.columns {
e.idxColFieldTypes = append(e.idxColFieldTypes, &col.FieldType)
e.idxColFieldTypes = append(e.idxColFieldTypes, col.FieldType.ArrayType())
xhebox marked this conversation as resolved.
Show resolved Hide resolved
}
return e.idxColFieldTypes
}
Expand Down
45 changes: 45 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,51 @@ func TestAdminRecoverIndex(t *testing.T) {
tk.MustExec("admin check table admin_test")
}

func TestAdminCleanupMVIndex(t *testing.T) {
store, domain := testkit.CreateMockStoreAndDomain(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(pk int primary key, a json, index idx((cast(a as signed array))))")
tk.MustExec("insert into t values (0, '[0,1,2]')")
tk.MustExec("insert into t values (1, '[1,2,3]')")
tk.MustExec("insert into t values (2, '[2,3,4]')")
tk.MustExec("insert into t values (3, '[3,4,5]')")
tk.MustExec("insert into t values (4, '[4,5,6]')")
tk.MustExec("admin check table t")

// Make some corrupted index. Build the index information.
ctx := mock.NewContext()
ctx.Store = store
is := domain.InfoSchema()
dbName := model.NewCIStr("test")
tblName := model.NewCIStr("t")
tbl, err := is.TableByName(dbName, tblName)
require.NoError(t, err)
tblInfo := tbl.Meta()
idxInfo := tblInfo.Indices[0]
tk.Session().GetSessionVars().IndexLookupSize = 3
tk.Session().GetSessionVars().MaxChunkSize = 3

cpIdx := idxInfo.Clone()
cpIdx.MVIndex = false
indexOpr := tables.NewIndex(tblInfo.ID, tblInfo, cpIdx)

txn, err := store.Begin()
require.NoError(t, err)
_, err = indexOpr.Create(ctx, txn, types.MakeDatums(9), kv.IntHandle(9), nil)
require.NoError(t, err)
err = txn.Commit(context.Background())
require.NoError(t, err)
err = tk.ExecToErr("admin check table t")
require.Error(t, err)

r := tk.MustQuery("admin cleanup index t idx")
r.Check(testkit.Rows("1"))
tk.MustExec("admin check table t")
}

func TestClusteredIndexAdminRecoverIndex(t *testing.T) {
store, domain := testkit.CreateMockStoreAndDomain(t)

Expand Down
3 changes: 2 additions & 1 deletion table/tables/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func (c *index) getIndexedValue(indexedValues []types.Datum) [][]types.Datum {
if !c.tblInfo.Columns[c.idxInfo.Columns[i].Offset].FieldType.IsArray() {
val = append(val, v)
} else {
if v.IsNull() {
// if the datum type is not JSON, it must come from cleanup index.
if v.IsNull() || v.Kind() != types.KindMysqlJSON {
val = append(val, v)
jsonIsNull = true
continue
Expand Down