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

tree: handle null in suboperator expressions #37775

Merged
merged 1 commit into from
May 24, 2019
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
4 changes: 3 additions & 1 deletion pkg/sql/sem/tree/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -3670,7 +3670,9 @@ func (expr *ComparisonExpr) Eval(ctx *EvalContext) (Datum, error) {
if op.hasSubOperator() {
var datums Datums
// Right is either a tuple or an array of Datums.
if tuple, ok := AsDTuple(right); ok {
if !expr.fn.NullableArgs && right == DNull {
return DNull, nil
} else if tuple, ok := AsDTuple(right); ok {
datums = tuple.D
} else if array, ok := AsDArray(right); ok {
datums = array.Array
Expand Down
63 changes: 63 additions & 0 deletions pkg/sql/sem/tree/testdata/eval/any_some_all
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,69 @@ eval
----
NULL

# Regression test for #37547 - ensure that null RHS of comparisons with
# suboperators are correctly handled. A null RHS always results in null.
eval
1 = ANY(NULL::int[])
----
NULL

eval
1 = SOME(NULL::int[])
----
NULL

eval
1 = ALL(NULL::int[])
----
NULL

eval
NULL::int = ANY(NULL::int[])
----
NULL

eval
NULL::int = SOME(NULL::int[])
----
NULL

eval
NULL::int = ALL(NULL::int[])
----
NULL

# A null LHS has different behavior if the array is empty or not
eval
NULL::int = ANY(ARRAY[1,2])
----
NULL

eval
NULL::int = SOME(ARRAY[1,2])
----
NULL

eval
NULL::int = ALL(ARRAY[1,2])
----
NULL

eval
NULL::int = ANY(ARRAY[]::int[])
----
false

eval
NULL::int = SOME(ARRAY[]::int[])
----
false

eval
NULL::int = ALL(ARRAY[]::int[])
----
true

eval
1 = ALL (ARRAY[1, 2, NULL])
----
Expand Down