Skip to content

Commit

Permalink
opt: add ContainedBy operator (<@) to FoldNullComparisonLeft norm rule
Browse files Browse the repository at this point in the history
Fixes: #77745

When we originally made the ContainedBy operator (<@) distinct from the
Contains operator (@>) we forgot to add ContainedBy to the
FoldNullComparisonLeft normalization rule. It was only added to the
FoldNullComparisonRight rule. Correct this.

Release note (bug fix): fix an optimizer bug that prevented expressions
of the form (NULL::STRING[] <@ ARRAY['x']) from being folded to NULL.
This bug was introduced in v21.2.0.

Release justification: high priority bug fix.
  • Loading branch information
michae2 committed Mar 18, 2022
1 parent 682eba5 commit 43cb62c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/opt/norm/rules/comp.opt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
[FoldNullComparisonLeft, Normalize]
(Eq | Ne | Ge | Gt | Le | Lt | Like | NotLike | ILike | NotILike
| SimilarTo | NotSimilarTo | RegMatch | NotRegMatch
| RegIMatch | NotRegIMatch | Contains | Overlaps
| JsonExists | JsonSomeExists | JsonAllExists
| RegIMatch | NotRegIMatch | Contains | ContainedBy
| Overlaps | JsonExists | JsonSomeExists | JsonAllExists
$left:(Null)
*
)
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/norm/testdata/rules/comp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ WHERE
null::string !~* 'foo' OR 'foo' !~* null::string OR
null::string[] && ARRAY['foo'] OR ARRAY['foo'] && null::string[] OR
null::jsonb @> '"foo"' OR '"foo"' <@ null::jsonb OR
null::jsonb <@ '"foo"' OR '"foo"' @> null::jsonb OR
null::jsonb ? 'foo' OR '{}' ? null::string OR
null::jsonb ?| ARRAY['foo'] OR '{}' ?| null::string[] OR
null::jsonb ?& ARRAY['foo'] OR '{}' ?& null::string[]
Expand Down

0 comments on commit 43cb62c

Please sign in to comment.