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: use before statement snapshot for UnionScan #19276

Merged
merged 6 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/mem_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func iterTxnMemBuffer(ctx sessionctx.Context, kvRanges []kv.KeyRange, fn process
return err
}
for _, rg := range kvRanges {
iter, err := txn.GetMemBuffer().Iter(rg.StartKey, rg.EndKey)
iter, err := txn.GetMemBufferSnapshot().Iter(rg.StartKey, rg.EndKey)
if err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions executor/union_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,31 @@ func (s *testSuite7) TestForUpdateUntouchedIndex(c *C) {
tk.MustExec("admin check table t")
}

func (s *testSuite7) TestUpdateScanningHandles(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(a int primary key, b int);")
tk.MustExec("begin")
for i := 2; i < 100000; i++ {
tk.MustExec("insert into t values (?, ?)", i, i)
}
tk.MustExec("commit;")

tk.MustExec("set tidb_distsql_scan_concurrency = 1;")
tk.MustExec("set tidb_index_lookup_join_concurrency = 1;")
tk.MustExec("set tidb_projection_concurrency=1;")
tk.MustExec("set tidb_init_chunk_size=1;")
tk.MustExec("set tidb_max_chunk_size=32;")

tk.MustExec("begin")
tk.MustExec("insert into t values (1, 1);")
tk.MustExec("update /*+ INL_JOIN(t1) */ t t1, (select a, b from t) t2 set t1.b = t2.b where t1.a = t2.a + 1000;")
result := tk.MustQuery("select a, a-b from t where a > 1000 and a - b != 1000;")
c.Assert(result.Rows(), HasLen, 0)
tk.MustExec("rollback;")
}

// See https://github.com/pingcap/tidb/issues/19136
func (s *testSuite7) TestForApplyAndUnionScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
Expand Down
2 changes: 2 additions & 0 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ type Transaction interface {
Valid() bool
// GetMemBuffer return the MemBuffer binding to this transaction.
GetMemBuffer() MemBuffer
// GetMemBufferSnapshot is used to return a snapshot of MemBuffer without any statement modify.
GetMemBufferSnapshot() MemBuffer
// GetSnapshot returns the Snapshot binding to this transaction.
GetSnapshot() Snapshot
// SetVars sets variables to the transaction.
Expand Down
4 changes: 4 additions & 0 deletions kv/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (t *mockTxn) GetMemBuffer() MemBuffer {
return nil
}

func (t *mockTxn) GetMemBufferSnapshot() MemBuffer {
return nil
}

func (t *mockTxn) GetSnapshot() Snapshot {
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions session/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ func (st *TxnState) GetMemBuffer() kv.MemBuffer {
return kv.NewBufferStoreFrom(st.Transaction.GetMemBuffer(), st.stmtBuf)
}

// GetMemBufferSnapshot overrides the Transaction interface.
func (st *TxnState) GetMemBufferSnapshot() kv.MemBuffer {
return st.Transaction.GetMemBuffer()
}

// BatchGet overrides the Transaction interface.
func (st *TxnState) BatchGet(ctx context.Context, keys []kv.Key) (map[string][]byte, error) {
bufferValues := make([][]byte, len(keys))
Expand Down
4 changes: 4 additions & 0 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ func (txn *tikvTxn) GetMemBuffer() kv.MemBuffer {
return txn.us.GetMemBuffer()
}

func (txn *tikvTxn) GetMemBufferSnapshot() kv.MemBuffer {
panic("unsupported operation")
}

func (txn *tikvTxn) GetSnapshot() kv.Snapshot {
return txn.snapshot
}