From b01172f17c561b89c79a88733241e020ecf946e3 Mon Sep 17 00:00:00 2001
From: kommih <haribabuk@fast.au.fujitsu.com>
Date: Wed, 5 Sep 2018 17:18:09 +1000
Subject: [PATCH 2/3] Remove of Bulk insert state API

Currently there is no requirement of exposing Bulk Insert state
APIs, as there is no use of it currently.
---
 src/backend/access/heap/heapam_handler.c |  4 ---
 src/backend/commands/copy.c              |  6 ++---
 src/backend/commands/createas.c          |  4 +--
 src/backend/commands/matview.c           |  4 +--
 src/backend/commands/tablecmds.c         |  4 +--
 src/include/access/tableam.h             | 32 ------------------------
 6 files changed, 9 insertions(+), 45 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 382148ff1d..2d5074734b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -1771,10 +1771,6 @@ static const TableAmRoutine heapam_methods = {
 	.relation_copy_for_cluster = heap_copy_for_cluster,
 	.relation_sync = heap_sync,
 
-	.getbulkinsertstate = GetBulkInsertState,
-	.freebulkinsertstate = FreeBulkInsertState,
-	.releasebulkinsertstate = ReleaseBulkInsertStatePin,
-
 	.begin_index_fetch = heapam_begin_index_fetch,
 	.reset_index_fetch = heapam_reset_index_fetch,
 	.end_index_fetch = heapam_end_index_fetch,
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index a82389b1a8..49e654e4ee 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2546,7 +2546,7 @@ CopyFrom(CopyState cstate)
 	 */
 	ExecBSInsertTriggers(estate, resultRelInfo);
 
-	bistate = table_getbulkinsertstate(resultRelInfo->ri_RelationDesc);
+	bistate = GetBulkInsertState();
 	econtext = GetPerTupleExprContext(estate);
 
 	/* Set up callback to identify error line number */
@@ -2639,7 +2639,7 @@ CopyFrom(CopyState cstate)
 			 */
 			if (prev_leaf_part_index != leaf_part_index)
 			{
-				table_releasebulkinsertstate(resultRelInfo->ri_RelationDesc, bistate);
+				ReleaseBulkInsertStatePin(bistate);
 				prev_leaf_part_index = leaf_part_index;
 			}
 
@@ -2848,7 +2848,7 @@ next_tuple:
 	/* Done, clean up */
 	error_context_stack = errcallback.previous;
 
-	table_freebulkinsertstate(resultRelInfo->ri_RelationDesc, bistate);
+	FreeBulkInsertState(bistate);
 
 	MemoryContextSwitchTo(oldcontext);
 
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index f84ef0a65e..852c6becba 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -572,7 +572,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
 	 */
 	myState->hi_options = HEAP_INSERT_SKIP_FSM |
 		(XLogIsNeeded() ? 0 : HEAP_INSERT_SKIP_WAL);
-	myState->bistate = table_getbulkinsertstate(intoRelationDesc);
+	myState->bistate = GetBulkInsertState();
 
 	/* Not using WAL requires smgr_targblock be initially invalid */
 	Assert(RelationGetTargetBlock(intoRelationDesc) == InvalidBlockNumber);
@@ -611,7 +611,7 @@ intorel_shutdown(DestReceiver *self)
 {
 	DR_intorel *myState = (DR_intorel *) self;
 
-	table_freebulkinsertstate(myState->rel, myState->bistate);
+	FreeBulkInsertState(myState->bistate);
 
 	/* If we skipped using WAL, must heap_sync before commit */
 	if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index 83ee2f725e..80828ed4a6 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -466,7 +466,7 @@ transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
 	myState->hi_options = HEAP_INSERT_SKIP_FSM | HEAP_INSERT_FROZEN;
 	if (!XLogIsNeeded())
 		myState->hi_options |= HEAP_INSERT_SKIP_WAL;
-	myState->bistate = table_getbulkinsertstate(transientrel);
+	myState->bistate = GetBulkInsertState();
 
 	/* Not using WAL requires smgr_targblock be initially invalid */
 	Assert(RelationGetTargetBlock(transientrel) == InvalidBlockNumber);
@@ -499,7 +499,7 @@ transientrel_shutdown(DestReceiver *self)
 {
 	DR_transientrel *myState = (DR_transientrel *) self;
 
-	table_freebulkinsertstate(myState->transientrel, myState->bistate);
+	FreeBulkInsertState(myState->bistate);
 
 	/* If we skipped using WAL, must heap_sync before commit */
 	if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ff6e4486f0..d44d865ec7 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -4616,7 +4616,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
 	if (newrel)
 	{
 		mycid = GetCurrentCommandId(true);
-		bistate = table_getbulkinsertstate(newrel);
+		bistate = GetBulkInsertState();
 
 		hi_options = HEAP_INSERT_SKIP_FSM;
 		if (!XLogIsNeeded())
@@ -4901,7 +4901,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
 	heap_close(oldrel, NoLock);
 	if (newrel)
 	{
-		table_freebulkinsertstate(newrel, bistate);
+		FreeBulkInsertState(bistate);
 
 		/* If we skipped writing WAL, then we need to sync the heap. */
 		if (hi_options & HEAP_INSERT_SKIP_WAL)
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 6d50410166..5f6b39c0e0 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -125,10 +125,6 @@ typedef void (*RelationCopyForCluster_function)(Relation NewHeap, Relation OldHe
 
 typedef void (*RelationSync_function) (Relation relation);
 
-typedef BulkInsertState (*GetBulkInsertState_function) (void);
-typedef void (*FreeBulkInsertState_function) (BulkInsertState bistate);
-typedef void (*ReleaseBulkInsertState_function) (BulkInsertState bistate);
-
 typedef const TupleTableSlotOps* (*SlotCallbacks_function) (Relation relation);
 
 typedef TableScanDesc (*ScanBegin_function) (Relation relation,
@@ -217,10 +213,6 @@ typedef struct TableAmRoutine
 	RelationCopyForCluster_function relation_copy_for_cluster;
 	RelationSync_function relation_sync;
 
-	GetBulkInsertState_function getbulkinsertstate;
-	FreeBulkInsertState_function freebulkinsertstate;
-	ReleaseBulkInsertState_function releasebulkinsertstate;
-
 	/* Operations on relation scans */
 	ScanBegin_function scan_begin;
 	ScanSetlimits_function scansetlimits;
@@ -650,30 +642,6 @@ table_sync(Relation rel)
 	rel->rd_tableamroutine->relation_sync(rel);
 }
 
-/*
- * -------------------
- * storage Bulk Insert functions
- * -------------------
- */
-static inline BulkInsertState
-table_getbulkinsertstate(Relation rel)
-{
-	return rel->rd_tableamroutine->getbulkinsertstate();
-}
-
-static inline void
-table_freebulkinsertstate(Relation rel, BulkInsertState bistate)
-{
-	rel->rd_tableamroutine->freebulkinsertstate(bistate);
-}
-
-static inline void
-table_releasebulkinsertstate(Relation rel, BulkInsertState bistate)
-{
-	rel->rd_tableamroutine->releasebulkinsertstate(bistate);
-}
-
-
 static inline double
 table_index_build_scan(Relation heapRelation,
 					   Relation indexRelation,
-- 
2.18.0.windows.1

