Repository navigation
fix(#5463, #5462): pin count(*) against a relationship inline WHERE predicate - #5485
Conversation
A relationship inline WHERE predicate that reads an edge property returned count(*) = 0 while count(r) returned 1 for the same MATCH: the variable-usage analysis did not look inside inline pattern predicates, so the edge binding was elided whenever nothing outside the pattern referenced r, and the predicate was then evaluated against an unbound variable and rejected every row. The behavioral fix is already on main - it landed in 4755821 as the third defect of #5464 (tracked there as #5466), after the build both reporters used. What was missing is coverage: neither reported shape had a test pinning it. Adds Issue5463CountStarRelInlineWhereTest, verified to fail 8 of 10 methods at 4755821^ and to pass in full on main. It covers count(*) versus count(r), #5462's collect(r.tag) control, the literal-predicate and clause-level-WHERE controls, anonymous endpoints, direction and typing variants, other aggregates, grouping, OPTIONAL MATCH, and both pattern-parsing paths that accept a relationship inline predicate.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ -6.34% coverage variation |
| Diff coverage | ✅ ∅ diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (043309f) 145777 107842 73.98% Head commit (725adcb) 177789 (+32012) 120253 (+12411) 67.64% (-6.34%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#5485) 0 0 ∅ (not applicable) Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Review:
|
Review: PR #5485 — regression coverage for
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5485 +/- ##
============================================
+ Coverage 65.11% 65.49% +0.37%
+ Complexity 1118 1115 -3
============================================
Files 1742 1742
Lines 145777 145790 +13
Branches 31197 31200 +3
============================================
+ Hits 94923 95482 +559
+ Misses 37978 37436 -542
+ Partials 12876 12872 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #5463
Closes #5462
Two issues, one defect, one reproducer, so they are fixed and closed together.
Summary
With two
(:A {v:1})-[:E]->(:A {v:2})edges taggedokandbad,MATCH (a:A {v:1})-[r:E WHERE r.tag = 'ok']->(b:A) RETURN count(*)answered0whileRETURN count(r)on the identicalMATCHanswered1. The root cause is that the Cypher variable-usage analysis, which decides which pattern bindings the plan must materialize, did not look inside inline pattern predicates. When nothing outside the pattern referencedr, the edge binding was elided from the plan, the inline predicater.tag = 'ok'was then evaluated against an unbound variable, and every row was rejected. Any downstream mention ofrkept the binding alive and masked the defect, which is whycount(r),r.tag, and even acollect(r.tag)sitting next to thecount(*)(issue #5462's sharpest control) all looked correct, and why a literalWHERE 1=1was fine: it references no variable at all.The behavioral fix is already on
main. It landed in475582108("fix(cypher) #5464: honor inline WHERE predicates in node and relationship patterns"), whose third listed defect is precisely this one, tracked there as #5466: "the variable-usage analysis now looks inside inline pattern predicates." Both reporters ran build1134185d5494f5ab0583da4a508d846449f8e04c, which predates that commit, so #5463 and #5462 were filed against a build that could not yet contain the fix. The pattern-comprehension leg of the same defect class was closed separately by043309f61(PR #5471, #5460).This was verified, not assumed. The new test was run at
475582108^(116278160, the reporters' era) and at currentmain:116278160(pre-fix)count(*)answers0exactly as reported043309f61(currentmain)So this PR carries regression coverage only and changes no production code, because none needs changing. What was genuinely missing is a test: neither reported shape had anything pinning it, so the behavior could silently regress again.
Issue5463CountStarRelInlineWhereTest(10 methods) coverscount(*)agreeing withcount(r)and with the materializedr.tagrows; the predicate honored across every tag value including the empty and match-all cases; #5462'scollect(r.tag)control; the literal-predicate and clause-level-WHEREcontrols from both reports; anonymous source, anonymous target and both-ends-anonymous shapes; right-to-left, undirected and untyped variants;count(b),count(DISTINCT b),sum(b.v)andcount(*)throughWITH;count(*)under a grouping key;OPTIONAL MATCHhit and miss; and both pattern-parsing paths that accept a relationship inline predicate, theMATCHpath and the pattern-comprehension /COUNT {}/EXISTS {}path.Scope note: adjacent gap found, deliberately not fixed here
While probing the surrounding defect class on current
main, the relationship inlineWHEREis still ignored outright inside a variable-length pattern:The predicate changes nothing, so it is dropped rather than misevaluated, which is a different failure mode from the
0these two issues report on a single-hop pattern. It is left alone on purpose: it is out of scope here, itsshortestPathhalf is already tracked by #5481 and the node-pattern half by #5480 (both being worked separately), and the plain variable-length case has no open issue yet and deserves its own triage.Test plan
Issue5463CountStarRelInlineWhereTestfails 8 of 10 methods at475582108^, reproducingcount(*) = 0as reported in both issuesIssue5463CountStarRelInlineWhereTestpasses 10 of 10 on currentmainIssue5463CountStarRelInlineWhereTest,CypherInlinePatternWhereTest,Issue5464ExistsRelInlineWhereTest,OpenCypherPatternComprehensionInlineWhereTest,CypherInlinePropertyFilterTest,CypherInlinePropertyNormalizationTest,OpenCypherPatternPredicateTest,CypherPatternPredicateTest,CypherExistsTest,CypherCountSubqueryTest,CypherCountSubqueryCorrelatedTest,CypherCollectSubqueryTest,CountEdgesOptimizationTest,CypherCountNonExistingLabelTest,GAVEligibilityTest-Tests run: 170, Failures: 0, Errors: 0, Skipped: 0latest, since both reporters hit a snapshot image predating475582108