fix: General boolean constant folding in filter optimizer#703
Merged
Conversation
Add a BoolFoldingOptimizer pass that simplifies filter predicates
through bottom-up tree propagation of boolean constant folding.
Unlike the earlier NULL-specific isNullContradiction helper, the
new foldBool() function recursively simplifies children first so
that collapsed subtrees enable parent-level rules:
AND(OR(IS_NULL(x), IS_NOT_NULL(x)), y > 5)
-> AND(true, y > 5) [OR tautology folded]
-> y > 5 [AND(true, x) collapsed]
OR(AND(IS_NULL(x), IS_NOT_NULL(x)), n.k = 1)
-> OR(false, n.k = 1) [AND contradiction folded]
-> n.k = 1 [OR(false, x) collapsed]
The areNegations() helper recognises three negation forms:
NOT(p) and p
IS_NULL(x) and IS_NOT_NULL(x)
Files:
+ src/include/optimizer/bool_folding_optimizer.h
+ src/optimizer/bool_folding_optimizer.cpp
+ test/test_files/issue/issue698.test
M src/optimizer/CMakeLists.txt
M src/optimizer/optimizer.cpp
Fixes #698.
adsharma
force-pushed
the
fix/issue-698-null-contradiction
branch
from
July 18, 2026 18:01
3ac35e2 to
2455a35
Compare
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.
Add a new BoolFoldingOptimizer pass that simplifies boolean filter predicates through constant folding and contradiction detection.
Replaces the earlier NULL-specific isNullContradiction helper with a general-purpose foldBool() function and an areNegations() helper that recognizes:
Rules:
When a predicate folds to false/null the filter operator is replaced with an EmptyResult, avoiding unnecessary plan scans.
Fixes #698.