Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -3795,7 +3795,7 @@ func isTableTiFlashSupported(dbName pmodel.CIStr, tbl *model.TableInfo) error {
if util.IsMemOrSysDB(dbName.L) {
return errors.Trace(dbterror.ErrUnsupportedTiFlashOperationForSysOrMemTable)
} else if tbl.TempTableType != model.TempTableNone {
return dbterror.ErrOptOnTemporaryTable.GenWithStackByArgs("set on tiflash")
return dbterror.ErrOptOnTemporaryTable.GenWithStackByArgs("set TiFlash replica")
} else if tbl.IsView() || tbl.IsSequence() {
return dbterror.ErrWrongObject.GenWithStackByArgs(dbName, tbl.Name, "BASE TABLE")
}
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 TiFlash replica` 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 TiFlash replica` 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 `set TiFlash replica` settings for table contains gbk charset")
tk.MustContainErrMsg("create table mysql.t(a int, b vector(3), vector index((VEC_COSINE_DISTANCE(b))));",
"Unsupported `set TiFlash replica` 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 `set TiFlash replica` 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
2 changes: 1 addition & 1 deletion pkg/ddl/tests/tiflash/ddl_tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func TestAlterDatabaseBasic(t *testing.T) {
tk.MustQuery(`show warnings;`).Sort().Check(testkit.Rows(
"Note 1347 'tiflash_ddl_skip.t_seq' is not BASE TABLE",
"Note 1347 'tiflash_ddl_skip.t_view' is not BASE TABLE",
"Note 8006 `set on tiflash` is unsupported on temporary tables."))
"Note 8006 `set TiFlash replica` is unsupported on temporary tables."))
}

func execWithTimeout(t *testing.T, tk *testkit.TestKit, to time.Duration, sql string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/tiflash_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestSetTableFlashReplicaForSystemTable(t *testing.T) {
if tbl.Meta().View != nil {
require.ErrorIs(t, err, dbterror.ErrWrongObject)
} else {
require.Equal(t, "[ddl:8200]Unsupported ALTER TiFlash settings for system table and memory table", err.Error())
require.Equal(t, "[ddl:8200]Unsupported `set TiFlash replica` settings for system table and memory table", err.Error())
}
} else {
require.Equal(t, fmt.Sprintf("[planner:1142]ALTER command denied to user 'root'@'%%' for table '%s'", strings.ToLower(one)), err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/test/tiflashtest/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestNonsupportCharsetTable(t *testing.T) {
tk.MustExec("create table t(a int, b char(10) charset gbk collate gbk_bin)")
err := tk.ExecToErr("alter table t set tiflash replica 1")
require.Error(t, err)
require.Equal(t, "[ddl:8200]Unsupported ALTER TiFlash settings for tables not supported by TiFlash: table contains gbk charset", err.Error())
require.Equal(t, "[ddl:8200]Unsupported `set TiFlash replica` settings for table contains gbk charset", err.Error())

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(10) charset utf8)")
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/dbterror/ddl_terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ var (
// ErrAlterTiFlashModeForTableWithoutTiFlashReplica returns when set tiflash mode on table whose tiflash_replica is null or tiflash_replica_count = 0
ErrAlterTiFlashModeForTableWithoutTiFlashReplica = ClassDDL.NewStdErr(0, parser_mysql.Message("TiFlash mode will take effect after at least one TiFlash replica is set for the table", nil))
// ErrUnsupportedTiFlashOperationForSysOrMemTable means we don't support the alter tiflash related action(e.g. set tiflash mode, set tiflash replica) for system table.
ErrUnsupportedTiFlashOperationForSysOrMemTable = ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "ALTER TiFlash settings for system table and memory table"), nil))
ErrUnsupportedTiFlashOperationForSysOrMemTable = ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "`set TiFlash replica` settings for system table and memory table"), nil))
// ErrUnsupportedTiFlashOperationForUnsupportedCharsetTable is used when alter alter tiflash related action(e.g. set tiflash mode, set tiflash replica) with unsupported charset.
ErrUnsupportedTiFlashOperationForUnsupportedCharsetTable = ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "ALTER TiFlash settings for tables not supported by TiFlash: table contains %s charset"), nil))
ErrUnsupportedTiFlashOperationForUnsupportedCharsetTable = ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "`set TiFlash replica` settings for table contains %s charset"), nil))
// ErrTiFlashBackfillIndex is the error that tiflash backfill the index failed.
ErrTiFlashBackfillIndex = ClassDDL.NewStdErr(mysql.ErrTiFlashBackfillIndex,
parser_mysql.Message(mysql.MySQLErrName[mysql.ErrTiFlashBackfillIndex].Raw, nil))
Expand Down