Skip to content

Commit

Permalink
ddl: forbit alter table cache in system db (#29998)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd authored Nov 24, 2021
1 parent 71e64bf commit b57c1e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5664,6 +5664,30 @@ func (s *testSerialDBSuite) TestSetTableFlashReplica(c *C) {
c.Assert(err.Error(), Equals, "the tiflash replica count: 2 should be less than the total tiflash server count: 0")
}

func (s *testSerialDBSuite) TestForbitCacheTableForSystemTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
sysTables := make([]string, 0, 24)
memOrSysDB := []string{"MySQL", "INFORMATION_SCHEMA", "PERFORMANCE_SCHEMA", "METRICS_SCHEMA"}
for _, db := range memOrSysDB {
tk.MustExec("use " + db)
tk.Se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)
rows := tk.MustQuery("show tables").Rows()
for i := 0; i < len(rows); i++ {
sysTables = append(sysTables, rows[i][0].(string))
}
for _, one := range sysTables {
_, err := tk.Exec(fmt.Sprintf("alter table `%s` cache", one))
if db == "MySQL" {
c.Assert(err.Error(), Equals, "[ddl:8200]ALTER table cache for tables in system database is currently unsupported")
} else {
c.Assert(err.Error(), Equals, fmt.Sprintf("[planner:1142]ALTER command denied to user 'root'@'%%' for table '%s'", strings.ToLower(one)))
}

}
sysTables = sysTables[:0]
}
}

func (s *testSerialDBSuite) TestSetTableFlashReplicaForSystemTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
sysTables := make([]string, 0, 24)
Expand Down
5 changes: 4 additions & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6606,7 +6606,10 @@ func (d *ddl) AlterTableCache(ctx sessionctx.Context, ti ast.Ident) (err error)
return nil
}

if t.Meta().TempTableType != model.TempTableNone {
// forbit cache table in system database.
if util.IsMemOrSysDB(schema.Name.L) {
return errors.Trace(errUnsupportedAlterCacheForSysTable)
} else if t.Meta().TempTableType != model.TempTableNone {
return errors.Trace(ErrOptOnTemporaryTable.GenWithStackByArgs("alter temporary table cache"))
}

Expand Down
1 change: 1 addition & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
errUnsupportedAlterTableWithoutValidation = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("ALTER TABLE WITHOUT VALIDATION is currently unsupported", nil))
errUnsupportedAlterTableOption = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("This type of ALTER TABLE is currently unsupported", nil))
errUnsupportedAlterReplicaForSysTable = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("ALTER table replica for tables in system database is currently unsupported", nil))
errUnsupportedAlterCacheForSysTable = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("ALTER table cache for tables in system database is currently unsupported", nil))
errBlobKeyWithoutLength = dbterror.ClassDDL.NewStd(mysql.ErrBlobKeyWithoutLength)
errKeyPart0 = dbterror.ClassDDL.NewStd(mysql.ErrKeyPart0)
errIncorrectPrefixKey = dbterror.ClassDDL.NewStd(mysql.ErrWrongSubKey)
Expand Down

0 comments on commit b57c1e1

Please sign in to comment.