Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: fix the bug that VIEWs can be dropped by DROP TABLE syntax (#14048) #14052

Merged
merged 6 commits into from Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ddl/ddl_api.go
Expand Up @@ -2987,6 +2987,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,
Expand Down
6 changes: 5 additions & 1 deletion executor/ddl_test.go
Expand Up @@ -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")
Expand Down
11 changes: 9 additions & 2 deletions session/session_test.go
Expand Up @@ -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))
}
}
}

Expand Down