Skip to content

Cypher: SET/REMOVE of a label rewrites every edge of the vertex, so a label write on a supernode is O(degree) and churns RIDs #6335

Closed

Description

@lvca

Surfaced while fixing #6312/#6313. Not a defect in that fix - it is the cost of the model the fix had to work within, and it deserves its own decision.

A Cypher label set maps to an ArcadeDB type, and a record's type comes from the bucket it lives in, so there is no in-place retype. LabelReplacements.replace() therefore has to:

  1. create a new vertex under the new type,
  2. copy every property,
  3. re-create every incident edge, in both directions, each of which also mutates the neighbour's edge list,
  4. delete the original.

Two consequences worth deciding about rather than inheriting:

Cost. SET n:Label on a vertex with a million edges rewrites a million edge records and touches a million neighbour edge lists, for what the user wrote as a metadata change. On a supernode this is the difference between a millisecond and a stall, and nothing in the query says so. It also interacts badly with the striping/append-merge work: a label write undoes the locality those paths build.

Identity. The vertex's RID changes, and so does every edge's. Anything holding a RID across the write - an application-side reference, a stored link from a non-graph type, an external index, a client that cached the result of an earlier query - is left pointing at a deleted record. #6326 makes the query's own row follow the move; nothing can make an outside reference follow it.

Worth exploring, roughly in order of appetite:

  • Reject rather than silently pay it. A label write on a vertex above a degree threshold could fail with a message that says why and what to do instead, which is at least honest. Cheap, and strictly better than the stall.
  • Multi-label without a type change. Model the extra labels as a property (or a small dedicated structure) consulted by Labels.getLabels()/hasLabel() and by the label-scan planning, so a label write is a property write and the record never moves. This is the real fix and the large one: every place that resolves a label to a type - ensureCompositeType, NodeByLabelScan, the composite-type naming - has to learn the second source, and existing databases carry composite types that must keep working.
  • Keep the rewrite but make it cheaper. Edges are re-created one at a time through the public API today; a bulk path that moves the edge lists wholesale would cut the constant, though not the complexity, and would not help the RID churn at all.

Whatever is chosen, the current behaviour should at minimum be documented: today nothing warns that SET n:Label is a write proportional to degree that invalidates the node's RID.

Activity

  1. self-assigned this
    on Aug 17, 2026
  2. added theissue type on Aug 18, 2026
  3. added this to the 26.9.1 milestone on Aug 18, 2026
  4. added 4 commits that reference this issue on Aug 18, 2026
  5. lvca commented on Aug 18, 2026

    @lvca
    MemberAuthor

    Settled in #6348, merged as 34482fd, with the first of the three options in the issue.

    The decision was that the rewrite is slow, not wrong - what was actually broken is that it was silent. So:

    • LabelReplacements.replace() counts the edges it migrates, which is free because it walks them anyway, and logs a WARNING naming the node, both types and the count above arcadedb.opencypher.labelWriteDegreeWarning (default 10000, 0 disables). A stall that has already happened now has a line in the log explaining it.
    • arcadedb.opencypher.labelWriteDegreeLimit refuses the write above a degree, checked before any record moves, with a message saying what the write would have cost and what to do instead. Off by default: a query that merely takes too long should not start failing on upgrade, so refusing is the operator's choice. Enabling it costs one extra edge-list walk per label write.
    • The cost and the RID churn are spelled out in the javadoc of replace() - where the next person tracing a label write will actually be - and in docs/6335-cypher-label-write-cost.md, which also records why the other two options were not taken.

    One thing the review sharpened: the guard counts what the migration re-creates, not countEdges(BOTH). Those differ - countEdges(BOTH) sums the two edge lists independently, so a self-loop counts twice while the migration re-creates it once - and a feature whose whole point is reporting the true cost should not have its limit refuse on a number its warning would never print. countEdgesToMigrate() mirrors the migration's own traversal, and aSelfLoopIsCountedOnceBecauseItIsMigratedOnce pins it.

    Not done, and worth its own issue if there is appetite: the real fix - modelling extra labels as a property so the record never moves. Every place that resolves a label to a type (Labels.ensureCompositeType, NodeByLabelScan and the label-scan planning, the composite-type naming, labels() itself) has to learn a second source, and existing databases carry composite types that must keep working. It is an epic, not a line item. The middle option - a bulk edge move - was rejected outright rather than deferred: an edge record stores the RIDs of both endpoints and each neighbour's edge-list entry stores the edge's RID and the other endpoint's, so every one of them has to be rewritten whichever way the write is spelled. It would cut the constant, not the complexity, and would not help the RID churn at all.

    Closing as settled. Reopen or file the multi-label epic separately if the property-backed model is wanted.

  6. added 2 commits that reference this issue on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions