Skip to content

Commit

Permalink
executor: add drop if exists warnings(close pingcap#7867)
Browse files Browse the repository at this point in the history
Signed-off-by: Rustin-Liu <[email protected]>
  • Loading branch information
Rustin170506 committed Feb 16, 2020
1 parent 63b71a3 commit c2e4e2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx
}
return infoschema.ErrTableDropExists.GenWithStackByArgs(strings.Join(notExistTables, ","))
}
// We need add warning when use if exists.
if len(notExistTables) > 0 && ifExists {
for _, table := range notExistTables {
if obt == sequenceObject {
e.ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrSequenceDropExists.GenWithStackByArgs(table))
} else {
e.ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrTableDropExists.GenWithStackByArgs(table))
}
}
}
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,10 @@ func (s *testRecoverTable) TestRenameTable(c *C) {
tk.MustExec("drop database rename1")
tk.MustExec("drop database rename2")
}

func (s *testRecoverTable) TestDropTableIfExists(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustQuery("show warnings;").Check(testkit.Rows("Note 1051 Unknown table 'test.t'"))
}

0 comments on commit c2e4e2b

Please sign in to comment.