Skip to content

feat(r2rml): an R2RML graph source answers over the set of triples its mapping defines - #2317

Merged
aaj3f merged 54 commits into
mainfrom
feat/r2rml-set-semantics
Nov 13, 2026
Merged

aaj3f merged 54 commits into
mainfrom
feat/r2rml-set-semantics

Conversation

@aaj3f

@aaj3f aaj3f commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An R2RML mapping defines a set of triples (R2RML §11; an RDF graph is a set), but its tables are bags of rows. A history table's versions of one customer, an exact duplicate row, or two tables minting the same subject each returned a triple once per row, so COUNT, SUM and AVG were silently wrong unless every query remembered DISTINCT. A referencing object map over a non-unique parent key went the other way: it kept only the smallest parent subject and dropped the other edges.

With this PR every lane answers as a native ledger loaded with the mapping's triples does: the generic Iceberg scan, the fused star, the fused aggregate and the COUNT shortcuts, the SQL lane, and the fluree materialize twin. Native-ledger differentials on SPARQL and JSON-LD pin it.

Proven-unique maps pay nothing. When a table key (f:key, an Iceberg table's identifier fields, or a SQL source's registration probe) proves a map's subjects unique, every existing plan runs unchanged. Keyless maps remove repeated solutions as they stream, charged to the query's memory budget.

Fixes #2238
Fixes #1583

Behavior

Set semantics apply to the data, not to SPARQL algebra

Deduplication is at the triple level. Each pattern's matches are distinct triples, per map and across maps that can mint the same triple. Above that, SPARQL stays bag-valued as before: UNION branches stay a bag union, projection keeps duplicates (a native ledger returns them too), and input rows that repeat keep their copies. A same-subject star over a subject that spans rows returns that subject's cross product of distinct objects: ?s :name ?n ; :city ?c gives each subject's names × cities, as the graph does.

When it is free

A map's own rows are checked for repeats unless both of these hold:

  • its subject is unique under a key of its logical table: an rr:column subject over a key column, or a template that covers a key and keeps its values apart (every separator between placeholders holds a character the IRI escape always encodes);
  • one row never yields the same solution twice (no two predicate-object maps that can mint one (p, o), no rr:class beside an rdf:type map naming the same class).

Maps that can mint the same subject are checked against each other unless their templates are provably disjoint. A map proven on every count runs exactly as before: same plans, same statements, same numbers.

The key evidence:

  • f:key declared on the logical table (see the vocabulary below).
  • Iceberg identifier fields (identifier-field-ids), for format versions 1 to 3. A version 4 reader must ignore them, and version 4 table constraints are not read yet. Delta sources report no key.
  • The SQL registration probe. The duplicate-subject probe now records the key it verified per table (verified_subject_keys), and the lane trusts it until the next fluree sql check. An endpoint unreachable at registration verifies nothing, and a source registered before this change keeps its trust. The probe records a key only when its columns can identify a term: not floating point, and not a timestamp finer than the microsecond or of unreported precision.

Keys are trusted, not verified, whichever way they are learned. Iceberg does not enforce identifier fields, and the probe sees a table only as it was when it ran. Over a table that breaks its key, queries return the repeated solutions the key ruled out, and a count read from table metadata is presented as exact. A check of each snapshot's keys is a follow-up (#2320).

What deduplicates, and what it costs

  • Generic scan. Each scan pass removes repeated solutions as it emits them: streaming and first-seen, so emission order is scan order and a LIMIT still stops early. Solutions are compared exactly, never by hash alone, in a compact byte encoding exact under the engine's term equality; terms compared by value across representations (decimal, double, temporal) stay as terms. Keys live in one arena, and the set charges what it holds (table allocation plus chunks, growth included) to the query's memory budget, so a set that outgrows the budget fails typed with MemoryBudgetExceeded before it allocates. Only solutions that join an input row are remembered.
  • Same-subject stars and the crawl's folded constant read every member from one row, so they fuse only where every covering map is subject-unique and no subject has a row in two covering maps (provably disjoint, or the same row minting every member alike). Otherwise the members run as separate scans joined on the subject.
  • Fused aggregate. COUNT/SUM/AVG/GROUP BY over one keyless map whose subject is an injective IRI template, with an object read from a column whose coercion keeps distinct values distinct, folds each solution once, deduplicating on the raw column bytes. A NULL has a tag of its own in that key, apart from its type's default. A batch with no exact raw encoding (floating point, timestamps) hands the query to the generic pipeline. Other keyless shapes take the generic pipeline.
  • Manifest and Delta log COUNT run only for maps whose rows are their solutions.
  • Scan-side top-k (ORDER BY … LIMIT k) counts rows, not triples, so it is declined over a map whose rows can repeat a solution. That scan reads every file. A keyed map keeps it, including one that overlaps another map.
  • SQL lane. Wherever a map's subject columns hold a key, the statement is byte-identical to before. Elsewhere it is a SELECT DISTINCT over every block variable's columns, and GROUP BY/COUNT/SUM/AVG read that distinct set as a derived table. Union entities whose maps can mint one subject tag rows by decoding class and deduplicate together. Shapes where no DISTINCT is exact decline to the per-scan lane: a star or folded OPTIONAL over a subject a map may mint from several rows, a reference joining on columns other than the parent's subject, a non-injective template, a string DISTINCT that folds case (MySQL), a repeated VALUES row, and a class policy over such a subject. allow_duplicate_subjects now skips the probe and answers with set semantics instead of returning duplicate rows.
  • Kill switch. With fast paths disabled (FLUREE_DISABLE_QUERY_FAST_PATHS) every scan deduplicates and the top-k is declined, so the differential lane relies on no key.

Routing stamps: r2rml_scan_proven_distinct, fused_r2rml_aggregate_dedupe, r2rml_scan_topk. A debug event reports each deduplication set's size and peak charge when it is released.

