Repository navigation
fix(query): vector identity follow-up: one-round cold builds, the whole-graph distinct count, cancellation, EXISTS - #2468
Merged
Merged
Conversation
…na in one round On a host that serves reads from a resident tier (a browser), a read of a shard that isn't resident records the miss and fails, and the caller fetches what was recorded and retries. Building a vector arena's identity table reads every shard, so a cold build failed once per shard, one retry round each. The rounds are capped at 256, so a COUNT(DISTINCT ?v) or group count over an arena of more shards than that failed, where it had answered (by handle) before the identity tables existed. The build now records every shard the resident tier lacks before it starts, as the routed scan cursors record their remaining leaves, so one retry round fetches the whole arena. No answer changes. `a_cold_identity_table_build_fetches_its_arena_in_one_round` builds a table over eight shards that are stored but not resident and counts the retry rounds: one with the change, eight without it.
… holds vectors The whole-graph COUNT(DISTINCT ?o) walks OPST leaflet directories, and a vector's key is a handle, not a value, so it declined on any graph holding a vector: the general pipeline then scanned and keyed every triple. It now counts the vectors the walk leaves out from their arenas' identity tables, as it already counts big numbers from theirs. Within an arena the distinct canonical handles of the live handles are its values; across predicates only a hash two arenas share needs a component compare. Liveness is proved from POST directories, as for big numbers, and the four helpers that prove it now take the arena's o_type rather than assuming NUM_BIG_OVERFLOW. The count builds each vector predicate's identity table on first use, once per store, as the per-predicate count already does. `distinct_object_count_counts_vectors_by_value` counts a vector repeated under one predicate and one shared by two once each, before and after retractions (a rebuild, then an incremental build that leaves a predicate with no live vector). Ignoring liveness answers 4 and 3 for 3 and 2; skipping the cross-arena compare answers 15 for 14 on the vector fixture; with the decline put back, the lane never serves the vector graph.
… is cancelled Building a vector arena's identity table reads the whole arena, inside an operator's open, and nothing stopped it: a query cancelled or timed out during the first value-keyed count after an index publish read on until the arena ended. The build now looks at the query's cancellation every 1,024 vectors and before each run of repeated hashes, and stops with the cancellation's reason, which `QueryError::from_io` returns as `Cancelled` rather than an I/O failure. The table's once-only cell is left empty, so the next caller builds it. The build still charges no fuel. Tests: a cancelled build stops and leaves no table (with the check removed it builds anyway); a cancelled read stays a cancellation (without the new arm it is an internal error).
…iled to read The semijoin keys the inner solutions into a hash set and probes it per row, and a failed vector read inside either counted two equal keys apart: EXISTS dropped a row and NOT EXISTS kept one. Only the runner and the WHERE cursor caught it, after the batch. It now checks the query's key-read slot after each build batch and after each probe batch, before any row is decided, as DISTINCT, GROUP BY and the hash join do. The failed-read test now runs EXISTS and NOT EXISTS over two arenas too. With the runner and cursor checks removed, they answered [] and [f, g] without an error before this change, and fail with one after it.
The vector equality's `Arc::ptr_eq` shortcut described a decode memo that no longer exists; it is a cheap identity check before the component compare. `o_key_is_predicate_identifying` now says it is a property of the o_type, not of a given arena, and points at `objects_keyed_by_value` for an arena's contents (a legacy decimal arena keeps scale variants under two handles).
No bench covered keying a vector, so a regression on the embedding shape (one distinct 768-dimension vector per subject) could land unnoticed, as keying a decoded vector by its Debug text did. `query_hot_vector_keying` times a counted DISTINCT, GROUP BY and cross-predicate join on `?v`, and a MINUS, on an indexed ledger before the arenas' identity tables exist, then the three keying cells and a per-predicate COUNT(DISTINCT) after one has built them. Its regression budget matches the other query-hot benches'.
`FlakeValue`'s `Hash` for a vector went through `vector_value_hash`, which checks that every component narrows to `f32`, narrows them, then hashes: right for keys that meet an arena slice, but MINUS, the union's fact dedup and COUNT(DISTINCT *) hash decoded values only against each other, once or more per row. A MINUS on a vector across 100K 768-dimension vectors came to 2.35G instructions, against 976M before #2201; with this it is 1.27G. `FlakeValue` now hashes a vector's `f64` bits with one `xxh3` pass, which its bitwise equality agrees with, and stays strong on widened `f32` components (`FxHasher` alone is weak on their zero low bits).
bplatz
approved these changes
Nov 20, 2026
bplatz
left a comment
Contributor
There was a problem hiding this comment.
Approving to unblock. Please address the inline comments before merging.
On the open question in the description: yes, please fold the MINUS / fact-dedup / COUNT(DISTINCT *) keying onto value keys into this PR.
This was referenced Nov 21, 2026
Merged
The directory walk leaves out the arena-keyed objects, big numbers and vectors, and each kind is counted from its arenas. Counting big numbers only when some NumBig arena held entries, and vectors only when the graph held vectors, let rows of a kind with no arena to count them (an inconsistent index) add nothing, so the count came back low where it declined before. The walk now tallies the rows of vector-only leaflets apart from the rest it leaves out, and distinct_objects_of_walk counts each kind it left rows of: the other rows go to the big-number count as they always did, which declines without an arena, and vector rows need the graph's vectors. A kind with no rows left out is not counted, so a graph of vectors with no big numbers does not consult them. The comments that still said a graph holding vectors declines now describe the vector count. rows_the_walk_leaves_out_are_counted_or_decline covers each case; counting a missing big-number count as 0, as the gate on the arenas did, fails it.
…round The whole-graph distinct count compares the vectors of every hash two arenas share, reading each through the shard cache in hash order. On a residency host, once an earlier query had built the identity tables and the shards had left the resident tier, each shard the compare read failed in turn and cost its own retry round, and past the retry budget's cap the count failed where it fell back before. BinaryIndexStore::register_missing_vector_shards records every shard holding one of a set of handles that the resident tier lacks, through the arena's register_missing_shards_of (the per-handle sibling of the build's register_missing_shards). The count calls it for the handles of every shared hash before its first read, so one retry round fetches them all. registered_vector_reads_fetch_their_shards_in_one_round reads one vector of each of eight shards out of shard order after registering them: one round, where without the registration it took eight. The residency arena fixture and the fetch-and-retry loop are shared with the build's one-round test.
Both callers of group_count_v6 fell back to the general pipeline on any error, so a cancelled identity-table build, an exhausted budget or a residency miss declined instead of ending the query or asking for a fetch. answer_or_decline raises those, the errors the general pipeline would meet too, and declines on the rest, the group count's own failures. a_fast_path_declines_only_on_its_own_failures pins which errors decline.
… check The cross-arena compare calls vector_eq_f32, the comparison the identity build uses, rather than its own copy. f64_bytes holds the one unsafe f64 byte view beside f32_bytes, for vector_value_hash and vector_bits_hash. The gate tests' vector count check is check_liveness with the exact site as a parameter.
bplatz
added a commit
that referenced
this pull request
Nov 21, 2026
Brings #2453 (a GRAPH scope's columns leave as they are when nothing decodes), #2455 (a governed graph source honors its model's override control), #2467 (R2RML scan join emit; iceberg top-k read budget) and #2468 (vector identity follow-up: the whole-graph distinct-object count counts vectors by value, a cold identity-table build fetches its arena in one round, and the build stops on cancellation). Conflicts: - fast_count.rs: main's vector count on next's lead walk. count_distinct_lead_groups_inner tallies vector-only leaflets apart from the rest, and the NumBig liveness helpers take an ArenaRange (a store's NumBig o_types, or the vector o_type alone), so they serve count_distinct_vector_objects as main's generalized helpers do. count_distinct_objects_for_predicate takes next's tracker and main's cancellation, as do its callers in fast_predicate_scalar_agg.rs and fast_whole_graph_agg.rs. - fast_group_count_firsts.rs: next's pooled-graph guard with main's answer_or_decline. - o_type.rs: next's NumBig wording plus main's paragraph on arena contents. - fluree_ext.rs: next's SourcePolicy and model-instance check, with main's async config and the model's override control. - core lib.rs: main's MemoryCharge re-export; annotation_index has no home on next. - Cargo.toml, regression-budget.json: both benches. Ports: - vector.rs: register_missing asks ContentStore::get_local whether a shard is resident; next has no resolve_cached_bytes, and a shard's cid is not optional. - Tests: the residency vector arena stores its shards through write_test_shard_in, and BinaryIndexStore::empty() takes no directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2201. An independent re-review of that PR turned up a handful of things late in its life. The per-query shard pins, the build-once table, the in-place compare and the clippy list went into #2201 itself before it merged. This picks up the rest, starting with two regressions that merge brought to
main.Regressions from #2201
f777ab5e4). On a host that serves reads from a resident tier (the browser build), a read of a shard that isn't resident records the miss and fails, and the caller fetches what was recorded and retries. Building a vector arena's identity table reads every shard, so a cold build failed once per shard. The rounds are capped at 256, so aCOUNT(DISTINCT ?v)or group count over an arena of more shards than that failed on that host, where before fix(query): compare vector literals by value, not by arena handle #2201 it answered (by handle). The build now records every shard the resident tier lacks before it starts, as the routed scan cursors do for their remaining leaves, so one retry round fetches the whole arena. No answer changes.a_cold_identity_table_build_fetches_its_arena_in_one_roundcounts the rounds over eight stored-but-not-resident shards: one now, eight without the change.COUNT(DISTINCT ?o)declined any graph holding a vector (42f77564a). Its directory walk keys objects by(o_type, o_key), which isn't a value for a vector, so fix(query): compare vector literals by value, not by arena handle #2201 sent such a graph to the general pipeline, which scans and keys every triple. It now leaves the vectors out of the walk, as it already did big numbers, and counts them exactly from the arenas' identity tables. Within an arena, the distinct canonical handles of its live handles are its values. Across predicates, only a hash two arenas share needs a component compare. Liveness comes from POST directories, as for big numbers (an arena keeps the handles of retracted facts), and the four helpers that prove it now take the arena's o_type rather than assumingNUM_BIG_OVERFLOW.distinct_object_count_counts_vectors_by_valuecounts a vector repeated under one predicate and one under two once each, before and after retractions (a rebuild, then an incremental build that leaves a predicate with no live vector), and the fast lane, the general pipeline and the hand count agree. Ignoring liveness answers 4 and 3 for 3 and 2. Skipping the cross-arena compare answers 15 for 14 on the vector fixture. Putting the decline back, the lane never serves.The rest
ede710175). It reads the whole arena inside an operator'sopen, and nothing stopped it. It now looks at the query's cancellation every 1,024 vectors and before each run of repeated hashes, and stops with the cancellation as the error, whichQueryError::from_ionow returns asCancelledrather than an internal I/O error. The table's once-only cell stays empty, so the next caller builds it. It still charges no fuel, as decided in fix(query): compare vector literals by value, not by arena handle #2201.EXISTSsemijoin checks the query's key-read slot itself (45457a382). It keys the inner solutions into a hash set and probes it per row, and a failed vector read inside either counted two equal keys apart:EXISTSdropped a row andNOT EXISTSkept one. Only the runner's and the WHERE cursor's checks caught it, after the batch. It now checks after each build batch and each probe batch, asDISTINCT,GROUP BYand the hash join do, and the failed-read test runsFILTER EXISTSandFILTER NOT EXISTSover two arenas too. With the runner's and cursor's checks removed, those answered[]and[f, g]with no error before this, and fail with one after it.b6fccade8).FlakeValue'sHashfor a vector went throughvector_value_hash, which checks every component narrows tof32, narrows them, then hashes. That's right for keys that meet an arena slice, butMINUS, the union's fact dedup andCOUNT(DISTINCT *)hash decoded values only against each other, a row at a time. It's now onexxh3pass over thef64bits, which its bitwise equality agrees with (and which stays strong on widenedf32components, whereFxHasheralone is weak).3b05a66f4). Nothing benched keying a stored vector, which is how keying one by itsDebugtext reachedmainfor a while unnoticed.query_hot_vector_keyingtimes a countedDISTINCT,GROUP BYand cross-predicate join on?v, and aMINUS, on an indexed ledger with one distinct 768-dimension vector per subject, before and after the identity tables are built, plus a per-predicateCOUNT(DISTINCT)and, after the tables, the whole-graphCOUNT(DISTINCT ?o). It has aregression-budget.jsonentry like the other query-hot benches. On the box below, itsMINUScell is 18.3 ms onmainand 11.4 ms here, and the other cells are within run-to-run noise ofmain(three interleaved runs each).a2e20b307): the vector equality'sArc::ptr_eqnote described a memo that's gone, ando_key_is_predicate_identifyingnow points atobjects_keyed_by_valuefor what an arena actually holds.Numbers
instructions:u, median of three runs of three iterations each, on a quietc7i.8xlarge: an indexed ledger of 100K subjects, each with one distinct vector and one decimal, where every tenth also holds a copy of its vector under a second predicate (so the count compares 10K vectors across arenas). "Before #2201" isb1977e0fe,mainjust before that merge. Every answer matched across the three builds.COUNT(DISTINCT ?o)mainmain)main)MINUSon?vacross two predicatesmainmain)main)Wall clock for the count is 190 ms on
mainand 21 ms here at 768 (230 ms and 29 ms at 1536). Before #2201 it was 3 ms, but it counted by handle there, which is wrong once a vector repeats. In instructions the count is 2–2.3x that older lane, which is the liveness proof and the cross-arena compare.The first run on a fresh index builds the identity tables. That's the same build the per-predicate
COUNT(DISTINCT ?v)already pays onmainfor its first run (3.39G at 1536), and the two share the tables, so whichever runs first pays for both. With the tables already built, the count's first run is 2.54G againstmain's 3.92G at 1536. Peak RSS is a little lower thanmain(391 MB against 424 MB at 768).Every other cell is within 1% of
mainwith the tables unbuilt: countedDISTINCT,GROUP BY, a join andFILTER EXISTSon?v, the per-predicateCOUNT(DISTINCT ?v), decimal and subjectDISTINCT, and adotProducttop-10. With the tables built, the four?vcells come to 0.37x–0.72x ofmain, as they did in #2201.One thing I left as it is:
MINUSis still 1.30x (768) and 1.40x (1536) of before #2201. The hash isn't the cost any more: in a profile,xxh3is 10% of the run, whereFxHasherwas 28% before #2201. What grew instead is decoding each vector to key it (thef32widening and shard parsing), whichMINUS, the union's fact dedup andCOUNT(DISTINCT *)still do, rather than use the value key the hashed operators use. Moving them over means retyping their ownBinding-based keys, which felt like more than this follow-up should take on, but happy to fold it in here if we want that last 30–40% back.Follow-up: #2483 (moving
MINUS, the union's fact dedup andCOUNT(DISTINCT *)onto the value key).Gates
All on one
c7i.8xlarge, at this branch's tree:cargo fmt(workspace andtestsuite-sparql); clippy--all --all-features --all-targets -D warnings;cargo checkfor the workspace and for the server'snative-only build; the wasm32 clippy lanes and the Node wasm probe; workspace nextest--all-features(16,569 passed, 46 skipped, including the residency-gated test); doctests;testsuite-sparqlclippy and tests; the harness coverage test; and the new bench under--test. The server-onlycargo checkprints one dead-code warning, influree-db-server/src/extract/credential.rs, which this doesn't touch.