Skip to content

Commit

Permalink
executor: buffer snapshotChunk to avoid too many object memory alloca…
Browse files Browse the repository at this point in the history
…tion (pingcap#6312)
  • Loading branch information
XuHuaiyu authored Apr 18, 2018
1 parent 5725b43 commit cc8c38d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions executor/union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ type UnionScanExec struct {
sortErr error
snapshotRows []types.DatumRow
cursor4SnapshotRows int
snapshotChunkBuffer *chunk.Chunk
}

// Open implements the Executor Open interface.
func (us *UnionScanExec) Open(ctx context.Context) error {
if err := us.baseExecutor.Open(ctx); err != nil {
return errors.Trace(err)
}
us.snapshotChunkBuffer = us.newChunk()
return nil
}

// Next implements the Executor Next interface.
Expand Down Expand Up @@ -182,13 +192,12 @@ func (us *UnionScanExec) getSnapshotRow(ctx context.Context) (types.DatumRow, er
us.cursor4SnapshotRows = 0
us.snapshotRows = us.snapshotRows[:0]
for len(us.snapshotRows) == 0 {
chk := chunk.NewChunkWithCapacity(us.retTypes(), us.maxChunkSize)
err = us.children[0].Next(ctx, chk)
if err != nil || chk.NumRows() == 0 {
err = us.children[0].Next(ctx, us.snapshotChunkBuffer)
if err != nil || us.snapshotChunkBuffer.NumRows() == 0 {
return nil, errors.Trace(err)
}
it := chunk.NewIterator4Chunk(chk)
for row := it.Begin(); row != it.End(); row = it.Next() {
iter := chunk.NewIterator4Chunk(us.snapshotChunkBuffer)
for row := iter.Begin(); row != iter.End(); row = iter.Next() {
snapshotHandle := row.GetInt64(us.belowHandleIndex)
if _, ok := us.dirty.deletedRows[snapshotHandle]; ok {
continue
Expand Down

0 comments on commit cc8c38d

Please sign in to comment.