Skip to content

Commit

Permalink
return err when INSERT/UPDATE/ANALYZE/DELETE a sequence (#16936) (#16957
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sre-bot authored May 6, 2020
1 parent eccb800 commit 0cbecf4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
17 changes: 17 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0cbecf4

Please sign in to comment.