Skip to content

Commit

Permalink
executor: fix table id to partition id mapping in select lock executor (
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Jul 21, 2021
1 parent 16d947d commit cdc0397
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,9 @@ func (e *SelectLockExec) Next(ctx context.Context, req *chunk.Chunk) error {
if len(e.partitionedTable) > 0 {
// Replace the table ID with partition ID.
// The partition ID is returned as an extra column from the table reader.
offset := e.tblID2PIDColumnIndex[id]
physicalID = row.GetInt64(offset)
if offset, ok := e.tblID2PIDColumnIndex[id]; ok {
physicalID = row.GetInt64(offset)
}
}

for _, col := range cols {
Expand Down
32 changes: 32 additions & 0 deletions executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3056,3 +3056,35 @@ func (s *partitionTableSuite) TestIssue25528(c *C) {
tk.MustExec("INSERT INTO issue25528 (`c1`, `c2`, `c3`, `c4`) VALUES (1, 1, 1, 1) , (3, 3, 3, 3) , (2, 2, 2, 2) , (4, 4, 4, 4);")
tk.MustQuery("select * from issue25528 where c1 in (3, 4) order by c2 for update;").Check(testkit.Rows("3 3 3 3", "4 4 4 4"))
}

func (s *partitionTableSuite) TestIssue26251(c *C) {
tk1 := testkit.NewTestKit(c, s.store)
tk1.MustExec("use test")
tk1.MustExec("create table tp (id int primary key) partition by range (id) (partition p0 values less than (100));")
tk1.MustExec("create table tn (id int primary key);")
tk1.MustExec("insert into tp values(1),(2);")
tk1.MustExec("insert into tn values(1),(2);")

tk2 := testkit.NewTestKit(c, s.store)
tk2.MustExec("use test")

tk1.MustExec("begin pessimistic")
tk1.MustQuery("select * from tp,tn where tp.id=tn.id and tn.id<=1 for update;").Check(testkit.Rows("1 1"))

ch := make(chan struct{}, 1)
tk2.MustExec("begin pessimistic")
go func() {
// This query should block.
tk2.MustQuery("select * from tn where id=1 for update;").Check(testkit.Rows("1"))
ch <- struct{}{}
}()

select {
case <-time.After(100 * time.Millisecond):
// Expected, query blocked, not finish within 100ms.
tk1.MustExec("rollback")
case <-ch:
// Unexpected, test fail.
c.Fail()
}
}

0 comments on commit cdc0397

Please sign in to comment.