From 71ecc03b10a2877172d7a46dd4ef756bbe5ab879 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] 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 7f594b3e4f..6655a95433 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 62c5f9fa9f..3dc1444739 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2308,7 +2308,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 f579fb0d71..a2da7b7809 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -394,3 +394,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 7c9c4f5e98..dd67e7e270 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 428ff90cad..4aa4369366 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -89,7 +89,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);
 
@@ -389,15 +388,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)
 {
@@ -799,6 +789,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.18.0.windows.1

