From c2e4e2b53895e74ec3f21d8264f0d429d48ad64e Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 16 Feb 2020 10:57:17 +0800 Subject: [PATCH] executor: add drop if exists warnings(close #7867) Signed-off-by: Rustin-Liu --- executor/ddl.go | 10 ++++++++++ executor/ddl_test.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/executor/ddl.go b/executor/ddl.go index 77511030ff7f2..abfec4164b341 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -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 } diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 6d002c3a28211..aa914cfda5ea8 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -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'")) +}