Referencing object maps join every parent subject (#1583)

A child row now links to every distinct subject the matching parent rows mint. A key whose rows all mint one subject (a history table's versions) still gives one edge. Keep-min also answered a bound object that was not its key's smallest subject with no rows; that now answers.

  • The parent lookup maps a key to its sorted, distinct subjects (ParentSubjects, one held inline, so a unique key costs what one term did). The query operator and the twin builder fill it through one shared insert. Scans, stars (two fan-out members give their cross product), constant objects, star constraints, bound subjects, wildcards and keyed parent probes all take every subject.
  • The keyed parent index from the base branch carries this: one index per parent and join columns, shared by every map that references it, holding every distinct subject of a key. A probe folds only the rows of the keys it probed and marks only those keys resolved.
  • The fused aggregate declines a parent key minting a second subject where its maps are single-valued (a GROUP BY key on a referenced subject; a branching star's semi-join membership). A key minting one subject still folds.
  • fluree materialize no longer refuses such sources. --allow-duplicate-parent-keys is accepted, has no effect, and prints a note. Rebuilding an override-built twin restores the edges it dropped.
  • Windows and budget. Scan windows were sized in child rows, so a 512K-row window over a parent with about nine subjects per key produced about 4.7M rows, charged only after they were built. A window is now bounded by the rows it will produce: an upper bound per child row comes from the parent lookup, and the window keeps what fits (at least one row) while the remainder waits, in scan order, for the next window. The bound is charged before anything is built, so a window the budget can't hold fails typed without allocating. Scans whose parent keys each map to one subject skip this entirely. A complete lookup releases spare capacity once built, and its per-key lists grow by half instead of doubling.

A graph-source GRAPH block streams its answer

This was pre-existing on main. Every FROM <graph-source> or GRAPH <graph-source> query drained each inner subplan into an uncharged buffer of per-row vectors, then copied the buffer into one output batch, so a large answer was held twice, invisible to the budget, before the first row left the operator. On the fan-out fixture below, that alone held peak live heap at 5.3 GB after the window fix. The operator now runs inner subplans one at a time and hands each batch on as it arrives, mapped to the output schema. The ?g join check and empty-schema rows behave as before. A data-bound GRAPH ?g naming an unreadable graph source still yields no rows: the queued work carries that allowance to where it opens.

/info: a virtual count is exact or null

A class or property count for a graph source now means the exact number a native ledger loaded with the mapping's triples would report. Where table metadata cannot prove it, count is null, with count-upper-bound when a bound is provable. A count is exact only when all of these hold:

  • each contributing map reads its whole table (no row filter) under a row count that is not a merge-on-read bound;
  • each map mints one distinct subject per row (a subject built from a key, no subject column nullable);
  • for a property, also: an object that is never null, and one value of the property per row;
  • the maps provably mint disjoint subjects.

A reference is never exact, since a child key may match no parent. It is bounded by the child's rows when one join value matches at most one parent subject, and unbounded when it can fan out. "Never null" means required in the schema, trusted for format version 2 or older. A Direct (--table-location) source now reports table row counts too, from each table's metadata file. The MCP data-model markdown shows a count that is not exact as "at most N" or "not counted" instead of 0.

Filtered logical tables

The restricted Iceberg rr:sqlQuery from #2309 composes with set semantics. A key declared next to the query holds for the rows the filter keeps, even when the whole table repeats the column across versions:

rr:logicalTable [
  rr:sqlQuery "SELECT * FROM customers_history WHERE is_current = 1" ;
  f:key ( "customer_id" )
] ;

Maps over it take the lanes that skip deduplication (the proven-distinct scan, the fused star, the fused COUNT); without the key the same map takes the deduplicating lanes. A key over a column the select list leaves out is refused when the source is mapped. The table's identifier fields hold for its filtered rows too, when the query selects them. The key, row-count and file-count lookups resolve a query's alias to its table, as the scan does.

The f:key vocabulary

f:key (https://ns.flur.ee/db#key) on an rr:logicalTable node: an rdf:List of one or more column-name strings. A composite key is one list; repeat f:key for alternative keys. It means that no two rows of the logical table (after its filter) with no NULL in the key columns agree on all of them. It applies to every triples map over the same rr:tableName, and on an rr:sqlQuery to the query's rows only.

rr:logicalTable [ rr:tableName "sales.customers_current" ; f:key ( "customer_id" ) ] ;

Validation fails closed:

  • At mapping load. Refused: an f:key that is not a list, an empty list, an item that is not a plain string, a column named twice in one key, f:key anywhere but on a logical table, and any other f: term on a logical table (so a misspelled f:keys cannot leave a table silently keyless).
  • At query time. A declared key naming a column the queried table lacks (casing included), or a column whose values cannot identify a row, refuses the query: floating point (NaN is unequal to itself), nested, a type the reader does not decode, or, on a SQL source, a timestamp finer than the microsecond. Over Iceberg that is 400 err:db/InvalidQuery.
  • Dry-run. POST /iceberg/r2rml/validate reports the same columns before the mapping is saved.

RML-LV's rml:PrimaryKeyAnnotation is not accepted for now. A mapping that declares no key keeps its serialization and its twin's mapping_hash (pinned by a test over four existing mappings).

Docs: graph-sources/r2rml.md ("Declaring a Table's Keys"), graph-sources/sql.md ("Repeated rows and subject keys"), graph-sources/iceberg.md, cli/sql.md, cli/materialize.md, api/endpoints.md, operations/admin-and-health.md.

Design

  • One question, one place. fluree-db-r2rml::mapping::uniqueness answers "can two rows of this map mint the same triple?" for every lane: TableKeys (declared ∪ source-reported), TriplesMap::subject_unique_under, emits_distinct_per_row / emits_distinct_triples_per_row, and subjects_provably_disjoint (moved here from the query rewrite, which re-exports it).
  • One way to get keys. R2rmlTableProvider::table_keys reports a source's own keys (the default reports none, which is always correct). fluree_db_query::r2rml::effective_table_keys unites them with the declared ones and is the only path a lane uses, so the schema check always runs before a declaration is trusted.
  • Dedupe lives in the query operators and the SQL statement only, never in scan_for_materialize_stream, emit_row_terms or MaterializeStats. Callers that stream raw rows through those seams keep seeing every row.
  • Streaming, first-seen. No lane blocks on deduplication, so LIMIT/OFFSET without ORDER BY costs what it did.
  • Key lookups cost no extra resolution. A query resolves each Iceberg table once (FlureeR2rmlProvider reuses a resolution under the same snapshot pin for up to 10 s) and each source's compiled mapping once per query session.
  • Which maps deduplicate is decided before any scan opens, so the top-k, the star fusion and the fold all read the same decision.

Measurements

All on shared machines unless noted. Each mitigation was measured against the commit before it. The figures below are the final state, with "before" as the base branch. Release builds, interleaved runs, warm medians.

Keyless 9M-row history table (1M keys × 9 versions)

The "before" answers were wrong. With a declared key, every shape below is unchanged against the base: −1.0% to +1.1% instructions, within the base's own spread.

shape before (bag answer) after (set answer) lane
COUNT(?n) { ?s :name ?n } 0.14 s (9,000,000) 0.49 s, RSS 699 MiB (1,300,219) fused fold, dedupe set 52 MB
COUNT(?s) { ?s a :C } 0.4 ms (manifest, 9,000,000) 0.25 s, RSS 386 MiB (1,000,000) fused fold
GROUP BY ?city count 0.22 s 0.63 s fused fold
?s :name ?n, full drain 8.1 s about 4.8 s (fewer rows out) scan, dedupe set 69 MB
same-subject star 11.5 s about 22 s, RSS 2.8 GB separate scans + join
?s :name ?n LIMIT 25 unchanged unchanged scan

Before the compact encoding and the arena, the scan's set for ?s :name ?n held 285 B per solution (371 MB). It now holds about 53 B (69 MB). The generic pipeline, which the fold replaces for the aggregates above, took 4.7 s for the COUNT.

Keyless 9M-row table whose rows are unique

This is the cost of not declaring a key that holds; with the key the numbers equal the base.

shape before after, no key
COUNT 0.14 s, 648 MiB 1.06 s, RSS 1,059 MiB (set 352 MB charged, 394 MB peak)
class COUNT 0.5 ms 0.9 s
GROUP BY 0.22 s 1.25 s
full drain not measured 8.7 s (set 403 MB charged)

Key checks on proven shapes

  • Iceberg: one table-key fetch per table per query, +0.8% instructions on a resolve-heavy probe. Keyed class COUNT, COUNT and LIMIT 25 are within noise (+0.05%).
  • SQL lane, probe-verified source, statements byte-identical to the base (µs, min / median of 15 per-run medians):
shape base this PR
pattern 107 / 117 110 / 116
FK join 148 / 157 142 / 148
count 110 / 120 108 / 116

Fan-out

  • 1M-row child whose keys match about 9 parent subjects each (9M edges), window cut and GRAPH streaming together: peak live heap 5,306 → 1,518 MiB for COUNT and full drain, 1,543 → 1,314 MiB for LIMIT 25. Instructions equal or lower. Under a 2 GiB budget the COUNT now answers; before, it overshot the budget by about 0.5 GB and failed.
  • 6M-row child over a 9M-row parent whose key repeats with one subject per key: whole-parent joins use the same CPU (82.7 vs 82.4 s; 96.1 vs 95.1 s) and RSS (1.80 vs 1.77 GB on the filtered join). The keyed shapes (VALUES, LIMIT 5) are unchanged (min 8.6 vs 8.5 ms, 10.3 vs 9.7 ms).
  • The fan-out figures come from a loaded machine, so they are peak live heap (tracking allocator), instructions retired, and CPU. Wall time is not reported.

/info

A Direct source reads each table's metadata file, about 1 ms per call on local storage, under the existing count budget.

Tests

  • it_r2rml_set_scan: every shape against a native ledger holding the triples the sets.* fixtures define, on SPARQL and JSON-LD, fast paths on and off. Covered: predicates, a class over one and two maps, a projected type, wildcards, stars and star constants, OPTIONAL, joins, VALUES, a UNION whose input rows repeat, DISTINCT, COUNT/SUM/GROUP BY, LIMIT 1..n, a crawl with a folded constant, top-k over keyless and keyed maps, and two keyed maps minting one subject. Keyed maps keep every existing plan, pinned by routing stamps and table-scan counts.
  • it_r2rml_ref_fanout: every fan-out shape on both surfaces, fast paths on and off and through the twin, against a native ledger (new fixture sets.parents_dup), with fused-aggregate stamps pinned both ways and windows of two produced rows.
  • it_sql_set_semantics: the SQL lane, its per-scan fallback and the Iceberg lanes over the same rows against a native ledger, on both surfaces. Proven-key statements are pinned byte for byte, the lane trusts only what the probe verified, and a declared key the table cannot hold refuses. Live-bridge variants run in CI against SQLite, Postgres and MySQL. it_sql_pushdown_lane: six union-entity goldens now carry DISTINCT; every other golden is unchanged.
  • it_iceberg_filtered_logical_table: a keyed filtered map serves the non-deduplicating lanes and the keyless one the deduplicating lanes, both against a native oracle; a key the query does not select is refused at registration.
  • it_graph_scope_streams: GRAPH <g> over a native named graph and FROM over an Iceberg source arrive in several batches no larger than the batch size, with the full answer. Both fail on the buffered operator.
  • it_iceberg_local_fs, it_iceberg_policy: each top-k shape over a keyless twin of its keyed source reads every file. The view-policy top-k guard was vacuous at the base (an untyped score never pruned) and now prunes.
  • Units: f:key compile refusals and schema checks, template injectivity, the compact encoding's exactness, ArenaSet and ChargedTable charges (including a growth the budget cannot hold), raw fold keys (a NULL apart from 0), windows that never exceed their size under fan-out, a fan-out the budget cannot hold failing typed before it is materialized.
  • Tests that exercise fusion mechanics over tables whose rows are unique now declare that key (it_fused_aggregate_routing, it_graph_source_r2rml, it_r2rml_untyped_columns, it_delta_differential, which also gains a keyless twin).
  • Revert checks at e6d9d89, one mutation per fix reverting its load-bearing hunk, each failing an assertion in the named tests:
    • top-k declining over rows that can repeat a solution: it_r2rml_set_scan::a_top_k_counts_triples_not_rows, it_iceberg_local_fs::a_top_k_over_a_keyless_map_reads_every_file;
    • cross-map star fusion only when the maps' subjects are apart or alike: it_r2rml_set_scan::a_star_over_a_subject_two_maps_mint_pairs_their_rows, star_two_covering_maps_fuse_only_when_apart_or_alike;
    • fused-aggregate fold keys: NULL encoded as the default value (a_raw_key_tags_null_apart_from_the_default), validity columns from the old field (validity_columns_come_from_the_subject_template), the builder not recording a subject template's columns (the_builder_records_a_subject_templates_columns);
    • fan-out keeping only a key's first parent subject: it_r2rml_ref_fanout::a_referencing_map_joins_every_parent_its_key_matches, it_graph_source_r2rml::materialize_emits_an_edge_to_every_parent_a_duplicate_key_matches;
    • a window cut by produced rows dropping its tail: it_r2rml_ref_fanout::windows_cut_by_produced_rows_keep_every_answer.
  • Gates at 36eefdc (the merges after it bring only the base's docs commit and test-capture fix), on a quiet dedicated 32-vCPU cloud machine with CI's environment: fmt (workspace and testsuite-sparql), cargo clippy --all --all-features --all-targets --locked -- -D warnings, the wasm32 fluree-db-api and parse lanes, cargo check --workspace --all-targets, and fluree-db-server with no default features. Tests: fluree-db-r2rml 219, fluree-db-iceberg 536, fluree-db-query 1872 and fluree-db-delta 86 (each --all-features); fluree-db-api with iceberg,native: lib 1243, grp_graphsource 282, grp_query_sparql 559, it_graph_source_r2rml 69 (two keep-min materialize tests from the base become one edge-to-every-parent test), it_iceberg_local_fs 51, it_iceberg_policy 15, it_r2rml_set_scan 8, it_r2rml_ref_fanout 4, it_iceberg_filtered_logical_table 7, it_fused_aggregate_routing 1; with sql,native: it_sql_set_semantics 9, it_sql_graph_source 6, it_sql_pushdown_lane 21, it_r2rml_untyped_columns 2; with delta,native: it_delta_local_fs 16, it_delta_differential 3; the W3C suite 85. No failures. Only the merge tips were gated, not each commit. Not run there: CI's SQL live-bridge differential job, the Python wheel, the wasm browser and Node smoke tests, and macOS. A later commit moves one test's log capture onto fluree_test_support::scoped_default, which the workspace harness check (harness_coverage, run by CI and not in the list above) requires.

Breaking changes (for embedders)

Answers

  • Keyless maps return distinct triples. Counts and aggregates over a map whose subject no key proves unique can drop, and fused, manifest or Delta-log COUNTs over such maps read the table. ORDER BY … LIMIT over such a map reads every file. Declare f:key on the logical table to keep the previous plans where the table's rows are unique.
  • Same-subject stars over a subject that spans rows, or that two maps can both mint, return each subject's cross product of objects, so there can be more rows than before.
  • Fan-out. A referencing object map over a non-unique parent key that mints more than one subject gives one row per subject, and a bound object matching a non-smallest subject now answers. Fused aggregates over such keys fall back to the generic pipeline.
  • SQL sources. Statements over sources registered with allow_duplicate_subjects, or over tables whose probed key is not within a map's subject columns, now carry DISTINCT (or decline), and their answers lose repeated solutions. Six union-entity statements over maps sharing a subject template gain DISTINCT. allow_duplicate_subjects skips the probe. Stored SQL configs gain verified_subject_keys; a record without it trusts the probe keys of unflagged tables.
  • Refusals. A mapping with a malformed f:key, or with any other f: term on a logical table, no longer compiles. A declared key the table cannot hold refuses the query.
  • Memory budget. Deduplication sets and each fan-out window's upper bound are charged before they allocate. A query close to its budget can now fail with MemoryBudgetExceeded where it used to overshoot and sometimes finish. Scans over proven maps with unique parent keys are unaffected.
  • Batches. QueryResult::batches for a query that reads a graph source through FROM or GRAPH can now hold several batches, each at most the batch size, where it used to hold one batch with the whole answer. Callers that read only batches[0] must iterate. Rows and order are unchanged.

/info

  • Virtual class and property counts that are not provably exact are count: null, with count-upper-bound where one is provable. Consumers that showed the row count must read count-upper-bound. A count that is unknown for one contributing table leaves the whole count null rather than a partial sum.
  • PropertyInfo::ref_classes is now BTreeMap<String, Option<i64>>. A virtual reference's entry used to read 0 when unknown; it is now null, with a new additive ref-classes-upper-bound map. Native entries are unchanged. A struct literal must set ref_classes_upper_bound.
  • VirtualSourceMeta gains table_columns (VirtualTableColumns is new); HashMap::new() keeps the old inputs, with every virtual count then null.
  • /info for a Direct source reads each table's metadata file (about 1 ms per call; FLUREE_ICEBERG_INFO_COUNT_BUDGET_MS=0 turns it off).

Rust API

  • rewrite_patterns_for_r2rml takes a &TableKeyEvidence; callers should use the async rewrite_patterns_for_r2rml_source, which fetches the table keys its fusion decisions need.

  • TriplesMap gains a public declared_keys: TableKeys; a struct literal must set it (TableKeys::none()). R2rmlTableProvider::table_keys is new and defaults to no keys.

  • fluree_db_r2rml::materialize::parent_key_insert_keep_min is removed. Use parent_key_insert(map, key, subject) -> ParentKeyInsert over a HashMap<Vec<String>, ParentSubjects>; ParentSubjects::as_slice() gives a key's sorted distinct subjects (the old pick is as_slice()[0]).

  • emit_row_terms / emit_row / emit_batch may call TripleObserver::observe more than once per referencing object map per row, once per distinct parent subject. MaterializeStats::ref_triples and ref_edges count edges, not rows. Nothing in these seams deduplicates.

  • MaterializeStats::dup_parent_keys and ParentIndexSet::dup_parent_keys() count the parent keys that fan out (informational); nothing declines on them.

  • materialize::drive_virtual_import drops its allow_duplicate_parent_keys: bool parameter. ImportBuilder::allow_duplicate_parent_keys is deprecated and does nothing. MaterializeError::DuplicateParentKeys is no longer returned (kept so matches compile).

  • WatermarkStamp::dup_parent_keys is empty for every twin built now; stamps that carry dupParentKeys still parse.

  • Additive: ParentSubjects::heap_bytes() and ParentSubjects::shrink_to_fit().

  • Unchanged: ParentIndexSet::new, is_parent, index_batch, emit_row_terms's signature, MaterializeStats: Default and its fields, TripleObserver::observe, TmEmitContext::new.

  • DiagCode gains KeylessMap. An exhaustive match must handle it, and a client that deserializes diagnostics into an older enum will reject "keylessMap".

  • R2rmlCreateResult, DeltaCreateResult, SqlCreateResult and SqlCheckResult gain diagnostics: Vec<Diagnostic>; a struct literal must set it.

  • TriplesMap::subject_key_proof is the single reading behind subject_unique_under; the keylessMap advisory reads it too, so the advisory cannot disagree with the lane a query takes.

Python

  • map_* raise a UserWarning per keyless map (see below). Delta tables report no key of their own, so most Delta mappings without f:key will warn.

Twins

A mapping that declares no key keeps its mapping_hash, so existing twins stay current. A twin built with --allow-duplicate-parent-keys dropped edges; rebuilding it restores them.

Release notes

  • /info counts for graph sources are exact or null. A virtual class or property count is now the number a native ledger loaded with the mapping's triples would report, or null when table metadata cannot prove it. Most counts over maps without a declared key are null, where they used to hold the tables' row counts. Clients that display counts must read count, fall back to count-upper-bound ("at most N"), and show neither as unknown, never 0; read ref-classes / ref-classes-upper-bound the same way.
  • Mapping a source reports keyless maps. POST /iceberg/map, /delta/map and /sql/map, sql check, the validate dry runs, the generators and the CLI return a keylessMap advisory (in a new diagnostics field on the map responses; an advisory: line on the CLI) for each triples map that no key proves subject-unique. Queries over such a map deduplicate and are slower; declare f:key on its logical table where the subject's columns identify a row. The graph-source troubleshooting docs ("A map with no key (most likely after an upgrade)") cover the symptom, how to see which lane a query took (r2rml_scan_proven_distinct), and the fix.

Follow-ups

Not covered here: engine-side deduplication for SQL shapes where no DISTINCT is exact (they decline to the per-scan lane), a star self-join on the SQL lane, joins over non-injective templates, Iceberg format-version-4 table constraints, and RML-LV key annotations. #2223 (the cost of selectDistinct ?s … LIMIT n) is related and unchanged.

Stacking

aaj3f added 30 commits November 3, 2026 01:41
…hen a map's rows cannot repeat a triple

An R2RML graph source answers over a set of triples, while its tables are bags
of rows that can mint the same triple more than once. Deciding where a lane
must remove duplicates needs one shared answer to "can two rows of this map
mint the same triple?", and evidence about the table's keys to answer it.

f:key (https://ns.flur.ee/db#key) on an rr:logicalTable node declares a key:
an rdf:List of one or more column names, repeatable for alternative keys.
The extractor compiles it onto TriplesMap::declared_keys, a TableKeys that
serializes only when non-empty, so every mapping that declares no key keeps
its serialization and its twin's mapping_hash (pinned by a test over four
existing mappings, hashes taken before this change). Refused at compile: an
f:key that is not a list, an empty list, an item that is not a plain string,
a column named twice in one key, an unknown f: term on a logical table, and
f:key anywhere but on a triples map's logical table.

fluree-db-r2rml::mapping::uniqueness holds the shared predicates:
- TableKeys: normalized keys (sorted, deduplicated, empty keys dropped),
  union of declared and source-reported (with_reported);
  CompiledR2rmlMapping::declared_keys(table) unites every map over a table.
- TriplesMap::subject_unique_under(&TableKeys): an rr:column subject over a
  key column, or a template subject whose columns hold a key and whose
  expansion is injective (template_is_injective: every separator between
  adjacent placeholders holds a character the IRI escape always encodes and
  that is not '%'; '-', '.', ':', ';' and the other characters the escape
  passes through do not separate). Constant and sourceless subjects never.
- TriplesMap::emits_distinct_per_row(predicate) and
  emits_distinct_triples_per_row(): false when two object sources for one
  predicate can collide (two POMs, a computed predicate, rr:class beside an
  explicit rdf:type naming the same class).
- TriplesMap::subjects_provably_disjoint(other), with constant_prefix and
  templates_provably_disjoint moved here from the query rewrite (which now
  re-exports them).

R2rmlTableProvider::table_keys(gs, table, as_of_t) reports a source's own
keys; the default reports none, which is always correct.

Fixtures for set semantics live in their own namespace, sets.*, written by a
block in scripts/local/write_local_iceberg_table.py: customers_history (no
key covers customer_id; same-value and changed-value versions straddling two
files; a NULL city; a NULL customer_id), customers_current (customer_id an
Iceberg identifier field), and orders (references the history table; one
exact duplicate row across two files; a dangling and a NULL reference).

State: interface done. Next: schema-dependent key validation (absent column,
float/double/nested), the Iceberg provider's table_keys (identifier fields,
format version <= 3 only), docs.
… and refuses a declared key its table cannot hold

R2rmlTableProvider::table_keys for an Iceberg table reports the pinned
snapshot's identifier fields, under current names, as one key: only through
format version 3 (a version 4 reader must ignore them), and only when every
field is a top-level column whose values can identify a row. Before
reporting, it checks every key the mapping declares on the table (f:key)
against the same schema and refuses the query on a column the table lacks
(casing included) or one whose values cannot identify a row: floating point
(NaN is unequal to itself, so a column declared unique can hold two NaNs that
mint one subject), nested, or a type the reader does not decode. A key the
source reports with such a column is dropped instead, since it is not the
mapping author's to fix. SQL and Delta sources report no key.

fluree_db_query::r2rml::effective_table_keys(provider, mapping, gs, table,
as_of_t) is the one way a lane obtains keys for a uniqueness decision:
declared keys united with the reported ones, through table_keys, so the
schema check always runs before a declaration is trusted.

TableKeys::check_columns / retain_usable and usable_in_key carry the column
rule. The validate dry-run reports declared key columns the way a query
checks them: ColumnNotFound, CasingMismatch, or NonKeyTypeSkipped, each an
error, once per table and column.

State: (a) interface f488eee, (b) + (c) here. Next: mutation checks, clippy
with iceberg/sql/delta, docs (docs/graph-sources/r2rml.md f:key).
What a key means and promises, when it makes a map's subjects unique (an
rr:column over a key column, or a template that covers a key and keeps its
values apart), what is deduplicated whatever the keys say, Iceberg
identifier fields as keys through format version 3, and the refusals at
mapping load, at query time, and in the validate dry-run's diagnostics.
The local-fs suite's module doc lists the sets.* tables beside the silver
ones and how to regenerate them: their own warehouse directory
(/tmp/fluree-local-iceberg-sets, the path their metadata records), since the
script rewrites its whole warehouse and every run mints new file names and
snapshot ids, then a copy of only the sets tables over the old ones.
An R2RML graph source answers over the set of triples its mapping defines
(R2RML §11), while a table is a bag of rows that can mint one triple more
than once: a history table's versions of one customer, an exact duplicate
row, two tables minting the same subject and class.

it_r2rml_set_scan checks every shape against a native ledger holding the
triples the mapping defines over the sets.* fixtures, computed in the test
from the fixture rows, on SPARQL and JSON-LD, with fast paths on and off:
predicates, a class over one and two maps, a projected type, a wildcard and
a bound subject's wildcard, a same-subject star (each subject's cross
product of objects) and a star constant, OPTIONAL, joins, VALUES and a
UNION whose input rows repeat (each copy keeps its matches), DISTINCT,
COUNT and GROUP BY, LIMIT 1..n, and a subgraph crawl with a folded
constant. Maps keyed with f:key (or an Iceberg identifier field) must keep
every existing plan, pinned by routing stamps and table-scan counts; a
declared key the table cannot hold refuses the query on both surfaces.

Most of these fail at this commit, as the answers they pin are what the
following commits deliver: today a predicate over versions repeats triples
(10 rows for 7), a class over two maps counts a subject per row (16 for 6),
a fused star pairs objects within each row, a star constant matches only
its own row, and COUNT counts rows (10 for 7). The crawl and DISTINCT cases
already pass.
… cannot repeat one

The scan turned each table row into solutions, so a pattern over rows that
mint the same triple (a history table's versions, an exact duplicate row,
two tables minting one subject) answered over a bag of triples.

r2rml::set_semantics holds what a scan asks before it trusts a row per
solution:
- TableKeyEvidence: each table's keys, fetched once per table through
  effective_table_keys (the mapping's f:key declarations united with what
  the source reports; the source checks a declaration against the table and
  refuses the query on one it cannot hold);
- emits_distinct_for(pattern, map): whether one row of the map never yields
  the same solution of the pattern twice, read off the solution shapes the
  scan materializes;
- SeenSolutions: the streaming, first-seen set of solutions a pass emitted,
  exact (solutions compared as terms, never by hash alone), charged to the
  query's memory budget as it grows and released when the pass ends or the
  LIMIT budget is met; a set past the budget fails the query with the typed
  MemoryBudgetExceeded.

Each scan pass fetches the keys of every map it reads (so a declared key
the table cannot hold always refuses) and checks a map's solutions against
the pass's set unless fast paths are on, its subject is unique under its
table's keys, its rows emit each solution once, and no other map in the
pass can mint its subjects. A solution is remembered only once it joins
an input row, and goes to every input row it joins, so the set holds what
reaches the output and repeated input rows keep their copies. Emission
order is scan order and a LIMIT still stops the scan early. Stamp
r2rml_scan_proven_distinct: proceed when nothing is deduplicated; with fast
paths disabled every scan deduplicates, so the differential lane relies on
no key. A debug event reports each set's size when it is released.

r3b_scan_windows_release_no_false_abort declares its key so it measures
window release alone; a_dedupe_set_past_the_budget_aborts_typed is its
keyless twin.

The star, crawl-fold and fused COUNT cases of it_r2rml_set_scan still fail
here; the next commit makes them pass.
…ts span rows, and so do fused folds

Two lanes read a solution from one row and so answered wrongly over a map
whose subject spans rows.

The rewrite fuses a same-subject star into one scan that reads every member
from one row: where several rows mint a subject, the graph pairs each object
of one member with each object of another across those rows and matches a
constant member on any of them, while the fused scan pairs and matches
within each row alone. The crawl's fold of a constant onto its wildcard
keeps a wildcard row only when that row holds the constant. Both now fuse
only when every map covering their predicates is subject-unique
(one_row_per_subject); otherwise the members stay separate scans the engine
joins on the subject. rewrite_patterns_for_r2rml takes the table-key
evidence; an unanswered table is recorded, and
rewrite_patterns_for_r2rml_source (the GRAPH operator, both sites, and the
fused aggregate) fetches the recorded tables' keys and rewrites again, so a
table no fusion asks about is never fetched. Without a mapping no members
fuse.

The fused aggregate folds table rows, and its manifest COUNT counts them:
both now run only when rows_are_solutions holds, every candidate map of
every rewritten pattern being subject-unique, emitting each solution once
per row, and pairwise disjoint from the pattern's other candidates;
otherwise the generic pipeline answers. The Delta log count is the same
shortcut and declines the same way.

Tests that exercise fusion mechanics over tables whose rows are unique now
say so: cfg(test) evidence and mappings keyed by each map's subject columns
for the rewrite and fused-aggregate unit tests; f:key declared where the
data has the key in it_fused_aggregate_routing (silver.people id), the scan-
plan guards of it_graph_source_r2rml (surrogate keys), it_r2rml_untyped_
columns (cells id) and it_delta_differential (partitioned id), which also
gains a keyless twin whose bare count must read its rows. New rewrite unit
tests pin both declines and the evidence recording. it_r2rml_set_scan passes.
…ck costs no extra resolution

Every touch of a table through the provider (each scan, count, file count,
and now the key check) re-resolved it: graph-source lookup, config parse,
local path checks, and an atomic write of the catalog pointer to the disk
cache. A keyed class COUNT paid one more resolution for its key check than
before set semantics (~300 us, measured with a per-call probe; the pointer
write dominates a sampled profile).

FlureeR2rmlProvider now keeps the tables it resolved, keyed by graph source
and table: a later touch under the same snapshot pin within 10 s reuses the
resolution. Within one query every touch reads one snapshot anyway (the pin
contract). The window keeps a provider that outlives a query (a bulk build)
resolving afresh, and stays inside the session's refresh margin for expiring
vended credentials. recent_context_serves is unit-tested (pin mismatch and
window).

Probe (fresh provider per iteration, 5000 iterations, instructions retired):
table_row_count alone 3.81M/call; table_keys then table_row_count 3.84M/call
(+0.8%). Harness (40 queries): keyed class COUNT 0.369G base vs 0.404G
branch per process (sub-1M/query deltas are within worker-thread noise),
COUNT +0.05%, LIMIT 25 +0.05%.

Tests: fluree-db-api lib graph_source 401, it_r2rml_set_scan 5,
it_iceberg_local_fs 33, it_iceberg_policy 15, it_graph_source_r2rml 68,
it_fused_aggregate_routing 1, it_iceberg_warehouse_root 1, grp_graphsource
256. Clippy clean on the lib and my targets (it_iceberg_local_fs has a
needless_borrow lint from 70d3777, not mine).
…t exact encoding

A scan's set of seen solutions held each as its terms: a slot per binding
plus the IRI and string text kept alive, ~285 bytes for a subject and a
name. It now holds a byte encoding exact under the engine's term equality:
each variable, then an IRI's text (without a prefix every subject the pass's
maps mint starts with, tagged so the forms never collide), a string or
boolean literal with its datatype or language tag (numbered per set), an
integer under an integer datatype, or unbound; lengths are prefixed. A
solution holding a term compared by value across representations (decimal,
double, temporal: 1 equals 1.0) stays as its terms. Whether a solution
encodes depends only on which equality classes its terms are in, so two
equal solutions always take the same form.

Raw column values were not used: they are not exact for objects ("01" and
"1" under xsd:integer are one term, as are 1.0 and 1.00).

Measured on the 9M-row history table, 1M keys x 9 versions, before (the previous commit)
vs after, keyless map, instructions per process (4 queries), warm medians:
?s ex:name ?n set 285.2 -> 58.2 B/entry (1,300,219 entries, 371 -> 76 MB);
?s a C set 177.9 -> 41.9 B/entry. COUNT 377.2G -> 366.1G instr, ~5.8 -> ~4.9
s, RSS 2012 -> 1749 MiB; full drain 374.2G -> 364.0G, ~5.7 -> ~4.8 s, RSS
1996 -> 1719 MiB; class COUNT 258.5G -> 257.6G, RSS 985 -> 866 MiB; star
1177.5G -> 1152.4G, RSS 3879 -> 2819 MiB. Load 13-23.

Tests: encoding exactness units (prefix strip vs a bare suffix, length
prefixes, datatype and language, variables, integer vs string "1", decimal
1 vs 1.0 kept as one solution), fluree-db-query r2rml 209, it_r2rml_set_scan
5, it_iceberg_local_fs 33, it_iceberg_policy 15, it_graph_source_r2rml 68,
grp_graphsource 256.
… once instead of declining

Since set semantics, COUNT/SUM/AVG/GROUP BY over a map whose rows can repeat
a solution declined the fused fold and ran the generic pipeline, which
materializes every row's terms before removing repeats. The fold now admits
one such shape: a single pattern over one candidate map whose subject is an
injective IRI template, with an object (if bound) read from a column whose
coercion keeps distinct values distinct (RawTerm: rendered text, an integer
coercion of an integer column, a decimal coercion of an integer or decimal
column, a date, a boolean). It folds a row only if its solution (the raw
bytes of the subject template's columns and the object column; integers
one value whether stored in 32 or 64 bits, strings length-prefixed) is new,
charging each remembered solution to the query budget. A batch whose column
type has no exact raw encoding (floating point, timestamps, a string under
an integer coercion) hands the query to the generic pipeline, as an i128
overflow does. Folded constants from other patterns, joins, two candidate
maps, and other object maps still decline. The manifest COUNT stays keyed
only. Stamp fused_r2rml_aggregate_dedupe.

Measured (release, interleaved, warm medians; instructions per 4-query
process), 9M-row history table, 1M keys x 9 versions, no key:
- COUNT(?n) {?s :name ?n}: base 0.14 s (9,000,000, wrong); generic 4.7 s,
  364.8G instr, RSS 1874 MiB; fold dedupe 0.6 s, 45.6G instr, RSS 747 MiB
  (1,300,219; set 70.7 MB charged, 54 B/entry).
- COUNT(?s) {?s a :C}: base 0.4 ms (manifest, wrong); generic 3.9 s; fold
  0.25 s, RSS 386 MiB (1,000,000; 41 B/entry).
- GROUP BY city: base 0.22 s (wrong counts); generic 5.2 s; fold 0.63 s.
9M-row table whose rows are unique but declare no key (keyed numbers equal
base): COUNT base 0.14 s / 648 MiB, fold 1.2 s / 1.57 GiB (9M solutions,
485 MB charged), generic 9.0 s / 5.3 GiB; class COUNT base 0.5 ms, fold
0.9 s / 1.05 GiB, generic 5.6 s; GROUP BY base 0.22 s, fold 1.25 s, generic
8.4 s. Answers equal across fold, generic and native everywhere.

Tests: it_r2rml_set_scan keyless COUNT, class COUNT, GROUP BY, and SUM over
a decimal with a duplicate row now fused + dedupe (MustFire), keyed stays
dedupe MustNotFire; mutation (never skip a repeated solution) fails all 5
(SUM 68.75 vs native 48.75). Units: RawTerm exactness, raw encoding (32 vs
64-bit integers equal, length prefixes), fold_dedupe_plan admission.
Suites: fluree-db-query lib 1751, api iceberg suites, delta and sql suites
all pass; clippy clean.
…rowth included

Both sets (a scan pass's seen solutions, a fused fold's seen keys) charged a
per-entry floor: 32 bytes plus the key. A hash table holds more: every
bucket's slot and control byte at a 7/8 load factor rounded to a power of
two, and while it grows, the old buckets and the new ones at once. On a
9M-row table the floor charged about half of what the set held.

ChargedTable (set_semantics) holds both: it charges the table's allocation
as hashbrown reports it plus each key's heap allocation in 16-byte size
classes; before a growth it charges the new allocation on top of the old one
and checks the budget, so a growth the budget cannot hold fails typed before
it allocates, then settles to the new allocation. Its release event reports
the peak.

9M-row table, unique rows, no key, COUNT (fold set), medians of 5 rounds:
charged at release 485 MB -> 573 MB, peak charged 663 MB (not tracked
before); RSS over the keyed run ~933 MB, peak footprint over it ~840 MB. The
charge now covers 61% (final) to 79% (peak vs peak footprint) of the measured
memory, against ~52% before; the rest is allocator overhead on 9M small key
allocations and old buckets the allocator retains. Scan set on the same
table (drain): 529 -> 707 MB at release, 864 MB peak. History table (1.3M
solutions): 70.7 -> 77.3 MB, peak 82.8 MB. Time and instructions unchanged
within noise (COUNT 50.9G vs 51.4G instr).

Tests: ChargedTable charges exactly its reported allocation and counts both
tables during growth; a growth whose transient the budget cannot hold fails
MemoryBudgetExceeded though the grown table alone would fit; the SeenSolutions
and operator budget-exceed tests still pass. fluree-db-query lib 1753, api
iceberg suites pass; clippy clean.
A remembered key was its own heap allocation: a boxed byte slice per entry,
16 bytes of table slot for its pointer and length, and the allocator's
per-block overhead the budget could only estimate.

ArenaSet appends keys to chunks (4 KiB doubling to 16 MiB; a key never spans
two, and a new chunk copies nothing) and keeps one u64 per key in the table
(chunk, offset, length). Its charge is exactly what it holds: the table's
allocation as hashbrown reports it plus every chunk's capacity. A new chunk,
and a table growth with both tables live, are charged and the budget
checked before they allocate. A key over 1 MiB is not held: the fold then
hands the query to the generic pipeline, and the scan keeps the solution as
its terms (equal solutions encode to equal lengths, so one never splits
across the two). The fused fold's set and the scan set's encoded solutions
use it; solutions held as terms stay in the term table.

Measured (release, medians of 3 interleaved rounds against the previous
commit), 9M-row table whose rows are unique, no key:
- fold COUNT: charged 573.2 -> 352.3 MB at release, peak 662.7 -> 394.3 MB;
  RSS 1472 -> 1059 MiB (keyed run 554 MiB, so the set's real memory is
  ~530 MB, 74% charged at peak; the rest is mostly the previous table the
  allocator keeps after the last growth); 1.22 -> 1.06 s warm, 34.3G ->
  27.7G instructions.
- scan set (full drain): charged 707.4 -> 402.6 MB, peak 864.0 -> 427.8 MB;
  8.7 s vs 9.7 s warm.
9M-row history table, 1M keys x 9 versions: fold COUNT charged 77.3 ->
52.4 MB (peak 82.8 -> 61.9 MB), RSS 774 -> 699 MiB, 585 -> 490 ms; scan set
(drain) 94.0 -> 69.2 MB, peak 108.0 -> 69.2 MB.

Tests: an ArenaSet holds each key once (lengths part of identity), charges
exactly the table allocation plus chunk capacities, refuses a key over the
limit, and fails a growth the budget cannot hold typed before allocating.
fluree-db-query lib 1755, it_r2rml_set_scan and the api iceberg suites pass;
clippy clean.
…ey matches

A referencing object map whose parent join key is not unique resolved each
child row to one parent subject (the lexicographically smallest), on the
query path and in the twin builder alike. R2RML defines one triple per
joined parent row, and a graph is a set, so a child row links to every
distinct subject the matching parent rows mint: a key whose rows mint
different subjects fans out, and a key whose rows all mint one subject (the
versions of a history table) still gives one edge. Keep-min answered a bound
object that was not its key's smallest subject with no rows at all.

The parent lookup now maps a key to its distinct parent subjects
(ParentSubjects: sorted, never empty, one subject held inline so a unique
key costs what a single term did), filled through one insert the query
operator and the twin builder share. Every reader of a referencing object
map takes zero or more objects: scans, stars (a star of two fan-out members
is their cross product), constant objects and star constraints, bound
subjects, wildcards, and the keyed probes of a partial parent, which read
every row of each key they push.

The fused aggregate's single-valued parent maps (a GROUP BY key on a
referenced subject, and the semi-join membership of a branching star)
decline a key that mints a second subject, so they flip with the generic
path; a key minting one subject still folds. The dimension-chain map
already declined any duplicate key.

