| From: | Ethan Tran <ethantran(at)quwin(dot)dev> |
|---|---|
| To: | Mario Karuza <mkaruza(dot)pg(at)icloud(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Improve hash aggregate spilling by writing only the needed columns |
| Date: | 2026-10-29 22:09:27 |
| Message-ID: | 8C78FE3C-2A3B-4855-A706-DA04834E6B79@quwin.dev |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Mario,
I reviewed CF 7310 v1
Improve hash aggregate spilling by writing only the needed columns [1]
The approach looks useful. The compact spill layout and
direct re-spilling fit the existing executor design.
Initial Run
===========
The patch applies cleanly. Automated testing used macOS arm64 and
Apple Clang 21. No compiler warnings or correctness failures were
observed.
Performance
===========
My local tests supported the spill-performance improvements.
> * At SF1 the query does not spill, so this shows that in-memory path is
> not affected.
I found a small startup cost in a different non-spilling case:
repeated aggregation over an empty, wide table. Across 10,000
executions, this measured 509 ms on master versus 535 ms with v1.
The attached follow-up initializes the compact layout on the first
actual spill. It allocates in es_query_cxt to survive resets and
rescans. This restored the startup result to 510 ms.
Nitpicking & Conclusion
=======================
Nit: A brief comment explaining that the reconstructed input slot
borrows Datums from the compact spill slot would help document
ownership.
The patch adds no regression tests. Coverage for sparse-column
reconstruction, NULL/by-reference values, recursive spilling, mixed
grouping sets and rescans would be helpful.
The attached lazy implementation is one tested option. Please feel
free to incorporate or adapt it.
Attachments:
- CF-7310-lazy-initialization.patch
Applies on top of v1; for discussion.
Regards,
Ethan
[1] CF 7310 v1, 2026-09-17, Improve hash aggregate spilling by writing only the needed columns
https://www.postgresql.org/message-id/flat/7247cfafe659f49340ebd5d9e31a5ced45381879(dot)camel(at)icloud(dot)com

| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hannu Krosing | 2026-10-29 22:15:57 | Re: ZSTD TOAST compression, and an extensible compression method encoding |
| Previous Message | Lukas Fittl | 2026-10-29 22:07:45 | Re: Assert failure in parallel query due to SubPlan double visit for hash join |