@@ -61,18 +61,22 @@ typedef struct pgstattuple_type
6161uint64 free_space ;/* free/reusable space in bytes */
6262}pgstattuple_type ;
6363
64- typedef void (* pgstat_page ) (pgstattuple_type * ,Relation ,BlockNumber );
64+ typedef void (* pgstat_page ) (pgstattuple_type * ,Relation ,BlockNumber ,
65+ BufferAccessStrategy );
6566
6667static Datum build_pgstattuple_type (pgstattuple_type * stat ,
6768FunctionCallInfo fcinfo );
6869static Datum pgstat_relation (Relation rel ,FunctionCallInfo fcinfo );
6970static Datum pgstat_heap (Relation rel ,FunctionCallInfo fcinfo );
7071static void pgstat_btree_page (pgstattuple_type * stat ,
71- Relation rel ,BlockNumber blkno );
72+ Relation rel ,BlockNumber blkno ,
73+ BufferAccessStrategy bstrategy );
7274static void pgstat_hash_page (pgstattuple_type * stat ,
73- Relation rel ,BlockNumber blkno );
75+ Relation rel ,BlockNumber blkno ,
76+ BufferAccessStrategy bstrategy );
7477static void pgstat_gist_page (pgstattuple_type * stat ,
75- Relation rel ,BlockNumber blkno );
78+ Relation rel ,BlockNumber blkno ,
79+ BufferAccessStrategy bstrategy );
7680static Datum pgstat_index (Relation rel ,BlockNumber start ,
7781pgstat_page pagefn ,FunctionCallInfo fcinfo );
7882static void pgstat_index_page (pgstattuple_type * stat ,Page page ,
@@ -273,12 +277,17 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
273277BlockNumber tupblock ;
274278Buffer buffer ;
275279pgstattuple_type stat = {0 };
280+ BufferAccessStrategy bstrategy ;
276281
277282/* Disable syncscan because we assume we scan from block zero upwards */
278283scan = heap_beginscan_strat (rel ,SnapshotAny ,0 ,NULL , true, false);
279284
280285nblocks = scan -> rs_nblocks ;/* # blocks to be scanned */
281286
287+ /* prepare access strategy for this table */
288+ bstrategy = GetAccessStrategy (BAS_BULKREAD );
289+ scan -> rs_strategy = bstrategy ;
290+
282291/* scan the relation */
283292while ((tuple = heap_getnext (scan ,ForwardScanDirection ))!= NULL )
284293{
@@ -312,7 +321,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
312321{
313322CHECK_FOR_INTERRUPTS ();
314323
315- buffer = ReadBuffer (rel ,block );
324+ buffer = ReadBufferExtended (rel ,MAIN_FORKNUM , block , RBM_NORMAL , bstrategy );
316325LockBuffer (buffer ,BUFFER_LOCK_SHARE );
317326stat .free_space += PageGetHeapFreeSpace ((Page )BufferGetPage (buffer ));
318327UnlockReleaseBuffer (buffer );
@@ -325,7 +334,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
325334{
326335CHECK_FOR_INTERRUPTS ();
327336
328- buffer = ReadBuffer (rel ,block );
337+ buffer = ReadBufferExtended (rel ,MAIN_FORKNUM , block , RBM_NORMAL , bstrategy );
329338LockBuffer (buffer ,BUFFER_LOCK_SHARE );
330339stat .free_space += PageGetHeapFreeSpace ((Page )BufferGetPage (buffer ));
331340UnlockReleaseBuffer (buffer );
@@ -343,12 +352,13 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
343352 * pgstat_btree_page -- check tuples in a btree page
344353 */
345354static void
346- pgstat_btree_page (pgstattuple_type * stat ,Relation rel ,BlockNumber blkno )
355+ pgstat_btree_page (pgstattuple_type * stat ,Relation rel ,BlockNumber blkno ,
356+ BufferAccessStrategy bstrategy )
347357{
348358Buffer buf ;
349359Page page ;
350360
351- buf = ReadBuffer (rel ,blkno );
361+ buf = ReadBufferExtended (rel ,MAIN_FORKNUM , blkno , RBM_NORMAL , bstrategy );
352362LockBuffer (buf ,BT_READ );
353363page = BufferGetPage (buf );
354364
@@ -386,13 +396,14 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
386396 * pgstat_hash_page -- check tuples in a hash page
387397 */
388398static void
389- pgstat_hash_page (pgstattuple_type * stat ,Relation rel ,BlockNumber blkno )
399+ pgstat_hash_page (pgstattuple_type * stat ,Relation rel ,BlockNumber blkno ,
400+ BufferAccessStrategy bstrategy )
390401{
391402Buffer buf ;
392403Page page ;
393404
394405_hash_getlock (rel ,blkno ,HASH_SHARE );
395- buf = _hash_getbuf (rel ,blkno ,HASH_READ ,0 );
406+ buf = _hash_getbuf_with_strategy (rel ,blkno ,HASH_READ ,0 , bstrategy );
396407page = BufferGetPage (buf );
397408
398409if (PageGetSpecialSize (page )== MAXALIGN (sizeof (HashPageOpaqueData )))
@@ -429,12 +440,13 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
429440 * pgstat_gist_page -- check tuples in a gist page
430441 */
431442static void
432- pgstat_gist_page (pgstattuple_type * stat ,Relation rel ,BlockNumber blkno )
443+ pgstat_gist_page (pgstattuple_type * stat ,Relation rel ,BlockNumber blkno ,
444+ BufferAccessStrategy bstrategy )
433445{
434446Buffer buf ;
435447Page page ;
436448
437- buf = ReadBuffer (rel ,blkno );
449+ buf = ReadBufferExtended (rel ,MAIN_FORKNUM , blkno , RBM_NORMAL , bstrategy );
438450LockBuffer (buf ,GIST_SHARE );
439451gistcheckpage (rel ,buf );
440452page = BufferGetPage (buf );
@@ -461,8 +473,12 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
461473{
462474BlockNumber nblocks ;
463475BlockNumber blkno ;
476+ BufferAccessStrategy bstrategy ;
464477pgstattuple_type stat = {0 };
465478
479+ /* prepare access strategy for this index */
480+ bstrategy = GetAccessStrategy (BAS_BULKREAD );
481+
466482blkno = start ;
467483for (;;)
468484{
@@ -483,7 +499,7 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
483499{
484500CHECK_FOR_INTERRUPTS ();
485501
486- pagefn (& stat ,rel ,blkno );
502+ pagefn (& stat ,rel ,blkno , bstrategy );
487503}
488504}
489505