Skip to content

isEdgeVariableReferenced has no CREATE/MERGE case: an edge read only inside a CREATE/MERGE inline property silently returns null #6573

Closed

Description

@lvca

Summary

Found during review of #6567/PR #6570. CypherVariableUsage.isEdgeVariableReferenced decides whether a MATCH-bound relationship variable keeps its real binding (vs. being anonymized for the CSR/GAV fast path) by walking every clause type in statement.getClausesInOrder(). The switch handles RETURN, WITH, UNWIND, SET, REMOVE, DELETE, FOREACH, SUBQUERY - but has no case CREATE / case MERGE, so it falls to default and the clause is never inspected.

Contrast with foreachReferencesVariable's own inner switch (same file), which explicitly treats a nested CREATE/MERGE conservatively:

case CREATE:
case MERGE:
  // Inline property expressions inside CREATE/MERGE patterns may reference the variable.
  // Enumerating them cheaply is awkward, so stay conservative: keep the edge binding.
  return true;

The top-level switch never got the same treatment.

Reproduction

CREATE (a:Person {id:'a'})-[r:KNOWS {since: 2001}]->(b:Person {id:'b'})
MATCH (a:Person)-[r:KNOWS]->(b:Person) CREATE (c:Note {since: r.since}) RETURN c.since AS s

Expected: s = 2001. Actual: s = null - the relationship step binds r under an internal anonymous name (since nothing else in the query appears, to this check, to reference it), so the CREATE clause's r.since reads a missing binding and silently evaluates to null instead of the real value.

Suggested fix

Add a case CREATE: case MERGE: arm to the top-level switch in isEdgeVariableReferenced, mirroring foreachReferencesVariable's conservative return true (a false positive there only forgoes the CSR/GAV fast path; a false negative silently drops a still-referenced edge, which is the failure class this whole method exists to prevent - same reasoning that motivated #6567's fix). A regression test parallel to the existing CypherVariableUsageTest cases (setReadsItAsTargetAndAsValue, removeReadsIt, etc.) should cover both CREATE {prop: r.x} and MERGE (n {prop: r.x}).

Where

engine/src/main/java/com/arcadedb/query/opencypher/executor/CypherVariableUsage.java, the isEdgeVariableReferenced switch (around the RETURN/WITH/... cases).

Activity

  1. added this to the 26.9.1 milestone on Aug 22, 2026
  2. self-assigned this
    on Aug 24, 2026
  3. added
    in progress
    on Aug 24, 2026
  4. added a commit that references this issue on Aug 24, 2026
  5. removed
    in progress
    on Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions