Skip to content

perf(r2rml): prune star TriplesMap fan-out — all-members intersection + disjoint-class hint (PR-3) - #1484

Closed
aaj3f wants to merge 9 commits into
perf/r2rml-pr2-decode-leversfrom
perf/r2rml-pr3-star-overscan
Closed

aaj3f wants to merge 9 commits into
perf/r2rml-pr2-decode-leversfrom
perf/r2rml-pr3-star-overscan

Conversation

@aaj3f

@aaj3f aaj3f commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Roadmap PR-3 (docs/audit/2026-07-virtual-dataset-perf/ROADMAP.md): the F8 star over-scan. A same-subject star resolved TriplesMaps by its base predicate alone, so a typed dimension star sharing a common predicate (edw:name) fanned out to every name-bearing table — 6 loadTables + 6 scans for a 500-row single-table query, tripling cold latency on the most common query shape.

The prunes (both behind FLUREE_R2RML_STAR_TM_PRUNE, default on)

(a) All-members intersection. Only TriplesMaps supplying every star predicate can produce a complete star row; resolution filters to that intersection. The load-bearing all-members-required assumption is pinned by test (OPTIONAL members never fuse into stars — verified + guarded).

(b') Disjoint-class hint. When the star's co-located class was not fused (class lives in a different TM) but wildcard_class_fusion_is_safe proves every non-class TM subject-template-disjoint from the class-declaring TMs, resolution prunes to the class TMs — the standalone class scan joined on subject would drop the pruned rows anyway. Resolution-only: rdf:type emission and materialization are untouched.

Design correction on the record: the ROADMAP's original fix (b) — prune to class-declaring TMs whenever fusion is refused — was proven unsound under vertical partitioning (class triple and data POMs in different TMs sharing a subject template: pruning strips the TM that carries the bindings). Counterexample annotated in the ROADMAP; permanent regression test class_prune_hint_refused_under_vertical_partition. The (b') formulation reuses the existing template-disjointness predicate rather than new machinery.

Crawl-side fan-out: no work needed — already class-constrained since 81b0ec601 (#1450); residual 429 backoff remains roadmap PR-8.

Live results (SF01, 16-core host)

measure before after
q001 loadTable / scan_table spans 6 / 7 1 / 2
q001 cold wall 14.18s 2.94s (4.8×)
switch off — 6 loadTables / 14.18s faithfully reproduced

q022/q054 sentinels hash-OK; native corpus 55 queries, 0 hash mismatches.

q002/q042 mismatch: pre-existing, filed as F9

Both mismatch identically with the switch on and off ⇒ not this PR. Root cause (head-row diff): native compacts predicate/type IRIs to CURIEs (edw:name), virtual emits full IRIs — all values byte-identical after namespace folding. Unmasked by PR-0's row-count fix. Filed as F9 in the findings register with the which-side-conforms product decision escalated (SPARQL 1.1 results-JSON favors full IRIs, but changing native output affects existing users). No harness masking — they stay honestly red until decided.

Gates

query suite 1200/1200 (6 new tests: intersection prune, class-hint prune, vertical-partition refusal, optional-member guard, switch-off fan-out, disjointness edge); api all bins green; native 0 hash mismatches; live table above.

Stacks on #1482 (PR-2) ← #1478 (PR-1) ← #1476 (PR-0) ← #1475 ← #1450.

Review follow-ups (7b21684)

  • fmt gate (blocking): cleared — cargo fmt --all -- --check green at HEAD via the per-PR rustfmt commits (12102a075 + inherited stack passes).
  • F10 filed (review optional 1): the pre-existing split-member star-formation gap (same-subject members split across template-sharing TMs ⇒ zero star rows; the data-data analog of the (b') counterexample) is now a registered residual — 04-findings-register.md F10 + ROADMAP §PR-3 residual note + cross-refs at tm_passes_star_prune and the rewrite star-fusion loop. Future fix in the rewrite (refuse to fuse when no TM covers all members); preserved, not caused, by fix (a).
  • Switch-family helper (review optional 2): all five fluree-db-query R2RML switches now route through one env_switch_enabled helper with a single falsy spelling set (0/false/off/no); the fluree-db-api crawl helper and fluree-db-iceberg footer switch already mirror it (cross-referenced — no common crate to share the symbol). The perf(iceberg): eliminate per-file footer round-trips + raise decode concurrency (PR-2) #1482 OnceLock-idiom aside had already landed in 0590613a7.

aaj3f added 2 commits July 13, 2026 12:18
… + disjoint-class hint (PR-3)

A same-subject star resolved its TriplesMaps by BASE predicate alone, so a
typed dim star sharing a common predicate (edw:name) fanned out to every
name-bearing table (q001: 6 loadTables/scans for a 500-row single-table
query). Two provably-safe resolution prunes behind
FLUREE_R2RML_STAR_TM_PRUNE (default on):

(a) All-members intersection: only TMs supplying EVERY star predicate can
produce a complete star row; resolution filters to that intersection. The
all-members-required assumption is pinned by test (optional members never
fuse into stars).

(b') Disjoint-class hint: when the star's co-located class was NOT fused
(class in a different TM) but wildcard_class_fusion_is_safe proves every
non-class TM subject-template-disjoint from the class-declaring TMs, prune
resolution to the class TMs — the standalone class scan joined on subject
would drop the pruned rows anyway. Resolution-only; rdf:type emission and
materialization unchanged. The ROADMAP's original fix (b) (prune to
class-declaring TMs whenever fusion is refused) was proven UNSOUND under
vertical partitioning (counterexample in ROADMAP annotation; regression
test class_prune_hint_refused_under_vertical_partition).

Crawl-side fan-out needed no work: already class-constrained (81b0ec6).

Live SF01 (16-core host): q001 cold 14.18s -> 2.94s (4.8x), load_table
n=6 -> 1; switch-off faithfully reproduces the fan-out. Native corpus 55
queries, 0 hash mismatches; q022/q054 sentinels hash-OK. q002/q042
mismatch proven PRE-EXISTING (identical both switch states): native/virtual
IRI-serialization divergence, filed as F9 (product decision escalated).
Suites: query 1200/1200 (6 new tests), api all bins green.
aaj3f added 7 commits July 13, 2026 18:05
cargo fmt --all --check fails on four hunks of this PR's own delta
(operator.rs star-fanout block, rewrite.rs disjoint-class-hint + tests)
with rustfmt from stable 1.97.0 — what CI's dtolnay/rust-toolchain@stable
resolves. CI never ran here (ci.yml triggers only on base=main), flagged
by the #1476 review stack-wide note.
…ormation gap on record

Two optional items from the PR-3 review:

- One switch helper for the R2RML family: the five fluree-db-query
  boolean switches (LIMIT_PUSHDOWN, STAR_TM_PRUNE, SCAN_CACHE,
  FILTER_CONSUMPTION, CRAWL_CLASS_FUSION) had drifted into two falsy
  spelling sets (0/false/off vs 0/false/off/no). All now route through
  r2rml::env_switch_enabled (0/false/off/no — the superset; the only
  behavior change is that "no" now disables the three switches that
  previously ignored it, aligning with the documented family intent).
  The fluree-db-api crawl helper and the fluree-db-iceberg footer
  switch already match these spellings; cross-crate symbol sharing
  isn't possible without a new common home, so they stay mirrored and
  are cross-referenced from the helper doc.

- F10 filed: the pre-existing split-member star-formation gap
  (required same-subject members split across template-sharing
  TriplesMaps yield zero star rows; native would subject-join) is now
  a registered residual in 04-findings-register.md plus a ROADMAP
  §PR-3 residual note, with cross-refs at the two seams
  (tm_passes_star_prune doc, rewrite star-fusion loop). Pre-existing
  and preserved (not caused) by fix (a)'s intersection prune; future
  fix in the rewrite — refuse to fuse when no TM covers all members.

The review's blocking fmt item was already cleared by the per-PR
rustfmt commits (cargo fmt --all --check green at this HEAD); the
OnceLock-idiom aside for the #1482 footer switch landed in 0590613.

Gates: fluree-db-query 1260/1260 (nextest); scoped clippy 0 errors;
fmt --all --check green.
@aaj3f

aaj3f commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Consolidating at maintainer request. #1484 (PR-3 — the star TriplesMap fan-out prune) is carried forward in #1507 (the R2RML/Iceberg virtual-dataset performance program), which brings the #1475–#1507 lineage forward as a single reviewable unit. Its verification of record is the program's corpus benchmark, published as C2-bench-wave1.md (native == virtual, 0 hash mismatches). The pre-consolidation branch tip is preserved at tag archive/pre-refactor-2026-07-21/perf_r2rml-pr3-star-overscan — no history was rewritten. Closing in favor of #1507; discussion continues there.

@aaj3f aaj3f closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant