MCPcopy Create free account
hub / github.com/apache/cloudberry / hashagg_spill_finish

Function hashagg_spill_finish

src/backend/executor/nodeAgg.c:3416–3453  ·  view source on GitHub ↗

* hashagg_spill_finish * * Transform spill partitions into new batches. */

Source from the content-addressed store, hash-verified

3414 * Transform spill partitions into new batches.
3415 */
3416static void
3417hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
3418{
3419 int i;
3420 int used_bits = 32 - spill->shift;
3421
3422 if (spill->npartitions == 0)
3423 return; /* didn't spill */
3424
3425 for (i = 0; i < spill->npartitions; i++)
3426 {
3427 LogicalTapeSet *tapeset = aggstate->hash_tapeinfo->tapeset;
3428 int tapenum = spill->partitions[i];
3429 HashAggBatch *new_batch;
3430 double cardinality;
3431
3432 /* if the partition is empty, don't create a new batch of work */
3433 if (spill->ntuples[i] == 0)
3434 continue;
3435
3436 cardinality = estimateHyperLogLog(&spill->hll_card[i]);
3437 freeHyperLogLog(&spill->hll_card[i]);
3438
3439 /* rewinding frees the buffer while not in use */
3440 LogicalTapeRewindForRead(tapeset, tapenum,
3441 HASHAGG_READ_BUFFER_SIZE);
3442
3443 new_batch = hashagg_batch_new(tapeset, tapenum, setno,
3444 spill->ntuples[i], cardinality,
3445 used_bits);
3446 aggstate->hash_batches = lappend(aggstate->hash_batches, new_batch);
3447 aggstate->hash_batches_used++;
3448 }
3449
3450 pfree(spill->ntuples);
3451 pfree(spill->hll_card);
3452 pfree(spill->partitions);
3453}
3454
3455/*
3456 * Free resources related to a spilled HashAgg.

Callers 2

agg_refill_hash_tableFunction · 0.85

Calls 6

estimateHyperLogLogFunction · 0.85
freeHyperLogLogFunction · 0.85
LogicalTapeRewindForReadFunction · 0.85
hashagg_batch_newFunction · 0.85
lappendFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected