Skip to content

Commit 6e146a6

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 42a46f5 commit 6e146a6

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
@@ -1262,9 +1262,19 @@ LogicalTapeTell(LogicalTapeSet *lts, int tapenum,
12621262

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

0 commit comments

Comments
 (0)