Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3bd35d4

Browse files
committed
HashAgg: release write buffers sooner by rewinding tape.
This was an oversight. The purpose of 7fdd919 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
1 parent 69bd606 commit 3bd35d4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/executor/nodeAgg.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,8 +2639,6 @@ agg_refill_hash_table(AggState *aggstate)
26392639
*/
26402640
hashagg_recompile_expressions(aggstate, true, true);
26412641

2642-
LogicalTapeRewindForRead(tapeinfo->tapeset, batch->input_tapenum,
2643-
HASHAGG_READ_BUFFER_SIZE);
26442642
for (;;)
26452643
{
26462644
TupleTableSlot *spillslot = aggstate->hash_spill_rslot;
@@ -2923,6 +2921,7 @@ hashagg_tapeinfo_assign(HashTapeInfo *tapeinfo, int *partitions,
29232921
static void
29242922
hashagg_tapeinfo_release(HashTapeInfo *tapeinfo, int tapenum)
29252923
{
2924+
/* rewinding frees the buffer while not in use */
29262925
LogicalTapeRewindForWrite(tapeinfo->tapeset, tapenum);
29272926
if (tapeinfo->freetapes_alloc == tapeinfo->nfreetapes)
29282927
{
@@ -3152,6 +3151,7 @@ hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
31523151

31533152
for (i = 0; i < spill->npartitions; i++)
31543153
{
3154+
LogicalTapeSet *tapeset = aggstate->hash_tapeinfo->tapeset;
31553155
int tapenum = spill->partitions[i];
31563156
HashAggBatch *new_batch;
31573157
double cardinality;
@@ -3163,9 +3163,13 @@ hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
31633163
cardinality = estimateHyperLogLog(&spill->hll_card[i]);
31643164
freeHyperLogLog(&spill->hll_card[i]);
31653165

3166-
new_batch = hashagg_batch_new(aggstate->hash_tapeinfo->tapeset,
3167-
tapenum, setno, spill->ntuples[i],
3168-
cardinality, used_bits);
3166+
/* rewinding frees the buffer while not in use */
3167+
LogicalTapeRewindForRead(tapeset, tapenum,
3168+
HASHAGG_READ_BUFFER_SIZE);
3169+
3170+
new_batch = hashagg_batch_new(tapeset, tapenum, setno,
3171+
spill->ntuples[i], cardinality,
3172+
used_bits);
31693173
aggstate->hash_batches = lcons(new_batch, aggstate->hash_batches);
31703174
aggstate->hash_batches_used++;
31713175
}

0 commit comments

Comments
 (0)