Skip to content

Commit

Permalink
planner: include "CREATE/DROP TEMPORARY TABLE" to noop functions (##609
Browse files Browse the repository at this point in the history
…) (#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 <[email protected]>

Co-authored-by: bb7133 <[email protected]>
Co-authored-by: Morgan Tocker <[email protected]>
  • Loading branch information
3 people authored Feb 28, 2021
1 parent 53a68b5 commit 4b90ef4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions planner/core/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 4b90ef4

Please sign in to comment.