Skip to content

Commit c8aeaf3

Browse files
committed
Change LogicalTapeSetBlocks() to use nBlocksWritten.
Previously, it was based on nBlocksAllocated to account for tapes with open write buffers that may not have made it to the BufFile yet. That was unnecessary, because callers do not need to get the number of blocks while a tape has an open write buffer; and it also conflicted with the preallocation logic added for HashAgg. Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/ce5af05900fdbd0e9185747825a7423c48501964.camel@j-davis.com Backpatch-through: 13
1 parent 3bd35d4 commit c8aeaf3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/backend/executor/nodeAgg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2704,8 +2704,8 @@ agg_refill_hash_table(AggState *aggstate)
27042704

27052705
if (spill_initialized)
27062706
{
2707-
hash_agg_update_metrics(aggstate, true, spill.npartitions);
27082707
hashagg_spill_finish(aggstate, &spill, batch->setno);
2708+
hash_agg_update_metrics(aggstate, true, spill.npartitions);
27092709
}
27102710
else
27112711
hash_agg_update_metrics(aggstate, true, 0);

src/backend/utils/sort/logtape.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,9 +1264,19 @@ LogicalTapeTell(LogicalTapeSet *lts, int tapenum,
12641264

12651265
/*
12661266
* Obtain total disk space currently used by a LogicalTapeSet, in blocks.
1267+
*
1268+
* This should not be called while there are open write buffers; otherwise it
1269+
* may not account for buffered data.
12671270
*/
12681271
long
12691272
LogicalTapeSetBlocks(LogicalTapeSet *lts)
12701273
{
1271-
return lts->nBlocksAllocated - lts->nHoleBlocks;
1274+
#ifdef USE_ASSERT_CHECKING
1275+
for (int i = 0; i < lts->nTapes; i++)
1276+
{
1277+
LogicalTape *lt = &lts->tapes[i];
1278+
Assert(!lt->writing || lt->buffer == NULL);
1279+
}
1280+
#endif
1281+
return lts->nBlocksWritten - lts->nHoleBlocks;
12721282
}

0 commit comments

Comments
 (0)