Skip to content

perf(data): COPY account-link rows in primary-key order - #696

Closed
aditya1702 wants to merge 1 commit into
ingest-db-observabilityfrom
live-ingest-copy-locality
Closed

perf(data): COPY account-link rows in primary-key order#696
aditya1702 wants to merge 1 commit into
ingest-db-observabilityfrom
live-ingest-copy-locality

Conversation

@aditya1702

Copy link
Copy Markdown
Contributor

What

Sort the transactions_accounts / operations_accounts COPY batches by (account_id, id) before shipping them.

Why

The rows were built from nested map iteration, so each COPY paid a randomized btree descent per row on the account_id-led primary key. On the loadtest rig these two COPYs are the slowest persist siblings (~400ms median vs 135ms for the transactions COPY). The balance upserts already sort by PK for the same reason.

Testing

  • go test ./internal/data/ green; COPY correctness is order-independent, so existing coverage applies.
  • A/B on the phase-3 loadtest rig follows via the deployed image.

🤖 Generated with Claude Code

The link rows are built by iterating nested maps, so the COPY hit the
(account_id, ...)-led primary key in randomized order — one random btree
descent per row, and on a cold cache a random page read each. Sorting the
batch by (account_id, id) walks the index left-to-right instead, the same
ordering the balance upserts already apply. Measured on the loadtest rig,
the two link-table COPYs were the slowest persist siblings at ~400ms
median per commit — 3x the parent transactions COPY at a third of its
per-row work.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@aditya1702 aditya1702 closed this Aug 22, 2026
@aditya1702
aditya1702 deleted the live-ingest-copy-locality branch August 22, 2026 15:06
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.

1 participant