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

Fix incorrect simplification of CASE with constant boolean results #23796

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

martint
Copy link
Member

@martint martint commented Oct 16, 2024

Expressions such as:

   CASE
      WHEN <e1> THEN <boolean>
      WHEN <e2> THEN <boolean>
      ...
      ELSE <boolean>
   END

were being incorrectly optimized. The terms in the rewritten boolean expression need to reflect the fact that all the preceding conditions should've evaluated to false in order for a given condition to evaluate to true. The optimization was ignoring them, which could result in incorrect results when the conditions are not exclusive.

For example:

   CASE
      WHEN a OR b THEN false
      WHEN a OR c THEN true
   END

Previously, it was being rewritten as:

   (a OR c) ≡ true

However, if a is true, then the first branch of the CASE should be evaluated and the expression should return false.

Fixes #23787

Release notes

(x) Release notes are required, with the following suggested text:

## Section
* Fix incorrect results for certain CASE expressions that return boolean results. ({issue}`23787`)

Expressions such as:

   CASE
      WHEN <e1> THEN <boolean>
      WHEN <e2> THEN <boolean>
      ...
      ELSE <boolean>
   END

were being incorrectly optimized. The terms in the rewritten boolean expression
need to reflect the fact that all the preceding conditions should've evaluated
to false in order for a given condition to evaluate to true. The optimization
was ignoring them, which could result in incorrect results when the conditions
are not exclusive.

For example:

   CASE
      WHEN a OR b THEN false
      WHEN a OR c THEN true
   END

Previously, it was being rewritten as:

   (a OR c) ≡ true

However, if `a` is true, then the first branch of the CASE should be evaluated and
the expression should return false.
@martint martint merged commit c11c258 into trinodb:master Oct 16, 2024
93 checks passed
@martint martint deleted the issue-23787 branch October 16, 2024 20:25
@github-actions github-actions bot added this to the 462 milestone Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Incorrect results for CASE in comparison expression
3 participants