Skip to content

Commit

Permalink
Fix error result union scan with apply (#19245) (#19298)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Aug 26, 2020
1 parent bfc82cd commit 77f7faf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions executor/union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func (us *UnionScanExec) Next(ctx context.Context, req *chunk.Chunk) error {
return nil
}

// Close implements the Executor Close interface.
func (us *UnionScanExec) Close() error {
us.cursor4AddRows = 0
us.cursor4SnapshotRows = 0
us.addedRows = us.addedRows[:0]
us.snapshotRows = us.snapshotRows[:0]
return us.children[0].Close()
}

// getOneRow gets one result row from dirty table or child.
func (us *UnionScanExec) getOneRow(ctx context.Context) ([]types.Datum, error) {
for {
Expand Down
14 changes: 14 additions & 0 deletions executor/union_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,17 @@ func (s *testSuite4) TestForUpdateUntouchedIndex(c *C) {
tk.MustExec("commit")
tk.MustExec("admin check table t")
}

// See https://github.com/pingcap/tidb/issues/19136
func (s *testSuite4) TestForApplyAndUnionScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")

tk.MustExec("create table t ( c_int int, c_str varchar(40), primary key(c_int, c_str) )")
tk.MustExec("begin")
tk.MustExec("insert into t values (1, 'amazing almeida'), (2, 'boring bardeen'), (3, 'busy wescoff')")
tk.MustQuery("select c_int, (select t1.c_int from t t1 where t1.c_int = 3 and t1.c_int > t.c_int order by t1.c_int limit 1) x from t").Check(testkit.Rows("1 3", "2 3", "3 <nil>"))
tk.MustExec("commit")
tk.MustQuery("select c_int, (select t1.c_int from t t1 where t1.c_int = 3 and t1.c_int > t.c_int order by t1.c_int limit 1) x from t").Check(testkit.Rows("1 3", "2 3", "3 <nil>"))
}

0 comments on commit 77f7faf

Please sign in to comment.