Subject: [PATCH] Remove dead code in ExecForPortionOfLeftovers()

From: Aleksander Alekseev <[email-masked]>
Date: Tue, 21 Apr 2026 15:22:29 +0300

Hi,

While reading 8e72d914c528 I noticed that
ForPortionOfState.fp_leftoverstypcache is not used for anything. I
suggest removing it, as attached.

-- 
Best regards,
Aleksander Alekseev
From 2c7e1f434322ddbb7517b87773ef8c80307d1398 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email-masked]>
Date: Tue, 21 Apr 2026 15:11:13 +0300
Subject: [PATCH v1] Remove unused ForPortionOfState.fp_leftoverstypcache field

Oversight of commit 8e72d914c528.

Author: Aleksander Alekseev <[email-masked]>
Reviewed-by: TODO FIXME
Discussion: TODO FIXME
---
 src/backend/executor/nodeModifyTable.c | 13 -------------
 src/include/nodes/execnodes.h          |  1 -
 2 files changed, 14 deletions(-)

diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 4cb057ca4f9..6ee26d9803f 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1411,7 +1411,6 @@ ExecForPortionOfLeftovers(ModifyTableContext *context,
 	ForPortionOfExpr *forPortionOf = (ForPortionOfExpr *) node->forPortionOf;
 	AttrNumber	rangeAttno;
 	Datum		oldRange;
-	TypeCacheEntry *typcache;
 	ForPortionOfState *fpoState;
 	TupleTableSlot *oldtupleSlot;
 	TupleTableSlot *leftoverSlot;
@@ -1491,18 +1490,6 @@ ExecForPortionOfLeftovers(ModifyTableContext *context,
 		elog(ERROR, "found a NULL range in a temporal table");
 	oldRange = oldtupleSlot->tts_values[rangeAttno - 1];
 
-	/*
-	 * Get the range's type cache entry. This is worth caching for the whole
-	 * UPDATE/DELETE as range functions do.
-	 */
-
-	typcache = fpoState->fp_leftoverstypcache;
-	if (typcache == NULL)
-	{
-		typcache = lookup_type_cache(forPortionOf->rangeType, 0);
-		fpoState->fp_leftoverstypcache = typcache;
-	}
-
 	/*
 	 * Get the ranges to the left/right of the targeted range. We call a SETOF
 	 * support function and insert as many temporal leftovers as it gives us.
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 13359180d25..db11e7042ea 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -480,7 +480,6 @@ typedef struct ForPortionOfState
 	Oid			fp_rangeType;	/* the type of the FOR PORTION OF expression */
 	int			fp_rangeAttno;	/* the attno of the range column */
 	Datum		fp_targetRange; /* the range/multirange from FOR PORTION OF */
-	TypeCacheEntry *fp_leftoverstypcache;	/* type cache entry of the range */
 	TupleTableSlot *fp_Existing;	/* slot to store old tuple */
 	TupleTableSlot *fp_Leftover;	/* slot to store leftover */
 } ForPortionOfState;
-- 
2.43.0

---

From: Quan Zongliang <[email-masked]>
Date: Wed, 22 Apr 2026 11:58:24 +0800

> suggest removing it, as attached.

Agree.
It indeed did not make any reference anywhere.

Quan Zongliang

---

From: jian he <[email-masked]>
Date: Wed, 22 Apr 2026 12:24:08 +0800

> It indeed did not make any reference anywhere.

I raised this issue at [1].
But apparently, it's actually being used for fixing a bug at [2].

[1]: https://www.postgresql.org/message-id/CACJufxHYntqy2fo9CFWDDrqKjcMK8DGRM3kse4YnXYnPYq2Hiw%40mail.gmail.com
[2]: https://www.postgresql.org/message-id/CA%2BrenyU5%3Dmihx6O8%2BERBmarZcuV1QiWB3X5bZhdptWoRM9G-Aw%40mail.gmail.com