Skip to content
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
11 changes: 7 additions & 4 deletions pkg/ddl/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func buildTableInfoWithCheck(ctx *metabuild.Context, store kv.Storage, s *ast.Cr
if err = checkTableInfoValidWithStmt(ctx, tbInfo, s); err != nil {
return nil, err
}
if err = checkTableInfoValidExtra(ctx.GetExprCtx().GetEvalCtx().ErrCtx(), store, tbInfo); err != nil {
if err = checkTableInfoValidExtra(ctx.GetExprCtx().GetEvalCtx().ErrCtx(), store, s.Table.Schema, tbInfo); err != nil {
return nil, err
}
return tbInfo, nil
Expand Down Expand Up @@ -511,7 +511,7 @@ func checkGeneratedColumn(ctx *metabuild.Context, schemaName pmodel.CIStr, table
return nil
}

func checkVectorIndexIfNeedTiFlashReplica(store kv.Storage, tblInfo *model.TableInfo) error {
func checkVectorIndexIfNeedTiFlashReplica(store kv.Storage, dbName pmodel.CIStr, tblInfo *model.TableInfo) error {
var hasVectorIndex bool
for _, idx := range tblInfo.Indices {
if idx.VectorInfo != nil {
Expand All @@ -525,6 +525,9 @@ func checkVectorIndexIfNeedTiFlashReplica(store kv.Storage, tblInfo *model.Table
if store == nil {
return errors.New("the store is nil")
}
if err := isTableTiFlashSupported(dbName, tblInfo); err != nil {
return errors.Trace(err)
}

if tblInfo.TiFlashReplica == nil || tblInfo.TiFlashReplica.Count == 0 {
replicas, err := infoschema.GetTiFlashStoreCount(store)
Expand All @@ -551,7 +554,7 @@ func checkVectorIndexIfNeedTiFlashReplica(store kv.Storage, tblInfo *model.Table
// name length and column count.
// (checkTableInfoValid is also used in repairing objects which don't perform
// these checks. Perhaps the two functions should be merged together regardless?)
func checkTableInfoValidExtra(ec errctx.Context, store kv.Storage, tbInfo *model.TableInfo) error {
func checkTableInfoValidExtra(ec errctx.Context, store kv.Storage, dbName pmodel.CIStr, tbInfo *model.TableInfo) error {
if err := checkTooLongTable(tbInfo.Name); err != nil {
return err
}
Expand All @@ -574,7 +577,7 @@ func checkTableInfoValidExtra(ec errctx.Context, store kv.Storage, tbInfo *model
if err := checkGlobalIndexes(ec, tbInfo); err != nil {
return errors.Trace(err)
}
if err := checkVectorIndexIfNeedTiFlashReplica(store, tbInfo); err != nil {
if err := checkVectorIndexIfNeedTiFlashReplica(store, dbName, tbInfo); err != nil {
return errors.Trace(err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ func (e *executor) createTableWithInfoJob(
}
}

if err := checkTableInfoValidExtra(ctx.GetSessionVars().StmtCtx.ErrCtx(), ctx.GetStore(), tbInfo); err != nil {
if err := checkTableInfoValidExtra(ctx.GetSessionVars().StmtCtx.ErrCtx(), ctx.GetStore(), dbName, tbInfo); err != nil {
return nil, err
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/ddl/index_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,10 @@ func TestCreateTableWithVectorIndex(t *testing.T) {
require.Equal(t, model.DistanceMetricCosine, indexes[0].VectorInfo.DistanceMetric)
require.Equal(t, "vector_index", tbl.Meta().Indices[0].Name.O)
require.Equal(t, "vector_index_2", tbl.Meta().Indices[1].Name.O)
tk.MustExec("insert into t values (1, '[1,2.1,3.3]');")
tk.MustQuery("select * from t;").Check(testkit.Rows("1 [1,2.1,3.3]"))
tk.MustExec("create view v as select * from t;")
tk.MustQuery("select * from v;").Check(testkit.Rows("1 [1,2.1,3.3]"))
tk.MustExec(`DROP TABLE t`)
}

Expand All @@ -1124,13 +1128,20 @@ func TestCreateTableWithVectorIndex(t *testing.T) {

// test unsupported table types
tk.MustContainErrMsg("create temporary table t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))) USING HNSW)",
"`vector index` is unsupported on temporary tables.")
"`set on tiflash` is unsupported on temporary tables.")
// global and local temporary table using different way to handle, so we have two test cases.
tk.MustContainErrMsg("create global temporary table t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))) USING HNSW) on commit delete rows;",
"`vector index` is unsupported on temporary tables.")
"`set on tiflash` is unsupported on temporary tables.")
tk.MustContainErrMsg("create table pt(id bigint, b vector(3), vector index((VEC_COSINE_DISTANCE(b))) USING HNSW) "+
"partition by range(id) (partition p0 values less than (20), partition p1 values less than (100));",
"Unsupported add vector index: unsupported partition table")
tk.MustContainErrMsg("create table t(a int, b vector(3), c char(210) CHARACTER SET gbk COLLATE gbk_bin, vector index((VEC_COSINE_DISTANCE(b))));",
"Unsupported ALTER TiFlash settings for tables not supported by TiFlash: table contains gbk charset")
tk.MustContainErrMsg("create table mysql.t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))));",
"Unsupported ALTER TiFlash settings for system table and memory table")
tk.MustContainErrMsg("create table information_schema.t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))));",
"Unsupported ALTER TiFlash settings for system table and memory table")

// a vector index with invisible
tk.MustContainErrMsg("create table t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))) USING HNSW INVISIBLE)",
"Unsupported set vector index invisible")
Expand Down