Push single-variable WHERE predicates across all MATCH clauses#4
Merged
Conversation
Build the pushdown map once from every non-optional MATCH's WHERE so a single-variable predicate prunes the scan that first binds its variable, even when the WHERE is written on a later clause. Previously pushdown was per-clause, so `MATCH (t)-[:R]->(c) MATCH (c)-..-(x) WHERE t.name = ...` materialized the entire (t)-[:R]->(c) relation before filtering t. The global map is only applied while evaluating non-optional MATCH patterns (gated by pushdown_active); it must stay off during OPTIONAL MATCH expansion and EXISTS subqueries, where pruning a candidate that fails a single-variable predicate can change results — e.g. an `OPTIONAL MATCH ... WHERE t IS NULL` anti-join would otherwise null-fill every row and wrongly keep them all. Adds the cross-clause pushdown regression test and a pushdown/OPTIONAL MATCH safety test. Co-authored-by: River <shopify.river@shopify.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.
Builds the pushdown map once from every non-optional MATCH's WHERE, so a single-variable predicate prunes the scan that first binds its variable even when the WHERE is written on a later clause.
MATCH (t)-[:R]->(c) MATCH (c)-..-(x) WHERE t.name = ...previously materialized the whole(t)-[:R]->(c)relation before filteringt.Review note / correctness fix
The original patch made the pushdown map global and always-on, which introduced a latent correctness bug: it would then be applied inside
OPTIONAL MATCHandEXISTS. A pushedt IS NULLpredicate on an optionally-boundtwould prune every realt, null-fill every row, and wrongly keep them all (breaking the anti-join). This PR keeps the global map but gates application to non-optional MATCH pattern evaluation (pushdown_active), restoring the pre-existing invariant that pushdown never fires in OPTIONAL MATCH / EXISTS.Includes the cross-clause regression test and a new
pushdown_optional_safetytest that fails against the always-on variant.Co-authored-by: River shopify.river@shopify.com