Re: Memory-Bounded Hash Aggregation
Taylor Vesely <tvesely@pivotal.io>
Attachments
- v1-0001-Rebased-memory-bounded-hash-aggregation.patch (application/octet-stream) patch v1-0001
I started to review this patch yesterday with Melanie Plageman, so we rebased this patch over the current master. The main conflicts were due to a simplehash patch that has been committed separately[1]. I've attached the rebased patch. I was playing with the code, and if one of the table's most common values isn't placed into the initial hash table it spills a whole lot of tuples to disk that might have been avoided if we had some way to 'seed' the hash table with MCVs from the statistics. Seems to me that you would need some way of dealing with values that are in the MCV list, but ultimately don't show up in the scan. I imagine that this kind of optimization would most useful for aggregates on a full table scan. Some questions: Right now the patch always initializes 32 spill partitions. Have you given any thought into how to intelligently pick an optimal number of partitions yet? > That can be done as an add-on to approach #1 by evicting the entire > Hash table (writing out the partial states), then resetting the memory > Context. By add-on approach, do you mean to say that you have something in mind to combine the two strategies? Or do you mean that it could be implemented as a separate strategy? > I think it's clear there's no perfect eviction strategy - for every > algorithm we came up with we can construct a data set on which it > performs terribly (I'm sure we could do that for the approach used by > Greenplum, for example). > > So I think it makes sense to do what Jeff proposed, and then maybe try > improving that in the future with a switch to different eviction > strategy based on some heuristics. I agree. It definitely feels like both spilling strategies have their own use case. That said, I think it's worth mentioning that with parallel aggregates it might actually be more useful to spill the trans values instead, and have them combined in a Gather or Finalize stage. [1] https://www.postgresql.org/message-id/flat/48abe675e1330f0c264ab2fe0d4ff23eb244f9ef.camel%40j-davis.com
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