Skip to content

perf(retain): read existing documents' tags in one go for a scoped retain - #6402

Merged
nicoloboschi merged 2 commits into
mainfrom
triage/6327
Nov 6, 2026
Merged

nicoloboschi merged 2 commits into
mainfrom
triage/6327

Conversation

@nicoloboschi

@nicoloboschi nicoloboschi commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #6327 (thanks @harshitgupta31415 for the report, numbers and patch).

What changes

A caller with a tag scope who retains a batch into existing documents had each document checked with its own query (3,500 docs ≈ 3 s). Now the tags are read together, in groups of 1,000, and checked in the same order.

Same answers as before

  • New store method existing_documents_tags: Postgres reads all rows at once; other stores keep the per-document read.
  • It does not reuse documents_tags for other stores: that one drops a record with no tags field, which would make an existing document look new and let a restricted writer through. A test covers this.
  • pg/documents.documents_tags now reads in groups of 1,000, since Oracle expands = ANY into an IN list capped at 1,000 (also fixes the source-text visibility read past 1,000 docs on Oracle).

Tests

  • Per-document vs batched reads agree on 2,500 random ids (tagged, untagged, empty, other bank, missing). Local timing: ~138 ms → ~5 ms.
  • test_tag_scope: a batch mixing a new doc, an allowed doc and a forbidden doc is refused with 403 naming the forbidden one.

…tain (#6327)

A tag-scoped retain checked each existing document with its own query. Read
them together (groups of 1,000, the Oracle IN-list cap) and check in the same
order. A store record without tags still counts as an existing document, so
the allow/deny answer is unchanged. Thanks @harshitgupta31415 for the report
and benchmark.
@nicoloboschi
nicoloboschi merged commit aaa6848 into main Nov 6, 2026
112 checks passed
@nicoloboschi
nicoloboschi deleted the triage/6327 branch November 6, 2026 13:54
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.

batch document tag reads during scoped retain (3.04 s → 84.82 ms, 35.89× faster)

1 participant