From 1e99ab2ee9a8f54140c148a5ddb37bcf9f4be321 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Thu, 27 Nov 2025 07:35:29 +0000
Subject: [PATCH v2 4/6] Removing unused function parameters in postgres_fdw

A few parameters are not used, let's remove them.

Unused rte parameter in create_foreign_modify() is oversight in commit
a61b1f74823.
---
 contrib/postgres_fdw/postgres_fdw.c | 59 +++++++++--------------------
 1 file changed, 17 insertions(+), 42 deletions(-)
 100.0% contrib/postgres_fdw/

diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 06b52c65300..be66195495c 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -444,7 +444,6 @@ static void adjust_foreign_grouping_path_cost(PlannerInfo *root,
 											  double retrieved_rows,
 											  double width,
 											  double limit_tuples,
-											  int *p_disabled_nodes,
 											  Cost *p_startup_cost,
 											  Cost *p_run_cost);
 static bool ec_member_matches_foreign(PlannerInfo *root, RelOptInfo *rel,
@@ -455,7 +454,6 @@ static void fetch_more_data(ForeignScanState *node);
 static void close_cursor(PGconn *conn, unsigned int cursor_number,
 						 PgFdwConnState *conn_state);
 static PgFdwModifyState *create_foreign_modify(EState *estate,
-											   RangeTblEntry *rte,
 											   ResultRelInfo *resultRelInfo,
 											   CmdType operation,
 											   Plan *subplan,
@@ -464,8 +462,7 @@ static PgFdwModifyState *create_foreign_modify(EState *estate,
 											   int values_end,
 											   bool has_returning,
 											   List *retrieved_attrs);
-static TupleTableSlot **execute_foreign_modify(EState *estate,
-											   ResultRelInfo *resultRelInfo,
+static TupleTableSlot **execute_foreign_modify(ResultRelInfo *resultRelInfo,
 											   CmdType operation,
 											   TupleTableSlot **slots,
 											   TupleTableSlot **planSlots,
@@ -1924,7 +1921,6 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
 	bool		has_returning;
 	int			values_end_len;
 	List	   *retrieved_attrs;
-	RangeTblEntry *rte;
 
 	/*
 	 * Do nothing in EXPLAIN (no ANALYZE) case.  resultRelInfo->ri_FdwState
@@ -1945,21 +1941,12 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
 	retrieved_attrs = (List *) list_nth(fdw_private,
 										FdwModifyPrivateRetrievedAttrs);
 
-	/* Find RTE. */
-	rte = exec_rt_fetch(resultRelInfo->ri_RangeTableIndex,
-						mtstate->ps.state);
-
 	/* Construct an execution state. */
-	fmstate = create_foreign_modify(mtstate->ps.state,
-									rte,
-									resultRelInfo,
+	fmstate = create_foreign_modify(mtstate->ps.state, resultRelInfo,
 									mtstate->operation,
-									outerPlanState(mtstate)->plan,
-									query,
-									target_attrs,
-									values_end_len,
-									has_returning,
-									retrieved_attrs);
+									outerPlanState(mtstate)->plan, query,
+									target_attrs, values_end_len,
+									has_returning, retrieved_attrs);
 
 	resultRelInfo->ri_FdwState = fmstate;
 }
@@ -1984,7 +1971,7 @@ postgresExecForeignInsert(EState *estate,
 	 */
 	if (fmstate->aux_fmstate)
 		resultRelInfo->ri_FdwState = fmstate->aux_fmstate;
-	rslot = execute_foreign_modify(estate, resultRelInfo, CMD_INSERT,
+	rslot = execute_foreign_modify(resultRelInfo, CMD_INSERT,
 								   &slot, &planSlot, &numSlots);
 	/* Revert that change */
 	if (fmstate->aux_fmstate)
@@ -2013,7 +2000,7 @@ postgresExecForeignBatchInsert(EState *estate,
 	 */
 	if (fmstate->aux_fmstate)
 		resultRelInfo->ri_FdwState = fmstate->aux_fmstate;
-	rslot = execute_foreign_modify(estate, resultRelInfo, CMD_INSERT,
+	rslot = execute_foreign_modify(resultRelInfo, CMD_INSERT,
 								   slots, planSlots, numSlots);
 	/* Revert that change */
 	if (fmstate->aux_fmstate)
@@ -2106,7 +2093,7 @@ postgresExecForeignUpdate(EState *estate,
 	TupleTableSlot **rslot;
 	int			numSlots = 1;
 
-	rslot = execute_foreign_modify(estate, resultRelInfo, CMD_UPDATE,
+	rslot = execute_foreign_modify(resultRelInfo, CMD_UPDATE,
 								   &slot, &planSlot, &numSlots);
 
 	return rslot ? rslot[0] : NULL;
@@ -2125,7 +2112,7 @@ postgresExecForeignDelete(EState *estate,
 	TupleTableSlot **rslot;
 	int			numSlots = 1;
 
-	rslot = execute_foreign_modify(estate, resultRelInfo, CMD_DELETE,
+	rslot = execute_foreign_modify(resultRelInfo, CMD_DELETE,
 								   &slot, &planSlot, &numSlots);
 
 	return rslot ? rslot[0] : NULL;
@@ -2254,14 +2241,9 @@ postgresBeginForeignInsert(ModifyTableState *mtstate,
 					 &retrieved_attrs, &values_end_len);
 
 	/* Construct an execution state. */
-	fmstate = create_foreign_modify(mtstate->ps.state,
-									rte,
-									resultRelInfo,
-									CMD_INSERT,
-									NULL,
-									sql.data,
-									targetAttrs,
-									values_end_len,
+	fmstate = create_foreign_modify(mtstate->ps.state, resultRelInfo,
+									CMD_INSERT, NULL, sql.data,
+									targetAttrs, values_end_len,
 									retrieved_attrs != NIL,
 									retrieved_attrs);
 
@@ -2385,10 +2367,7 @@ postgresRecheckForeignScan(ForeignScanState *node, TupleTableSlot *slot)
  * error condition, we just abandon trying to do the update directly.
  */
 static ForeignScan *
-find_modifytable_subplan(PlannerInfo *root,
-						 ModifyTable *plan,
-						 Index rtindex,
-						 int subplan_index)
+find_modifytable_subplan(ModifyTable *plan, Index rtindex, int subplan_index)
 {
 	Plan	   *subplan = outerPlan(plan);
 
@@ -2477,7 +2456,7 @@ postgresPlanDirectModify(PlannerInfo *root,
 	/*
 	 * Try to locate the ForeignScan subplan that's scanning resultRelation.
 	 */
-	fscan = find_modifytable_subplan(root, plan, resultRelation, subplan_index);
+	fscan = find_modifytable_subplan(plan, resultRelation, subplan_index);
 	if (!fscan)
 		return false;
 
@@ -3495,7 +3474,6 @@ estimate_path_cost_size(PlannerInfo *root,
 				adjust_foreign_grouping_path_cost(root, pathkeys,
 												  retrieved_rows, width,
 												  fpextra->limit_tuples,
-												  &disabled_nodes,
 												  &startup_cost, &run_cost);
 			}
 			else
@@ -3642,7 +3620,6 @@ adjust_foreign_grouping_path_cost(PlannerInfo *root,
 								  double retrieved_rows,
 								  double width,
 								  double limit_tuples,
-								  int *p_disabled_nodes,
 								  Cost *p_startup_cost,
 								  Cost *p_run_cost)
 {
@@ -3955,7 +3932,6 @@ close_cursor(PGconn *conn, unsigned int cursor_number,
  */
 static PgFdwModifyState *
 create_foreign_modify(EState *estate,
-					  RangeTblEntry *rte,
 					  ResultRelInfo *resultRelInfo,
 					  CmdType operation,
 					  Plan *subplan,
@@ -4074,8 +4050,7 @@ create_foreign_modify(EState *estate,
  *		postgresExecForeignDelete.)
  */
 static TupleTableSlot **
-execute_foreign_modify(EState *estate,
-					   ResultRelInfo *resultRelInfo,
+execute_foreign_modify(ResultRelInfo *resultRelInfo,
 					   CmdType operation,
 					   TupleTableSlot **slots,
 					   TupleTableSlot **planSlots,
@@ -5657,7 +5632,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
  * outer rel.
  */
 static bool
-semijoin_target_ok(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel)
+semijoin_target_ok(RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel)
 {
 	List	   *vars;
 	ListCell   *lc;
@@ -5719,7 +5694,7 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
 	/*
 	 * We can't push down semi-join if its reltarget is not safe
 	 */
-	if ((jointype == JOIN_SEMI) && !semijoin_target_ok(root, joinrel, outerrel, innerrel))
+	if ((jointype == JOIN_SEMI) && !semijoin_target_ok(joinrel, outerrel, innerrel))
 		return false;
 
 	/*
-- 
2.34.1

