diff options
author | Noah Misch <noah@leadboat.com> | 2014-06-30 16:59:19 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2014-06-30 16:59:19 -0400 |
commit | 9d0826c595e2a376f6645eb575a9d81d5f5ececf (patch) | |
tree | 938c6191630a1d94fa7f113a6b4070fc6e40fb52 | |
parent | 6647f59fd256927aaf9e35929b5c284d10d18839 (diff) | |
download | postgresql-9d0826c595e2a376f6645eb575a9d81d5f5ececf.tar.gz postgresql-9d0826c595e2a376f6645eb575a9d81d5f5ececf.zip |
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.
-rw-r--r-- | contrib/pgstattuple/pgstattuple.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c index edc603f6a1b..10077483d35 100644 --- a/contrib/pgstattuple/pgstattuple.c +++ b/contrib/pgstattuple/pgstattuple.c @@ -274,7 +274,6 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo) BlockNumber tupblock; Buffer buffer; pgstattuple_type stat = {0}; - BufferAccessStrategy bstrategy; SnapshotData SnapshotDirty; /* Disable syncscan because we assume we scan from block zero upwards */ @@ -283,10 +282,6 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo) nblocks = scan->rs_nblocks; /* # blocks to be scanned */ - /* prepare access strategy for this table */ - bstrategy = GetAccessStrategy(BAS_BULKREAD); - scan->rs_strategy = bstrategy; - /* scan the relation */ while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { @@ -320,26 +315,28 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo) { CHECK_FOR_INTERRUPTS(); - buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, RBM_NORMAL, bstrategy); + buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, + RBM_NORMAL, scan->rs_strategy); LockBuffer(buffer, BUFFER_LOCK_SHARE); stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer)); UnlockReleaseBuffer(buffer); block++; } } - heap_endscan(scan); while (block < nblocks) { CHECK_FOR_INTERRUPTS(); - buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, RBM_NORMAL, bstrategy); + buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, + RBM_NORMAL, scan->rs_strategy); LockBuffer(buffer, BUFFER_LOCK_SHARE); stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer)); UnlockReleaseBuffer(buffer); block++; } + heap_endscan(scan); relation_close(rel, AccessShareLock); stat.table_len = (uint64) nblocks *BLCKSZ; |