Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix table id to partition id mapping in select lock executor (#26380) #26631

Merged
merged 9 commits into from
Sep 16, 2021
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 @@ -3055,3 +3055,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()
}
}