Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.2.0: colexec: use tree.DNull when projection is called on null input #89347

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,499 changes: 1,407 additions & 2,092 deletions pkg/sql/colexec/colexecproj/proj_non_const_ops.eg.go

Large diffs are not rendered by default.

50 changes: 29 additions & 21 deletions pkg/sql/colexec/colexecproj/proj_non_const_ops_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,7 @@ func (p _OP_NAME) Next() coldata.Batch {
// of a projection is Null.
// */}}
_outNulls := projVec.Nulls()

// {{/*
// If calledOnNullInput is true, the function’s definition can handle
// null arguments. We would still want to perform the projection, and
// there is no need to call projVec.SetNulls(). The behaviour will just
// be the same as _HAS_NULLS is false. Since currently only
// ConcatDatumDatum needs this calledOnNullInput == true behaviour,
// logic for calledOnNullInput is only added to the if statement for
// function with Datum, Datum. If we later introduce another projection
// operation that has calledOnNullInput == true, we should update this
// code accordingly.
// */}}
// {{if and (eq .Left.VecMethod "Datum") (eq .Right.VecMethod "Datum")}}
hasNullsAndNotCalledOnNullInput :=
(vec1.Nulls().MaybeHasNulls() || vec2.Nulls().MaybeHasNulls()) && !p.calledOnNullInput
// {{else}}
hasNullsAndNotCalledOnNullInput := (vec1.Nulls().MaybeHasNulls() || vec2.Nulls().MaybeHasNulls())
// {{end}}
if hasNullsAndNotCalledOnNullInput {
if vec1.Nulls().MaybeHasNulls() || vec2.Nulls().MaybeHasNulls() {
_SET_PROJECTION(true)
} else {
_SET_PROJECTION(false)
Expand All @@ -158,6 +140,7 @@ func _SET_PROJECTION(_HAS_NULLS bool) {
// {{define "setProjection" -}}
// {{$hasNulls := $.HasNulls}}
// {{with $.Overload}}
// {{$isDatum := (and (eq .Left.VecMethod "Datum") (eq .Right.VecMethod "Datum"))}}
// {{if _HAS_NULLS}}
col1Nulls := vec1.Nulls()
col2Nulls := vec2.Nulls()
Expand All @@ -183,7 +166,13 @@ func _SET_PROJECTION(_HAS_NULLS bool) {
// projVec.Nulls() so there is no need to call projVec.SetNulls().
// */}}
// {{if _HAS_NULLS}}
projVec.SetNulls(_outNulls.Or(*col1Nulls).Or(*col2Nulls))
// {{if $isDatum}}
if !p.calledOnNullInput {
// {{end}}
projVec.SetNulls(_outNulls.Or(*col1Nulls).Or(*col2Nulls))
// {{if $isDatum}}
}
// {{end}}
// {{end}}
// {{end}}
// {{end}}
Expand All @@ -198,19 +187,38 @@ func _SET_SINGLE_TUPLE_PROJECTION(_HAS_NULLS bool, _HAS_SEL bool) { // */}}
// {{$hasNulls := $.HasNulls}}
// {{$hasSel := $.HasSel}}
// {{with $.Overload}}
// {{$isDatum := (and (eq .Left.VecMethod "Datum") (eq .Right.VecMethod "Datum"))}}
// {{if _HAS_NULLS}}
if !col1Nulls.NullAt(i) && !col2Nulls.NullAt(i) {
if p.calledOnNullInput || (!col1Nulls.NullAt(i) && !col2Nulls.NullAt(i)) {
// We only want to perform the projection operation if both values are not
// null.
// {{end}}
// {{if and (.Left.Sliceable) (not _HAS_SEL)}}
//gcassert:bce
// {{end}}
arg1 := col1.Get(i)
// {{if (and _HAS_NULLS $isDatum)}}
if col1Nulls.NullAt(i) {
// {{/*
// If we entered this branch for a null value, calledOnNullInput must be
// true. This means the projection should be calculated on null arguments.
// When a value is null, the underlying data in the slice is invalid and
// can be anything, so we need to overwrite it here. calledOnNullInput is
// currently only true for ConcatDatumDatum, so only the datum case needs
// to be handled.
// */}}
arg1 = tree.DNull
}
// {{end}}
// {{if and (.Right.Sliceable) (not _HAS_SEL)}}
//gcassert:bce
// {{end}}
arg2 := col2.Get(i)
// {{if (and _HAS_NULLS $isDatum)}}
if col2Nulls.NullAt(i) {
arg2 = tree.DNull
}
// {{end}}
_ASSIGN(projCol[i], arg1, arg2, projCol, col1, col2)
// {{if _HAS_NULLS}}
}
Expand Down
Loading