Skip to content

fix(#6573): isEdgeVariableReferenced has no CREATE/MERGE case - #6689

Merged
robfrank merged 1 commit into
mainfrom
fix/6573-isedgevariablereferenced-has-no-create
Aug 24, 2026
Merged

robfrank merged 1 commit into
mainfrom
fix/6573-isedgevariablereferenced-has-no-create

Conversation

@robfrank

Copy link
Copy Markdown
Collaborator

Closes #6573

Summary

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 top-level switch handled RETURN, WITH, UNWIND, SET,
REMOVE, DELETE, FOREACH, SUBQUERY - but had no case CREATE / case MERGE, so a top-level
CREATE/MERGE clause fell to default and was never inspected.

Contrast with foreachReferencesVariable's own inner switch (same file), which already 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 (before fix): s = null - the relationship step bound r under an
internal anonymous name (nothing else in the query appeared, to this check, to reference it), so the
CREATE clause's r.since read a missing binding and silently evaluated to null.

Fix

Added 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).

File: engine/src/main/java/com/arcadedb/query/opencypher/executor/CypherVariableUsage.java

Test plan

  • CypherVariableUsageTest.createReadsItInAnInlineProperty / .mergeReadsItInAnInlineProperty -
    unit-level checks parallel to the existing cases in that file (setReadsItAsTargetAndAsValue,
    removeReadsIt, etc.). Verified to fail (assert true, got false) without the fix.
  • Issue6573CreateMergeEdgeVariableTest - new end-to-end regression test running the issue's own
    reproducer through the real Cypher engine. Verified to fail with a null result (matching the
    issue's reported symptom exactly) without the fix, via a temporary stash of the production
    change.
  • Full com.arcadedb.query.opencypher.** package (excluding benchmark/slow/vector lanes): 8906
    tests, 0 failures, 0 errors, 98 skipped (pre-existing, unrelated).

🤖 Generated with Claude Code

The top-level switch in CypherVariableUsage.isEdgeVariableReferenced
had no case for CREATE/MERGE, so a top-level CREATE/MERGE clause fell
to default and was never inspected. An edge read only inside a
CREATE/MERGE inline property (e.g. CREATE (c {prop: r.x})) was
therefore anonymized and silently evaluated to null instead of the
real value.

Mirror foreachReferencesVariable's existing conservative handling of
nested CREATE/MERGE: keep the edge binding whenever a top-level
CREATE/MERGE clause is present, since enumerating its inline property
expressions cheaply is awkward.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 26 minutes.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e65b6857-cb4f-4a6c-97e2-aa347ddf39df

📥 Commits

Reviewing files that changed from the base of the PR and between 7e716af and 1e4f69f.

📒 Files selected for processing (4)
  • docs/6573-isedgevariablereferenced-create-merge.md
  • engine/src/main/java/com/arcadedb/query/opencypher/executor/CypherVariableUsage.java
  • engine/src/test/java/com/arcadedb/query/opencypher/CypherVariableUsageTest.java
  • engine/src/test/java/com/arcadedb/query/opencypher/Issue6573CreateMergeEdgeVariableTest.java

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

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.

@claude

claude Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review

Small, well-scoped fix — a case CREATE: case MERGE: arm was genuinely missing from the top-level switch in isEdgeVariableReferenced, while the sibling foreachReferencesVariable switch already had it. The reproducer and root-cause explanation in the PR description are clear and check out against the code.

Correctness

  • The fix mirrors foreachReferencesVariable's existing case CREATE: case MERGE: return true; exactly, so the two switches are now consistent with each other. isEdgeVariableReferenced is the single method both CypherOptimizer and CypherExecutionPlan call into (no other copy of this switch to update).
  • Erring conservative (always keep the binding on CREATE/MERGE, rather than trying to parse whether the pattern's inline properties actually reference the variable) is the right call here given the failure mode: a false negative silently drops data (the isEdgeVariableReferenced has no CREATE/MERGE case: an edge read only inside a CREATE/MERGE inline property silently returns null #6573 symptom), while a false positive only costs the CSR/GAV fast path. This matches the precedent already set by foreachReferencesVariable.
  • return true; without a following break is fine since it exits the method directly — same idiom used in the FOREACH inner switch a few lines below.

Performance

  • Worth flagging explicitly since CLAUDE.md calls out performance as a priority: this makes every query with a top-level CREATE/MERGE clause after a MATCH-bound edge skip the CSR/GAV fast path, even when the CREATE/MERGE pattern doesn't reference the edge variable at all (e.g. MATCH (a)-[r]->(b) CREATE (c:Note {x: 1}) RETURN c). That's a real, if narrow, regression opportunity for queries that mix relationship matching with unrelated writes. It's an accepted, documented trade-off (and consistent with existing conservative behavior elsewhere in this file), so not a blocker — just flagging it as a possible follow-up if this pattern turns out to be common: walking the CREATE/MERGE pattern's inline property expressions with the existing expressionReferencesVariable(Expression, String) AST walker (rather than blanket return true) could recover the fast path in the common case where the new pattern truly doesn't touch the edge variable.

Tests

  • Good coverage: a unit-level pair in CypherVariableUsageTest parallel to the existing per-clause cases, plus an end-to-end regression test (Issue6573CreateMergeEdgeVariableTest) exercising the real reported symptom through the engine for both CREATE and MERGE. The PR description states both were verified to fail without the fix, which is the right way to validate a regression test actually tests something.
  • One gap, not blocking: there's no test pinning the "conservative" trade-off itself, e.g. that a CREATE/MERGE clause which does not reference the edge variable still returns true (currently true unconditionally, by design). A test like that would make the deliberate over-approximation explicit and guard against someone "optimizing" it into a false negative later.

Docs

  • docs/6573-isedgevariablereferenced-create-merge.md follows the repo's existing per-issue write-up convention (matches the many NNNN-description.md files already in docs/), so no concerns there.

Security

No concerns — this is a pure control-flow fix in query-plan analysis, no new I/O, parsing, or trust boundary involved.

Overall: correct, minimal, well-tested fix for a real silent-data-loss bug. The performance note above is the only thing I'd want acknowledged (even just in the PR discussion) before merging, not a required change.

@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@robfrank

Copy link
Copy Markdown
Collaborator Author

@claude review

@claude

claude Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Claude finished @robfrank's task in 1m 2s —— View job


Review

  • Gather context (PR diff, files, prior review comments)
  • Review CypherVariableUsage.java change
  • Review tests (CypherVariableUsageTest.java, Issue6573CreateMergeEdgeVariableTest.java)
  • Review added doc file
  • Post final review

Re-reviewed the current state of the branch (not just the diff) directly from the checked-out files.

Correctness

Tests

  • CypherVariableUsageTest.createReadsItInAnInlineProperty / .mergeReadsItInAnInlineProperty (lines 127-139) are unit-level checks in the same style as the file's other per-clause cases, and the PR states they were verified to fail without the fix.
  • Issue6573CreateMergeEdgeVariableTest is a real end-to-end regression test running the issue's exact repro through the engine, checking the actual result value (s = 2001) rather than just that no exception is thrown - this is what actually pins the silent-null symptom from the issue, not just the internal boolean.
  • I wasn't able to execute mvn test in this sandboxed environment (Bash tool required an approval step that isn't available here), so I could not independently re-run the suite - I'm relying on the PR's stated verification (8906 tests, 0 failures) and static reading of the code, which is internally consistent.

Docs

  • docs/6573-isedgevariablereferenced-create-merge.md matches the existing docs/NNNN-description.md per-issue write-up convention used by ~20+ other files in that directory (e.g. 5788-gav-restore-await-timeout.md, 5835-cypher-and-or-short-circuit.md) - not a one-off addition.

Performance note (non-blocking, already raised in-thread)

Every top-level CREATE/MERGE after a MATCH-bound edge now skips the CSR/GAV fast path unconditionally, even when the new pattern doesn't actually reference the edge (e.g. MATCH (a)-[r]->(b) CREATE (c:Note {x:1}) RETURN c). This is an accepted, explicit trade-off given the correctness stakes, and mirrors the same conservatism already accepted for foreachReferencesVariable. A follow-up could walk the CREATE/MERGE pattern's inline property expressions with the existing expressionReferencesVariable(Expression, String) AST walker to recover the fast path in the common non-referencing case, but that's optional polish, not a blocker.

Verdict

Small, correct, well-tested fix for a genuine silent-data-loss bug (relationship property silently reading as null after a top-level CREATE/MERGE). No changes requested.

@robfrank
robfrank merged commit 580bcfe into main Aug 24, 2026
28 of 31 checks passed
@robfrank
robfrank deleted the fix/6573-isedgevariablereferenced-has-no-create branch August 24, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant