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

ddl: forbit alter table cache in system db #29998

Merged
merged 2 commits into from
Nov 24, 2021
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
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