Skip to content

Cypher: FOREACH over a runtime list, and CALL { … }, before or among multi-clause writes #2235

Open

Description

@aaj3f

Two shapes are refused in a write statement today, on their own and in multi-clause statements:

  • FOREACH iterates only a constant list (inline literal, constant range(), a $param array): it unrolls during
    parameter substitution (fluree-db-cypher/src/params.rs, expand_foreach). A runtime list
    (FOREACH (x IN n.tags | SET …)) and a MERGE/DELETE/nested FOREACH body are refused there.
  • CALL { … } before a write clause is refused by the single-Txn lowering and deferred by the sequential driver
    (cypher_seq.rs, validate_members).

Plan:

  1. FOREACH over a runtime list: stage it in the sequential driver as a per-row expansion — evaluate the list per
    row in the row table (hoist_clause_value_exprs already turns value expressions into row columns), unnest it
    into the table with a row index, and stage the body clauses seeded with the unnested rows, as a SET/REMOVE/CREATE
    is seeded today. A body MERGE reuses the driver's MERGE partition; a body DELETE reuses the seeded DELETE.
  2. CALL { … } before the writes: the read prefix already runs as an ordinary read query, which supports
    CALL { … }; lift the validate_members refusal once a test pins that the subquery's rows seed the writes as a
    MATCH's rows do (correlated import, and an aggregate in the body).
  3. Tests: twins against the equivalent SPARQL ; update where one exists; routing assertions with
    detect_sequential.
  4. Perf: statements that use neither shape keep their plans; check set_set_all and merge_chain in the harness.

Raised in review of #2184.

Activity

  1. added
    enhancement
    P3
    area:transact
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:transactenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions