Skip to content

Iceberg graph sources: push bound subject sets and child join keys into the scan (VALUES subjects, parent tables of referencing object maps) #2239

Closed

Description

@aaj3f

Problem

Two common query shapes over an Iceberg-backed R2RML graph source read whole tables even though the query already holds the keys it needs.

1. A set of subjects.

SELECT ?s ?n WHERE { VALUES ?s { ex:customer/1 ex:customer/2 ex:customer/3 } ?s ex:name ?n }

This scans every row of the table and joins against the VALUES rows in memory. The same three subjects written as a UNION of constant-subject patterns are pushed down, because a single constant subject is reversed through the subject template into a key-column predicate. Measured on a table of about 2M rows: 13.5 s for the VALUES form, 2.1 s for the UNION form. A subject variable bound by an earlier pattern (?a ex:currentVersion ?v . ?v ex:score ?x) has the same problem, and on a ~9M-row table it ran past a minute.

2. Referencing object maps. For rr:parentTriplesMap + rr:joinCondition, the parent table is scanned with no filters and collected in full into a hash lookup, however few child rows reach it. A LIMIT only reaches the child scan, so ?fact ex:forCustomer ?c LIMIT 5 over a ~30M-row fact table joined to a ~9M-row dimension took ~50 s. When the parent is larger than one materialize window (512K rows), the lookup also isn't memoized and is rebuilt for each child batch.

Expected

A bound subject set should become an IN over the key columns recovered from the subject template. The mechanism already exists for one constant subject. The distinct child join keys of a batch should be pushed as an IN into the parent scan (a semi-join), so file and row-group pruning apply to the parent too. The SQL graph-source lane already sends outer bindings into its statement as a key set (fluree-db-query/src/r2rml/sql_lane/mod.rs:1-12); Iceberg sources never get that lane (fluree-db-api/src/graph_source/r2rml.rs:2785-2795).

Where (at ca682e2b8)

  • fluree-db-query/src/r2rml/rewrite.rs:672-675: subject variables are deliberately excluded from pushdown ("Only object-position vars map to columns").
  • rewrite.rs:881-907: collect_values_pushdown accepts literal cells only (:897).
  • fluree-db-query/src/execute/where_plan.rs:2462-2490: a single-row VALUES is inlined into object position only.
  • operator.rs:673-675: scan filters come from the pattern alone, never from child-row bindings.
  • One constant subject: operator.rs:2031-2055 and fluree-db-r2rml/src/materialize/term.rs:254 (reverse_subject_template).
  • Parent scan: operator.rs:1311-1322 (&[] filters, then collect_stream), build_parent_lookup at :2794-2860, memo bound at :1328-1342. build_ref_shortcut (:171) only applies in the browse crawl (:1276-1281).

Possible direction

  • Generalize the single-constant-subject reversal to a set: reverse each IRI and emit ScanCmpOp::In on the key column(s), or Eq for one member. IRIs that don't match the template simply produce no rows.
  • For referencing object maps, collect the distinct child keys per batch and pass them as an In filter to the parent scan_table.
  • Bound both by in_pushdown_max() and fall back to today's path above it. Cover non-reversible templates and composite keys.

This is also the structural fix for the largest unaccounted allocation in these joins (see the note on #1841).

Activity

  1. added
    P2
    area:iceberg
    area:query
    performance
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:icebergarea:queryperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions