Skip to content

Commit

Permalink
colexec: fixed nullableArgs projection operators
Browse files Browse the repository at this point in the history
Previously, the projection operators for binary or comparison expressions
directly copy nulls into the output without performing the actual projection
whenever either argument was null. This is incorrect because some function
operators can handle null arguments, and we want the actual projection result
instead. This PR fixed this by adding the boolean field nullableArgs to the
logic. Note that this pr is reviewable but not ready to merge yet.

Fixes: cockroachdb#83091

Release note (bug fix): Fixed a bug in projection operators that gave output of
nulls when the expression can actually handle null arguments and may result in
a non-null output.
  • Loading branch information
wenyihu6 committed Jul 13, 2022
1 parent 6374bd8 commit 7d7facf
Show file tree
Hide file tree
Showing 11 changed files with 25,954 additions and 13,890 deletions.
11 changes: 6 additions & 5 deletions pkg/sql/colexec/colbuilder/execplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ func planProjectionOperators(
}
return planProjectionExpr(
ctx, evalCtx, t.Operator, t.ResolvedType(), t.TypedLeft(), t.TypedRight(),
columnTypes, input, acc, factory, t.Op.EvalOp, nil /* cmpExpr */, releasables,
columnTypes, input, acc, factory, t.Op.EvalOp, nil /* cmpExpr */, releasables, t.Op.NullableArgs,
)
case *tree.CaseExpr:
allocator := colmem.NewAllocator(ctx, acc, factory)
Expand Down Expand Up @@ -2141,7 +2141,7 @@ func planProjectionOperators(
case *tree.ComparisonExpr:
return planProjectionExpr(
ctx, evalCtx, t.Operator, t.ResolvedType(), t.TypedLeft(), t.TypedRight(),
columnTypes, input, acc, factory, nil /* binFn */, t, releasables,
columnTypes, input, acc, factory, nil /* binFn */, t, releasables, t.Op.NullableArgs,
)
case tree.Datum:
op, err = projectDatum(t)
Expand Down Expand Up @@ -2308,6 +2308,7 @@ func planProjectionExpr(
binOp tree.BinaryEvalOp,
cmpExpr *tree.ComparisonExpr,
releasables *[]execreleasable.Releasable,
nullableArgs bool,
) (op colexecop.Operator, resultIdx int, typs []*types.T, err error) {
if err := checkSupportedProjectionExpr(left, right); err != nil {
return nil, resultIdx, typs, err
Expand Down Expand Up @@ -2344,7 +2345,7 @@ func planProjectionExpr(
// appended to the input batch.
op, err = colexecprojconst.GetProjectionLConstOperator(
allocator, typs, left.ResolvedType(), outputType, projOp, input,
rightIdx, lConstArg, resultIdx, evalCtx, binOp, cmpExpr,
rightIdx, lConstArg, resultIdx, evalCtx, binOp, cmpExpr, nullableArgs,
)
} else {
var leftIdx int
Expand Down Expand Up @@ -2421,7 +2422,7 @@ func planProjectionExpr(
// all other projection operators.
op, err = colexecprojconst.GetProjectionRConstOperator(
allocator, typs, right.ResolvedType(), outputType, projOp,
input, leftIdx, rConstArg, resultIdx, evalCtx, binOp, cmpExpr,
input, leftIdx, rConstArg, resultIdx, evalCtx, binOp, cmpExpr, nullableArgs,
)
}
} else {
Expand All @@ -2436,7 +2437,7 @@ func planProjectionExpr(
resultIdx = len(typs)
op, err = colexecproj.GetProjectionOperator(
allocator, typs, outputType, projOp, input, leftIdx, rightIdx,
resultIdx, evalCtx, binOp, cmpExpr,
resultIdx, evalCtx, binOp, cmpExpr, nullableArgs,
)
}
}
Expand Down
Loading

0 comments on commit 7d7facf

Please sign in to comment.