Skip to content

Commit

Permalink
Fix error result union scan with apply (#19245)
Browse files Browse the repository at this point in the history
* fix union scan

* fix fmt

* Update union_scan.go

Recursively close children.

* Update union_scan.go

Co-authored-by: ti-srebot <[email protected]>
  • Loading branch information
ichn-hu and ti-srebot authored Aug 19, 2020
1 parent a113adf commit c15a405
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 @@ -192,6 +192,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) {
snapshotRow, err := us.getSnapshotRow(ctx)
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 @@ -328,3 +328,17 @@ func (s *testSuite7) TestForUpdateUntouchedIndex(c *C) {
tk.MustExec("commit")
tk.MustExec("admin check table t")
}

// See https://github.com/pingcap/tidb/issues/19136
func (s *testSuite7) 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 c15a405

Please sign in to comment.