Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 37a4d3d

Browse files
committed
Don't prematurely free the BufferAccessStrategy in pgstat_heap().
This function continued to use it after heap_endscan() freed it. In passing, don't explicit create a strategy here. Instead, use the one created by heap_beginscan_strat(), if any. Back-patch to 9.2, where use of a BufferAccessStrategy here was introduced.
1 parent 6ad903d commit 37a4d3d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

contrib/pgstattuple/pgstattuple.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
274274
BlockNumber tupblock;
275275
Buffer buffer;
276276
pgstattuple_type stat = {0};
277-
BufferAccessStrategy bstrategy;
278277
SnapshotData SnapshotDirty;
279278

280279
/* Disable syncscan because we assume we scan from block zero upwards */
@@ -283,10 +282,6 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
283282

284283
nblocks = scan->rs_nblocks; /* # blocks to be scanned */
285284

286-
/* prepare access strategy for this table */
287-
bstrategy = GetAccessStrategy(BAS_BULKREAD);
288-
scan->rs_strategy = bstrategy;
289-
290285
/* scan the relation */
291286
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
292287
{
@@ -320,26 +315,28 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
320315
{
321316
CHECK_FOR_INTERRUPTS();
322317

323-
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, RBM_NORMAL, bstrategy);
318+
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
319+
RBM_NORMAL, scan->rs_strategy);
324320
LockBuffer(buffer, BUFFER_LOCK_SHARE);
325321
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
326322
UnlockReleaseBuffer(buffer);
327323
block++;
328324
}
329325
}
330-
heap_endscan(scan);
331326

332327
while (block < nblocks)
333328
{
334329
CHECK_FOR_INTERRUPTS();
335330

336-
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, RBM_NORMAL, bstrategy);
331+
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
332+
RBM_NORMAL, scan->rs_strategy);
337333
LockBuffer(buffer, BUFFER_LOCK_SHARE);
338334
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
339335
UnlockReleaseBuffer(buffer);
340336
block++;
341337
}
342338

339+
heap_endscan(scan);
343340
relation_close(rel, AccessShareLock);
344341

345342
stat.table_len = (uint64) nblocks *BLCKSZ;

0 commit comments

Comments
 (0)