@@ -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,
29232921static void
29242922hashagg_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