Conversation
…on sweep The 6h cleanup deletes in batches via WHERE last_seen_at < ?, which full-scanned every batch without an index. Covers the remaining open item of diegosouzapw#13973 (TRUNCATE removal landed in diegosouzapw#14005).
Owner
|
Thanks for the PR and for pinpointing the missing index — the analysis was right. It turns out #13973 was already fixed on |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Covers the remaining open item of #13973 (the TRUNCATE removal landed in #14005; the scheduler stagger and this index were deliberately left out).
Problem
cleanupConversationTurnNodes()runs every 6h and deletes in batches viaWHERE last_seen_at < ?(deleteFromTableBeforeInBatches).conversation_turn_nodeshas indexes on(conversation_id),(parent_id), and(conversation_id, content_hash)— none covers the retention predicate, so every cleanup batch full-scans the table.Fix
Migration
186_turn_nodes_last_seen_index.sql:CREATE INDEX IF NOT EXISTS idx_turn_nodes_last_seen ON conversation_turn_nodes(last_seen_at). Numbered 186 — clear of the three open PRs currently claiming 187.Verification
tests/unit/db/migration-186-turn-nodes-last-seen.test.ts: migration applies + idempotent re-run, andEXPLAIN QUERY PLANon the exact retention predicate uses the index (seeded 500 rows + bound cutoff so the planner can't trivially scan).check-migration-numbering: OK (183 migrations, 0 duplicates).check-file-size: OK both suites. Changelog fragment included.