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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
* Copyright (c) 2025-2026 Anton Kundenko <singaraiona@gmail.com>
* All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
;
/* Whole-column totals of a single-file column's directory, in one pass
* (what a loop of ray_enccol_chunk_stat over every chunk would add up):
* the wrapping sum of the chunk low words, the exact 128-bit sum, the
* non-null rows, and the extremes over the chunks with min/max (integer
* types in min_i / max_i from INT64_MAX / INT64_MIN, float types in
* min_f / max_f from +inf / -inf). */
typedef struct ray_enc_col_totals_t;
typedef struct ray_enccol_s ray_enccol_t;
/* A STR_DICT side entry (heap blob; offs / bytes point into the
* immutable mapping). Entries are pairwise distinct; "" (the STR null, in
* band) is an ordinary entry, null_code its code (UINT32_MAX when no entry
* is empty). slot[] is an open-addressing table over ray_hash_bytes of the
* entry bytes: code + 1, 0 empty. */
typedef struct ray_enc_sdict_t;
static inline void
ray_enccol_t* ;
ray_t* ;
ray_t* ;
void ;
void ;
void ;
size_t ;
int ;
/* Chunk c's 64 descriptors, in place in the mapping (valid while the
* column is). The file is ours: they are read as written. */
const ray_enc_desc_t* ;
/* Vector j of chunk c read in place: the mapped payload of a RAW vector
* with no nulls and no trailer (F32, F64 and the integer types, SYM
* included), whose bits equal its decode. NULL: decode it instead. */
const void* ;
/* Decode vector j of chunk c into `out` (vlen elements, generation-0
* element width). STR: pooled bytes are copied to pool_out[pool_base ...]
* (sized by ray_enccol_desc_pool_bytes) and descriptors get pool_off =
* pool_base + offset within the vector; hash32 is left 0. The decoded
* bytes are returned in *produced instead of counted; the caller counts
* them with ray_enccol_note_decoded. NULL or an owned error (oom of a
* side entry, the FP environment). */
ray_t* ;
/* Vector j of chunk c straight into an expression register: RAY_I64 or
* RAY_F64 elements (`wide`), nulls as NULL_I64 / NULL_F64, for a FOR_BP,
* DELTA_BP, CONST or RLE vector of a narrow integer column (BOOL, U8, I16,
* I32, DATE, TIME). 1 decoded (*produced as ray_enccol_decode_into), 0 declined: the
* caller reads the vector by range. */
int ;
/* Row `row` of a single-file integer column (not SYM), read from its packed
* vector without decoding the vector: a FOR_BP vector, DICT over a FOR_BP
* code child, CONST or RLE (the row's run found by binary search, no row
* expanded), with no nulls. 1 served (*out: the value widened to int64,
* as the decode would hold it), 0 declined (read the vector by range), -1
* an owned error in *err (the dictionary's oom). */
int ;
/* ray_enccol_point_i64 of rows rows[q] - base, q in [0, n): ascending
* rows of one vector, its body read once (CONST / RLE: the runs parsed
* once, not once per row). 1: every row served into out; 0: declined (as
* ray_enccol_point_i64; above open decision D2's limit for the codec,
* RAY_ENC_VEC / 32 rows of a FOR_BP vector, RAY_ENC_VEC / 16 of an RLE,
* CONST or DICT one; a RAW vector without nulls, which a view reads; a
* vector with nulls; SYM; any other codec; or rows outside one vector or
* not ascending), out partly written; -1: an owned error in *err. */
int ;
/* ray_enccol_points_i64 for a gather, which takes nulls and SYM ids: also
* serves a vector with a null bitmap (nul[q] 1 for a row in it, out[q]
* then 0, and nothing else of the row read) and a SYM column's ids (id 0,
* the in-band null, as itself). nul[q] is 0 for every other row. The
* codecs and their per-vector row limits are ray_enccol_points_i64's:
* FOR_BP, DICT over FOR_BP codes, CONST or RLE, and RAW with a bitmap.
* 1 / 0 / -1 as there. */
int ;
/* RAY_ENC_VEC lane values at the kind's width T (the fast kernels' own
* buffer: enccol.c's fk_vals_t is a typedef of this). */
typedef union ray_enc_lanes_t;
/* A parsed top-level vector body; never expanded to values.
* About 21 KB: a scan task keeps one on its stack (never the heap).
* Floats (CONST, RLE, DICT): k is { 32 | 64, unsigned, float }; cbits, the
* run values and the dictionary entries are F32 / F64 bit patterns. */
typedef struct ray_enc_vview_s ray_enc_vview_t;
/* Column-global vector `vec` of a single-file column as a view. 1: a
* view of a CONST, RLE, FOR_BP or DICT (over a U32 FOR_BP code child)
* integer body, a CONST, RLE or DICT float body (no trailer), or a STR
* STR_DICT vector as its codes (k U32, type RAY_STR, dict NULL, dict_n the
* entry count, nullmap NULL: the null is the empty entry's code, in band).
* A FOR_BP body's base is the vector minimum (the writer's), so its
* residuals compare in logical order. 0: declined (RAW, DELTA_BP, another
* code child, a float trailer, STR other than STR_DICT): read the vector
* by range; -1: an owned error in *err (a side entry's oom). Never counts
* decoded bytes. A declined view may be partly written; the caller
* ignores it. */
int ;
/* The FOR_BP residuals of a view (no base added) at width T into out
* (n elements of T bits), through the lane kernels (fk_forT, base 0).
* FOR_BP views only (any other view has packed NULL); out is aligned to
* T / 8 bytes and holds n elements. */
void ;
/* The residuals of a FOR_BP view comparing true (op: OP_EQ .. OP_GE, at
* the lane width, unsigned) against t, unpacked and compared in one pass
* of the lane kernels without storing them (perf fix 6's count). */
uint32_t ;
/* A reference on the column's payload (the RAY_ENCCOL headers share it). */
void ;
void ;
/* Count decoded bytes (global and per column counters). */
void ;
/* Decoded-pool bytes of vector j of chunk c (STR; 0 otherwise). */
ray_t* ;
/* Column-global vector decoded into out (its bytes counted); STR pooled
* bytes at pool_out[pool_base ...], sized by ray_enccol_vec_pool_bytes. */
ray_t* ;
ray_t* ;
uint8_t ; /* generation-0 element width */
/* The plain column (borrowed, cached for the object's lifetime) or an
* owned RAY_ERROR. Single and (Task 12) parted objects. */
ray_t* ;
/* The cached plain column when the materialization has completed, else NULL;
* never decodes and is safe against a concurrent materialize. */
ray_t* ;
/* Whether a whole decode of the column would stay cached from one
* statement to the next: its generation-0 bytes fit the budget
* ray_enccol_cache_trim keeps (a quarter of the anonymous watermark; no
* watermark keeps everything). A consumer that can read the column by
* range does so when it would not: such a decode takes the column's whole
* size at once and is dropped at the statement's end, so every query pays
* it again. Metadata only. */
bool ;
/* Test hook: a positive budget replaces the quarter of the watermark in
* ray_enccol_decode_kept until reset to 0. */
void ;
/* At a statement boundary: drop the whole-column decodes, least recently
* asked for first, until those still kept fit a quarter of the anonymous
* watermark. A decode something else retains is neither counted nor
* dropped (dropping it would free nothing and the next read would decode a
* second copy). Does nothing while an evaluation is on this thread's stack
* (a request served from inside a statement's sync send) or a dispatch is in
* flight, and without a watermark. */
void ;
/* Bytes of the whole-column decodes currently kept (test hook). */
int64_t ;
/* Counters (spec "Instrumentation"); reset by tests. decoded_bytes is
* the bytes vector decodes produce, plus the bytes an integer RAW vector
* read in place delivers (ray_enccol_raw_view through a range read); a
* float RAW view delivers its bytes uncounted. */
typedef struct ray_enc_counters_t;
void ;
void ;
void ;
/* Test hooks. fail_alloc: the nth allocation inside generation-2 decode
* or materialization (and a string-domain build's per-segment code remap,
* strdom.c) fails (1 = the next one); 0 disables. fail_path:
* while set, every such allocation fails for a column whose path contains
* `sub` (NULL disables); both report "oom" (transient). */
void ;
void ;
/* The fail_alloc counter, for a materialization step outside this file
* (the index-region parse): true when this allocation is the nth. It is
* the counter only (ray_enc_index_parse takes no path). fail_path never
* reaches the region: it fails the column's first materialization
* allocation ("materialize"), before the region is parsed;
* the parse is reached by the nth counter (the materializer's own check
* before the parse, then this one inside it) and by fail_index_parse. */
bool ;
/* Test hook: while set, the index parse of every materialization fails
* with "oom" ("column <path>: index parse"); transient, so not cached. */
void ;
/* interrupt_after: the nth chunk decoded successfully from now on calls
* ray_request_interrupt() (0 disables), exercising the per-chunk poll. */
void ;
/* Parted materialization: 0 auto, 1 always on the coordinator, 2 always per-segment tasks. */
void ;
/* Encoded column objects alive (opened, not yet freed). */
int64_t ;
/* One top-level integer vector body (`enc`, `width`) of a column of `type`
* (SYM: `attrs` width class), vlen rows, `bm` the null bitmap or NULL,
* n_nulls as its descriptor says. fast: through the fast kernel only,
* writing `wide` elements (0: the generation-0 width; RAY_I64 / RAY_F64:
* an expression register); else through the reference path (wide must be
* 0). 1 decoded, 0 the fast kernel declined, -1 the reference path
* failed (oom). */
int ;
/* One top-level DICT vector body of a column of `type` whose VALUE_DICT
* holds dict[0, n_dict) (T-bit patterns); otherwise as
* ray_enccol_test_decode_body at the generation-0 width (fast: the
* dictionary published first, as a column's first decode leaves it). */
int ;
/* One top-level float vector body (`enc`, any float encoding; F32 / F64)
* of a column with the VALUE_DICT dict[0, n_dict) (NULL: none), n_nulls
* as its descriptor says, no trailer. fast: through the fast kernel only
* (the dictionary published first); else through dec_floats. 1 decoded,
* 0 the fast kernel declined, -1 the reference path failed. */
int ;
/* ray_enccol_point_i64's body read of every row [0, vlen) of one top-level
* body (`enc`, `width`, n_nulls as its descriptor says) of a column of
* `type` with the VALUE_DICT dict[0, n_dict) (NULL: none): res[i] is the
* point read's 1 / 0 / -1 and out[i] its value when served. 0, or -1 on
* OOM. */
int ;
/* Wrap a plain-type parted wrapper (RAY_PARTED_BASE + base) whose segments
* include at least one RAY_ENCCOL; retains the wrapper. */
ray_t* ;
/* Segment i: its RAY_ENCCOL or plain vector (borrowed; NULL for a missing
* segment, which ray_read_parted never builds: a ragged partition's absent
* column is a lazy all-null RAY_ENCCOL segment, or for LIST a heap fill). */
ray_t* ;
/* Segment i materialized (borrowed plain vector, NULL for a missing one)
* or an owned error. */
ray_t* ;
bool ;
/* A synthetic column stands in for data that was never saved encoded (a
* ragged partition's absent column, ray_read_parted): generation
* inheritance treats it as plain. Parted: every encoded segment is
* synthetic. */
void ;
bool ;
/* A column's format, for .idx.info: vectors per encoding code (RAW ..
* FSST), file bytes, generation-0 bytes, whether the plain column exists.
* Reads descriptors only (statistics are reported, never trusted to size
* memory) and never decodes a payload. */
typedef struct ray_enccol_info_t;
/* Generation-0 payload bytes of a plain vector: len * width (+ STR pool). */
uint64_t ;
/* NULL, or an owned type error (not an encoded column). */
ray_t* ;
/* One chunk's directory statistics. */
typedef struct ray_enc_chunk_stat_s ray_enc_chunk_stat_t;
/* Chunk c of a single-file encoded column. c must be below e->n_chunks. */
void ;
/* STR code bounds (membership bounds, spec "Statistics") of chunk c (j < 0)
* or of vector j of chunk c: true with [*lo, *hi] when present. The only
* reader of STR statistics as statistics; every generic accessor reports
* none for STR (chunk_stat with min / max 0, dir_totals, vec_stat), and the
* ZONE / CHUNK_ZONE synthesis treats STR chunks as without them. */
bool ;
/* The totals below, computed once per column (the directory is immutable). */
void ;
/* File byte range holding rows [lo, hi): from the first touched chunk's
* descriptors to the end of the last touched chunk. Precondition:
* 0 <= lo < hi <= e->len (a row past the end would read a directory entry
* past the last chunk). */
void ;
void ;
/* Could materialization attach an index: a recorded kind or UNIQUE
* (single-file)? Known without decoding. */
bool ;
/* The column's STR dictionary (*out NULL when it has none, or the column
* is not STR), or an owned oom error (read once). */
ray_t* ;
/* Code of `s` in the column's dictionary: *code >= 0, -1 absent, -2 no
* dictionary. NULL, or an owned oom error (*code untouched). */
ray_t* ;
/* A persisted DICT (spec "STR dictionary index"), parsed. Pointers into
* the immutable mapping; ent is a STR_DICT-form view of the entries (offs
* / bytes in the mapping, slots in the blob). */
typedef struct ray_enc_idict_t;
/* The column records a persisted DICT (P6b): a single file, not synthetic,
* its header naming kind 7. The one gate of every DICT reader. */
bool ;
/* The column's persisted DICT, parsed once (*out NULL: the column
* records none, or is parted / synthetic), or an owned error (once). */
ray_t* ;
/* Code of s: *code >= 0, -1 absent, -2 no persisted DICT. */
ray_t* ;
/* Codes of rows [start, start + n) in place (vector scope); no decode, no
* decoded bytes. The column must record a DICT (ray_enccol_idict gave
* one). */
ray_t* ;
/* The whole codes as a heap RAY_I32 vector,
* made once and kept for the object's lifetime (borrowed: retain to keep). */
ray_t* ;
/* Test hook: how many STR pools materialization has allocated so far. */
uint64_t ;
/* A fresh SYM vector `out` (runtime domain) takes the domain the column's ids
* resolve over, as its materialization would; no decode. */
void ;
/* RAY_ENCCOL_H */