Re: Memory-Bounded Hash Aggregation
Jeff Davis <pgsql@j-davis.com>
On Wed, 2019-08-28 at 12:52 -0700, Taylor Vesely wrote: > 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. Great, thanks! > 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. Interesting idea, I didn't think of that. > 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? Yes. The idea is to guess how many groups are remaining, then guess how much space they will need in memory, then divide by work_mem. I just didn't get around to it yet. (Same with the costing work.) > 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? It would be an extension of the existing patch, but would add a fair amount of complexity (dealing with partial states, etc.) and the benefit would be fairly modest. We can do it later if justified. > 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. That's a good point. Regards, Jeff Davis
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