Skip to content

Raise work_mem for the tag swap transaction - #284

Merged
ericmj merged 1 commit into
mainfrom
raise-work-mem-for-tag-swap
Aug 10, 2026
Merged

Raise work_mem for the tag swap transaction#284
ericmj merged 1 commit into
mainfrom
raise-work-mem-for-tag-swap

Conversation

@ericmj

@ericmj ericmj commented Aug 9, 2026

Copy link
Copy Markdown
Member

Both statements in swap_docker_tags/2 process the whole staged set, about 1M rows for hexpm/elixir, and both spill at the server's 4MB work_mem.

From one night's Cloud SQL temp file logs, a single swap wrote 391MB. The INSERT ... DISTINCT ON sorts into one 229MB external merge file, and the DELETE ... NOT EXISTS anti-join runs at 64 batches, writing 63 files of 2.58MB. That is most of the 395MB bob wrote in 24 hours.

256MB holds the hash side in one batch and cuts the sort to a single merge pass. Reconcile walks its repos with Enum.each, so one of these transactions is open at a time on one connection.

Same shape as the SET LOCAL work_mem the hexpm stats job already uses for its matview refresh. hexpm/hexpm-ops#240 raises the instance-wide default to 16MB, which is sized for ordinary web queries and nowhere near enough for this one.

The test asserts the statement is issued during a swap, filtered to the test process because telemetry handlers are global. I checked it discriminates by removing the SET LOCAL and confirming it fails.

Both statements in swap_docker_tags/2 process the whole staged set, which is
about 1M rows for hexpm/elixir, and both spill at the server's 4MB work_mem.

From one night's Cloud SQL temp file logs, a single swap wrote 391MB: the
INSERT ... DISTINCT ON sorts into a 229MB external merge file, and the DELETE's
anti-join runs at 64 batches, writing 63 files of 2.58MB. That is most of the
395MB bob wrote in 24 hours.

256MB holds the hash side in one batch and cuts the sort to a single merge
pass. Reconcile walks its repos with Enum.each, so only one of these
transactions is open at a time on one connection.
@ericmj
ericmj marked this pull request as ready for review August 10, 2026 16:14
@ericmj
ericmj merged commit b616258 into main Aug 10, 2026
4 checks passed
@ericmj
ericmj deleted the raise-work-mem-for-tag-swap branch August 10, 2026 16:14
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