diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 4e913bd..0f0cd1f 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -1542,7 +1542,8 @@ heap_beginscan_internal(Relation relation, Snapshot snapshot, */ void heap_rescan(HeapScanDesc scan, - ScanKey key) + ScanKey key, + bool keep_startblock) { /* * unpin scan buffers @@ -1553,7 +1554,7 @@ heap_rescan(HeapScanDesc scan, /* * reinitialize scan descriptor */ - initscan(scan, key, true); + initscan(scan, key, keep_startblock); } /* ---------------- @@ -1574,7 +1575,7 @@ heap_rescan_set_params(HeapScanDesc scan, ScanKey key, scan->rs_allow_sync = allow_sync; scan->rs_pageatatime = allow_pagemode && IsMVCCSnapshot(scan->rs_snapshot); /* ... and rescan */ - heap_rescan(scan, key); + heap_rescan(scan, key, true); } /* ---------------- @@ -1772,6 +1773,29 @@ heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan) } /* ---------------- + * heap_parallel_rescan - restart a parallel relation scan + * ---------------- + */ +void +heap_parallel_rescan(ParallelHeapScanDesc pscan, + HeapScanDesc scan) +{ + if (pscan != NULL) + scan->rs_parallel = pscan; + + heap_rescan(scan, /* scan desc */ + NULL, /* new scan keys */ + false); /* don't preserve start block */ + + /* + * Ensure all the backends participating in parallel scan must share the + * syncscan property. + */ + if (pscan) + scan->rs_syncscan = pscan->phs_syncscan; +} + +/* ---------------- * heap_getnext - retrieve next tuple in scan * * Fix to work with index relations. diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c index c784b9e..9131dae 100644 --- a/src/backend/executor/nodeBitmapHeapscan.c +++ b/src/backend/executor/nodeBitmapHeapscan.c @@ -452,7 +452,7 @@ ExecReScanBitmapHeapScan(BitmapHeapScanState *node) PlanState *outerPlan = outerPlanState(node); /* rescan to release any page pin */ - heap_rescan(node->ss.ss_currentScanDesc, NULL); + heap_rescan(node->ss.ss_currentScanDesc, NULL, true); if (node->tbmiterator) tbm_end_iterate(node->tbmiterator); diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index 3cb81fc..75607b2 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -268,7 +268,8 @@ ExecReScanSeqScan(SeqScanState *node) scan = node->ss_currentScanDesc; heap_rescan(scan, /* scan desc */ - NULL); /* new scan keys */ + NULL, /* new scan keys */ + true); /* preserve start block */ ExecScanReScan((ScanState *) node); } diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 98a586d..894ee3f 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -121,9 +121,10 @@ extern HeapScanDesc heap_beginscan_sampling(Relation relation, extern void heap_setscanlimits(HeapScanDesc scan, BlockNumber startBlk, BlockNumber endBlk); extern void heapgetpage(HeapScanDesc scan, BlockNumber page); -extern void heap_rescan(HeapScanDesc scan, ScanKey key); +extern void heap_rescan(HeapScanDesc scan, ScanKey key, bool keep_startblock); extern void heap_rescan_set_params(HeapScanDesc scan, ScanKey key, bool allow_strat, bool allow_sync, bool allow_pagemode); +extern void heap_parallel_rescan(ParallelHeapScanDesc pscan, HeapScanDesc scan); extern void heap_endscan(HeapScanDesc scan); extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);