aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2020-09-15 21:16:31 -0700
committerJeff Davis <jdavis@postgresql.org>2020-09-15 21:18:22 -0700
commit3bd35d4f516adfc492360b20e72911949c961e47 (patch)
tree89736eb4c69d2a83d8da538d1d09bcede9b9c24c /src
parent69bd60672af63eaa8b19cdcea175df5ff172e80e (diff)
downloadpostgresql-3bd35d4f516adfc492360b20e72911949c961e47.tar.gz
postgresql-3bd35d4f516adfc492360b20e72911949c961e47.zip
HashAgg: release write buffers sooner by rewinding tape.
This was an oversight. The purpose of 7fdd919ae7 was to avoid keeping tape buffers around unnecessisarily, but HashAgg didn't rewind early enough. Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/1fb1151c2cddf8747d14e0532da283c3f97e2685.camel@j-davis.com Backpatch-through: 13
Diffstat (limited to 'src')
-rw-r--r--src/backend/executor/nodeAgg.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index f74d4841f17..28802e6588d 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -2639,8 +2639,6 @@ agg_refill_hash_table(AggState *aggstate)
*/
hashagg_recompile_expressions(aggstate, true, true);
- LogicalTapeRewindForRead(tapeinfo->tapeset, batch->input_tapenum,
- HASHAGG_READ_BUFFER_SIZE);
for (;;)
{
TupleTableSlot *spillslot = aggstate->hash_spill_rslot;
@@ -2923,6 +2921,7 @@ hashagg_tapeinfo_assign(HashTapeInfo *tapeinfo, int *partitions,
static void
hashagg_tapeinfo_release(HashTapeInfo *tapeinfo, int tapenum)
{
+ /* rewinding frees the buffer while not in use */
LogicalTapeRewindForWrite(tapeinfo->tapeset, tapenum);
if (tapeinfo->freetapes_alloc == tapeinfo->nfreetapes)
{
@@ -3152,6 +3151,7 @@ hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
for (i = 0; i < spill->npartitions; i++)
{
+ LogicalTapeSet *tapeset = aggstate->hash_tapeinfo->tapeset;
int tapenum = spill->partitions[i];
HashAggBatch *new_batch;
double cardinality;
@@ -3163,9 +3163,13 @@ hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
cardinality = estimateHyperLogLog(&spill->hll_card[i]);
freeHyperLogLog(&spill->hll_card[i]);
- new_batch = hashagg_batch_new(aggstate->hash_tapeinfo->tapeset,
- tapenum, setno, spill->ntuples[i],
- cardinality, used_bits);
+ /* rewinding frees the buffer while not in use */
+ LogicalTapeRewindForRead(tapeset, tapenum,
+ HASHAGG_READ_BUFFER_SIZE);
+
+ new_batch = hashagg_batch_new(tapeset, tapenum, setno,
+ spill->ntuples[i], cardinality,
+ used_bits);
aggstate->hash_batches = lcons(new_batch, aggstate->hash_batches);
aggstate->hash_batches_used++;
}