Skip to content

Query memory accounting ignores heap behind bindings #1841

Open

Description

@bplatz

Query memory accounting charges bindings at a flat BINDING_EST_BYTES (size_of::<Binding>(), fluree-db-query/src/context.rs) and groups at GROUP_EST_BYTES. Neither counts heap owned behind a binding — long string literals, NumBig values, maps/lists, GROUP_CONCAT/collect accumulators — so a query whose bindings carry large values is accounted well below its real footprint, and the per-query memory limit can be exceeded in practice without MemoryBudgetExceeded firing.

Every charging site inherits this: subquery.rs (retained batches, materialization, output windows), hash_join.rs, group_aggregate.rs, and the R2RML operators.

Raised in review of #1828 (#1828 (comment)), which is explicitly out of scope there.

Open questions:

  • Whether to measure heap per binding at charge time (cost on the hot path) or sample/approximate by value kind.
  • Whether this should land with the shared concurrency memory-admission work, which relies on the same counter.

Activity

  1. added
    P2
    area:query
    performance
    on Sep 15, 2026
  2. aaj3f commented on Nov 2, 2026

    @aaj3f
    Contributor

    One more site for this, found while looking at referencing-object-map joins over an Iceberg graph source: R2rmlScanOperator collects the whole parent table (fluree-db-query/src/r2rml/operator.rs:1322, collect_stream) before build_parent_lookup starts charging the budget (:2806-2820, ~200 B per entry). The raw column batches are never counted, and the per-file buffers are excluded on purpose (:253-255, :1524). So a join over a multi-million-row parent can pass the budget while holding both the raw parent and its lookup. We saw peaks right at a 10 GB container's limit on a ~9M-row parent. #2239 (pushing the child keys into the parent scan) would be the structural fix; counting the collected batches would be the cheap guard in the meantime.

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:queryperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions