Skip to content

Commit

Permalink
colexecjoin: optimize building output on the left in merge joiner
Browse files Browse the repository at this point in the history
This commit updates the way we're building output in the merge joiner
from the left input when building directly from the left batch (i.e. not
from the buffered group). There, we need to repeat a single tuple
`toAppend` times, so we do it in a loop. This commit adds the
optimization of using `Bytes.Copy` for the bytes-like types as well as
BCE for sliceable types.
```
MergeJoiner/rows=32-24                     29.3MB/s ± 3%  29.5MB/s ± 3%     ~     (p=0.684 n=10+10)
MergeJoiner/rows=512-24                    79.4MB/s ± 2%  77.8MB/s ± 3%   -1.91%  (p=0.043 n=10+10)
MergeJoiner/rows=4096-24                    192MB/s ± 2%   189MB/s ± 1%   -1.36%  (p=0.029 n=10+10)
MergeJoiner/rows=32768-24                   278MB/s ± 1%   275MB/s ± 0%   -1.30%  (p=0.000 n=10+10)
MergeJoiner/oneSideRepeat-rows=32-24       37.3MB/s ± 3%  38.0MB/s ± 2%   +1.78%  (p=0.029 n=10+10)
MergeJoiner/oneSideRepeat-rows=512-24       212MB/s ± 1%   215MB/s ± 2%   +1.42%  (p=0.003 n=9+10)
MergeJoiner/oneSideRepeat-rows=4096-24      765MB/s ± 4%   770MB/s ± 3%     ~     (p=0.436 n=10+10)
MergeJoiner/oneSideRepeat-rows=32768-24    1.22GB/s ± 2%  1.23GB/s ± 2%     ~     (p=0.393 n=10+10)
MergeJoiner/bothSidesRepeat-rows=32-24     22.7MB/s ± 2%  22.9MB/s ± 2%     ~     (p=0.203 n=9+10)
MergeJoiner/bothSidesRepeat-rows=512-24     102MB/s ± 4%   104MB/s ± 2%   +2.38%  (p=0.011 n=10+10)
MergeJoiner/bothSidesRepeat-rows=4096-24    117MB/s ± 1%   127MB/s ± 1%   +9.11%  (p=0.000 n=10+9)
MergeJoiner/bothSidesRepeat-rows=32768-24  59.2MB/s ± 1%  67.1MB/s ± 1%  +13.48%  (p=0.000 n=10+10)
```

Release note: None
  • Loading branch information
yuzefovich committed Mar 23, 2022
1 parent 645f3c4 commit d82affe
Show file tree
Hide file tree
Showing 16 changed files with 3,382 additions and 2,180 deletions.
4 changes: 2 additions & 2 deletions pkg/col/coldata/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func (b *Bytes) Window(start, end int) *Bytes {
}
}

// copy copies a single value from src at position srcIdx into position destIdx
// Copy copies a single value from src at position srcIdx into position destIdx
// of the receiver. It is faster than b.Set(destIdx, src.Get(srcIdx)).
func (b *Bytes) copy(src *Bytes, destIdx, srcIdx int) {
func (b *Bytes) Copy(src *Bytes, destIdx, srcIdx int) {
if buildutil.CrdbTestBuild {
if b.isWindow {
panic("copy is called on a window into Bytes")
Expand Down
2 changes: 1 addition & 1 deletion pkg/col/coldata/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func applyMethodsAndVerify(
destIdx := rng.Intn(n)
srcIdx := rng.Intn(sourceN)
debugString += fmt.Sprintf("(%d, %d)", destIdx, srcIdx)
b1.copy(b1Source, destIdx, srcIdx)
b1.Copy(b1Source, destIdx, srcIdx)
b2[destIdx] = append([]byte(nil), b2Source[srcIdx]...)
case copySlice, appendSlice:
// Generate a length-inclusive destIdx.
Expand Down
6 changes: 3 additions & 3 deletions pkg/col/coldata/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func (js *JSONs) Window(start, end int) *JSONs {
}
}

// copy copies a single value from src at position srcIdx into position destIdx
// Copy copies a single value from src at position srcIdx into position destIdx
// of the receiver.
func (js *JSONs) copy(src *JSONs, destIdx, srcIdx int) {
js.Bytes.copy(&src.Bytes, destIdx, srcIdx)
func (js *JSONs) Copy(src *JSONs, destIdx, srcIdx int) {
js.Bytes.Copy(&src.Bytes, destIdx, srcIdx)
}

// CopySlice copies srcStartIdx inclusive and srcEndIdx exclusive []byte values
Expand Down
8 changes: 4 additions & 4 deletions pkg/col/coldata/vec.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/col/coldata/vec_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (m *memColumn) Copy(args SliceArgs) {
m.nulls.SetNull(i + args.DestIdx)
} else {
// {{if .IsBytesLike}}
toCol.copy(fromCol, i+args.DestIdx, selIdx)
toCol.Copy(fromCol, i+args.DestIdx, selIdx)
// {{else}}
v := fromCol.Get(selIdx)
// {{if .Sliceable}}
Expand Down Expand Up @@ -238,7 +238,7 @@ func (m *memColumn) Copy(args SliceArgs) {
//gcassert:bce
selIdx := sel[i]
// {{if .IsBytesLike}}
toCol.copy(fromCol, i+args.DestIdx, selIdx)
toCol.Copy(fromCol, i+args.DestIdx, selIdx)
// {{else}}
v := fromCol.Get(selIdx)
// {{if .Sliceable}}
Expand Down Expand Up @@ -285,7 +285,7 @@ func _COPY_WITH_REORDERED_SOURCE(_SRC_HAS_NULLS bool) { // */}}
// {{end}}
{
// {{if .IsBytesLike}}
toCol.copy(fromCol, destIdx, srcIdx)
toCol.Copy(fromCol, destIdx, srcIdx)
// {{else}}
v := fromCol.Get(srcIdx)
toCol.Set(destIdx, v)
Expand Down
Loading

0 comments on commit d82affe

Please sign in to comment.