diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 4e2d0d3ff1d9..aadcf1ed4fa6 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2991,6 +2991,10 @@ func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident) (err error) { return errors.Trace(err) } + if tb.Meta().IsView() { + return infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name) + } + job := &model.Job{ SchemaID: schema.ID, TableID: tb.Meta().ID, diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 8505f8ce5e3e..c0d6b2071131 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -286,7 +286,11 @@ func (s *testSuite3) TestCreateDropView(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create or replace view drop_test as select 1,2") - _, err := tk.Exec("drop view if exists drop_test") + + _, err := tk.Exec("drop table drop_test") + c.Assert(err.Error(), Equals, "[schema:1051]Unknown table 'test.drop_test'") + + _, err = tk.Exec("drop view if exists drop_test") c.Assert(err, IsNil) _, err = tk.Exec("drop view mysql.gc_delete_range") diff --git a/session/session_test.go b/session/session_test.go index ca70da13faa4..4987d96fb86b 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -85,10 +85,17 @@ func (s *testSessionSuite) TearDownSuite(c *C) { func (s *testSessionSuite) TearDownTest(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) - r := tk.MustQuery("show tables") + r := tk.MustQuery("show full tables") for _, tb := range r.Rows() { tableName := tb[0] - tk.MustExec(fmt.Sprintf("drop table %v", tableName)) + tableType := tb[1] + if tableType == "VIEW" { + tk.MustExec(fmt.Sprintf("drop view %v", tableName)) + } else if tableType == "BASE TABLE" { + tk.MustExec(fmt.Sprintf("drop table %v", tableName)) + } else { + panic(fmt.Sprintf("Unexpected table '%s' with type '%s'.", tableName, tableType)) + } } }