`fluree materialize` no longer refuses a source with duplicate parent keys:
it emits one edge per distinct parent subject. --allow-duplicate-parent-keys
is still accepted and does nothing, the builder method is deprecated, new
completion stamps never record dupParentKeys, and old ones still read.

The new it_r2rml_ref_fanout target checks every shape on SPARQL and JSON-LD,
with fast paths on and off and through the twin, against a native ledger
loaded with the triples the mapping defines, over a new fixture
(sets.parents_dup) whose join columns repeat. The mapping declares the
fixture's unique id as the table's key, so the fused aggregate may fold
over it at all.
it_sql_set_semantics (sql,native; own binary) runs the sets.* rows through a
fake SQL endpoint (hist-sql: History+Order maps; both-sql: History+Current;
registered with allow_duplicate_subjects so the registration probe does not
refuse them), the local Iceberg fixture (hist-ice, both-ice) and native
ledgers holding the mapped triples written out by hand (hist-native,
both-native), with SPARQL and JSON-LD twins for every case:

- the_sql_lane_answers_each_triple_once: every keyless shape (a pattern, a
  projection, a constant subject, a reference into a keyless parent and its
  entity, top-k, UNION branches, a class and a predicate over two maps,
  COUNT, SUM, GROUP BY, a grouped sub-select) answers each triple once, and
  a star or folded optional over a keyless subject declines;
