Preserve NULL matches in extended CASE filters - #30992
Draft
bvolpato wants to merge 1 commit into
Draft
Conversation
Remove the filter simplifier's assumption that a NULL CASE operand always selects ELSE. Extended CASE predicates can match NULL, so predicate-aware evaluation must decide which branch is selected.
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.
Description
Preserve extended CASE clauses that can match a NULL operand when simplifying filters. The old shortcut always selected ELSE for a NULL operand, which is invalid for predicates such as
IS NOT DISTINCT FROM.Before the fix this returns no rows; afterward it returns the required NULL row. Swapping THEN and ELSE previously admitted the NULL row incorrectly.
Remove the obsolete shortcut and leave predicate-aware evaluation to the IR optimizer. The rule retains its existing simplifications when all result branches agree.
Additional context and related issues
The regression tests cover both filter outcomes, with projection, searched CASE, and ordinary equality CASE controls. Two existing rule expectations are updated to stop asserting the obsolete shortcut.
Before the production change, the selected rule and query tests had three failures and two passing controls. Afterward, all 30 tests in
TestSimplifyFilterPredicate,TestExtendedCase, andTestEvaluateMatchpassed. Module validation, including Checkstyle and Airstyle, passed../mvnw -pl core/trino-main -Dtest=TestSimplifyFilterPredicate,TestExtendedCase,TestEvaluateMatch -Dair.check.skip-all=true test ./mvnw -pl core/trino-main validateRelease notes
(x) Release notes are required, with the following suggested text: