diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 923fd2bdfaca..aa77ef128682 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -3142,6 +3142,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 f3c10fdd4433..38493e6e519e 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -286,7 +286,11 @@ func (s *testSuite6) 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 44487241af18..8839fb6b4423 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -99,10 +99,17 @@ func (s *testSessionSuiteBase) TearDownSuite(c *C) { func (s *testSessionSuiteBase) 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)) + } } }