Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
49242: sql: add tests for IS (NOT) NULL with empty tuples r=mgartner a=mgartner

Logic for `IS NULL` and `IS NOT NULL` with tuple operands was recently
fixed in #48299. This commit adds tests for empty tuples as operands
that were forgotten in that commit. This makes the correct evaluation
logic of such an expression explicit and will help prevent regressions.

Release note: None

49274: authors: add John Sheaffer to authors file r=sheaffej a=sheaffej

Release note: None

49275: Add alexl@ to AUTHORS file. r=lunevalex a=lunevalex

Release note: None


Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: John Sheaffer <[email protected]>
Co-authored-by: Alex Lunev <[email protected]>
  • Loading branch information
4 people committed May 19, 2020
4 parents ef3fe57 + a22f0b8 + 7da3b8b + 0194583 commit dfe5126
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Aditya Maru <[email protected]>
Aid Idrizović <[email protected]>
Ajaya Agrawal <[email protected]>
Alex Gaynor <[email protected]>
Alex Lunev <[email protected]> <[email protected]>
Alex Robinson <[email protected]> <[email protected]> <@cockroachlabs.com>
Alfonso Subiotto Marqués <[email protected]> Alfonso Subiotto Marques <[email protected]>
Alyshan Jahani <[email protected]>
Expand Down Expand Up @@ -144,6 +145,7 @@ Joel Kenny <[email protected]>
Joey Pereira <[email protected]> <[email protected]> <[email protected]>
joezxy <[email protected]> <[email protected]>
Johan Brandhorst <[email protected]> <[email protected]>
John Sheaffer <[email protected]>
Jon Derryberry <[email protected]>
Jonas <[email protected]>
joowon <[email protected]>
Expand Down
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

0 comments on commit dfe5126

Please sign in to comment.