From 8c098ad66e26635cb937fcb8bd4c1947c258db81 Mon Sep 17 00:00:00 2001
From: kommih <haribabuk@fast.au.fujitsu.com>
Date: Tue, 22 Jan 2019 11:29:20 +1100
Subject: [PATCH 2/5] Removal of scan_update_snapshot callback

The snapshot structure is avaiable in the tablescandesc
structure itself, so it can be accessed outside itself,
no need of any callback.
---
 src/backend/access/heap/heapam.c         | 18 ------------------
 src/backend/access/heap/heapam_handler.c |  1 -
 src/backend/access/table/tableam.c       | 13 +++++++++++++
 src/include/access/heapam.h              |  1 -
 src/include/access/tableam.h             | 16 ++++++----------
 5 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index c1e4d07864..16a3a378eb 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -1252,24 +1252,6 @@ heap_endscan(TableScanDesc sscan)
 	pfree(scan);
 }
 
-/* ----------------
- *		heap_update_snapshot
- *
- *		Update snapshot info in heap scan descriptor.
- * ----------------
- */
-void
-heap_update_snapshot(TableScanDesc sscan, Snapshot snapshot)
-{
-	HeapScanDesc scan = (HeapScanDesc) sscan;
-
-	Assert(IsMVCCSnapshot(snapshot));
-
-	RegisterSnapshot(snapshot);
-	scan->rs_scan.rs_snapshot = snapshot;
-	scan->rs_scan.rs_temp_snap = true;
-}
-
 /* ----------------
  *		heap_getnext	- retrieve next tuple in scan
  *
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index f2719bb017..eab6a107a6 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2307,7 +2307,6 @@ static const TableAmRoutine heapam_methods = {
 	.scan_begin = heap_beginscan,
 	.scan_end = heap_endscan,
 	.scan_rescan = heap_rescan,
-	.scan_update_snapshot = heap_update_snapshot,
 	.scan_getnextslot = heap_getnextslot,
 
 	.parallelscan_estimate = table_block_parallelscan_estimate,
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 43e5444dcb..9b17cf1cd9 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -395,3 +395,16 @@ table_block_parallelscan_nextpage(Relation rel, ParallelBlockTableScanDesc pbsca
 
 	return page;
 }
+
+/*
+ * Update snapshot info in table scan descriptor.
+ */
+void
+table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot)
+{
+	Assert(IsMVCCSnapshot(snapshot));
+
+	RegisterSnapshot(snapshot);
+	scan->rs_snapshot = snapshot;
+	scan->rs_temp_snap = true;
+}
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index a290e4f053..0ae7923c95 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -182,7 +182,6 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
 				   HeapTuple tup);
 
 extern void heap_sync(Relation relation);
-extern void heap_update_snapshot(TableScanDesc scan, Snapshot snapshot);
 
 extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
 														 ItemPointerData *items,
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index d0240d46f7..054f2102c8 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -90,7 +90,6 @@ typedef struct TableAmRoutine
 	void		(*scan_end) (TableScanDesc scan);
 	void		(*scan_rescan) (TableScanDesc scan, struct ScanKeyData *key, bool set_params,
 								bool allow_strat, bool allow_sync, bool allow_pagemode);
-	void		(*scan_update_snapshot) (TableScanDesc scan, Snapshot snapshot);
 	TupleTableSlot *(*scan_getnextslot) (TableScanDesc scan,
 										 ScanDirection direction, TupleTableSlot *slot);
 
@@ -390,15 +389,6 @@ table_rescan_set_params(TableScanDesc scan, struct ScanKeyData *key,
 										 allow_pagemode);
 }
 
-/*
- * Update snapshot info in heap scan descriptor.
- */
-static inline void
-table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot)
-{
-	scan->rs_rd->rd_tableam->scan_update_snapshot(scan, snapshot);
-}
-
 static inline TupleTableSlot *
 table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
 {
@@ -800,6 +790,12 @@ extern BlockNumber table_block_parallelscan_nextpage(Relation rel, ParallelBlock
 extern void table_block_parallelscan_startblock_init(Relation rel, ParallelBlockTableScanDesc pbscan);
 
 
+/* ----------------------------------------------------------------------------
+ * Helper function to update the snapshot of the scan descriptor
+ * ----------------------------------------------------------------------------
+ */
+extern void table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot);
+
 /* ----------------------------------------------------------------------------
  * Functions in tableamapi.c
  * ----------------------------------------------------------------------------
-- 
2.20.1.windows.1

