Skip to content

Commit

Permalink
planner: fix partition selection of point plan for the update stateme…
Browse files Browse the repository at this point in the history
  • Loading branch information
TszKitLo40 authored Apr 2, 2021
1 parent c637388 commit 85da7b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6765,7 +6765,7 @@ func (s *testSuite1) TestInsertIntoGivenPartitionSet(c *C) {
func (s *testSuite1) TestUpdateGivenPartitionSet(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t1,t2,t3")
tk.MustExec("drop table if exists t1,t2,t3,t4")
tk.MustExec(`create table t1(
a int(11),
b varchar(10) DEFAULT NULL,
Expand Down Expand Up @@ -6817,6 +6817,11 @@ func (s *testSuite1) TestUpdateGivenPartitionSet(c *C) {

tk.MustExec("update t2 partition(p0) set a = 3 where a = 2")
tk.MustExec("update t2 partition(p0, p3) set a = 33 where a = 1")

tk.MustExec("create table t4(a int primary key, b int) partition by hash(a) partitions 2")
tk.MustExec("insert into t4(a, b) values(1, 1),(2, 2),(3, 3);")
err = tk.ExecToErr("update t4 partition(p0) set a = 5 where a = 2")
c.Assert(err.Error(), Equals, "[table:1748]Found a row not matching the given partition set")
}

func (s *testSuiteP2) TestApplyCache(c *C) {
Expand Down
20 changes: 20 additions & 0 deletions planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,26 @@ func buildPointUpdatePlan(ctx sessionctx.Context, pointPlan PhysicalPlan, dbName
updatePlan.tblID2Table = map[int64]table.Table{
tbl.ID: t,
}
if tbl.GetPartitionInfo() != nil {
pt := t.(table.PartitionedTable)
var updateTableList []*ast.TableName
updateTableList = extractTableList(updateStmt.TableRefs.TableRefs, updateTableList, true)
updatePlan.PartitionedTable = make([]table.PartitionedTable, 0, len(updateTableList))
for _, updateTable := range updateTableList {
if len(updateTable.PartitionNames) > 0 {
pids := make(map[int64]struct{}, len(updateTable.PartitionNames))
for _, name := range updateTable.PartitionNames {
pid, err := tables.FindPartitionByName(tbl, name.L)
if err != nil {
return updatePlan
}
pids[pid] = struct{}{}
}
pt = tables.NewPartitionTableithGivenSets(pt, pids)
}
updatePlan.PartitionedTable = append(updatePlan.PartitionedTable, pt)
}
}
return updatePlan
}

Expand Down

0 comments on commit 85da7b3

Please sign in to comment.