Skip to content

Commit

Permalink
planner: report error when UPDATE set generated column with non-defau…
Browse files Browse the repository at this point in the history
…lt value (pingcap#21460)
  • Loading branch information
dyzsr authored and asiafrank committed Dec 8, 2020
1 parent 5aa824d commit 74817dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,25 @@ func (s *testIntegrationSuite) TestUpdateMultiUpdatePK(c *C) {
tk.MustQuery("SELECT * FROM t").Check(testkit.Rows("2 12"))
}

func (s *testIntegrationSuite) TestUpdateSetDefault(c *C) {
// #20598
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table tt (x int, z int as (x+10) stored)")
tk.MustExec("insert into tt(x) values (1)")
tk.MustExec("update tt set x=2, z = default")
tk.MustQuery("select * from tt").Check(testkit.Rows("2 12"))

tk.MustGetErrMsg("update tt set z = 123",
"[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.")
tk.MustGetErrMsg("update tt as ss set z = 123",
"[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.")
tk.MustGetErrMsg("update tt as ss set x = 3, z = 13",
"[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.")
tk.MustGetErrMsg("update tt as s1, tt as s2 set s1.z = default, s2.z = 456",
"[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.")
}

func (s *testIntegrationSerialSuite) TestPreferRangeScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,7 @@ func (b *PlanBuilder) buildUpdateLists(
if !colInfo.IsGenerated() {
continue
}
columnFullName := fmt.Sprintf("%s.%s.%s", tn.Schema.L, tn.Name.L, colInfo.Name.L)
columnFullName := fmt.Sprintf("%s.%s.%s", tn.DBInfo.Name.L, tn.Name.L, colInfo.Name.L)
isDefault, ok := modifyColumns[columnFullName]
if ok && colInfo.Hidden {
return nil, nil, false, ErrUnknownColumn.GenWithStackByArgs(colInfo.Name, clauseMsg[fieldList])
Expand Down

0 comments on commit 74817dc

Please sign in to comment.