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, executor: forbid truncate view #16251

Merged
merged 4 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ func onTruncateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ erro
if err != nil {
return ver, errors.Trace(err)
}
if tblInfo.IsView() {
job.State = model.JobStateCancelled
return ver, infoschema.ErrTableNotExists.GenWithStackByArgs(job.SchemaName, tblInfo.Name.O)
}

err = t.DropTableOrView(schemaID, tblInfo.ID, true)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ func (s *testSuite6) TestCreateView(c *C) {
tk.MustExec("drop view v_nested, v_nested2")
}

func (s *testSuite6) TestIssue16250(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table if not exists t(a int)")
tk.MustExec("create view view_issue16250 as select * from t")
_, err := tk.Exec("truncate table view_issue16250")
c.Assert(err.Error(), Equals, "[schema:1146]Table 'test.view_issue16250' doesn't exist")
}

func (s *testSuite6) TestCreateViewWithOverlongColName(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down