Skip to content

Commit

Permalink
cherry pick pingcap#16251 to release-3.1
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <sre-bot@pingcap.com>
  • Loading branch information
XuHuaiyu authored and sre-bot committed Apr 15, 2020
1 parent ba735e9 commit 0f892fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,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
13 changes: 13 additions & 0 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,20 @@ func (s *testSuite3) TestCreateView(c *C) {
tk.MustExec("drop view v_nested, v_nested2")
}

<<<<<<< HEAD
func (s *testSuite3) TestCreateViewWithOverlongColName(c *C) {
=======
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) {
>>>>>>> 0ec8d33... ddl, executor: forbid truncate view (#16251)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table t(a int)")
Expand Down

0 comments on commit 0f892fa

Please sign in to comment.