diff --git a/ddl/table.go b/ddl/table.go index be05743a10992..f298222d587dc 100644 --- a/ddl/table.go +++ b/ddl/table.go @@ -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 { diff --git a/executor/ddl_test.go b/executor/ddl_test.go index ad8c25d07ec4e..915a01aa187b5 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -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)")