perf(server): batch hydrateRows; per-table catch-up reads use the (tbl,seq) index#8
Open
grrowl wants to merge 1 commit into
Open
Conversation
…l,seq) index Eliminates the N+1 SELECT in hydrateRows by issuing chunked IN queries (64 keys per chunk), cutting SQLite rows-read on reconnect storms. Adds readChangesSinceFor for emitCatchUp's per-table read, activating the _sync_changes_tbl_seq composite index that previously went unused — the JS .filter() after readChangesSince is gone. drainAndBroadcast's all-tables readChangesSince call is intentionally unchanged (one scan, N tables). New tests in cdc.test.ts pin: chunking over 150 rows (no drops/dups, TEXT pk keying), and readChangesSinceFor table isolation + mid-stream cursor windowing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Executes plan 004 from the advisor audit. Stacked on #4 (plan 001) — merge that first, then retarget/merge this; the diff vs its base is
src/server/changes.ts+ theemitCatchUpcall site + two new tests.What
hydrateRows: N+1 (oneSELECT … WHERE pk = ? LIMIT 1per changed key) → chunkedINqueries (CHUNK=64, quoted identifiers, bound values,String(row[pk])keying preserved per ADR-0007/D9).readChangesSinceFor(sql, tbl, cursor): per-table changelog read that actually uses the_sync_changes_tbl_seqindex (whose comment always claimed it "serves per-table catch-up" — now true).emitCatchUpuses it;drainAndBroadcast's deliberate one-scan-all-tables read is untouched.Why
Cuts SQLite rows-read (billed) and DO wall-clock exactly where reconnect storms concentrate: a 500-key catch-up was 500 queries over a full-log scan; now ~8 queries over an index range.
Verification
Two new falsifiable tests in
tests/cdc.test.ts(3-chunk hydration with missing keys; table isolation + mid-stream cursor windowing);catchup/reconnect/multiplexwire tests green; full suite green on the reviewer's re-run.🤖 Generated with Claude Code