@@ -2639,8 +2639,6 @@ agg_refill_hash_table(AggState *aggstate)
2639
2639
*/
2640
2640
hashagg_recompile_expressions (aggstate , true, true);
2641
2641
2642
- LogicalTapeRewindForRead (tapeinfo -> tapeset , batch -> input_tapenum ,
2643
- HASHAGG_READ_BUFFER_SIZE );
2644
2642
for (;;)
2645
2643
{
2646
2644
TupleTableSlot * spillslot = aggstate -> hash_spill_rslot ;
@@ -2923,6 +2921,7 @@ hashagg_tapeinfo_assign(HashTapeInfo *tapeinfo, int *partitions,
2923
2921
static void
2924
2922
hashagg_tapeinfo_release (HashTapeInfo * tapeinfo , int tapenum )
2925
2923
{
2924
+ /* rewinding frees the buffer while not in use */
2926
2925
LogicalTapeRewindForWrite (tapeinfo -> tapeset , tapenum );
2927
2926
if (tapeinfo -> freetapes_alloc == tapeinfo -> nfreetapes )
2928
2927
{
@@ -3152,6 +3151,7 @@ hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
3152
3151
3153
3152
for (i = 0 ; i < spill -> npartitions ; i ++ )
3154
3153
{
3154
+ LogicalTapeSet * tapeset = aggstate -> hash_tapeinfo -> tapeset ;
3155
3155
int tapenum = spill -> partitions [i ];
3156
3156
HashAggBatch * new_batch ;
3157
3157
double cardinality ;
@@ -3163,9 +3163,13 @@ hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
3163
3163
cardinality = estimateHyperLogLog (& spill -> hll_card [i ]);
3164
3164
freeHyperLogLog (& spill -> hll_card [i ]);
3165
3165
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 );
3169
3173
aggstate -> hash_batches = lcons (new_batch , aggstate -> hash_batches );
3170
3174
aggstate -> hash_batches_used ++ ;
3171
3175
}
0 commit comments