Skip to content

aggregation: charge the term dictionary of computed text sources against the memory limit - #3205

Open
0xamlab wants to merge 1 commit into
quickwit-oss:mainfrom
0xamlab:computed-text-dictionary-memory-limit
Open

0xamlab wants to merge 1 commit into
quickwit-oss:mainfrom
0xamlab:computed-text-dictionary-memory-limit

Conversation

@0xamlab

@0xamlab 0xamlab commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #3172.

Root cause

Computed text sources intern values in DynamicTermDictionary, but its term buffer, offsets, and hash-table buckets grow without charging AggregationLimitsGuard. The issue repro interns 50,000 unique terms under a 1,024-byte limit and succeeds despite a several-MB dictionary.

Fix

  • Add ValueSource::memory_consumption(), defaulting to zero for physical columns whose memory belongs to the index.
  • Report computed/constant text dictionary heap usage and charge its per-block growth in the terms, string-cardinality, and value-count collectors.
  • Include pre-populated dictionaries in the request-data charge, covering constant sources interned before collection.

Regression coverage

With 2,000 unique terms, all three aggregations fail at a 1 KB limit and succeed at 10 MB with correct results. A 4,096-byte constant literal is rejected at 1 KB for all three collectors, covering allocation before collection.

Verified after rebasing on d66f88d8

  • make test: 1,343 passed, 8 ignored.
  • cargo test -p tantivy --features jitexpr --lib: 1,395 passed, 8 ignored.
  • cargo test -p tantivy --no-default-features --features mmap,quickwit,failpoints,jitexpr --tests: 1,382 + 5 passed, 8 ignored.
  • Same feature set, --lib aggregation: 375 passed.
  • Clippy with -D warnings for both feature configurations: clean.
  • cargo +nightly fmt --all -- --check: clean.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T14:38:24.556347Z d3958eb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85663c2535

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@0xamlab
0xamlab force-pushed the computed-text-dictionary-memory-limit branch from 85663c2 to 72e7fd3 Compare October 22, 2026 19:15
…nst the memory limit

A computed text value source (e.g. a jitexpr field) interns its terms in
a DynamicTermDictionary that grows while blocks are loaded, and that
growth was never charged against AggregationLimitsGuard: a cardinality
aggregation over a jitexpr text field with a 1 KB memory limit happily
interned 50k terms (several MB).

ValueSource gains a memory_consumption() method (0 for sources backed by
a physical column: their memory belongs to the index, not to the
request), and the collectors that can drive a computed text source
(terms, cardinality over Str, and the metric collector behind
value_count) charge the source's growth per block, following the
existing mem_pre/mem_delta idiom of the terms and histogram bucket
structures. The request-data charge includes the source's initial
memory, covering the constant source, which interns its single term
when it is built.

Fixes quickwit-oss#3172.
@0xamlab
0xamlab force-pushed the computed-text-dictionary-memory-limit branch from 72e7fd3 to d3958eb Compare November 9, 2026 14:35

This branch has not been deployed

No deployments
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.

DynamicTermDictionary is not accounted for in AggregationLimits

1 participant