Re: Memory-Bounded Hash Aggregation
Tomas Vondra <tomas.vondra@2ndquadrant.com>
On Thu, Dec 12, 2019 at 06:10:50PM -0800, Jeff Davis wrote: >On Thu, 2019-11-28 at 18:46 +0100, Tomas Vondra wrote: >> 13) As for this: >> >> /* make sure that we don't exhaust the hash bits */ >> if (partition_bits + input_bits >= 32) >> partition_bits = 32 - input_bits; >> >> We already ran into this issue (exhausting bits in a hash value) in >> hashjoin batching, we should be careful to use the same approach in >> both >> places (not the same code, just general approach). > >I assume you're talking about ExecHashIncreaseNumBatches(), and in >particular, commit 8442317b. But that's a 10-year-old commit, so >perhaps you're talking about something else? > >It looks like that code in HJ is protecting against having a very large >number of batches, such that we can't allocate an array of pointers for >each batch. And it seems like the concern is more related to a planner >error causing such a large nbatch. > >I don't quite see the analogous case in HashAgg. npartitions is already >constrained to a maximum of 256. And the batches are individually >allocated, held in a list, not an array. > >It could perhaps use some defensive programming to make sure that we >don't run into problems if the max is set very high. > >Can you clarify what you're looking for here? > I'm talking about this recent discussion on pgsql-bugs: https://www.postgresql.org/message-id/CA%2BhUKGLyafKXBMFqZCSeYikPbdYURbwr%2BjP6TAy8sY-8LO0V%2BQ%40mail.gmail.com I.e. when number of batches/partitions and buckets is high enough, we may end up with very few bits in one of the parts. >Perhaps I can also add a comment saying that we can have less than >HASH_MIN_PARTITIONS when running out of bits. > Maybe. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Commits
-
Fix costing for disk-based hash aggregation.
- 7351bfeda33b 13.0 landed
-
Fixes for Disk-based Hash Aggregation.
- 64fe60227909 13.0 landed
-
Disk-based Hash Aggregation.
- 1f39bce02154 13.0 landed
-
Extend ExecBuildAggTrans() to support a NULL pointer check.
- c954d4904650 13.0 landed
-
Save calculated transitionSpace in Agg node.
- c11cb17dc55a 13.0 landed
-
Minor refactor of nodeAgg.c.
- 5b618e1f48ae 13.0 landed
-
Logical Tape Set: lazily allocate read buffer.
- 7fdd919ae755 13.0 landed
-
Introduce TupleHashTableHash() and LookupTupleHashEntryHash().
- 4eaea3db150a 13.0 landed
-
Logical Tape Set: use min heap for freelist.
- c02fdc922301 13.0 landed
-
Fix comments in execGrouping.c
- 30d47723fd15 13.0 landed
-
Avoid integer overflow while sifting-up a heap in tuplesort.c.
- 512f67c8d02c 10.0 cited
-
Make the overflow guards in ExecChooseHashTableSize be more protective.
- 8442317beb8f 9.0.0 cited
-
Improve performance of our private version of qsort. Per recent testing,
- a3f0b3d68f9a 8.2.0 cited