Re: Memory-Bounded Hash Aggregation
Jeff Davis <pgsql@j-davis.com>
Attachments
- hashagg-20200315.patch (text/x-patch) patch
On Thu, 2020-03-12 at 16:01 -0500, Justin Pryzby wrote:
> I don't understand what's meant by "the chosen plan".
> Should it say, "at execution ..." instead of "execution time" ?
I removed that wording; hopefully it's more clear without it?
> Either remove "plan types" for consistency with
> enable_groupingsets_hash_disk,
> Or add it there. Maybe it should say "when the memory usage would
> OTHERWISE BE
> expected to exceed.."
I added "plan types".
I don't think "otherwise be..." would quite work there. "Otherwise"
sounds to me like it's referring to another plan type (e.g.
Sort+GroupAgg), and that doesn't fit.
It's probably best to leave that level of detail out of the docs. I
think the main use case for enable_hashagg_disk is for users who
experience some plan changes and want the old behavior which favors
Sort when there are a lot of groups.
> +show_hashagg_info(AggState *aggstate, ExplainState *es)
> +{
> + Agg *agg = (Agg *)aggstate->ss.ps.plan;
> + long memPeakKb = (aggstate->hash_mem_peak + 1023) / 1024;
>
> I see this partially duplicates my patch [0] to show memory stats for
...
> You added hash_mem_peak and hash_batches_used to struct AggState.
> In my 0001 patch, I added instrumentation to struct TupleHashTable
I replied in that thread and I'm not sure that tracking the memory in
the TupleHashTable is the right approach. The group keys and the
transition state data can't be estimated easily that way. Perhaps we
can do that if the THT owns the memory contexts (and can call
MemoryContextMemAllocated()), rather than using passed-in ones, but
that might require more discussion. (I'm open to that idea, by the
way.)
Also, my patch also considers the buffer space, so would that be a
third memory number?
For now, I think I'll leave the way I report it in a simpler form and
we can change it later as we sort out these details. That leaves mine
specific to HashAgg, but we can always refactor it later.
I did change my code to put the metacontext in a child context of its
own so that I could call MemoryContextMemAllocated() on it to include
it in the memory total, and that will make reporting it separately
easier when we want to do so.
> + if (from_tape)
> + partition_mem += HASHAGG_READ_BUFFER_SIZE;
> + partition_mem = npartitions * HASHAGG_WRITE_BUFFER_SIZE;
>
> => That looks wrong ; should say += ?
Good catch! Fixed.
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