Skip to content

Commit

Permalink
Merge pull request #21303 from petermattis/pmattis/mergejoiner-fast-i…
Browse files Browse the repository at this point in the history
…nt-set

sql/distsqlrun: use FastIntSet to track unmatched right-side rows
  • Loading branch information
petermattis authored Jan 7, 2018
2 parents d8edf5f + 6bc0de0 commit 4051ba3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/sql/distsqlrun/mergejoiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/log"
)

Expand All @@ -36,7 +37,8 @@ type mergeJoiner struct {
leftSource, rightSource RowSource
leftRows, rightRows []sqlbase.EncDatumRow
leftIdx, rightIdx int
matchedRight []bool
emitUnmatchedRight bool
matchedRight util.FastIntSet
matchedRightCount int

streamMerger streamMerger
Expand Down Expand Up @@ -182,8 +184,8 @@ func (m *mergeJoiner) nextRow() (sqlbase.EncDatumRow, *ProducerMetadata) {
}
if renderedRow != nil {
m.matchedRightCount++
if m.matchedRight != nil {
m.matchedRight[ridx] = true
if m.emitUnmatchedRight {
m.matchedRight.Add(ridx)
}
return renderedRow, nil
}
Expand Down Expand Up @@ -211,17 +213,18 @@ func (m *mergeJoiner) nextRow() (sqlbase.EncDatumRow, *ProducerMetadata) {

// We've exhausted the left-side batch. If this is a right or full outer
// join (and thus matchedRight!=nil), emit unmatched right-side rows.
if m.matchedRight != nil {
if m.emitUnmatchedRight {
for m.rightIdx < len(m.rightRows) {
ridx := m.rightIdx
m.rightIdx++
if m.matchedRight[ridx] {
if m.matchedRight.Contains(ridx) {
continue
}
return m.renderUnmatchedRow(m.rightRows[ridx], rightSide), nil
}

m.matchedRight = nil
m.matchedRight = util.FastIntSet{}
m.emitUnmatchedRight = false
}

// Retrieve the next batch of rows to process.
Expand All @@ -235,10 +238,7 @@ func (m *mergeJoiner) nextRow() (sqlbase.EncDatumRow, *ProducerMetadata) {
}

// Prepare for processing the next batch.
m.matchedRight = nil
if shouldEmitUnmatchedRow(rightSide, m.joinType) {
m.matchedRight = make([]bool, len(m.rightRows))
}
m.emitUnmatchedRight = shouldEmitUnmatchedRow(rightSide, m.joinType)
m.leftIdx, m.rightIdx = 0, 0
}
}
Expand Down

0 comments on commit 4051ba3

Please sign in to comment.