Repository navigation
Conversation
…ot routing keys A leaflet's routing keys are widened over the history it holds, so they bound its rows without naming them. Distinct-group counts subtracted at a boundary the keys met but the rows did not, MIN/MAX could return a retracted extreme, and the range semijoin compared a key widened into another type with its bounds. The distinct walks now share one walk (fast_lead_walk). A leaflet with no history has routing keys that are its rows' keys; where a leaflet holds history and its routing group meets its neighbour's, the walk reads its first and last groups from the lead column, at most once per walk. MIN and MAX read the first or last row of the predicate's end leaflet, and the range semijoin prunes with post_o_key_bounds.
Each case puts a retraction at the leaflet boundaries and compares the fast path and the general pipeline on the same index against an unindexed ledger, after a full and an incremental build, walking serially and in parallel chunks. Also runs against indexes v4.2.6 wrote.
This branch has not been deployed
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.
Summary
The directory-only aggregates now judge a leaflet by its rows, not by its routing keys. This is the
mainhalf of the fix #2402 made onnext.A leaflet's routing keys are widened over the history it holds, so they bound its rows without naming them. Several fast paths treated them as the rows' own values:
COUNT(DISTINCT ?s),COUNT(DISTINCT ?o), per-predicate distinct counts, and the subject total of whole-graph aggregates.MINandMAXcould return a retracted extreme.Fixes #2394
Fixes #2398
Fixes #2399
Changes
fluree-db-query/src/fast_lead_walk.rs, as onnext). The whole-graph, per-predicate and live-arena-handle walks each had their own copy of the boundary dedup. They now share one walk with a single rule: add the counts, and subtract one where a leaflet's first row shares its group with the previous leaflet's last row.maindrops history. Those boundaries settle by comparing keys, as before.MIN/MAX. The numeric path reads the first row of the predicate's first leaflet, or the last row of its last. The string path takes each type-constant leaflet's first or last row the same way; it fires only on bulk-imported indexes, which hold no history, so it reads nothing more in practice.post_o_key_bounds, as the batched join already does.o_type_const. The arena classifier skips a leaflet whose rows all have one other type.Behaviour changes
lead_group_countnow sends the whole-graph walks to the general pipeline. They used to skip it, and undercount.count_distinct_lead_groupsreturnsOption, and its callers decline onNoneinstead of counting zero.Performance
A boundary costs a read only where a leaflet holds history and its routing group meets its neighbour's. The read decodes the leaflet's lead column through the leaflet cache, once per walk; a remote leaf is range-read. Leaflets without retractions hold no history, so a bulk-imported index, or a predicate never retracted from, stays directory-only.
Measured on a file-backed ledger built from commits: 400k subjects, about 2.4M facts, default leaflet size, one property retracted from 10% of subjects. That retraction puts history in every SPOT leaflet, the worst case for distinct subjects. Each query ran on a freshly opened instance (OS page cache warm),
dev-fastprofile, best of three:COUNT(DISTINCT ?s)COUNT(DISTINCT ?o)COUNT(DISTINCT ?o)of one predicateMAXof one predicateOn remote storage each of those reads is a range request; that cold cost is not measured here. A repeated query finds the leaflets in the leaflet cache.
Tests
it_leaflet_live_edges(new, its own binary, from fix(index): directory aggregates read leaflets' row groups, not routing keys #2402). Every case puts a retraction at the leaflet boundaries, then compares the fast path and the general pipeline on the same index against an unindexed ledger, with the lane's routing stamp pinned. Each runs after a full build and after an incremental build, walking leaves serially and in parallel chunks.SUM(STRLEN(GROUP_CONCAT)).MIN,MAXand the range semijoin.tests/fixtures/leaflet-edges-4.2.6, from fix(index): directory aggregates read leaflets' row groups, not routing keys #2402 without its erasure ledger), full-built and incremental.main's query code, six of the nine fail: distinct subjects, distinct objects,SUM(STRLEN(GROUP_CONCAT)),MIN/MAX, the range semijoin, and the v4.2.6 fixture. The three spanning cases pass there; with a walk that never subtracts at a boundary, they fail, as do the distinct-count cases and the fixture.fast_lead_walk: a group read from a leaflet's columns equals the group of a history-free leaflet's routing key, in every order; a leaflet's edges are unproven only where it holds history; with a loader that counts reads, the walk reads each leaflet at most once under every way of cutting the leaflets into chunks, and subtracts only where the rows share a group.docs/design/index-format.mdanddocs/design/performance.mddescribe routing keys as bounds.Merging into
nextnexthas this fix in its own form (#2402): stored live groups, with the lead-column read as its fallback for v4 indexes. Whenmainis next merged intonext, keepnext's side offast_lead_walk.rs,fast_count.rs,fast_min_max_string.rs,range_semijoin.rs, theLiveGroupadditions inleaflet.rs,holds_historyinleaf.rs, and the two docs. Keepnext'sit_leaflet_live_edges.rs, which has the v5 and erasure cases. The fixture directory differs only by the erasure ledgernextkeeps.