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 admin_checksum_table compatibility for temporary table #24867

Merged
merged 10 commits into from
May 31, 2021
7 changes: 7 additions & 0 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@ func (s *testSerialSuite) TestCreateTableWithLike(c *C) {
_, err = tk.Exec("create table temporary_table_t1 like temporary_table")
c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("create table like").Error())
tk.MustExec("drop table if exists temporary_table;")

tk.MustExec("drop table if exists temporary_table_like;")
tk.MustExec("create table temporary_table (a int, b int,index(a))")
tk.MustExec("drop table if exists temporary_table_like_t1;")
_, err = tk.Exec("create global temporary table temporary_table_like_t1 like temporary_table on commit delete rows;")
c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("create table like").Error())
tk.MustExec("drop table if exists temporary_table_like;")
}

// TestCancelAddIndex1 tests canceling ddl job when the add index worker is not started.
Expand Down
14 changes: 14 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
mysql "github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
Expand Down Expand Up @@ -90,6 +91,19 @@ func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) {
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;")

tk.MustExec("drop table if exists temporary_admin_checksum_table_with_index_test;")
tk.MustExec("drop table if exists temporary_admin_checksum_table_without_index_test;")
tk.MustExec("create global temporary table temporary_admin_checksum_table_with_index_test (id int, count int, PRIMARY KEY(id), KEY(count)) ON COMMIT DELETE ROWS;")
tk.MustExec("create global temporary table temporary_admin_checksum_table_without_index_test (id int, count int, PRIMARY KEY(id)) ON COMMIT DELETE ROWS;")
_, err := tk.Exec("admin checksum table temporary_admin_checksum_table_with_index_test;")
fmt.Println(core.ErrOptOnTemporaryTable.GenWithStackByArgs("admin checksum table"))
fmt.Println(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug log please ...

c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("admin checksum table").Error())
_, err = tk.Exec("admin checksum table temporary_admin_checksum_table_without_index_test;")
c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("admin checksum table").Error())
tk.MustExec("drop table if exists temporary_admin_checksum_table_with_index_test;")
tk.MustExec("drop table if exists temporary_admin_checksum_table_without_index_test;")
}

func (s *testSuite5) TestAdminRecoverIndex(c *C) {
Expand Down
3 changes: 3 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3444,6 +3444,9 @@ func (b *PlanBuilder) buildDDL(ctx context.Context, node ast.DDLNode) (Plan, err
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.IndexPriv, v.Table.Schema.L,
v.Table.Name.L, "", authErr)
case *ast.CreateTableStmt:
if v.TemporaryKeyword != ast.TemporaryNone && v.ReferTable != nil {
return nil, ErrOptOnTemporaryTable.GenWithStackByArgs("create table like")
}
if b.ctx.GetSessionVars().User != nil {
authErr = ErrTableaccessDenied.GenWithStackByArgs("CREATE", b.ctx.GetSessionVars().User.AuthUsername,
b.ctx.GetSessionVars().User.AuthHostname, v.Table.Name.L)
Expand Down
8 changes: 6 additions & 2 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,12 @@ func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) {
return
}
tempTableType := tableInfo.Meta().TempTableType
if stmt.Tp == ast.AdminCheckTable && tempTableType != model.TempTableNone {
p.err = infoschema.ErrAdminCheckTable
if (stmt.Tp == ast.AdminCheckTable || stmt.Tp == ast.AdminChecksumTable) && tempTableType != model.TempTableNone {
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
if stmt.Tp == ast.AdminChecksumTable {
p.err = ErrOptOnTemporaryTable.GenWithStackByArgs("admin checksum table")
} else {
p.err = infoschema.ErrAdminCheckTable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
p.err = infoschema.ErrAdminCheckTable
p.err = ErrOptOnTemporaryTable.GenWithStackByArgs("admin table")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrAdminCheckTable is another kind of error, it means the admin check table fails because of the table data corruption.
Here we should report something like "unsupported operation", although the operation fails and returns error, the reason is different.

}
return
}
}
Expand Down