Repository navigation
fix(#6338, #6334, #6328, #6336, #6335): a label disjunction means the same thing wherever the node sits, and the star is what the parser wrote rather than what it is called - #6348
Conversation
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -42 |
🟢 Coverage 93.55% diff coverage · -6.54% coverage variation
Metric Results Coverage variation ✅ -6.54% coverage variation Diff coverage ✅ 93.55% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (2304fba) 160517 127366 79.35% Head commit (adc7e15) 192752 (+32235) 140330 (+12964) 72.80% (-6.54%) 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 (#6348) 124 116 93.55% 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.
ReviewOverall this is a clean, well-scoped set of fixes. Consolidating label-disjunction semantics into A few things worth a look: 1.
|
ReviewNice, well-documented PR overall — the Correctness: the #6338 disjunction bug still exists in at least 4 other call sitesThe PR's stated goal for #6338 is that "the meaning of a disjunction now lives in one place... and the five copies that existed... all route through it." That's true for
All of these go through the same shared Everything else looks solid
No security or performance concerns beyond what's already called out in the PR description (the degree-limit walk is opt-in and documented). |
… same thing wherever the node sits, and the star is what the parser wrote rather than what it is called #6338 - A disjunction (y:A|B) written on a node a relationship expands INTO matched nothing, while the same disjunction on the pattern anchor matched. The anchor is served by MatchNodeStep, which has always had a disjunction branch; the expanded endpoint was filtered by MatchRelationshipStep, which ANDed the alternatives - so an ordinary Cypher pattern returned an empty result, with no error and no warning, which reads as "no such data" rather than as a bug. Three places in that step were wrong, not one: the loaded-vertex filter ANDed the labels, the bucket-id fast path tested only getLabels().get(0), and the schema pre-check required EVERY alternative to name an existing type, so a disjunction mentioning a label nobody had created rejected every row before the scan even started - an alternative that matches nothing is not a filter that matches nothing. All of them, plus MatchNodeStep, ExpandPathStep and the WHERE-side LabelCheckExpression, now go through Labels.matches(vertex|type, labels, disjunction) and Labels.canMatchInSchema(...): five copies of "what does a disjunction mean" became one, which is what let them disagree. The optimizer is not implicated - shouldUseOptimizer declines a disjunction on a node with incident relationships, because ExpandAll/ExpandInto carry a single targetLabel. #6334 - CypherExecutionPlan.applyProjectionToScope decided a projection item was the WITH * star by comparing its resolved NAME to "*", so WITH n AS `*` - alias "*", expression VariableExpression ("n") - was read as a star and forwarded the incoming scope instead of resetting it to the one name it projects, while the alias itself was never projected at all. A regression from #6326, which gave the same sentinel the stronger meaning. The star is now a property of the item rather than of its name: ReturnClause.ReturnItem.star() is the only thing that builds it, isStar() is the only thing that asks, and every name-based test - the scope application, the WITH projection step, the variable-projection strip, isReturnAll(), the referenced-variable walk and five sites in the semantic validator - now asks that instead of the name. That also settles the bare backticked WITH `*`, which the name-based predicate could never take apart from a real star. #6328 - SET calls propagateUpdateToSameNodeAliases after writing a property, so every alias in the row binding the same record observes the write; REMOVE replaced only the alias it was given, so a removed property stayed visible through a second alias of the same node while SET n.p = null - the same write spelled differently - answered null for both. Cypher has one binding per node per row. The helper moved out of SetStep into RowAliases, shared by both steps the way #6326 gave them one shared LabelReplacements. #6336 - EagerDistinctCollectOptionalMatchStep deleted. git log --follow shows it dead from birth: it landed in the same commit as the fix for #3218, which took a different route entirely (CypherFunctionFactory + AggregationStep), and nothing has constructed it since. It carried a whole alternative buffering strategy for OPTIONAL MATCH, so a reader tracing that plan had to work out it was not in the plan before they could trust what was. #6335 - A Cypher label write is O(degree) and changes RIDs, and nothing said so. A label is a type, a type is a bucket, and a record's type comes from the bucket it lives in, so SET n:Label cannot edit metadata: it rewrites the vertex under the new type and re-creates every incident edge in both directions, touching every neighbour's edge list, and hands the vertex and all of its edges new RIDs. On a supernode that is the difference between a millisecond and a stall. That is not fixable while a label is a type - modelling extra labels as a property is the real fix and its own epic, and a bulk edge move would cut the constant but neither the complexity nor the RID churn - so it is made visible instead. LabelReplacements.replace() counts the edges it migrates, which costs nothing because it walks them anyway, and logs a WARNING naming the node, both types and the count above arcadedb.opencypher.labelWriteDegreeWarning (10000, 0 disables). arcadedb.opencypher.labelWriteDegreeLimit refuses the write above a degree, checked before any record moves; it is off by default, because the rewrite is slow rather than wrong and a query that merely takes too long should not start failing on upgrade. The cost and the RID change are now in the javadoc of the method that pays them, and in docs/6335-cypher-label-write-cost.md.
…the degree guard refuses on the number it would report Three points from the code review, all valid. checkDuplicateAliases was the one site the #6334 sweep missed, and it is the same bug one call further on: it decided an item was the star by comparing its name to "*", so it exempted any projection whose alias happened to be that - and now that a user can legitimately alias to the backticked `*`, two such columns collided without being reported. It asks item.isStar() like the rest of the file. The degree guard measured with countEdges(BOTH), which sums the two edge lists independently and so counts a self-loop twice, while the migration right below it re-creates a self-loop exactly once. The limit therefore refused on a number the warning would never print, in a feature whose whole point is to report the true cost. countEdgesToMigrate() mirrors the migration's own traversal instead - the OUT list in full, the IN list skipping the self-loops the OUT pass already took - and walks the connected RIDs rather than the edges, so the skip costs a list walk and not a record load per edge. The WARNING itself was never asserted: deleting the log call left every assertion in crossingTheWarningThresholdReportsWithoutRefusing green, which is the exact failure mode #6335 is about. The test now installs a capturing Logger through LogManager.setLogger - documented as this hook, previous logger restored in a finally - and checks the record's message and arguments. Each of the three is pinned by a test verified to fail without its fix: removing the log call fails the warning assertion, countEdges(BOTH) fails the new self-loop test with "the vertex has 7 edges and ... limit is 6", and restoring the "*" name guard fails the collision test.
…ion from the grammar, and the clauses that write refuse a label expression
The code review found four more copies of the AND-only label check, and it was
right, but tracing them turned up one cause underneath rather than four bugs:
CypherExpressionBuilder.parseNodePattern built every node pattern in EXPRESSION
position with the disjunction flag hardcoded to false. A pattern comprehension or
a pattern predicate therefore received (y:A|B) already indistinguishable from
(y:A:B), and no amount of fixing the executor could recover what the parser had
thrown away. It now reads the flag off the grammar through
ParserUtils.isLabelDisjunction, exactly as the MATCH-side builder does.
Two of these were observable:
[(a)-->(y:Author|Topic) | y.k] returned [] expected ["t1"]
exists((a)-->(:Author|Topic)) returned no row expected the row
the second while the block form EXISTS { (a)-->(:Author|Topic) } answered
correctly all along, because it takes the subquery path - two spellings of one
predicate disagreeing about what a disjunction means.
MERGE was worse than an under-count. MERGE (n:A|B {k:'x'}) ANDed its match, so it
missed an existing :B node, and then created a second one under an invented A~B
composite type: a duplicate, silently, from a clause whose entire purpose is not
to make one. CREATE (n:A|B) invented the same composite. Neo4j refuses a label
expression in both clauses, for the reason that settles it - a disjunction says
which labels a node MAY have, and there is no node a write can produce that
satisfies "A or B" without picking one. Both are now refused, with a message that
names the spelling that does mean something (:A:B).
PatternPredicateExpression, PatternComprehensionExpression (start and end) and
MergeStep.matchesNodePattern route through Labels.matches like the rest, so the
one-home claim holds for every site the review listed. MergeStep can no longer
see a disjunction at all, but it does not get to be the odd one out.
Left for its own issue, being a different defect: PatternComprehensionExpression
.traverseUncorrelatedStart picks getLabels().get(0) as its scan root, so an
UNBOUND comprehension start node with a disjunction still under-scans.
openCypher package 4664 tests green, openCypher TCK 3897 green - the TCK is what
pins the CREATE/MERGE refusal as the spec behaviour and not just a preference.
8d4a32c to
c205c83
Compare
ReviewRead through the full diff (5 commits, ~1080 additions) plus the linked issues. This is a well-scoped, well-documented fix set - the "one home for a disjunction" consolidation ( Correctness - verified, no issues found
Minor / non-blocking
Test coverageGood: each of the four new test classes pins a specific pre-fix failure with a comment noting what failed and why, and cross-cutting shapes are covered (disjunction at each position of a chain, self-loop counting, backticked-star alias forwarding vs. being projected, REMOVE-then-UNWIND re-observation). Nothing further to ask for. Nice work overall, especially the "route five copies through one helper" approach rather than patching each site independently - that's exactly the kind of fix that prevents the next regression in the same shape. |
ReviewThis is a well-scoped, carefully reasoned PR. Five related openCypher defects, each traced to a single root cause rather than patched at each call site, with regression tests written to fail without the fix (per repo convention) and thorough javadoc explaining why, not just what. I read the full diff; here's my assessment. CorrectnessI traced the trickiest parts by hand and didn't find a bug:
Minor / non-blocking observations
Test coverageStrong. Each of the four new test classes targets the exact regression (anchor vs. expanded-node position, each position in a chain, variable-length target, missing-schema-label alternative, pattern comprehensions, both PerformanceNo concerns — the degree-guard walk is opt-in (off by default, SecurityNone relevant — no new I/O, deserialization, or external input handling. Nice work tracing five separate-looking bugs back to two shared root causes rather than patching each site independently. |
…ls came back with it
Both reviewers asked why checkNoLabelDisjunction guarded on getLabels().size() > 1,
and the answer turned out to be that it should not: the guard was a hole rather
than dead defensiveness. collectStaticLabels leaves a Cypher 25 dynamic
$(expression) alternative out of the static list, so CREATE (n:Author|$('Topic'))
arrives carrying one static label and a disjunction flag, and the count-based
guard let it straight through - in the shape where a write acting on "A or B" is
least defensible of all, the second label not being known until the query runs.
It now refuses on the flag alone, which is what actually means "a | was written",
and names the conjunction spelling only when there are two labels to name.
Pinned by a test that fails with the count restored.
Two readability notes from the same reviews, neither a behaviour change: the
CapturingLogger javadoc records the sequential-execution assumption it and the
GlobalConfiguration writes rest on, so turning on class parallelism for engine
does not quietly invalidate them; and RowAliases says why it does not consult
LabelReplacements' map - it answers "the row holds an older copy of a record
that is still there", a different question from "the row holds a record that was
deleted and replaced", and SetStep.applyLabels is the caller that needs both.
openCypher package 4665 green, openCypher TCK 3897 green.
ReviewWent through the full diff (base vs head, not the per-commit patches) plus the four new test classes. This is a well-scoped, well-tested PR — five related openCypher defects consolidated into one shared abstraction ( Correctness — looks solid
Minor observations (non-blocking)
Test coverageStrong — each of the four new test classes maps directly to a described defect, includes the "must not regress" neighboring cases (conjunction still AND-only, real Docs
Nothing here changes my assessment: this looks correct, consistent, and well-tested. Nice work consolidating five independent-looking bugs into one root-cause fix rather than four executor patches. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6348 +/- ##
==========================================
+ Coverage 70.62% 70.67% +0.05%
==========================================
Files 1850 1850
Lines 160517 160387 -130
Branches 33762 33713 -49
==========================================
- Hits 113361 113353 -8
+ Misses 33192 33085 -107
+ Partials 13964 13949 -15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
One conflict: #6348 deleted EagerDistinctCollectOptionalMatchStep, which this branch had touched for the unbalanced profiling parenthesis. The deletion wins - nothing on main references the class any more, and the fix dies with the file. The eight remaining paren fixes are unaffected, and no step added by #6348 carries the pattern.
Fixes #6338, #6334, #6328, #6336, and settles #6335.
Five small openCypher issues that came out of the reviews of #6322 and #6326. Two of them are the same shape - a fact about a query that two places decided separately and disagreed about - so both are fixed by giving that fact one home rather than by patching the disagreeing site.
#6338 - a label disjunction on an expanded node matched nothing
(y:A|B)written on a node a relationship expands into rejected every row, silently, while the same disjunction on the pattern anchor matched. An empty result reads as "no such data" rather than as a bug, so this is the kind of defect that does not get reported.Three things in
MatchRelationshipStepwere wrong, not one:matchesTargetLabel(Vertex)getLabels().get(0)onlytargetLabelsExistInSchemaThe third is its own silent-empty:
(y:NoSuchLabel|Topic)short-circuited the step to nothing before the scan started. An alternative that matches nothing is not a filter that matches nothing.Rather than fix three call sites, the meaning of a disjunction now lives in one place -
Labels.matches(vertex|type, labels, disjunction)andLabels.canMatchInSchema(...)- and the five copies that existed (MatchNodeStepx2,ExpandPathStep,MatchRelationshipStep, and the WHERE-sideLabelCheckExpression) all route through it. The type-level overload keeps the bucket-id path free of a record load.The optimizer is not implicated:
shouldUseOptimizerdeclines a disjunction on a node with incident relationships, becauseExpandAll/ExpandIntocarry a singletargetLabel. Verified, not assumed.A second root cause, found while acting on review round 2. The review pointed at four more copies of the AND-only check; tracing them found one cause underneath rather than four bugs.
CypherExpressionBuilder.parseNodePatternbuilt every node pattern in expression position with the disjunction flag hardcoded tofalse, so a pattern comprehension or a pattern predicate received(y:A|B)already indistinguishable from(y:A:B), and no executor-side fix could recover what the parser had discarded. It now reads the flag off the grammar throughParserUtils.isLabelDisjunction, as the MATCH-side builder does. Two shapes were observably wrong:[(a)-->(y:Author|Topic) | y.k][]["t1"]exists((a)-->(:Author|Topic))the second while the block form
EXISTS { (a)-->(:Author\|Topic) }answered correctly all along, because it takes the subquery path - two spellings of one predicate disagreeing about what a disjunction means.MERGE was worse than an under-count.
MERGE (n:A|B {k:'x'})ANDed its match, missed an existing:Bnode, and then created a second one under an inventedA~Bcomposite type: a silent duplicate, from the one clause whose purpose is not to make one.CREATE (n:A|B)invented the same composite. Neo4j refuses a label expression in both, for the reason that settles it - a disjunction says which labels a node may have, and no node a write produces satisfies "A or B" without picking one. Both are now refused, with a message naming the spelling that does mean something.The refusal keys on the disjunction flag, not on the label count:
collectStaticLabelsleaves a dynamic$(expression)alternative out of the static list, soCREATE (n:Author|$('Topic'))carries a single static label and slipped past a count-based guard - the shape where a write acting on "A or B" is least defensible, the second label not being known until the query runs.Filed as #6352 rather than widened into this PR, being a different defect in a path none of these five issues reach:
PatternComprehensionExpression.traverseUncorrelatedStartpicksgetLabels().get(0)as its scan root, so an unbound comprehension start node with a disjunction under-scans ([(y:Author|Topic)-->() | y.k]gives["a1"]where the equivalent MATCH gives["a1","t1"]), and a missing first alternative empties the result outright.#6334 -
WITH n AS \*`was mistaken forWITH *` (regression from #6326)applyProjectionToScopedecided an item was the star by comparing its resolved name to"*". A user can write a variable called`*`, soWITH n AS \*`` was read as a star: the incoming scope was forwarded instead of being reset to the one name projected, and the alias itself was never projected at all.The issue suggested keying on the expression type. That leaves the bare
WITH `*`ambiguous, so this goes one step further: being the star is now a property of the item.ReturnClause.ReturnItem.star()is the only thing that builds one - the parser has exactly three sites - andisStar()is the only thing that asks. Every name-based test moved over: the scope application,WithStep's projection, the variable-projection strip,isReturnAll(), the referenced-variable walk, and five sites in the semantic validator. No spelling of a user variable can now be confused for the star.#6328 -
REMOVEdid not update the other aliases of the same nodeSETpoints every alias in the row that binds the same record at the updated document;REMOVEreplaced only the alias it was given, soREMOVE n.pleftm.preporting the removed value whileSET n.p = null- the same write, spelled differently - answered null for both. Cypher has one binding per node per row.The helper moved out of
SetStepintoRowAliases, shared by both steps the way #6326 gave them one sharedLabelReplacements. It deliberately does not descend into paths/lists/maps, and says why: there the record is alive and merely older, not deleted, so the walk would be charged to every row of everySETto fix a stale read in an unusual shape.#6336 -
EagerDistinctCollectOptionalMatchStepdeleted296 lines nothing constructs.
git log --followanswers the question the issue asked: it was dead from birth. It landed in the same commit as the fix for #3218, which took a different route entirely (CypherFunctionFactory+AggregationStep), and nothing has referenced it since.docs/5789-...md, which had flagged it as dead code to keep in step with aDISTINCTfix, is updated to say it is gone.#6335 - a label write is O(degree) and changes RIDs; now it says so
Not a defect - the cost of the model, and it deserved a decision rather than being inherited. A label is a type, a type is a bucket, and a record's type comes from the bucket it lives in, so
SET n:Labelcannot edit metadata: it rewrites the vertex under the new type, re-creates every incident edge in both directions (mutating each neighbour's edge list), and hands the vertex and all of its edges new RIDs. On a supernode that is the difference between a millisecond and a stall, and it undoes the locality the striping/append-merge work builds.The two real fixes are both out of scope for this PR and are recorded as such in
docs/6335-cypher-label-write-cost.md: modelling extra labels as a property is the right answer and its own epic, and a bulk edge move would cut the constant but neither the complexity nor the RID churn. What was actually broken is that the cost was silent, so:LabelReplacements.replace()counts the edges it migrates - free, it walks them anyway - and logs aWARNINGnaming the node, both types and the count abovearcadedb.opencypher.labelWriteDegreeWarning(default 10000,0disables). A stall that has already happened now has a line in the log that explains it.arcadedb.opencypher.labelWriteDegreeLimitrefuses the write above a degree, checked before any record moves. Off by default (0): the rewrite is slow rather than wrong, and a query that merely takes too long should not start failing on upgrade. Enabling it costs one extra edge-list walk per label write.Tests
Four new classes, each verified to fail without its fix (temporarily reverted, run, restored):
CypherLabelDisjunctionOnExpandedNodeIssue6338Test- the disjunction in each position of a chain (anchor, intermediate, final), since only the anchor was covered before; plus a variable-length target, an alternative absent from the schema, and a conjunction that must still require every label. 3 of 7 failed before the fix.CypherBacktickedStarAliasIssue6334Test- the alias case, the alias being projected, the alias forwarded onwards, the real star still forwarding (alone and combined with a projection), andRETURN *. 3 of 7 failed before.CypherRemovePropertyAliasIssue6328Test- two aliases in one row, the same node reached again on a later row viaUNWIND,SET n.p = nullanswering identically, persistence, and a no-op removal leaving the other alias alone. 2 of 5 failed before.CypherLabelWriteDegreeGuardIssue6335Test- limit off by default, refusal above it with nothing moved,REMOVEguarded the same way, a write at the limit allowed, and crossing the warning threshold reporting without refusing.Green: the full
engineunit suite (12487 tests), the openCypher package (4665 after the tests added across review rounds), and the openCypher TCK suite (3897) - the TCK is what pins the CREATE/MERGE refusal as spec behaviour rather than a preference.One unrelated failure appeared in a single run and is not from this change:
Issue6301AlgoSteinerTreeWeightAlignmentTest.anActiveOverlayDoesNotLendItsWeightsToTheWrongEdges. It callsAlgoBellmanFord.execute()directly with aBasicCommandContext- no Cypher parsing, no MATCH, no projection - and depends on JVM-globalGraphAnalyticalViewoverlay state shared across test classes. It passes in isolation, at algo-package scope, and in the re-run of the same wide selection.Review rounds
Three rounds, every point acted on:
checkDuplicateAliasesstill decided the star by name - the one site theisStar()sweep missed, and now a real collision since a column can legitimately be named`*`. The degree guard measured withcountEdges(BOTH), which counts a self-loop twice while the migration re-creates it once, so the limit refused on a number the warning would never print;countEdgesToMigrate()mirrors the migration's own traversal. The WARNING was never asserted, so deleting the log call kept every test green.size() > 1guard on the CREATE/MERGE refusal, which turned out to be a hole rather than dead defensiveness (the dynamic-label shape above). Plus two readability notes now in the code: the sequential-execution assumption behind theCapturingLoggerswap, and whyRowAliasesdoes not need to consultLabelReplacements' map.Every fix in every round is pinned by a test verified to fail without it, by temporarily reverting the fix and re-running.