From 0cbecf47263cbaca1dc7cc9d55b642fb09f516ad Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Wed, 6 May 2020 16:35:55 +0800 Subject: [PATCH] return err when INSERT/UPDATE/ANALYZE/DELETE a sequence (#16936) (#16957) --- executor/write_test.go | 17 +++++++++++++++++ planner/core/cbo_test.go | 7 ++++++- planner/core/logical_plan_builder.go | 9 +++++++++ planner/core/planbuilder.go | 12 +++++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/executor/write_test.go b/executor/write_test.go index ab4c24acd40b3..425be7557f37a 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -300,6 +300,13 @@ func (s *testSuite) TestInsert(c *C) { _, err = tk.Exec("replace into v values(1,2)") c.Assert(err.Error(), Equals, "replace into view v is not supported now.") tk.MustExec("drop view v") + + tk.MustExec("create sequence seq") + _, err = tk.Exec("insert into seq values()") + c.Assert(err.Error(), Equals, "insert into sequence seq is not supported now.") + _, err = tk.Exec("replace into seq values()") + c.Assert(err.Error(), Equals, "replace into sequence seq is not supported now.") + tk.MustExec("drop sequence seq") } func (s *testSuiteP2) TestMultiBatch(c *C) { @@ -1511,6 +1518,11 @@ func (s *testSuite8) TestUpdate(c *C) { c.Assert(err.Error(), Equals, core.ErrViewInvalid.GenWithStackByArgs("test", "v").Error()) tk.MustExec("drop view v") + tk.MustExec("create sequence seq") + _, err = tk.Exec("update seq set minvalue=1") + c.Assert(err.Error(), Equals, "update sequence seq is not supported now.") + tk.MustExec("drop sequence seq") + tk.MustExec("drop table if exists t1, t2") tk.MustExec("create table t1(a int, b int, c int, d int, e int, index idx(a))") tk.MustExec("create table t2(a int, b int, c int)") @@ -1811,6 +1823,11 @@ func (s *testSuite) TestDelete(c *C) { _, err = tk.Exec("delete from v where name = 'aaa'") c.Assert(err.Error(), Equals, core.ErrViewInvalid.GenWithStackByArgs("test", "v").Error()) tk.MustExec("drop view v") + + tk.MustExec("create sequence seq") + _, err = tk.Exec("delete from seq") + c.Assert(err.Error(), Equals, "delete sequence seq is not supported now.") + tk.MustExec("drop sequence seq") } func (s *testSuite4) TestPartitionedTableDelete(c *C) { diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index 97b44f22fcff4..5a84c2a0ad2de 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -355,9 +355,14 @@ func (s *testAnalyzeSuite) TestAnalyze(c *C) { testKit.MustExec("create view v as select * from t") _, err = testKit.Exec("analyze table v") - c.Assert(err.Error(), Equals, "analyze v is not supported now.") + c.Assert(err.Error(), Equals, "analyze view v is not supported now.") testKit.MustExec("drop view v") + testKit.MustExec("create sequence seq") + _, err = testKit.Exec("analyze table seq") + c.Assert(err.Error(), Equals, "analyze sequence seq is not supported now.") + testKit.MustExec("drop sequence seq") + var input, output []string s.testData.GetTestCases(c, &input, &output) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index aeea10e4146f0..6abb0a30df9e2 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -3244,6 +3244,9 @@ func (b *PlanBuilder) buildUpdate(ctx context.Context, update *ast.UpdateStmt) ( if t.TableInfo.IsView() { return nil, errors.Errorf("update view %s is not supported now.", t.Name.O) } + if t.TableInfo.IsSequence() { + return nil, errors.Errorf("update sequence %s is not supported now.", t.Name.O) + } b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SelectPriv, dbName, t.Name.L, "", nil) } @@ -3606,6 +3609,9 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) ( if tn.TableInfo.IsView() { return nil, errors.Errorf("delete view %s is not supported now.", tn.Name.O) } + if tn.TableInfo.IsSequence() { + return nil, errors.Errorf("delete sequence %s is not supported now.", tn.Name.O) + } b.visitInfo = appendVisitInfo(b.visitInfo, mysql.DeletePriv, tn.Schema.L, tn.TableInfo.Name.L, "", nil) } } else { @@ -3614,6 +3620,9 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) ( if v.TableInfo.IsView() { return nil, errors.Errorf("delete view %s is not supported now.", v.Name.O) } + if v.TableInfo.IsSequence() { + return nil, errors.Errorf("delete sequence %s is not supported now.", v.Name.O) + } dbName := v.Schema.L if dbName == "" { dbName = b.ctx.GetSessionVars().CurrentDB diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index e053f4c0a9ba2..61d917c7f69cb 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1325,7 +1325,10 @@ func (b *PlanBuilder) buildAnalyzeTable(as *ast.AnalyzeTableStmt, opts map[ast.A p := &Analyze{Opts: opts} for _, tbl := range as.TableNames { if tbl.TableInfo.IsView() { - return nil, errors.Errorf("analyze %s is not supported now.", tbl.Name.O) + return nil, errors.Errorf("analyze view %s is not supported now.", tbl.Name.O) + } + if tbl.TableInfo.IsSequence() { + return nil, errors.Errorf("analyze sequence %s is not supported now.", tbl.Name.O) } idxInfo, colInfo, pkInfo := getColsInfo(tbl) physicalIDs, names, err := getPhysicalIDsAndPartitionNames(tbl.TableInfo, as.PartitionNames) @@ -1943,6 +1946,13 @@ func (b *PlanBuilder) buildInsert(ctx context.Context, insert *ast.InsertStmt) ( } return nil, err } + if tableInfo.IsSequence() { + err := errors.Errorf("insert into sequence %s is not supported now.", tableInfo.Name.O) + if insert.IsReplace { + err = errors.Errorf("replace into sequence %s is not supported now.", tableInfo.Name.O) + } + return nil, err + } // Build Schema with DBName otherwise ColumnRef with DBName cannot match any Column in Schema. schema, names := expression.TableInfo2SchemaAndNames(b.ctx, tn.Schema, tableInfo) tableInPlan, ok := b.is.TableByID(tableInfo.ID)