Skip to content

Commit

Permalink
check create table like
Browse files Browse the repository at this point in the history
Signed-off-by: lihaowei <haoweili35@gmail.com>
  • Loading branch information
Howie59 committed May 22, 2021
1 parent be56ca6 commit b5659ed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ var (
// ErrPartitionNoTemporary returns when partition at temporary mode
ErrPartitionNoTemporary = dbterror.ClassDDL.NewStd(mysql.ErrPartitionNoTemporary)

// ErrOptOnTemporaryTable returns when exec unsupported opt at temporary mode
ErrOptOnTemporaryTable = dbterror.ClassDDL.NewStd(mysql.ErrOptOnTemporaryTable)

errUnsupportedOnCommitPreserve = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("TiDB doesn't support ON COMMIT PRESERVE ROWS for now", nil))
Expand Down
10 changes: 10 additions & 0 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
Expand Down Expand Up @@ -524,6 +525,15 @@ func (s *testSerialSuite) TestCreateTableWithLike(c *C) {

tk.MustExec("drop database ctwl_db")
tk.MustExec("drop database ctwl_db1")

// Test create table like at temporary mode.
tk.MustExec("use test")
tk.MustExec("drop table if exists temporary_table;")
tk.MustExec("create global temporary table temporary_table (a int, b int,index(a)) on commit delete rows")
tk.MustExec("drop table if exists temporary_table_t1;")
_, 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;")
}

// TestCancelAddIndex1 tests canceling ddl job when the add index worker is not started.
Expand Down
15 changes: 15 additions & 0 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) {
}

func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) {
if stmt.ReferTable != nil {
schema := model.NewCIStr(p.ctx.GetSessionVars().CurrentDB)
if stmt.ReferTable.Schema.String() != "" {
schema = stmt.ReferTable.Schema
}
tableInfo, err := p.is.TableByName(schema, stmt.ReferTable.Name)
if err != nil {
p.err = err
return
}
if tableInfo.Meta().TempTableType != model.TempTableNone {
p.err = ErrOptOnTemporaryTable.GenWithStackByArgs("create table like")
return
}
}
tName := stmt.Table.Name.String()
if isIncorrectName(tName) {
p.err = ddl.ErrWrongTableName.GenWithStackByArgs(tName)
Expand Down

0 comments on commit b5659ed

Please sign in to comment.