Skip to content

Commit 7b88b73

Browse files
author
James Cor
committed
fix
1 parent c71e3ac commit 7b88b73

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

sql/planbuilder/ddl.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,11 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
254254
tableScope, ok := b.buildResolvedTableForTablename(inScope, t, nil)
255255
if ok {
256256
// attempting to drop a non-temporary table with DROP TEMPORARY, results in Unknown table
257-
if _, isTmpTbl := tableScope.node.(sql.TemporaryTable); !isTmpTbl && c.Temporary {
258-
err := sql.ErrUnknownTable.New(tableName)
259-
b.handleErr(err)
257+
if tbl, ok := tableScope.node.(sql.Table); ok {
258+
if tmpTbl := getTempTable(tbl); tmpTbl != nil && !tmpTbl.IsTemporary() && c.Temporary {
259+
err := sql.ErrUnknownTable.New(tableName)
260+
b.handleErr(err)
261+
}
260262
}
261263
dropTables = append(dropTables, tableScope.node)
262264
} else if !c.IfExists {
@@ -269,6 +271,19 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
269271
return
270272
}
271273

274+
func getTempTable(t sql.Table) sql.TemporaryTable {
275+
switch t := t.(type) {
276+
case sql.TemporaryTable:
277+
return t
278+
case sql.TableWrapper:
279+
return getTempTable(t.Underlying())
280+
case *plan.ResolvedTable:
281+
return getTempTable(t.Table)
282+
default:
283+
return nil
284+
}
285+
}
286+
272287
func (b *Builder) buildTruncateTable(inScope *scope, c *ast.DDL) (outScope *scope) {
273288
outScope = inScope.push()
274289
tableScope, ok := b.buildResolvedTableForTablename(inScope, c.Table, nil)

sql/rowexec/show_iters.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func (i *showCreateTablesIter) produceCreateTableStatement(ctx *sql.Context, tab
499499
}
500500

501501
temp := ""
502-
if _, ok := table.(sql.TemporaryTable); ok {
502+
if tbl := getTempTable(table); tbl != nil && tbl.IsTemporary() {
503503
temp = " TEMPORARY"
504504
}
505505

@@ -544,6 +544,19 @@ func getAutoIncrementTable(t sql.Table) sql.AutoIncrementTable {
544544
}
545545
}
546546

547+
func getTempTable(t sql.Table) sql.TemporaryTable {
548+
switch t := t.(type) {
549+
case sql.TemporaryTable:
550+
return t
551+
case sql.TableWrapper:
552+
return getTempTable(t.Underlying())
553+
case *plan.ResolvedTable:
554+
return getTempTable(t.Table)
555+
default:
556+
return nil
557+
}
558+
}
559+
547560
func formatReplicaStatusTimestamp(t *time.Time) string {
548561
if t == nil {
549562
return ""

0 commit comments

Comments
 (0)