Skip to content

Commit

Permalink
col: operate on Nulls value, not reference
Browse files Browse the repository at this point in the history
This commit changes `col.Vec.SetNulls` to accept a `Nulls` struct by
value instead of by pointer. This lets us avoid a heap allocation on
each call to `Nulls.Or`.
  • Loading branch information
nvanbenschoten committed Jan 8, 2022
1 parent 40cbbfb commit e1ecea5
Show file tree
Hide file tree
Showing 12 changed files with 1,258 additions and 1,259 deletions.
4 changes: 2 additions & 2 deletions pkg/col/coldata/nulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ func (n *Nulls) SetNullBitmap(bm []byte, size int) {

// Or returns a new Nulls vector where NullAt(i) iff n1.NullAt(i) or
// n2.NullAt(i).
func (n *Nulls) Or(n2 *Nulls) *Nulls {
func (n Nulls) Or(n2 Nulls) Nulls {
// For simplicity, enforce that len(n.nulls) <= len(n2.nulls).
if len(n.nulls) > len(n2.nulls) {
n, n2 = n2, n
}
res := &Nulls{
res := Nulls{
maybeHasNulls: n.maybeHasNulls || n2.maybeHasNulls,
nulls: make([]byte, len(n2.nulls)),
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/col/coldata/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ func TestNullsSet(t *testing.T) {
}
for _, withSel := range []bool{false, true} {
t.Run(fmt.Sprintf("WithSel=%t", withSel), func(t *testing.T) {
var srcNulls *Nulls
var srcNulls Nulls
if withSel {
args.Sel = make([]int, BatchSize())
// Make a selection vector with every even index. (This turns nulls10 into
// nulls5.)
for i := range args.Sel {
args.Sel[i] = i * 2
}
srcNulls = &nulls10
srcNulls = nulls10
} else {
args.Sel = nil
srcNulls = &nulls5
srcNulls = nulls5
}
for _, destStartIdx := range pos {
for _, srcStartIdx := range pos {
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestNullsOr(t *testing.T) {
n1Choice, n2Choice := rng.Intn(len(nullsToChooseFrom)), rng.Intn(len(nullsToChooseFrom))
n1 := nullsToChooseFrom[n1Choice].Slice(0, length1)
n2 := nullsToChooseFrom[n2Choice].Slice(0, length2)
or := n1.Or(&n2)
or := n1.Or(n2)
require.Equal(t, or.maybeHasNulls, n1.maybeHasNulls || n2.maybeHasNulls)
maxLength := length1
if length2 > length1 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/col/coldata/vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type Vec interface {
Nulls() *Nulls

// SetNulls sets the nulls vector for this column.
SetNulls(*Nulls)
SetNulls(Nulls)

// Length returns the length of the slice that is underlying this Vec.
Length() int
Expand Down Expand Up @@ -294,8 +294,8 @@ func (m *memColumn) Nulls() *Nulls {
return &m.nulls
}

func (m *memColumn) SetNulls(n *Nulls) {
m.nulls = *n
func (m *memColumn) SetNulls(n Nulls) {
m.nulls = n
}

func (m *memColumn) Length() int {
Expand Down
452 changes: 226 additions & 226 deletions pkg/sql/colexec/colexecproj/proj_const_left_ops.eg.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/sql/colexec/colexecproj/proj_const_ops_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func _SET_PROJECTION(_HAS_NULLS bool) {
// If _HAS_NULLS is false, then there are no input Nulls. _outNulls is
// projVec.Nulls() so there is no need to call projVec.SetNulls().
// {{if _HAS_NULLS}}
projVec.SetNulls(_outNulls.Or(colNulls))
projVec.SetNulls(_outNulls.Or(*colNulls))
// {{end}}
// {{end}}
// {{end}}
Expand Down
824 changes: 412 additions & 412 deletions pkg/sql/colexec/colexecproj/proj_const_right_ops.eg.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions pkg/sql/colexec/colexecproj/proj_like_ops.eg.go

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

Loading

0 comments on commit e1ecea5

Please sign in to comment.