Skip to content

perf(db): bound since-limited events reads with the month-floor literal - #9197

Merged
TheSentinel454 merged 3 commits into
mainfrom
mention-join-partition-prune
Nov 6, 2026
Merged

TheSentinel454 merged 3 commits into
mainfrom
mention-join-partition-prune

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A newest-first events read whose own since is at or above the recent-pass floor now runs as a single recent pass. Postgres prunes it to the recent monthlies at plan time instead of locking every partition. Results are unchanged.

Why. split_for skipped any read whose since was at or above the floor (since_prunes), on the theory that its since already prunes. It does, but only as a bind parameter. Once a prepared statement switches to a cached generic plan, Postgres prunes bind-parameter bounds at execution, after AcquireExecutorLocks has already locked every events partition and its indexes. Live REQs with a recent since are this shape, for example #p mention reads from reconnecting agents. Under load they spill past the 16 fast-path lock slots and contend on LWLock:LockManager. The ceiling PR (#9157) named this gap as identified debt.

What changes. Such a read now gets the same Split as other recent reads, so the recent pass carries the floor literal (plus the ceiling literal for regular-kind reads) on e.created_at and on m.event_created_at for #p. Split gains older: bool. It is false when the read's own since is at or above the floor, because no row below the floor can match, so no older pass follows a short recent pass. A read whose until falls below the floor stays unsplit, as before.

No protocol, schema, index or client change.

Related issue

Follow-up to #9157 (its identified debt: bind-parameter since reads).

Testing

  • recent_pass::tests::split_eligibility: the table now records not split / ceiled / open and whether an older pass follows. New rows: since at the floor, a recent since with regular, any and addressable-only kinds, and a recent since with until below the floor.

  • recent_pass::tests in-memory exactness: adds a since-at-floor split that runs exactly one pass and returns the rows at or above the floor.

  • postgres_tests::since_bounded_mention_read_locks_only_recent_partitions (new): runs partition maintenance, inserts #p rows at the floor, now, one second below the ceiling and one day below the floor, then reads with since = floor. The production path returns the three recent rows through the mention join. Under plan_cache_mode = force_generic_plan the recent pass locks only the partitions holding those rows. The unsplit read locks every partition.

  • The partition-lock helper from perf(db): stop the events recent pass at a ceiling for regular-kind reads #9157's test is now shared by both lock tests.

  • Diagnostic on Postgres 17.11 with the 19-partition layout partition maintenance keeps, for a #p read with since at the floor (not committed):

    events partitions locked Relation locks Non-fast-path locks
    Before (bind-only since, generic plan after five runs) 19 26 10
    After (floor and ceiling literals) 2 9 0

    EXPLAIN (GENERIC_PLAN) before appends all 19 partitions. After, it appends only the previous and current monthlies.

Mutation-checked on Blox. Each of these fails the new Postgres test or the unit tests: removing the since_prunes split, ignoring older, and dropping the e. literal.

What got simpler

Nothing got simpler. The change adds one flag to the existing Split type and no new concept. The duplicated partition-lock reader in the #9157 test became one shared helper.

🤖 Generated with Claude Code

A newest-first read whose own `since` is at or above the recent-pass floor
was read whole, bounded only by the `since` bind. A cached generic plan
prunes a bind only at execution, after it has locked every `events`
partition and its indexes, so live REQs with a recent `since` (`#p` mention
reads from reconnecting agents) contended on `LWLock:LockManager`.

Such a read now runs as one recent pass: the floor literal (and the ceiling
for regular kinds) bounds it at plan time, and no older pass follows since
no row below the floor can match.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Luke Tornquist <[email protected]>
@TheSentinel454
TheSentinel454 marked this pull request as ready for review November 6, 2026 16:43
@TheSentinel454
TheSentinel454 requested a review from a team as a code owner November 6, 2026 16:43
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: 1bb2ad443d4ee4512dd0927888ad21a4a1c041bc...e3e8ccf5a8eb3207a36a442e3d2370a7949f96d8
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete security, correctness, or reliability findings in the authorized PR range. The new since-bounded path preserves query filters and correctly skips the older pass.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Review used read-only source and history inspection. Builds and tests were not run, as requested.

Generated by Codex Security Review |
Requested by: @TheSentinel454 |
Workflow run

The lock checks built the recent pass directly, so routing recent-since
production reads back to the unsplit read would have kept the test green.
Assert the production read prepared exactly the recent pass's statement.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Luke Tornquist <[email protected]>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 6, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 6, 2026
An inline pattern made the lookup query match itself in
pg_prepared_statements.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Luke Tornquist <[email protected]>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 6, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 6, 2026

@wpfleger96 wpfleger96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good. the recent pass with since at or above the floor returns the same rows (the floor is implied by since, and the ceiling only applies to regular kinds, which can't sit past it), and older: false keeps it to one statement. the transaction cost doesn't change either, since the unsplit read already opens one for per-read deadlines and the session-deadline callers are inside a transaction anyway. one nonblocking nit inline.

Comment thread crates/buzz-db/src/store/recent_pass.rs Resolved
@TheSentinel454
TheSentinel454 merged commit 0d5edb8 into main Nov 6, 2026
90 checks passed
@TheSentinel454
TheSentinel454 deleted the mention-join-partition-prune branch November 6, 2026 19:29
bradseiler added a commit that referenced this pull request Nov 6, 2026
* origin/main:
  fix(relay): route live REQ events by each filter's own channel scope (#8519)
  fix(relay): deliver multi-node fan-out concurrently and never drop silently (#9195)
  perf(db): bound since-limited events reads with the month-floor literal (#9197)
  fix(mobile): match Agents sign-in to Home’s reconnect capsule (#9204)
  fix(cli): clearer desktop pairing errors, paired default relay, and auth desktop list (#9196)

Signed-off-by: Brad Seiler <[email protected]>

This branch was previously deployed

1 inactive deployment
codex-review — e3e8ccf5 Deployed Nov 6, 2026 by TheSentinel454 via Run Codex Security Review #13495
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants