Interpreter execution
The interpreter runs a validated physical plan against the graph database. It turns planned operations into rows, scalar values, counts, and request results while keeping one request's variables, storage view, search reads, and write state together. The planner selects the operations; the interpreter runs them in the required order.
This page is a child of Query planning and execution. Read Query language AST for the input model and Planner and optimizer for how the executable plan is selected. The Cypher language frontend describes how a query reaches planning.
Execution lifecycle
Request setup
The request enters execution after validation and planning. The interpreter classifies the plan as a read, graph write, or index lifecycle request, then selects the storage authority that can safely run it.
The request moves through these stages:
- Check request control state.
- Open a stable read view or writer-owned state.
- Run plan steps in execution order.
- Check the deadline and commit or abort write state.
- Materialize the root result and declared returns.
- Close the read view after successful materialization.
The diagram shows how a planned batch becomes a public response.
flowchart LR
A[Validated query] --> B[Physical plan]
B --> C[Request mode and storage view]
C --> D[Planned steps]
D --> E[Operation dispatch]
E --> F[Rows scalars or counts]
F --> G[Declared returns]
G --> H[Query response]
References: crates/…/query_service.rs• L283-320 crates/…/mod.rs• L127-180
Stage scheduling
The scheduler runs dependency-linked steps in the order required by the physical plan. Independent read and stream steps can run in isolated contexts when their inputs permit it. Stateful operations and barriers remain serial.
Parallel work shares immutable request inputs and reader snapshots. Step outputs are retained only while later consumers need them. Nested plans use the request context while keeping their temporary step outputs separate.
References: crates/…/scheduler.rs• L16-89 crates/…/scheduler.rs• L93-145 crates/…/subplan.rs• L11-38
Operation dispatch
Dispatch maps each validated operation to its runtime contract. A step checks its condition and mutation visibility, gathers dependency input, invokes the operation, checks the result shape, and records the output.
The operation families cover graph access, expansion, search, filtering, bounds, projection, aggregation, control flow, shortest paths, mutation, and index lifecycle work. Merge uses dependency provenance because it combines several stored outputs.
References: crates/…/dispatch.rs• L10-33 crates/…/dispatch.rs• L36-110
Runtime value model
Row streams
An execution row is the unit of graph work passed between operators. It carries the current node or edge together with bindings, traversal history, runtime-only properties, path visibility, and per-row sack state.
The interpreter streams rows from independent sources or continues from earlier rows. Expansion copies the row and changes its current element. Pattern completion then checks labels, properties, paths, and predicates against the request view.
References: crates/…/mod.rs• L137-283 crates/…/matches.rs• L82-132 crates/…/matches.rs• L411-547 crates/…/types.rs• L63-149
Pattern continuations
Pattern continuations hold the work needed to resume a multi-step match. They walk scans, index probes, joins, expansions, and relationship scans in plan order while reusing source results where possible.
The continuation stack supports depth-first progress. It keeps reusable source data separate from active traversal frames, so a consumer can stop when its demand is met without rebuilding the whole match.
References: crates/…/expansion_stack.rs• L44-152 crates/…/expansion_stack.rs• L156-353 crates/…/lookup_frames.rs• L529-623
Terminal values
The interpreter keeps row streams distinct from terminal values. A result can be a row stream, folded stream, count, Boolean, scalar list, index receipt, or index status. Operators accept only the shapes defined by the plan.
A folded stream marks an explicit boundary for materialized rows. Operators that need ordinary rows must unfold it. Final return handling also keeps an empty list distinct from an absent scalar value.
References: crates/…/types.rs• L281-358 crates/…/stream.rs• L36-53 crates/…/dispatch.rs• L5-22
Row-mode control
Row mode begins when rows carry bindings and can grow the result quickly. The interpreter applies a positive process-level row cap after operations that produce row output. Unbound element streams do not use this specific guard.
References: crates/…/row_mode.rs• L11-79 crates/…/row_mode.rs• L175-192
Graph access
Access sources
Access operators produce node or edge rows from the source selected by the physical plan. They can read parameters, variables, scans, label sets, equality and range indexes, secondary sets, authoritative predicate scans, or point records.
The access contract applies the tightest nested limit before it materializes rows. Index-derived IDs are checked against authoritative graph records so stale or wrong-kind IDs do not become graph rows.
References: crates/…/dispatch.rs• L16-45 crates/…/dispatch.rs• L48-180 crates/…/dispatch.rs• L183-297 crates/…/rows.rs• L14-90
Search access
Vector and text search provide node and edge access sources. The interpreter evaluates the search input, resolves the request-scoped index, applies the result limit, and turns hits into graph rows.
Search metadata remains available as runtime-only row properties. Vector results expose $distance; text results expose $score. The matching graph record is checked again before the row is accepted.
References: crates/…/dispatch.rs• L141-176 crates/…/dispatch.rs• L259-292 crates/…/rows.rs• L93-235
Graph expansion
Expansion turns each input row into rows for neighboring nodes or concrete edges. Direction selects outgoing, incoming, or both sides. A label narrows the edge or neighbor set.
The new row keeps the incoming state and adds the new element to its path. Missing adjacency or invalid endpoints produce no row when the operation permits an empty result.
References: crates/…/expand.rs• L15-25 crates/…/expand.rs• L28-111 crates/…/expand.rs• L128-270
Relationship scans
Relationship scans start patterns with an unbound typed relationship. They read candidate edges, resolve their endpoints, and bind the edge and endpoint nodes into each parent row.
The scan supports outgoing, incoming, and undirected patterns. It replays shared edge sets for each parent, skips invalid endpoint records, and avoids reusing an edge already bound in the row.
References: crates/…/relationship_scan.rs• L11-35 crates/…/relationship_scan.rs• L38-161 crates/…/relationship_scan.rs• L29-94
Result operations
Stream operators
Stream operators transform rows without changing the request's execution model. They filter, limit, skip, range, deduplicate, order, bind variables, branch, repeat, and control fold or path visibility.
The stream boundary rejects terminal values that cannot represent rows. This keeps a wrong handoff visible at the operator that receives it.
References: crates/…/stream.rs• L19-53 crates/…/dispatch.rs• L59-85
Projections
Projection converts rows or compatible scalar terminals into public values. A row projection can expose IDs, labels, properties, maps, aliases, bindings, edge endpoints, or existence.
Runtime-only properties take part in projection like other visible row data. Projection still keeps row input separate from scalar input. Only existence and ID projections accept scalar terminal items.
References: crates/…/dispatch.rs• L5-22 crates/…/rows.rs• L7-39 crates/…/rows.rs• L41-210 crates/…/bindings.rs• L17-79
Counting and aggregation
Count operators return cardinality without always building the full row result. Count sources include constants, input values, scans, point reads, indexes, search hits, and recursive stream cursors. Skip and take windows apply to accepted results.
Aggregation consumes rows or scalar items according to the plan. Group and group-count return grouped objects. Numeric aggregation supports count, sum, minimum, maximum, and mean. Scalar input supports the count form only.
References: crates/…/count.rs• L192-205 crates/…/count.rs• L204-495 crates/…/aggregate.rs• L10-158
Shortest paths
The shortest-path operator resolves one source node and one target node. It then runs an unweighted breadth-first search up to the depth selected by the planner.
No path is returned when an endpoint is absent or the target cannot be reached. An endpoint with more than one node is a query error because the operation needs one source and one target.
References: crates/…/shortest_path.rs• L16-96 crates/…/shortest_path.rs• L98-157 crates/…/shortest_path.rs• L160-214
Request context and storage
Execution context
The execution context is the shared request state for operation contracts. It carries the database handle, tenant scope, parameters, variables, step outputs, return-shape information, read and write ownership, catalog state, row cap, and execution control.
It also controls the lifetime of values retained by the plan. Linear values stay uniquely owned. Values with more than one live consumer become shared until those consumers finish.
References: crates/…/runtime_context.rs• L47-84 crates/…/runtime_context.rs• L270-290 crates/…/types.rs• L360-530
Variable and output state
Named variables and step outputs connect one plan step to another and define what the request can return. A step can discard its value or bind it to a variable. If later steps observe the same value, the interpreter keeps a shared view for both consumers.
Conditions can test whether a variable or prior step is empty, non-empty, or large enough. At completion, the root output and all bound variables remain available while only declared return variables are normalized for the public result. Empty list returns serialize as lists; missing scalar returns fail.
References: crates/…/state.rs• L12-139 crates/…/types.rs• L532-561
Read and write views
Each read request uses one stable storage view for all steps. A reader uses a pinned snapshot. A writer uses snapshot-isolated reads while holding its graph transaction.
Graph writes commit only after all steps succeed. Index lifecycle work uses a separate request mode. If it appears inside a write flow, the interpreter releases the graph write scope for that operation and resumes it after successful completion.
References: crates/…/read_view.rs• L15-38 crates/…/read_view.rs• L108-157 crates/…/mod.rs• L127-180 crates/…/dispatch.rs• L94-104
Deferred mutation visibility
Graph writes can hold topology and secondary-index changes in request-local state before a read operator can see them. The interpreter flushes only the deferred state needed by that operator. Vector and text search read queued transaction state through their own overlay.
Pattern stages combine the visibility needs of their scans, lookups, expansions, and relationship scans before they open continuations. Counts over held rows and runtime values do not need a storage flush.
References: crates/…/visibility.rs• L1-7 crates/…/visibility.rs• L57-169 crates/…/visibility.rs• L171-261 crates/…/matches.rs• L104-120
Storage boundary
Storage helpers turn logical graph reads into scoped raw gets, multi-gets, range scans, and prefix scans. They use the active write transaction first and the request read view next. Tenant scope applies to every key and scan.
Normal reads cannot escape the request view. Writer-only operations reject reader handles because they need write capability.
References: crates/…/storage.rs• L14-20 crates/…/storage.rs• L22-85 crates/…/storage.rs• L96-193
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
ExecOpdispatch table aligned with row-mode operation names and scheduler isolation rules. - Preserve the shape contract between
ExecutionValue, stream operators, projections, counts, and final return normalization. - Keep node and edge access paths paired with the matching authoritative keyspace and row materializer.
- Keep search metadata aligned with the virtual properties consumed by projection and response serialization.
- Preserve request-snapshot use for storage and authoritative verification reads, including tenant scope.
- Keep count cursor behavior equivalent to the corresponding row stream when a source or stream operator changes.
- Keep shortest-path endpoint cardinality and direction rules aligned with the planner payload.
- Keep relationship-scan type bitmaps, endpoint reads, direction rules, and parent-row replay aligned with pattern completion.
- Keep deferred mutation visibility aligned with every new access, count, pattern, and search operator.
- Keep variable conditions and declared return shapes aligned with output binding and final normalization.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A row operator receives a folded stream or terminal value | Execution stops with an input-shape error | Require the planned unfold or row input before the operator runs |
| An index returns a stale or wrong-kind ID | The invalid result does not become a graph row | Recheck the authoritative node or edge record during materialization |
| Search result kind does not match the access operator | Execution returns an invariant error | Validate the typed result kind before row construction |
| A relationship candidate has no valid endpoint record | The candidate produces no match row | Read and validate endpoints during the relationship scan |
| A read escapes its request view | Production execution fails instead of reading an unpinned view | Route storage access through scoped get, multi-get, and scan helpers |
| A shortest-path endpoint resolves to zero or many nodes | Zero nodes produce no path; many nodes fail the query | Enforce exact-one endpoint resolution |
Row output exceeds HELIX_ROW_MODE_MAX_ROWS | The operation fails before the oversized stream continues | Apply the row cap after row-producing operations |
| A declared scalar return variable is missing | Final result creation fails | Require the variable during return normalization |
| A write flow mixes graph mutation and index lifecycle work | Incompatible transaction modes cannot run together | Classify nested side effects before execution |
| A pattern reads deferred state without its required flush | The match can miss earlier writes in the same request | Compute visibility needs before opening the pattern source |
Key files
| File | Why to read it |
|---|---|
| crates/…/mod.rs | Interpreter entry point, request mode selection, commit, and close lifecycle |
| crates/…/dispatch.rs | Operation dispatch and pre- and post-step checks |
| crates/…/scheduler.rs | Dependency-stage execution and parallel isolation |
| crates/…/state.rs | Variable binding, step output retention, conditions, and final returns |
| crates/…/types.rs | Row, stream, scalar, count, virtual-property, and returned-value shapes |
| crates/…/mod.rs | Row-program lifecycle, streaming consumers, and response materialization |
| crates/…/matches.rs | Pattern sources, candidate completion, and row-stream production |
| crates/…/expansion_stack.rs | Resumable pattern traversal and reusable source state |
| crates/…/relationship_scan.rs | Typed relationship-root scans and endpoint binding |
| crates/…/dispatch.rs | Node, edge, and search access sources |
| crates/…/expand.rs | Traversal expansion through graph adjacency |
| crates/…/rows.rs | Authoritative graph-row and search-row materialization |
| crates/…/rows.rs | Public projection of row properties, bindings, IDs, and endpoints |
| crates/…/count.rs | Physical count sources, windows, and count cursors |
| crates/…/shortest_path.rs | Endpoint resolution and bounded shortest-path search |
| crates/…/visibility.rs | Deferred write visibility required by each operator and pattern |
| crates/…/runtime_context.rs | Request-owned parameters, variables, outputs, and controls |
| crates/…/read_view.rs | Stable request snapshots and read-view lifecycle |
| crates/…/storage.rs | Scoped raw reads, scans, and writer capability checks |
| crates/…/query_service.rs | Handoff from validated request and planning into execution |