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: grammar check for create unsupported temporary table #24723

Merged
merged 6 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2803,3 +2803,25 @@ func (s *testIntegrationSuite3) TestIssue21835(c *C) {
_, err := tk.Exec("create table t( col decimal(1,2) not null default 0);")
c.Assert(err.Error(), Equals, "[types:1427]For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'col').")
}

func (s *testIntegrationSuite3) TestCreateTemporaryTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")

// Grammar error.
tk.MustGetErrCode("create global temporary table t(a double(0, 0))", errno.ErrParse)
tk.MustGetErrCode("create temporary table t(id int) on commit delete rows", errno.ErrParse)
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
tk.MustGetErrCode("create temporary table t(id int) on commit preserve rows", errno.ErrParse)

// Not support yet.
tk.MustGetErrCode("create global temporary table t (id int) on commit preserve rows", errno.ErrUnsupportedDDLOperation)
// Engine type can only be 'memory' or empty for now.
tk.MustGetErrCode("create global temporary table t (id int) engine = 'innodb' on commit delete rows", errno.ErrUnsupportedDDLOperation)
// Follow the behaviour of the old version TiDB: parse and ignore the 'temporary' keyword.
tk.MustGetErrCode("create temporary table t(id int)", errno.ErrNotSupportedYet)

tk.MustExec("set @@tidb_enable_noop_functions = 1")
tk.MustExec("create temporary table t (id int)")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning 1105 local TEMPORARY TABLE is not supported yet, TEMPORARY will be parsed but ignored"))
}
14 changes: 13 additions & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1736,8 +1736,14 @@ func buildTableInfoWithStmt(ctx sessionctx.Context, s *ast.CreateTableStmt, dbCh
switch s.TemporaryKeyword {
case ast.TemporaryGlobal:
tbInfo.TempTableType = model.TempTableGlobal
// "create global temporary table ... on commit preserve rows"
if !s.OnCommitDelete {
return nil, errors.Trace(errUnsupportedOnCommitPreserve)
}
case ast.TemporaryLocal:
tbInfo.TempTableType = model.TempTableLocal
// TODO: set "tbInfo.TempTableType = model.TempTableLocal" after local temporary table is supported.
tbInfo.TempTableType = model.TempTableNone
ctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("local TEMPORARY TABLE is not supported yet, TEMPORARY will be parsed but ignored"))
case ast.TemporaryNone:
tbInfo.TempTableType = model.TempTableNone
}
Expand Down Expand Up @@ -2217,6 +2223,12 @@ func handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo) err
tbInfo.PreSplitRegions = op.UintValue
case ast.TableOptionCharset, ast.TableOptionCollate:
// We don't handle charset and collate here since they're handled in `getCharsetAndCollateInTableOption`.
case ast.TableOptionEngine:
if tbInfo.TempTableType != model.TempTableNone {
if op.StrValue != "" && op.StrValue != "memory" {
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
return errors.Trace(errUnsupportedEngineTemporary)
}
}
}
}
shardingBits := shardingBits(tbInfo)
Expand Down
3 changes: 3 additions & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,7 @@ var (

// ErrPartitionNoTemporary returns when partition at temporary mode
ErrPartitionNoTemporary = dbterror.ClassDDL.NewStd(mysql.ErrPartitionNoTemporary)

errUnsupportedOnCommitPreserve = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("TiDB doesn't support ON COMMIT PRESERVE ROWS for now", nil))
errUnsupportedEngineTemporary = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("TiDB doesn't this kind of engine for temporary table", nil))
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
)