@@ -61,18 +61,22 @@ typedef struct pgstattuple_type
61
61
uint64 free_space ; /* free/reusable space in bytes */
62
62
} pgstattuple_type ;
63
63
64
- typedef void (* pgstat_page ) (pgstattuple_type * , Relation , BlockNumber );
64
+ typedef void (* pgstat_page ) (pgstattuple_type * , Relation , BlockNumber ,
65
+ BufferAccessStrategy );
65
66
66
67
static Datum build_pgstattuple_type (pgstattuple_type * stat ,
67
68
FunctionCallInfo fcinfo );
68
69
static Datum pgstat_relation (Relation rel , FunctionCallInfo fcinfo );
69
70
static Datum pgstat_heap (Relation rel , FunctionCallInfo fcinfo );
70
71
static void pgstat_btree_page (pgstattuple_type * stat ,
71
- Relation rel , BlockNumber blkno );
72
+ Relation rel , BlockNumber blkno ,
73
+ BufferAccessStrategy bstrategy );
72
74
static void pgstat_hash_page (pgstattuple_type * stat ,
73
- Relation rel , BlockNumber blkno );
75
+ Relation rel , BlockNumber blkno ,
76
+ BufferAccessStrategy bstrategy );
74
77
static void pgstat_gist_page (pgstattuple_type * stat ,
75
- Relation rel , BlockNumber blkno );
78
+ Relation rel , BlockNumber blkno ,
79
+ BufferAccessStrategy bstrategy );
76
80
static Datum pgstat_index (Relation rel , BlockNumber start ,
77
81
pgstat_page pagefn , FunctionCallInfo fcinfo );
78
82
static void pgstat_index_page (pgstattuple_type * stat , Page page ,
@@ -273,12 +277,17 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
273
277
BlockNumber tupblock ;
274
278
Buffer buffer ;
275
279
pgstattuple_type stat = {0 };
280
+ BufferAccessStrategy bstrategy ;
276
281
277
282
/* Disable syncscan because we assume we scan from block zero upwards */
278
283
scan = heap_beginscan_strat (rel , SnapshotAny , 0 , NULL , true, false);
279
284
280
285
nblocks = scan -> rs_nblocks ; /* # blocks to be scanned */
281
286
287
+ /* prepare access strategy for this table */
288
+ bstrategy = GetAccessStrategy (BAS_BULKREAD );
289
+ scan -> rs_strategy = bstrategy ;
290
+
282
291
/* scan the relation */
283
292
while ((tuple = heap_getnext (scan , ForwardScanDirection )) != NULL )
284
293
{
@@ -312,7 +321,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
312
321
{
313
322
CHECK_FOR_INTERRUPTS ();
314
323
315
- buffer = ReadBuffer (rel , block );
324
+ buffer = ReadBufferExtended (rel , MAIN_FORKNUM , block , RBM_NORMAL , bstrategy );
316
325
LockBuffer (buffer , BUFFER_LOCK_SHARE );
317
326
stat .free_space += PageGetHeapFreeSpace ((Page ) BufferGetPage (buffer ));
318
327
UnlockReleaseBuffer (buffer );
@@ -325,7 +334,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
325
334
{
326
335
CHECK_FOR_INTERRUPTS ();
327
336
328
- buffer = ReadBuffer (rel , block );
337
+ buffer = ReadBufferExtended (rel , MAIN_FORKNUM , block , RBM_NORMAL , bstrategy );
329
338
LockBuffer (buffer , BUFFER_LOCK_SHARE );
330
339
stat .free_space += PageGetHeapFreeSpace ((Page ) BufferGetPage (buffer ));
331
340
UnlockReleaseBuffer (buffer );
@@ -343,12 +352,13 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
343
352
* pgstat_btree_page -- check tuples in a btree page
344
353
*/
345
354
static 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 )
347
357
{
348
358
Buffer buf ;
349
359
Page page ;
350
360
351
- buf = ReadBuffer (rel , blkno );
361
+ buf = ReadBufferExtended (rel , MAIN_FORKNUM , blkno , RBM_NORMAL , bstrategy );
352
362
LockBuffer (buf , BT_READ );
353
363
page = BufferGetPage (buf );
354
364
@@ -386,13 +396,14 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
386
396
* pgstat_hash_page -- check tuples in a hash page
387
397
*/
388
398
static 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 )
390
401
{
391
402
Buffer buf ;
392
403
Page page ;
393
404
394
405
_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 );
396
407
page = BufferGetPage (buf );
397
408
398
409
if (PageGetSpecialSize (page ) == MAXALIGN (sizeof (HashPageOpaqueData )))
@@ -429,12 +440,13 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
429
440
* pgstat_gist_page -- check tuples in a gist page
430
441
*/
431
442
static 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 )
433
445
{
434
446
Buffer buf ;
435
447
Page page ;
436
448
437
- buf = ReadBuffer (rel , blkno );
449
+ buf = ReadBufferExtended (rel , MAIN_FORKNUM , blkno , RBM_NORMAL , bstrategy );
438
450
LockBuffer (buf , GIST_SHARE );
439
451
gistcheckpage (rel , buf );
440
452
page = BufferGetPage (buf );
@@ -461,8 +473,12 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
461
473
{
462
474
BlockNumber nblocks ;
463
475
BlockNumber blkno ;
476
+ BufferAccessStrategy bstrategy ;
464
477
pgstattuple_type stat = {0 };
465
478
479
+ /* prepare access strategy for this index */
480
+ bstrategy = GetAccessStrategy (BAS_BULKREAD );
481
+
466
482
blkno = start ;
467
483
for (;;)
468
484
{
@@ -483,7 +499,7 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
483
499
{
484
500
CHECK_FOR_INTERRUPTS ();
485
501
486
- pagefn (& stat , rel , blkno );
502
+ pagefn (& stat , rel , blkno , bstrategy );
487
503
}
488
504
}
489
505
0 commit comments