You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Honor selection vector so we estimate the same cardinality regardless of inserting 1 row at a time or using UNWIND
CREATE NODE TABLE stats_node(
id INT64,
common INT64,
rare INT64,
PRIMARY KEY(id)
);
UNWIND range(0, 19) AS i
CREATE (:stats_node {id: i, common: i % 2, rare: i});
ANALYZE stats_node;
EXPLAIN LOGICAL
MATCH (n:stats_node)
WHERE n.common = 1 AND n.rare = 7
RETURN n.id;
now produces the same query plan as using 20 individual CREATE statements.
Followed this over from the note about UNWIND vs a CREATE loop changing the optimizer's behavior. Built from a checkout that still had the bug and reproduced it independently before applying #603.
With UNWIND range(0,19) AS i CREATE (:stats_node {id:i, common:i%2, rare:i}), rare comes out with numDistinct around 1 (vs ~20 with 20 literal CREATEs), so the stats-aware filter push down inverts and filters the non selective common first.
One useful tell while narrowing it down: rare: i (a direct reference to the UNWIND variable) collapses to 1, but rare: i + 0 (any computed expression) is fine. That lines up exactly with the flat position vs selection vector read issue that #603 fixes.
Applied #603 locally and it resolves it. All three variants then report rare numDistinct around 20 and produce the identical plan. 👍
One small observation in case it's useful: the existing FilterPushDownOrdersMostSelectivePredicateFirst test loads its rows via a literal CREATE loop, so it wouldn't catch this if it regressed, since the bug only surfaces on the UNWIND / selection vector path.
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
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.
Honor selection vector so we estimate the same cardinality regardless of inserting 1 row at a time or using
UNWINDnow produces the same query plan as using 20 individual
CREATEstatements.