diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index a39322c2f5b9c..b7a2b2a26e37a 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -2801,3 +2801,27 @@ 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) + tk.MustGetErrCode("create temporary table t(id int) on commit preserve rows", errno.ErrParse) + tk.MustGetErrCode("create table t(id int) on commit delete rows", errno.ErrParse) + tk.MustGetErrCode("create 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")) +} diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index d0289dc19e39f..2cfd3f524a29f 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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 } @@ -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 != "" && !strings.EqualFold(op.StrValue, "memory") { + return errors.Trace(errUnsupportedEngineTemporary) + } + } } } shardingBits := shardingBits(tbInfo) diff --git a/ddl/error.go b/ddl/error.go index 463c9c405a19e..6bde83badb41b 100644 --- a/ddl/error.go +++ b/ddl/error.go @@ -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 support this kind of engine for temporary table", nil)) ) diff --git a/go.mod b/go.mod index f82a8a187775f..82a394d8406de 100644 --- a/go.mod +++ b/go.mod @@ -89,3 +89,6 @@ require ( ) go 1.13 + +// Fix panic in unit test with go >= 1.14, ref: etcd-io/bbolt#201 https://github.com/etcd-io/bbolt/pull/201 +replace go.etcd.io/bbolt => go.etcd.io/bbolt v1.3.5 diff --git a/go.sum b/go.sum index 14986c3d1f025..cf26e5ebe4089 100644 --- a/go.sum +++ b/go.sum @@ -600,9 +600,8 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= +go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.etcd.io/etcd v0.5.0-alpha.5.0.20200824191128-ae9734ed278b h1:3kC4J3eQF6p1UEfQTkC67eEeb3rTk+shQqdX6tFyq9Q=