fix: WHERE filter pushdown silently corrupts OR/CASE queries#155
Open
fix: WHERE filter pushdown silently corrupts OR/CASE queries#155
Conversation
The extract_raw_column_predicates function used visit_expressions which recursively walks into ALL sub-expressions, including children of OR and CASE nodes. This meant WHERE block_num = 1 OR block_num = 2 would extract both sides as separate AND predicates in the CTE, silently changing query semantics from a disjunction to a conjunction. Fix: Replace visit_expressions with a manual walk that only recurses through top-level AND conjuncts. At OR, CASE, or any non-AND expression, we stop recursing — only simple leaf predicates on raw columns are extracted. Mixed expressions like 'a AND (b OR c)' correctly push down only 'a'. Amp-Thread-ID: https://ampcode.com/threads/T-019d458d-01b9-76ca-9fb1-ac75d2653f95 Co-authored-by: Amp <amp@ampcode.com>
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.
Problem
extract_raw_column_predicatesusedvisit_expressionswhich recursively walks all sub-expressions, including children ofORandCASEnodes. This meant:Would extract both
block_num = 1ANDblock_num = 2as separate AND predicates in the CTE, silently changing query semantics from a disjunction to a conjunction — returning fewer rows than expected.Fix
Replace
visit_expressionswith a manual walk (collect_and_conjuncts) that only recurses through top-level AND conjuncts. AtOR,CASE, or any non-AND expression, we stop recursing. Only simple leaf predicates on raw columns are extracted.Mixed expressions like
a AND (b OR c)correctly push down onlya.Tests
test_or_predicates_not_pushed_down— OR predicates are NOT pushed downtest_case_predicates_not_pushed_down— CASE predicates are NOT pushed downtest_simple_and_predicates_pushed_down— simple AND conjuncts still worktest_mixed_and_or_only_pushes_safe_conjuncts— mixed AND/OR only pushes safe partstest_nested_or_inside_and_not_pushed_down— nested OR inside AND correctly skipped