From 4b90ef471ccbbda048e02108fc64af61798f870d Mon Sep 17 00:00:00 2001 From: Nayuta Yanagisawa Date: Sun, 28 Feb 2021 15:31:06 +0900 Subject: [PATCH] planner: include "CREATE/DROP TEMPORARY TABLE" to noop functions (##609) (#22860) * planner: include "CREATE/DROP TEMPORARY TABLE" to noop functions (##609) TiDB ignores the TEMPORARY keyword in "CREATE/DROP TEMPORARY TABLE" statements. Report errors when and only when tidb_enable_noop_functions = OFF. * Add link to pingcap/parser issue Co-authored-by: bb7133 Co-authored-by: bb7133 Co-authored-by: Morgan Tocker --- planner/core/preprocess.go | 10 ++++++++++ planner/core/preprocess_test.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go index 1ec6008c5bc65..628658515d413 100644 --- a/planner/core/preprocess.go +++ b/planner/core/preprocess.go @@ -562,6 +562,11 @@ func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) { p.err = ddl.ErrWrongTableName.GenWithStackByArgs(tName) return } + enableNoopFuncs := p.ctx.GetSessionVars().EnableNoopFuncs + if stmt.IsTemporary && !enableNoopFuncs { + p.err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("CREATE TEMPORARY TABLE") + return + } countPrimaryKey := 0 for _, colDef := range stmt.Cols { if err := checkColumn(colDef); err != nil { @@ -669,6 +674,11 @@ func (p *preprocessor) checkDropSequenceGrammar(stmt *ast.DropSequenceStmt) { func (p *preprocessor) checkDropTableGrammar(stmt *ast.DropTableStmt) { p.checkDropTableNames(stmt.Tables) + enableNoopFuncs := p.ctx.GetSessionVars().EnableNoopFuncs + if stmt.IsTemporary && !enableNoopFuncs { + p.err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("DROP TEMPORARY TABLE") + return + } } func (p *preprocessor) checkDropTableNames(tables []*ast.TableName) { diff --git a/planner/core/preprocess_test.go b/planner/core/preprocess_test.go index 394a3fe273f4c..14b006c836ca9 100644 --- a/planner/core/preprocess_test.go +++ b/planner/core/preprocess_test.go @@ -288,6 +288,10 @@ func (s *testValidatorSuite) TestValidator(c *C) { {"select CONVERT( 2, DECIMAL(30,65) )", true, types.ErrMBiggerThanD.GenWithStackByArgs("2")}, {"select CONVERT( 2, DECIMAL(66,99) )", true, types.ErrMBiggerThanD.GenWithStackByArgs("2")}, + // https://github.com/pingcap/parser/issues/609 + {"CREATE TEMPORARY TABLE t (a INT);", false, expression.ErrFunctionsNoopImpl.GenWithStackByArgs("CREATE TEMPORARY TABLE")}, + {"DROP TEMPORARY TABLE t;", false, expression.ErrFunctionsNoopImpl.GenWithStackByArgs("DROP TEMPORARY TABLE")}, + // TABLESAMPLE {"select * from t tablesample bernoulli();", false, expression.ErrInvalidTableSample}, {"select * from t tablesample bernoulli(10 rows);", false, expression.ErrInvalidTableSample},