Skip to content

Commit e59c03e

Browse files
author
James Cor
committed
copy less in merge join
1 parent 7442b92 commit e59c03e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

sql/rowexec/merge_join.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ func newMergeJoinIter(ctx *sql.Context, b sql.NodeExecBuilder, j *plan.JoinNode,
4747
}
4848

4949
fullRow := sql.GetRow(len(row) + len(j.Left().Schema()) + len(j.Right().Schema()))
50-
// TODO: what is this for?
51-
fullRow[0] = row
5250
if len(row) > 0 {
5351
copy(fullRow[0:], row[:])
5452
}
@@ -202,7 +200,6 @@ func (i *mergeJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
202200
nextState = msExhaustCheck
203201
case msExhaustCheck:
204202
if i.lojFinalize() {
205-
ret = i.copyReturnRow()
206203
nextState = msRetLeft
207204
} else if i.exhausted() {
208205
return nil, io.EOF
@@ -228,7 +225,6 @@ func (i *mergeJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
228225
if i.leftMatched {
229226
nextState = msIncLeft
230227
} else {
231-
ret = i.copyReturnRow()
232228
nextState = msRetLeft
233229
}
234230
} else {
@@ -243,7 +239,6 @@ func (i *mergeJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
243239
left, _ := i.cmp.Left().Eval(ctx, i.fullRow)
244240
if left == nil {
245241
if i.typ.IsLeftOuter() && !i.leftMatched {
246-
ret = i.copyReturnRow()
247242
nextState = msRetLeft
248243
} else {
249244
nextState = msIncLeft
@@ -264,10 +259,9 @@ func (i *mergeJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
264259
}
265260
nextState = msExhaustCheck
266261
case msSelect:
267-
ret = i.copyReturnRow() // TODO: only copy once we know we're going to return this
268262
currLeftMatched := i.leftMatched
269263

270-
ok, err := i.sel(ctx, ret)
264+
ok, err := i.sel(ctx, i.fullRow)
271265
if err != nil {
272266
return nil, err
273267
}
@@ -296,14 +290,17 @@ func (i *mergeJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
296290
// |i.incMatch| call incremented the left row.
297291
// |currLeftMatched| indicates whether |ret| has already
298292
// successfully met a join condition.
293+
ret = i.copyReturnRow()
299294
return i.removeParentRow(i.nullifyRightRow(ret)), nil
300295
} else {
301296
nextState = msExhaustCheck
302297
}
303298

304299
case msRet:
300+
ret = i.copyReturnRow()
305301
return i.removeParentRow(ret), nil
306302
case msRetLeft:
303+
ret = i.copyReturnRow()
307304
ret = i.removeParentRow(i.nullifyRightRow(ret))
308305
err = i.incLeft(ctx)
309306
if err != nil {

0 commit comments

Comments
 (0)