Skip to content

Commit c67e997

Browse files
committed
DDL: Support Hybrid index creation and import - initial commit.
1 parent 9faed3c commit c67e997

File tree

14 files changed

+12853
-11451
lines changed

14 files changed

+12853
-11451
lines changed

‎pkg/ddl/executor.go‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,8 @@ func (e *executor) AlterTable(ctx context.Context, sctx sessionctx.Context, stmt
17821782
switch constr.Option.Tp {
17831783
case ast.IndexTypeFulltext:
17841784
err = e.createFulltextIndex(sctx, ident, ast.NewCIStr(constr.Name), spec.Constraint.Keys, constr.Option, constr.IfNotExists)
1785+
case ast.IndexTypeHybrid:
1786+
err = e.createHybridIndex(sctx, ident, ast.NewCIStr(constr.Name), spec.Constraint.Keys, constr.Option, constr.IfNotExists)
17851787
default:
17861788
err = e.createColumnarIndex(sctx, ident, ast.NewCIStr(constr.Name), spec.Constraint.Keys, constr.Option, constr.IfNotExists)
17871789
}
@@ -4721,6 +4723,60 @@ func (e *executor) createFulltextIndex(ctx sessionctx.Context, ti ast.Ident, ind
47214723
return errors.Trace(err)
47224724
}
47234725

4726+
func (e *executor) createHybridIndex(ctx sessionctx.Context, ti ast.Ident, indexName ast.CIStr,
4727+
indexPartSpecifications []*ast.IndexPartSpecification, indexOption *ast.IndexOption, ifNotExists bool) error {
4728+
schema, t, err := e.getSchemaAndTableByIdent(ti)
4729+
if err != nil {
4730+
return errors.Trace(err)
4731+
}
4732+
4733+
tblInfo := t.Meta()
4734+
if err := checkTableTypeForFulltextIndex(tblInfo); err != nil {
4735+
return errors.Trace(err)
4736+
}
4737+
4738+
metaBuildCtx := NewMetaBuildContextWithSctx(ctx)
4739+
indexName, _, err = checkIndexNameAndColumns(metaBuildCtx, t, indexName, indexPartSpecifications, model.ColumnarIndexTypeHybrid, ifNotExists)
4740+
if err != nil {
4741+
return errors.Trace(err)
4742+
}
4743+
if len(indexName.L) == 0 {
4744+
return nil
4745+
}
4746+
if _, err := buildHybridInfoWithCheck(indexPartSpecifications, indexOption, tblInfo); err != nil {
4747+
return errors.Trace(err)
4748+
}
4749+
4750+
if _, _, err := buildIndexColumns(metaBuildCtx, tblInfo.Columns, indexPartSpecifications, model.ColumnarIndexTypeHybrid); err != nil {
4751+
return errors.Trace(err)
4752+
}
4753+
4754+
sessionVars := ctx.GetSessionVars()
4755+
if _, err = validateCommentLength(sessionVars.StmtCtx.ErrCtx(), sessionVars.SQLMode, indexName.String(), &indexOption.Comment, dbterror.ErrTooLongTableComment); err != nil {
4756+
return errors.Trace(err)
4757+
}
4758+
4759+
job := buildAddIndexJobWithoutTypeAndArgs(ctx, schema, t)
4760+
job.Version = model.GetJobVerInUse()
4761+
job.Type = model.ActionAddHybridIndex
4762+
4763+
args := &model.ModifyIndexArgs{
4764+
IndexArgs: []*model.IndexArg{{
4765+
IndexName: indexName,
4766+
IndexPartSpecifications: indexPartSpecifications,
4767+
IndexOption: indexOption,
4768+
}},
4769+
OpType: model.OpAddIndex,
4770+
}
4771+
4772+
err = e.doDDLJob2(ctx, job, args)
4773+
if dbterror.ErrDupKeyName.Equal(err) && ifNotExists {
4774+
ctx.GetSessionVars().StmtCtx.AppendNote(err)
4775+
return nil
4776+
}
4777+
return errors.Trace(err)
4778+
}
4779+
47244780
func checkIndexNameAndColumns(ctx *metabuild.Context, t table.Table, indexName ast.CIStr,
47254781
indexPartSpecifications []*ast.IndexPartSpecification, columnarIndexType model.ColumnarIndexType, ifNotExists bool) (ast.CIStr, []*model.ColumnInfo, error) {
47264782
// Deal with anonymous index.
@@ -4924,6 +4980,8 @@ func (e *executor) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast
49244980
return dbterror.ErrUnsupportedIndexType.GenWithStack("SPATIAL index is not supported")
49254981
case ast.IndexKeyTypeColumnar:
49264982
switch indexOption.Tp {
4983+
case ast.IndexTypeHybrid:
4984+
return e.createHybridIndex(ctx, ti, indexName, indexPartSpecifications, indexOption, ifNotExists)
49274985
case ast.IndexTypeFulltext:
49284986
return e.createFulltextIndex(ctx, ti, indexName, indexPartSpecifications, indexOption, ifNotExists)
49294987
default:

0 commit comments

Comments
 (0)