Skip to content

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

Closed
aditya1702 wants to merge 1 commit into
ingest-db-observabilityfrom
live-ingest-persist-opts
Closed

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

Conversation

@aditya1702

Copy link
Copy Markdown
Contributor

(Recreates #696, closed by a head-branch rename.)

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. The balance upserts already sort by PK for the same reason.

Testing

  • go test ./internal/data/ green; COPY order is correctness-neutral.
  • A/B on the phase-3 loadtest rig: neutral there (the rig's ~26k-account population keeps the index cache-resident); the change is motivated by mainnet-scale indexes where random probes miss cache. Branch also hosts the upcoming persist-phase optimization batch (see handoff spec).

🤖 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

Copy link
Copy Markdown
Contributor Author

Duplicate of #696, which survived the branch rename.

@aditya1702 aditya1702 closed this Aug 22, 2026
@aditya1702 aditya1702 reopened this Aug 22, 2026
@aditya1702

Copy link
Copy Markdown
Contributor Author

Supersedes #696 (closed permanently by the head-branch rename to live-ingest-persist-opts).

@aditya1702

Copy link
Copy Markdown
Contributor Author

Holding off — this branch will get one PR together with the persist-phase optimization batch.

@aditya1702 aditya1702 closed this Aug 22, 2026
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