| From: | Ayoub Kazar <ayoub(dot)kazar(at)data-bene(dot)io> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Should we retain spilled hash tables across rescans? |
| Date: | 2026-12-03 16:44:37 |
| Message-ID: | dbab7bc8-7498-4aea-b73d-9c5278681236@data-bene.io |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Currently for hash joins, only a hash table that fits in memory (one
batch) is reused on each rescan, spilled hash tables need to be rebuilt
on each iteration.
The motivation comes from recursive CTEs where the Hash is on a base
table (mostly graph queries), rebuilding it on
every iteration hurts quite a bit, and I see very nice improvements when
we avoid the rebuilds.
Surely it can get dirty very quickly, because it must end up touching
EXEC_FLAG_REWIND / rescan infra,
so other rescan cases can benefit too (though I'm not sure how valuable
they can be in practice, what i know is that they are uncommon, hence
why its like this today).
Since other cases are rarer (e.g: Nested Loops) than graph queries with
a decent fan-out, one could argue that user should just raise
hash_mem_multiplier.
It does add some complexity and slightly unusual executor work (like
retaining batch 0, etc.). Would it be wise to pursue this?
I don't have a patch worth reviewing yet, if it makes sense doing, i'll
spend more time on it and follow up with something.
Regards,
Ayoub Kazar
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Henson Choi | 2026-12-03 16:46:04 | Re: Speed up tuplestore_seek() by starting from the nearest known position |
| Previous Message | Henson Choi | 2026-12-03 16:39:08 | Re: [PATCH v1] Fix for bug #19773 : pg_dump differing generation expressions of inherited columns |