@@ -80,8 +80,9 @@ bool synchronize_seqscans = true;
80
80
static HeapScanDesc heap_beginscan_internal (Relation relation ,
81
81
Snapshot snapshot ,
82
82
int nkeys , ScanKey key ,
83
- bool allow_strat , bool allow_sync ,
84
- bool is_bitmapscan , bool temp_snap );
83
+ bool allow_strat , bool allow_sync , bool allow_pagemode ,
84
+ bool is_bitmapscan , bool is_samplescan ,
85
+ bool temp_snap );
85
86
static HeapTuple heap_prepare_insert (Relation relation , HeapTuple tup ,
86
87
TransactionId xid , CommandId cid , int options );
87
88
static XLogRecPtr log_heap_update (Relation reln , Buffer oldbuf ,
@@ -294,9 +295,10 @@ initscan(HeapScanDesc scan, ScanKey key, bool is_rescan)
294
295
295
296
/*
296
297
* Currently, we don't have a stats counter for bitmap heap scans (but the
297
- * underlying bitmap index scans will be counted).
298
+ * underlying bitmap index scans will be counted) or sample scans (we only
299
+ * update stats for tuple fetches there)
298
300
*/
299
- if (!scan -> rs_bitmapscan )
301
+ if (!scan -> rs_bitmapscan && ! scan -> rs_samplescan )
300
302
pgstat_count_heap_scan (scan -> rs_rd );
301
303
}
302
304
@@ -315,7 +317,7 @@ heap_setscanlimits(HeapScanDesc scan, BlockNumber startBlk, BlockNumber numBlks)
315
317
* In page-at-a-time mode it performs additional work, namely determining
316
318
* which tuples on the page are visible.
317
319
*/
318
- static void
320
+ void
319
321
heapgetpage (HeapScanDesc scan , BlockNumber page )
320
322
{
321
323
Buffer buffer ;
@@ -1310,14 +1312,17 @@ heap_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
1310
1312
* HeapScanDesc for a bitmap heap scan. Although that scan technology is
1311
1313
* really quite unlike a standard seqscan, there is just enough commonality
1312
1314
* to make it worth using the same data structure.
1315
+ *
1316
+ * heap_beginscan_samplingscan is alternate entry point for setting up a
1317
+ * HeapScanDesc for a TABLESAMPLE scan.
1313
1318
* ----------------
1314
1319
*/
1315
1320
HeapScanDesc
1316
1321
heap_beginscan (Relation relation , Snapshot snapshot ,
1317
1322
int nkeys , ScanKey key )
1318
1323
{
1319
1324
return heap_beginscan_internal (relation , snapshot , nkeys , key ,
1320
- true, true, false, false);
1325
+ true, true, true, false, false, false);
1321
1326
}
1322
1327
1323
1328
HeapScanDesc
@@ -1327,7 +1332,7 @@ heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
1327
1332
Snapshot snapshot = RegisterSnapshot (GetCatalogSnapshot (relid ));
1328
1333
1329
1334
return heap_beginscan_internal (relation , snapshot , nkeys , key ,
1330
- true, true, false, true);
1335
+ true, true, true, false, false, true);
1331
1336
}
1332
1337
1333
1338
HeapScanDesc
@@ -1336,22 +1341,33 @@ heap_beginscan_strat(Relation relation, Snapshot snapshot,
1336
1341
bool allow_strat , bool allow_sync )
1337
1342
{
1338
1343
return heap_beginscan_internal (relation , snapshot , nkeys , key ,
1339
- allow_strat , allow_sync , false, false);
1344
+ allow_strat , allow_sync , true,
1345
+ false, false, false);
1340
1346
}
1341
1347
1342
1348
HeapScanDesc
1343
1349
heap_beginscan_bm (Relation relation , Snapshot snapshot ,
1344
1350
int nkeys , ScanKey key )
1345
1351
{
1346
1352
return heap_beginscan_internal (relation , snapshot , nkeys , key ,
1347
- false, false, true, false);
1353
+ false, false, true, true, false, false);
1354
+ }
1355
+
1356
+ HeapScanDesc
1357
+ heap_beginscan_sampling (Relation relation , Snapshot snapshot ,
1358
+ int nkeys , ScanKey key ,
1359
+ bool allow_strat , bool allow_pagemode )
1360
+ {
1361
+ return heap_beginscan_internal (relation , snapshot , nkeys , key ,
1362
+ allow_strat , false, allow_pagemode ,
1363
+ false, true, false);
1348
1364
}
1349
1365
1350
1366
static HeapScanDesc
1351
1367
heap_beginscan_internal (Relation relation , Snapshot snapshot ,
1352
1368
int nkeys , ScanKey key ,
1353
- bool allow_strat , bool allow_sync ,
1354
- bool is_bitmapscan , bool temp_snap )
1369
+ bool allow_strat , bool allow_sync , bool allow_pagemode ,
1370
+ bool is_bitmapscan , bool is_samplescan , bool temp_snap )
1355
1371
{
1356
1372
HeapScanDesc scan ;
1357
1373
@@ -1373,6 +1389,7 @@ heap_beginscan_internal(Relation relation, Snapshot snapshot,
1373
1389
scan -> rs_snapshot = snapshot ;
1374
1390
scan -> rs_nkeys = nkeys ;
1375
1391
scan -> rs_bitmapscan = is_bitmapscan ;
1392
+ scan -> rs_samplescan = is_samplescan ;
1376
1393
scan -> rs_strategy = NULL ; /* set in initscan */
1377
1394
scan -> rs_allow_strat = allow_strat ;
1378
1395
scan -> rs_allow_sync = allow_sync ;
@@ -1381,7 +1398,7 @@ heap_beginscan_internal(Relation relation, Snapshot snapshot,
1381
1398
/*
1382
1399
* we can use page-at-a-time mode if it's an MVCC-safe snapshot
1383
1400
*/
1384
- scan -> rs_pageatatime = IsMVCCSnapshot (snapshot );
1401
+ scan -> rs_pageatatime = allow_pagemode && IsMVCCSnapshot (snapshot );
1385
1402
1386
1403
/*
1387
1404
* For a seqscan in a serializable transaction, acquire a predicate lock
0 commit comments