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

sql: add tests for IS (NOT) NULL with empty tuples #49242

Merged
merged 1 commit into from
May 19, 2020
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
14 changes: 8 additions & 6 deletions pkg/sql/opt/norm/fold_constants_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ func (c *CustomFuncs) HasNullElement(input opt.ScalarExpr) bool {
}

// HasAllNullElements returns true if the input tuple has only constant, null
// elements. Note that it only returns true if all elements are known to be
// null. For example, given the tuple (NULL, x), it will return false because x
// is not guaranteed to be null.
// elements, or if the tuple is empty (has 0 elements). Note that it only
// returns true if all elements are known to be null. For example, given the
// tuple (NULL, x), it will return false because x is not guaranteed to be
// null.
func (c *CustomFuncs) HasAllNullElements(input opt.ScalarExpr) bool {
tup := input.(*memo.TupleExpr)
for _, e := range tup.Elems {
Expand Down Expand Up @@ -122,9 +123,10 @@ func (c *CustomFuncs) HasNonNullElement(input opt.ScalarExpr) bool {
}

// HasAllNonNullElements returns true if the input tuple has all constant,
// non-null elements. Note that it only returns true if all elements are known
// to be non-null. For example, given the tuple (1, x), it will return false
// because x is not guaranteed to be non-null.
// non-null elements, or if the tuple is empty (has 0 elements). Note that it
// only returns true if all elements are known to be non-null. For example,
// given the tuple (1, x), it will return false because x is not guaranteed to
// be non-null.
func (c *CustomFuncs) HasAllNonNullElements(input opt.ScalarExpr) bool {
tup := input.(*memo.TupleExpr)
for _, e := range tup.Elems {
Expand Down
20 changes: 20 additions & 0 deletions pkg/sql/opt/norm/testdata/rules/comp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,16 @@ values
├── fd: ()-->(1)
└── (true,)

norm expect=FoldNullTupleIsTupleNull
SELECT () IS NULL AS r
----
values
├── columns: r:1!null
├── cardinality: [1 - 1]
├── key: ()
├── fd: ()-->(1)
└── (true,)

norm expect-not=FoldNullTupleIsTupleNull
SELECT (k, NULL) IS NULL FROM a
----
Expand Down Expand Up @@ -535,6 +545,16 @@ values
├── fd: ()-->(1)
└── (true,)

norm expect=FoldNonNullTupleIsTupleNotNull
SELECT () IS NOT NULL AS r
----
values
├── columns: r:1!null
├── cardinality: [1 - 1]
├── key: ()
├── fd: ()-->(1)
└── (true,)

norm expect-not=FoldNonNullTupleIsTupleNotNull
SELECT (1, k) IS NOT NULL FROM a
----
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/sem/tree/testdata/eval/is
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,15 @@ eval
NOT ((NULL, NULL) IS DISTINCT FROM NULL)
----
false

# Empty tuples.

eval
() IS NULL
----
true

eval
() IS NOT NULL
----
true