1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//! Shared execution-context parameter objects threaded through clause
//! execution and expression evaluation — plus the PROFILE phase clocks (LABS-448) the phase wrappers stamp. The
//! pattern-walk vocabulary both walk engines (eval, exec) share —
//! bindings, hop bounds, stub binders, path-walk carriers — lives one
//! module over, [`crate::pattern_walk`] (LABS-668).
use Cell;
use BTreeMap;
use LocalKey;
use ;
use Instant;
use cratePhaseTimes;
use crateExecGraph;
use crateRedoOp;
use crateRow;
/// Statement-level context threaded through clause execution: the
/// statement's source text (which feeds `SHOW TRANSACTIONS`'
/// `currentQuery` column) and the connection's authenticated principal
/// (ADR-0273: set by a surface that verified an identity — the Bolt server
/// after a validated HELLO — else `None`). The principal is display-only;
/// both readers (`dbms.showCurrentUser`, `SHOW TRANSACTIONS`) render it
/// through `exec::catalog::principal_cell`, each passing the placeholder its command
/// documents for an unauthenticated connection.
pub
// The PROFILE phase clocks (LABS-448) — the thread-locals behind
// [`PhaseTimes`] and the wrappers every walker stamps through. They live
// here, the crate's lowest shared module, so both walk engines (eval,
// exec) read them downward (LABS-668): the eval walkers' phase spans made
// the old home beside the exec-only counters (`exec/profiling`) an upward
// import for `eval`. The clocks and their stamp body stay private to this
// module: the stamp→run→count pairing is the wrappers' implementation
// detail, never an API a walker could hand-roll beside them.
thread_local!
/// Arm the phase stamps for a PROFILE clause arm (LABS-448) — the metric
/// tick's first act, undone by its drop, so the stamps never run outside a
/// profiled statement.
pub
/// Disarm the phase stamps (LABS-448) — the metric tick's last act.
pub
/// The one phase-span body both wrappers delegate to (LABS-448; one
/// spelling since LABS-668's stellar round): take the stamp, run the
/// work, count its elapsed time into `sum`. The stamp is this helper's
/// local — taken only while a PROFILE statement's arm runs, so a
/// non-PROFILEd statement pays the one thread-local read and nothing
/// else, and a `None` stamp counts nothing. A run that errors counts
/// nothing either: the arm's `time_ns` covers what the phases do not.
/// One seek-phase span around a pattern node's candidate resolution
/// (LABS-448). Since the PR-604 stellar round the stamp is the counted
/// funnel's, not a per-walker obligation: `node_candidates`
/// (`crate::pattern_walk`, the shared walk tier) resolves through this —
/// the one caller — so the seek stamp lives beside the read count it
/// pairs with and every path that bumps the `Nodes` counter (both walk
/// engines' candidate reads) carries seek time, never a re-stamped copy
/// per walker. `None` stamps (non-PROFILEd statements) resolve unchanged.
pub
/// One walk-phase span around a relationship traversal (LABS-448): the
/// symmetric spelling of [`phase_seek`] over the walk clock — both
/// delegate to the one span body, so the walker sites never hand-roll
/// the stamp→run→count pairing, and the walk-phase contract (inclusive of
/// nested phases) is stated once, here. `None` stamps resolve unchanged
/// on non-PROFILEd statements.
pub
/// The phase-time sums right now (LABS-448), snapshotted at the clause
/// tick the way the store-read mix (`exec::profiling::store_reads`) is:
/// the delta across the arm is the clause's phase times, two thread-local
/// reads per clause.
pub
// The node-store reads (LABS-375): one per candidate a node match
// examined (the all-nodes scan, the label scan, the index seek) — the
// scan work the hop/neighbor counters never see, because they count
// relationship traversal only. It lives beside the phase clocks because
// its one counting point is the node-candidate funnel
// (`crate::pattern_walk::node_candidates`), which both walk engines read:
// a counter with an engine's name on it would be an upward import from
// the walk tier that bumps it.
thread_local!
/// Count `count` node-store reads (LABS-375) — batched because the one
/// funnel yields the whole candidate list at once, and every node-match
/// path reads it.
pub
/// The node-read total right now — read by the store-read mix
/// ([`crate::exec::profiling::store_reads`]) at clause boundaries, so a
/// per-clause delta costs one thread-local read, never a per-row one.
pub
/// Take the node-read total, leaving zero — the test-side snapshot the
/// store-read pins assert against.
pub
/// Per-batch commit sink for `CALL { … } IN TRANSACTIONS` (ADR-0210).
/// Called by the executor after each successful batch with the batch's
/// drained redo ops and the snapshot timestamp they were built against;
/// the implementation commits them durably (WAL + apply) before the next
/// batch starts, so live scratch state stays bounded by one batch.
/// Returns the commit timestamp the batch was applied at — the caller
/// rebases its scratch onto it, so only the sink (which owns the commit)
/// ever reads the base graph's clock.
/// Graph view + query parameters shared by clause execution and evaluation.
/// `principal` is the connection's authenticated principal (ADR-0273), read
/// by the `dbms.showCurrentUser` procedure arm; `None` when the surface set
/// none.
pub
/// Expression-evaluation context: graph view, current row, and parameters.
pub