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

parser, ddl: support vector index at the parser #55698

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions pkg/ddl/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,10 @@ func BuildTableInfo(
}
foreignKeyID := tbInfo.MaxForeignKeyID
for _, constr := range constraints {
if constr.Tp == ast.ConstraintVector {
return nil, dbterror.ErrUnsupportedAddVectorIndex.FastGenByArgs("not currently supported")
}

// Build hidden columns if necessary.
hiddenCols, err := buildHiddenColumnInfoWithCheck(ctx, constr.Keys, model.NewCIStr(constr.Name), tbInfo, tblColumns)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ func (e *executor) AlterTable(ctx context.Context, sctx sessionctx.Context, stmt
} else {
err = e.CreateCheckConstraint(sctx, ident, model.NewCIStr(constr.Name), spec.Constraint)
}
case ast.ConstraintVector:
err = createVectorIndex()
default:
// Nothing to do now.
}
Expand Down Expand Up @@ -4537,6 +4539,10 @@ func (e *executor) CreatePrimaryKey(ctx sessionctx.Context, ti ast.Ident, indexN
return errors.Trace(err)
}

func createVectorIndex() error {
return dbterror.ErrUnsupportedAddVectorIndex.FastGenByArgs("not currently supported")
}

func (e *executor) CreateIndex(ctx sessionctx.Context, stmt *ast.CreateIndexStmt) error {
ident := ast.Ident{Schema: stmt.Table.Schema, Name: stmt.Table.Name}
return e.createIndex(ctx, ident, stmt.KeyType, model.NewCIStr(stmt.IndexName),
Expand Down Expand Up @@ -4571,6 +4577,9 @@ func (e *executor) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast
if keyType == ast.IndexKeyTypeFullText || keyType == ast.IndexKeyTypeSpatial {
return dbterror.ErrUnsupportedIndexType.GenWithStack("FULLTEXT and SPATIAL index is not supported")
}
if keyType == ast.IndexKeyTypeVector {
return createVectorIndex()
}
unique := keyType == ast.IndexKeyTypeUnique
schema, t, err := e.getSchemaAndTableByIdent(ti)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/ddl/index_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,3 +1058,17 @@ func TestAddIndexUniqueFailOnDuplicate(t *testing.T) {
require.Less(t, int(ddl.ResultCounterForTest.Load()), 6)
ddl.ResultCounterForTest = nil
}

func TestAddVectorIndex(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustContainErrMsg("create table t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))) USING HNSW);",
"Unsupported add vector index: not currently supported")
tk.MustExec("create table t (a int, b vector(3));")
tk.MustContainErrMsg("alter table t add vector index idx((VEC_COSINE_DISTANCE(b))) USING HNSW COMMENT 'b comment';",
"Unsupported add vector index: not currently supported")
tk.MustContainErrMsg("create vector index idx on t ((VEC_COSINE_DISTANCE(b))) USING HNSW COMMENT 'b comment';",
"Unsupported add vector index: not currently supported")
}
9 changes: 9 additions & 0 deletions pkg/parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ const (
ConstraintForeignKey
ConstraintFulltext
ConstraintCheck
ConstraintVector
)

// Constraint is constraint for table definition.
Expand Down Expand Up @@ -920,6 +921,11 @@ func (n *Constraint) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("NOT ENFORCED")
}
return nil
case ConstraintVector:
ctx.WriteKeyWord("VECTOR INDEX")
if n.IfNotExists {
ctx.WriteKeyWord(" IF NOT EXISTS")
}
}

if n.Tp == ConstraintForeignKey {
Expand Down Expand Up @@ -1807,6 +1813,7 @@ const (
IndexKeyTypeUnique
IndexKeyTypeSpatial
IndexKeyTypeFullText
IndexKeyTypeVector
)

// CreateIndexStmt is a statement to create an index.
Expand Down Expand Up @@ -1836,6 +1843,8 @@ func (n *CreateIndexStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("SPATIAL ")
case IndexKeyTypeFullText:
ctx.WriteKeyWord("FULLTEXT ")
case IndexKeyTypeVector:
ctx.WriteKeyWord("VECTOR ")
}
ctx.WriteKeyWord("INDEX ")
if n.IfNotExists {
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/keywords.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/parser/keywords_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestKeywordsLength(t *testing.T) {
reservedNr += 1
}
}
require.Equal(t, 232, reservedNr)
require.Equal(t, 233, reservedNr)
}

func TestKeywordsSorting(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ var tokenMap = map[string]int{
"HIGH_PRIORITY": highPriority,
"HISTORY": history,
"HISTOGRAM": histogram,
"HNSW": hnsw,
"HOSTS": hosts,
"HOUR_MICROSECOND": hourMicrosecond,
"HOUR_MINUTE": hourMinute,
Expand Down
3 changes: 3 additions & 0 deletions pkg/parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,8 @@ func (t IndexType) String() string {
return "RTREE"
case IndexTypeHypo:
return "HYPO"
case IndexTypeHNSW:
return "HNSW"
default:
return ""
}
Expand All @@ -1460,6 +1462,7 @@ const (
IndexTypeHash
IndexTypeRtree
IndexTypeHypo
IndexTypeHNSW
)

// IndexInfo provides meta data describing a DB index.
Expand Down
Loading