opt: simplify leak-proof boolean CASE statements#96545
Open
DrewKimball wants to merge 1 commit intocockroachdb:masterfrom
Open
opt: simplify leak-proof boolean CASE statements#96545DrewKimball wants to merge 1 commit intocockroachdb:masterfrom
DrewKimball wants to merge 1 commit intocockroachdb:masterfrom
Conversation
This patch adds a normalization rule `SimplifyLeakproofBooleanCase` that replaces a leak-proof boolean CASE statement with an equivalent boolean expression built using `AND` and `OR` operators. This is possible when the following conditions are satisfied: 1. The CASE statement returns a boolean value. 2. The CASE statement is leak-proof. 3. The CASE condition is a *constant* boolean value (True, False, NULL). 4. Each WHEN branch returns a *constant* boolean value. Example: ``` CASE WHEN a THEN False WHEN b THEN True ELSE c END => ((a IS NOT True) AND (b OR c)) ``` See the `ConvertCaseToCondition` comment for details. This is useful for strict UDFs, which implement the argument NULL check using a CASE statement. Informs cockroachdb#96218 Release note: None
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch adds a normalization rule
SimplifyLeakproofBooleanCasethat replaces a leak-proof boolean CASE statement with an equivalent boolean expression built usingANDandORoperators. This is possible when the following conditions are satisfied:Example:
See the
ConvertCaseToConditioncomment for details.This is useful for strict UDFs, which implement the argument NULL check using a CASE statement.
Informs #96218
Release note: None