- every_other_lane_answers_the_same_set: the per-scan and Iceberg lanes give
  the same answers;
- proven_keys_keep_the_statement_byte_for_byte: a probed or f:key source's
  statements are unchanged, a keyless source's gain DISTINCT (and COUNT over
  a DISTINCT derived table).

The lane cases fail until the next commit: today every keyless shape returns
rows, not triples (COUNT 10 for 7, SUM 68.75 for 48.75).
…n repeat one

The SQL graph-source lane lowered a block to one statement whose rows were
its solutions, so a table whose rows mint the same triple answered over a
bag.

- resolve_block fetches effective_table_keys for every table the block can
  reach (a refused declared key fails the query) and hands them to the
  lowering. The lowerer counts row-level constraints per table access
  (members, a column-derived class, a join on non-subject parent columns,
  folded optionals); two or more on an access whose map is not
  subject_unique_under its keys decline ("star over a subject its map does
  not prove unique"), as does a by-class policy predicate on such an access.
- Lowered gains rows_unique (every table access subject-unique; a union's
  resolutions unique and pairwise subjects_provably_disjoint), dedupe_exact
  (a binary string DISTINCT or no string output, equality-exact column
  classes, injective templates, literal templates only over one column,
  sub-select derived tables that are sets, no repeated VALUES row) and
  dedupes. lower_block: rows not unique and no DISTINCT above -> SELECT
  DISTINCT over every block variable's columns, or decline when that is not
  exact; a DISTINCT above keeps its single DISTINCT. UNION branches each
  dedupe and stay UNION ALL.
- Union entities whose resolutions can mint one subject tag rows by decoding
  class (the same term-map shape over the same slots) and the statement
  DISTINCTs; classes that decode apart must be provably disjoint, else the
  lane declines.
- Aggregates (SqlAggregateOperator, grouped sub-selects) over a deduplicating
  block read it as a SELECT DISTINCT derived table "s", columns renamed and
  output names kept; plain sub-selects over repeating rows re-lower over
  every variable and SELECT DISTINCT.
- SQL provider: SqlGsConfig.verified_subject_keys (additive); the
  registration probe records the composite key it verified per table (an
  unreachable endpoint records none); table_keys reports it unless the table
  is flagged, unverified, or the source allows duplicate subjects; a legacy
  record (field absent) trusts the probe keys of unflagged tables. Declared
  f:key columns are checked against the probed schema (absent or floating
  point refuses the query).
- The lowering's module doc states its set semantics.

Tests: it_sql_set_semantics pins the lane's answers (statements pinned),
proven keys keep today's statements byte for byte, the lane trusts only what
the probe verified (an unprobed table gets DISTINCT, a legacy record keeps
today's statement, check records the key), a declared key the table cannot
hold refuses on both surfaces, VALUES multiplicity and references into a
non-subject parent column hold, and a non-injective subject template over a
keyless map declines; every other lane answers the same set.
it_sql_pushdown_lane: six vertical-partition union-entity goldens now
DISTINCT with shared decoding tags; every other golden is unchanged.
docs/graph-sources/sql.md "Repeated rows and subject keys" replaces "Subject
keys must be unique": a SQL source answers over the set of triples, the
registration probe's verified key proves a map's subjects unique, and
allow_duplicate_subjects skips the probe and answers with set semantics.
Links follow in cli/sql.md and api/endpoints.md; the CLI, server and Python
help text say the same, and fluree sql check prints "not probed" for such a
source. Small clippy fixes in the lowering and the set-semantics test.
it_sql_set_semantics gains live_bridge_{sqlite,postgres,mysql}_answers_each_
triple_once: portable DDL seeds the sets rows into a live database, and the
SQL lane's rows are checked against the native ledger wherever the lane
fires (MySQL may decline a string DISTINCT, SQLite declines SUM over NUMERIC,
as in the pushdown suite). Wired into CI's bridge job.

The live pushdown suite's Word map declares f:key (id): tags reference words
on "word", so the probe's composite key (id, word) proves no map's subject
unique, and its string-join case would otherwise decline under set
semantics.
… session

Every schema probe the SQL lane runs, and now each reachable table's key
lookup, asked the provider for the compiled mapping, and each ask repeated
the nameservice lookup behind it (two object reads on a storage-backed
nameservice) before the mapping cache. The session memoizes it beside the
SQL-dispatch decision, so a query resolves each source's mapping once.

The SQL source's table_keys also stops reading the relation's schema when
the mapping declares no key, and reports the key the registration probe
verified as it stands. That trusts the probed key further than it holds: a
database keeps two timestamp(9) values apart that render one microsecond
term, so a key over such a column does not identify a term. The next commit
restores the check, and the one after moves it to the probe.

Measured (release, in-process fake endpoint, 5 interleaved rounds x 3 runs
x 300 queries, load ~16 on a shared 16-core box; min / median of the 15
per-run medians, microseconds), proven-unique shapes on a probe-verified
source whose statements are byte-identical to the base:
  pattern  base 107 / 117   branch 110 / 116
  fk-join  base 148 / 157   branch 142 / 148
  count    base 110 / 120   branch 108 / 116
Before the memo the branch measured +5..10 us per query (the added key
lookups).
…s no term

Restores the check of the probe-verified key against the relation's schema,
dropped in the previous commit: a database keeps timestamp(9) values apart
that render one microsecond term, so two rows can agree on the term while
the key tells them apart. A timestamp column of more than six fractional
digits, or of unreported precision, is unusable in a key: a declared one
refuses the query, a probed one is not reported. Pinned on both surfaces;
the f:key docs say so.
…ry query

The probe records a table's key only when every column can identify a term
(not floating point, not a timestamp finer than the microsecond or of
unreported precision), warning otherwise. A recorded key is reported without
reading the schema; the schema is read per query only to vet a declared key or
a legacy record's inferred key. Fixes the probe warning's broken string
continuation and its advice.
…its budget

A scan window was sized in child rows. Once a parent key can match several
subjects, each child row produces one row per subject, so a window of
512K child rows on a table whose keys match about nine parent subjects
produced about 4.7M rows. Those rows were charged to the memory budget only
after they were materialized, so a query the budget could not hold
allocated them first and then failed, or, with no budget, grew to several
GB.

A window is now bounded by the rows it produces. Where any parent index of
the scan fans out (it holds more subjects than keys, read whole or by
probes), each child row's output is bounded from the parent lookup the same
way materialize_row multiplies it out (ref objects per matched subject,
star members, projected classes). The window keeps the rows whose running
bound fits the window size, at least one, and puts the rest back, in scan
order, at the front of the pending queue for the next window. The kept
bound is charged before anything is materialized, so a window the budget
cannot hold, a single row's own fan-out included, fails with a typed
MemoryBudgetExceeded without allocating its rows. The ratio of produced to
child rows seen in the last window scales how many child rows the next
window pulls, so the cut leaves little behind. A scan whose parent keys
each map to one subject skips all of this and runs as before.

A complete parent lookup is read-only once built, so it releases the spare
capacity of each key's subject list, and a list grows by half rather than
doubling, which lowers the peak while the lookup is still being built. A
fan-out lookup still holds every distinct parent subject it can join, which
a correct answer needs; that memory is charged to the budget.

Tests: a unit test that no window produces more rows than its size under a
parent that fans out (read whole and probed, window sizes 1 to 100), with
the answer identical to the unwindowed one; a unit test that a fan-out the
budget cannot hold fails typed before it is materialized and that a larger
budget answers; and an integration test that every fan-out shape answers as
the native ledger does with windows of two produced rows.
… buffering the whole answer

The batched path GraphOperator takes for a graph source (every FROM or
GRAPH over an R2RML source) drained each inner subplan to completion into
a buffer of per-row vectors, charged none of it to the memory budget, and
then copied the buffer into a single output batch. A large answer was
therefore held twice at its peak, unaccounted, before the first row left
the operator.

The inner subplans now run one at a time from a work queue, and each inner
batch is mapped to the output schema and handed on as it arrives: no
buffer and no single giant batch. The ?g join check and rows of an empty
schema behave as before. When an inner subplan is rebuilt, the memory it
releases is the sum of what it recorded during the operator's own calls
into it, so the budget stays balanced across subplans.

Tests: a native named graph read through GRAPH <g> and a graph source read
through FROM both arrive in more than one batch, none larger than the batch
size, with the full answer, on SPARQL and JSON-LD. Both fail on the
buffered operator.
# Conflicts:
#	fluree-db-api/src/graph_source/r2rml.rs
#	fluree-db-iceberg/src/io/arrow_reader.rs
#	fluree-db-iceberg/src/io/send_parquet.rs
#	fluree-db-iceberg/src/scan/mod.rs
#	fluree-db-iceberg/src/scan/planner.rs
#	scripts/local/write_local_iceberg_table.py
…the rows its filter keeps

Merging the Iceberg row filter into set semantics left three provider
methods resolving a triples map's logical table by name: table_keys,
known_row_count and scan_file_counts passed an rr:sqlQuery alias to the
table loader, which the row filter makes an internal error, so every
query over a filtered map that asked for its keys failed. They resolve
through logical_scan now, as the scan and the COUNT shortcut do.

A key declared next to the query (f:key on the logical table) is checked
against the FROM table's schema and against the query's select list: a key
over a column the query does not select is refused at registration, and
again at query time. The table's Iceberg identifier fields hold for any
subset of its rows, so they are reported for a filtered logical table
too, when the query selects their columns. iceberg_validate checks a key
on a query the same way, against its FROM table and select list.

Tests: a keyed filtered map serves the lanes that skip deduplication
(proven-distinct scan, the fused star, the fused COUNT without its
deduplicating fold) and the same map without the key takes the
deduplicating ones, both equal to a native oracle on SPARQL and JSON-LD,
fast paths on and off; a keyed filtered map still refuses tracked
materialization; a key the query does not select is refused at
registration.

The row filter's paired manifest COUNT test assumed the shortcut is tried
for every unfiltered map. Under set semantics it is tried only for a map
whose rows are its subjects, so the test now declares the history map's
natural key, and checks the filtered decline on a keyed filtered map
(fired=false) beside the keyless one (never tried).

The SqlQueryPolicy and QueryTables variants that only the sql or delta
features construct no longer warn in builds without them.
…re one is provable

Under set semantics a virtual source's class and property counts are counts
of distinct subjects and triples, and a table's row count equals them only
when the metadata proves it. /info reported the row count for every map it
could, so a history table's class count was its number of versions. A count
now has one meaning, exact: where the metadata cannot prove it, count is
null, with count-upper-bound beside it when a bound is provable.

A map contributes its table's row count exactly when it reads the whole
table (no row filter) under a count that is not a merge-on-read bound, and
mints one distinct subject per row: its subject is unique under a key of its
logical table (f:key declared on it, or the table's identifier fields, each
restricted to the columns a query selects), and no subject column can be
null. A property needs, in addition, an object that cannot be null and a row
that never mints one (predicate, object) twice. Contributions sum exactly
only when the contributing maps provably mint disjoint subjects. Otherwise
the bound is the sum of the tables' row counts, when all are known. A
reference is never exact (a child key may match no parent row): it is
bounded by the child's rows when the parent's join key matches at most one
parent subject, and unbounded when it can fan out. ref-classes entries are
therefore null for a virtual reference, with ref-classes-upper-bound beside
them; a native ledger's are unchanged.

The facts come from the table metadata /info already loads: required columns
(trusted only through format version 2, since a version 3 column can be
added with a default older files do not store, and the reader reads an
absent column as null), key-usable columns, and identifier fields (through
format version 3). A Direct source, which has no catalog, now reads each
table's metadata file through the provider's table loader, for its
snapshot summary's total-records and its schema, under the same deadline.

The MCP data-model markdown shows a count that is not exact as "at most N"
or "not counted" instead of 0, and its note on virtual counts says what the
numbers mean.
… refuses the rest

The SQL suite's Iceberg case still expected every rr:sqlQuery to be refused
at registration. An Iceberg source now accepts a query in the restricted
subset it evaluates itself, so the case registers one and checks that a
query outside the subset (an OR) is still refused up front.
…s where rows can repeat one

The Iceberg top-k heap keeps the k best sort values among the rows a scan
reads and stops once no unread file can beat the k-th. Under set semantics a
map whose rows can repeat a solution has those repeats removed after the
scan, so the heap counted one solution several times: over a keyless table
whose first file holds one order's amount twice, `ORDER BY DESC(?a) LIMIT 2`
filled the heap from that file and skipped the file holding the second-best
amount, answering one row where the graph has two.

Which maps deduplicate is now decided before any scan opens, and a map's
scan takes the top-k only when its rows are its solutions: its subjects are
unique under a known key and one row never yields a solution twice. A keyed
map that overlaps another keeps its top-k, since the k rows its bound rests
on are k distinct solutions of the answer whichever map emits them. With
fast paths off nothing relies on a key, so the top-k is declined there.

A new routing stamp, r2rml_scan_topk, records the decision. The top-k tests
over keyless fixtures declare the key their data holds, so each still pins
its own decline rather than the missing key's; the view-policy guard also
gives its source a typed score, without which the bounds never pruned and
the guard passed vacuously.
…hat prunes

The local-fs and view-policy suites now run each top-k shape over a keyless
twin of their keyed source and assert it reads every file, so the decline
for maps whose rows can repeat a triple stays pinned beside the pruning it
replaces. The doc comment on the per-map flag states why a keyed map that
overlaps another may keep its top-k.
…in two of them

A same-subject star fuses its members into one scan that reads them from
one row, which answers the graph only where each subject is one row's. The
check asked each map covering the star whether it mints a subject from one
row, but not whether two covering maps could mint the same subject: two
tables each keyed by id, both minting customer/{id}, gave customer 7 a row
in each, and the fused scan paired each row's name with its own city where
the graph pairs every name with every city. `?s ex:name ?n ; ex:city ?c`
answered 4 rows where the graph has 6, a constant member lost the other
row's objects, a COUNT over the star counted 4, and a crawl folding a
constant listed one table's values.

Two covering maps now keep the star fused only when their subjects are
provably disjoint, or when they read the same row and mint every member
alike. The crawl's constant fold asks the same question. The row-local
pairing predates set semantics; keys made it reachable with keyed maps.

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics are right, and the uniqueness proofs I read hold up: a subject is proven unique only for a single key column or an injective template covering a key, each column type renders to distinct strings (timestamps keep microseconds, decimals a fixed scale, bytes base64; floats are refused), and every proof answers "no" when it cannot decide. I ran fluree-db-r2rml, the fluree-db-query lib suite, it_r2rml_set_scan, it_r2rml_ref_fanout, it_iceberg_filtered_logical_table, it_iceberg_local_fs and it_iceberg_policy on this head; all pass. This is a large PR and I did not read the dedupe operators, the fused fold, the SQL-lane DISTINCT lowering, the fan-out windows or the /info rewrite closely. Approving, but please look at the inline comments and the points below before merging.

The upgrade path for keyless maps is my main concern. No mapping generator emits f:key, and most Iceberg writers don't set identifier fields, so most existing mappings become keyless on upgrade. By your own numbers that is COUNT 0.14 s → 1.06 s with a 352 MB set charged, class COUNT 0.5 ms → 0.9 s, a same-subject star about 2x slower at 2.8 GB RSS, ORDER BY … LIMIT reading every file, and queries near their budget now failing with MemoryBudgetExceeded. The old answers were wrong where rows repeat, so the default is right, but an operator needs to be told. The two inline comments are what I'd like added.

Also:

  • Keys are trusted, never verified: a table that breaks its key silently returns bag answers and presents metadata counts as exact. Documented and deferred to #2320, which I'd treat as a near-term follow-up rather than a someday one.
  • /info counts go null for most virtual classes and properties. Anything that displays count needs to read count-upper-bound; worth a line in the release notes.
  • Landing order: this carries #2309's commits and sits on #2315 and #2316, so it lands last, after the rebases requested there.

diagnostics
}

/// Every declared key column (`f:key`) checked against its table's schema as

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A declared key is checked here, but nothing tells the operator when a map has no key at all. Neither this dry-run nor the create response reports that a map has no key evidence (no f:key, no identifier fields) and will take the deduplicating lanes. Please add an informational diagnostic per keyless map naming the map and the remedy, so the slowdown is visible when the source is mapped rather than discovered from query times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is the right place to make the slowdown visible -- added in 43fd95f. Each map whose subjects no known key of its logical table proves unique now gets an informational keylessMap diagnostic: it names the map, its subject columns and whatever keys the table does have, says its queries deduplicate (and what that costs), and gives the remedy -- f:key ( "col" … ) on the logical table, or the identifier fields on Iceberg. It never fails a request.

The part I cared most about is that it can't disagree with what the query lanes actually do, so it uses their decision rather than a parallel check: subject_unique_under now goes through a single TriplesMap::subject_key_proof, registration learns keys through effective_table_keys via the query provider, and the dry run shares identifier_fields_key with the provider (so v1-3 only, usable flat columns, only columns a filtered query selects). A map proven unique some other way -- f:key, identifier fields, a template covering a key, a SQL probe-verified key -- gets nothing.

It shows up everywhere mapping diagnostics already surface rather than just the dry run: the Iceberg / Delta / SQL map responses (a new diagnostics field), sql check, both validate routes and both generators, every CLI command that reports on a mapping (an advisory: line on stderr), and Python's map_* warnings. A registration whose tables didn't load, or whose SQL endpoint was unreachable, reports none, since its keys are unknown and the connection warning already says so. Tested on Iceberg, SQL, Delta, the dry run and the CLI, each also checking that keyed maps stay quiet; mutations that drop the advisory, ignore the keys, or drop identifier fields each fail them.

is malformed or misplaced; see [Declaring a Table's Keys](#declaring-a-tables-keys-fkey).
- At query time, `Graph source '…': Invalid value for f:key: on the logical table "…", a key names column "…", …`
(HTTP `400`): a declared key names a column the table does not have, or one
that cannot identify a row. Fix the key, or remove it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Slow Queries" section just below doesn't mention a missing key, and after this PR that is the most likely reason a COUNT, a same-subject star or an ORDER BY … LIMIT got slower on upgrade. Please add it there with the symptom and the fix (declare f:key), and say that the routing stamp r2rml_scan_proven_distinct shows which lane a query took. The upgrade note belongs in troubleshooting rather than the concept section above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it belongs in troubleshooting -- b31336b adds "A map with no key (most likely after an upgrade)" under Slow Queries rather than in the concept section above. It covers the symptom (COUNT, a same-subject star, ORDER BY … LIMIT, memory charged, MemoryBudgetExceeded), the cause, how to find the maps (the new keylessMap advisory), how to see which lane a query took (r2rml_scan_proven_distinct on the fluree::fastpath tracing target, with the RUST_LOG settings for the server and the CLI), and the fix (f:key, or identifier fields). Since an operator could land on any of several pages first, there are pointers to it from iceberg.md, sql.md, delta.md, the 507 error, the troubleshooting overview, and the API and CLI pages for the map responses.

}

/// One queued inner execution: a parent row's subplan in one graph.
struct GraphWork {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rewrite also changes native named-graph queries: QueryResult::batches can now hold several batches where it held one. It is listed under breaking changes, but it is unrelated to R2RML set semantics and was already a problem on main. Please keep it as its own commit when this is rebased so it can be bisected and reverted independently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense -- and it already is its own commit: d056728 ("a graph-source GRAPH block streams its batches instead of buffering the whole answer") carries the rewrite together with its tests (it_graph_scope_streams plus the cases in grp_query_sparql and it_iceberg_local_fs), with no other change mixed in. Since we merge rather than rebase, it stays that way, so bisect lands on it directly.

One honest caveat on the "revert independently" half: a plain git revert d056728d4 at this PR's head conflicts in graph.rs, because main's later edits to that file were merged in on top. It's a small resolution, but not a clean revert -- I'd rather say that now than have it be a surprise.

Most mappings declare no f:key and most Iceberg writers set no identifier
fields, so after set semantics most maps take the deduplicating lanes:
a COUNT reads the table, a same-subject star runs as separate scans, an
ORDER BY ... LIMIT reads every file, and the set of seen solutions is
charged to the query's memory budget. Nothing told the operator which
maps, so the slowdown surfaced as query times.

A new advisory diagnostic, keylessMap, names each map no known key of
its logical table proves subject-unique, says its queries deduplicate,
and gives the f:key that would prove it (or, on Iceberg, the identifier
fields). It never fails anything. A map whose subject cannot be proven
unique by any key (a template that runs values together, a constant
subject) is named with that reason instead.

The decision is the lanes' own. TriplesMap::subject_key_proof now holds
the one reading of a subject map (the columns a key must lie within, or
why none can), and subject_unique_under is defined through it. At
registration the keys come from effective_table_keys through the query
provider, as a query learns them. The dry run computes the same union
from the metadata preview, sharing identifier_fields_key with the
provider's table_keys (format version 1 to 3, flat usable columns, only
those a filtered logical table selects).

It surfaces everywhere mapping diagnostics do: POST /iceberg/map,
/delta/map and /sql/map (a diagnostics field, omitted when empty), the
Rust create results and fluree sql check, POST /iceberg/r2rml/validate
and the Delta validate route, both generators (a generated mapping
writes no f:key), every CLI command that reports on a mapping (iceberg,
delta and sql map, local and remote, sql check, delta generate and
validate), and the Python map_* calls' warnings. A registration whose
tables did not load, or whose SQL endpoint was unreachable, reports
none: its keys are unknown and its connection check says why. The CLI's
diagnostic printer is now shared by every command.

Also: the unprobed-endpoint warning of a SQL registration carried a run
of spaces from a string continuation without a backslash.
…bleshooting

After set semantics, a missing key is the most likely reason a COUNT, a
same-subject star or an ORDER BY ... LIMIT got slower on upgrade, or a
query near its memory budget now fails with MemoryBudgetExceeded. The
"Slow Queries" section did not mention it.

It now has its own entry there: the symptom, why it happens (and that the
old answers were wrong where rows repeat), how to find the maps (the
keylessMap advisory registration and the dry runs give), how to see per
query which lane ran (the r2rml_scan_proven_distinct stamp on the
fluree::fastpath tracing target, and how to turn it on for the server and
the CLI), and the fix (declare f:key, or set identifier fields). The
concept section above it is unchanged.

Where an operator would look instead, a pointer: Iceberg's Slow Queries
and its diagnostics table, SQL's subject-keys section, Delta's
performance section (whose log COUNT now also needs a key), the 507
error, and the troubleshooting overview. The map responses in the API
reference and the CLI pages document the new diagnostics field and the
advisory lines.
… null

Set semantics made a graph source's class and property counts exact or
null, and most counts of a mapping with no key are now null where they
used to hold the tables' row counts. A client that displays count shows
nothing, or 0, for most virtual classes.

Each page that shows or explains /info counts for a graph source now says
how to read them: count when it is a number, else count-upper-bound as
"at most N", else "not counted", never 0; the same for ref-classes and
ref-classes-upper-bound. The /info reference gains a graph-source example.
Clippy (unnecessary_to_owned) refused the String built from the ledger id
only to borrow it for keyless_sql_maps.
Pins the CLI surface of the keylessMap advisory: fluree delta map prints
one advisory line on standard error naming the map and the f:key that
would prove it, and none once the key is declared.
…f its parent

The sub-select branch rewrote nested scopes through one closure so that an
EXISTS embedded in a sub-select's HAVING or ORDER BY is lowered too; this
branch added the table-key evidence parameter to the rewrite. The merge left
the closure without it. Nested scopes read the same tables as the scope
around them, so they take the same evidence, as the expression arm already
does.
Brings f6b3160 forward. Set semantics already resolves the logical table
in scan_file_counts and known_row_count, so the tree is unchanged.
… the rewrite takes

The scan top-k branch's sub-select and EXISTS rewrite tests call
rewrite_patterns_for_r2rml without the key evidence set semantics added to
it, so the query crate's test target did not compile after the merge. They
pass none (TableKeyEvidence::default()), as the other rewrite tests do;
none of them depends on a key.
… the same local roots

The local-root guard reads FLUREE_ICEBERG_LOCAL_ROOTS once per process, so
the first test to build storage decides it for the whole binary. Two tests
set it to the fixtures directory alone, while the empty-table test reads a
table it stages under the scratch directory: run after either of them, it
failed with a path outside every allowed root. Every test now sets the one
value set_local_roots gives (fixtures and scratch), so the outcome no longer
depends on test order.
… its rows agree

The order test's two-subject fixtures also disagreed on the customer, so a
fold that declined only on disagreeing rows passed it. A third fixture mints
o50 with o10's customer: only the second subject can make it decline, as it
must, since the generic join counts a fact row once per subject its key
matches.
…emedy without warnings

KeyRemedy::Declare is reported only by Delta and SQL sources, and
declared_table_keys is used only by Delta, so a build with Iceberg alone
warned that both were never used. Allow it for exactly those builds.
@aaj3f

aaj3f commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @bplatz -- and thanks for running the suites on the head, especially on a PR this size.

The keyless upgrade path was the right thing to push on. The two inline threads cover what's in now (43fd95f for the per-map keylessMap advisory wherever mapping diagnostics surface, b31336b for the troubleshooting entry with the routing stamp), so an operator sees the slowdown when the source is mapped rather than discovering it from query times.

On the other points:

Base automatically changed from perf/r2rml-keyed-scans to main November 13, 2026 17:32
…yless advisory

The mapping in delta_http_integration declares no f:key, and a Delta
table reports no key of its own, so the dry run now also names the map
as one its queries deduplicate (keylessMap). The flawed-mapping case
reads the same table and gets it too; the missing-table case does not,
since its keys are unknown.
…-scan lane

A union entity's maps can mint one subject, so its statement needs a
SELECT DISTINCT over string columns to answer with set semantics.
MySQL's default collations fold case and accents, so that DISTINCT could
merge two distinct values, and the lane declines ("repeated solutions
the statement cannot remove exactly"). Six union cases of the live
differential now expect that decline on MySQL; their rows are still
checked against the per-scan lane. This is the rule the live case
"DISTINCT over strings runs in the engine where the database folds
case" already pins. SQLite and Postgres keep the statement.
@aaj3f
aaj3f merged commit 4adc62e into main Nov 13, 2026
19 checks passed
@aaj3f
aaj3f deleted the feat/r2rml-set-semantics branch November 13, 2026 20:04
bplatz added a commit that referenced this pull request Nov 13, 2026
Brings #2296, #2309, #2313, #2315, #2316, #2317, #2367, #2368, #2369,
#2373, #2374, #2378 and #2379.

Ports onto next:

- #2374 (bound-object probe reads POST): main's POST walk and per-type
  flush replace next's OPST walk. The lane keys (o_type, o_key), so next's
  triple-term handles are one more covered type (object_probe_covers takes
  TripleTermDict) rather than a flush per type; a term's matches are read
  whole, as a ref's are. The wildcard cursor still keys refs only. Pooled
  graphs decline through dedicated_branch(Post); o_i is 64-bit. Next's
  pair join keys its subject through the shared LaneKey.
- #2373 (leaflet type constant under replay): replays_history and
  o_type_const_for beside next's may_hold_keys; the row-labelling lanes
  take main's const-unless-replaying form over next's always-read-column.
- #2368: the cyclic join decodes for eager callers with next's list index
  sentinel; both reasoning tests kept (cyclic operator and pair lane).
- #2317 (GRAPH streams): main's work queue and InnerStream with next's
  pooled-graph pruning before each enumerated graph.
- #2315: list predicates are an ordered set in next's multi-ledger view;
  the annotation edge probe stays deleted (no bundle lane on next).
- #2296 (rebase reads its new line): ported onto next's fenced resets,
  erasure checks and peer sync (follow_record keeps next's unchanged-head
  arm); a non-fast-forward rebase moves head and index in one fenced
  reset.
- Main's new tests: async genesis_ledger, graph_source_store for mapping
  writes, leaf_rows for leaflets-per-leaf, storage lock off for two file
  instances. New pattern/function matches cover TermComponents and the
  triple-term functions; AnnotationTarget arms dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:iceberg Iceberg catalogs/credentials, R2RML, virtual datasets, materialize area:query Query execution, planning, fast paths, overlay, result formatting breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section enhancement New feature or request

Projects

None yet

2 participants