Allow pushing filters past Project nodes #3400
Merged
Conversation
146b50e to
0ca2ef9
Compare
zachmu
approved these changes
Jan 29, 2026
Member
zachmu
left a comment
There was a problem hiding this comment.
Seems like you've covered most of your bases here. I can't think of any additional edge cases other than the ones you've ruled out.
Some more tests are always a good idea though. I'm curious specifically about the behavior of pushing a filter composed of expressions on multiple tables being broken up and correctly pushed to their respective tables under a join or a subquery. I don't know if that transformation is even possible at the moment but tests verifying the existing behavior would be good. Also possible those are in the existing corpus, but good to verify.
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.
The analyzer tries to improve query plans by moving filter expressions to be directly above the table that they reference. Previously, this had a limitation in that it would treat references to aliases in Project nodes as opaque: if the alias expression references a table, the analysis wouldn't consider the filter to reference that table.
As a result, it wasn't possible to push a filter into multiple subqueries unless a previous optimization eliminated the Project node.
This PR enhances the analysis with the following steps:
Reasoning about the safety is tricky here. We should replace a GetField with the underlying expression if and only if we're actually moving the Filter beneath the Project.
The main concerns would be:
In practice I don't think the first concern can happen because it would require that the filter is getting pushed to some nameable-but-not-opaque node between the Projects, which I don't think exists.
The second concern requires that the project aliases an expression that doesn't reference any tables but can't be replaced with its underlying expression in a filter, and I don't think that's possible either.