| From: | Rui Zhao <zhaorui126(at)gmail(dot)com> |
|---|---|
| To: | John Naylor <johncnaylorls(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: memory leak in bounded sorts |
| Date: | 2026-12-02 13:28:31 |
| Message-ID: | 8EB70341-AECD-4C25-B789-F00F1B831C8A@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi John,
Thanks for the fix. It looks good to me.
> since the blocks can't be freed until the sort ends
The fix also allows whole blocks to be freed during the sort. Large
tuples get their own blocks, and AllocSetFree() calls free(block)
in the MemoryChunkIsExternal() branch (aset.c:1183 on master).
I used mem01 and the settings from your script to check this with
12 kB values.
BEGIN;
DECLARE c NO SCROLL CURSOR FOR
SELECT k, repeat(pad, 12) AS p FROM mem01
ORDER BY k DESC, p LIMIT 500;
FETCH 1 FROM c \g /dev/null
SELECT total_nblocks, total_bytes
FROM pg_backend_memory_contexts WHERE name = 'Caller tuples';
COMMIT;
While the cursor was open, I got these results on master.
total_nblocks total_bytes
without patch 1002 12108280
with patch 501 6052192
I got the same block counts and total_bytes on REL_15_STABLE.
make check passed on both versions with and without the patch.
Regards,
Rui
| From | Date | Subject | |
|---|---|---|---|
| Next Message | vignesh C | 2026-12-02 13:29:08 | Re: Show the conflict log table in \dRs+ output |
| Previous Message | Matheus Alcantara | 2026-12-02 12:56:39 | Re: [PATCH v1] Fix for Bug#19724 - ALTER TYPE ... ALTER ATTRIBUTE triggers internal error for base type of domain with check |