From aed6c3a7d237ffb4df443bcbc34e6f6509651a2b Mon Sep 17 00:00:00 2001
From: Junwang Zhao <zhjwpku@gmail.com>
Date: Sat, 21 Mar 2026 16:52:11 +0800
Subject: [PATCH v1 1/2] use TupleDescCompactAttr where possible

---
 src/backend/commands/copy.c    | 2 +-
 src/backend/commands/trigger.c | 2 +-
 src/pl/plpython/plpy_exec.c    | 2 +-
 src/pl/tcl/pltcl.c             | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index e837f417d0d..df3d1191151 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -177,7 +177,7 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt,
 				 * would need to expand them somewhere around here), but for
 				 * now we keep them consistent with the stored variant.
 				 */
-				if (TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
+				if (TupleDescCompactAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
 					ereport(ERROR,
 							errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
 							errmsg("generated columns are not supported in COPY FROM WHERE conditions"),
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 6596843a8d8..0ef49bb956d 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -654,7 +654,7 @@ CreateTriggerFiringOn(const CreateTrigStmt *stmt, const char *queryString,
 								 parser_errposition(pstate, var->location)));
 					if (TRIGGER_FOR_BEFORE(tgtype) &&
 						var->varattno > 0 &&
-						TupleDescAttr(RelationGetDescr(rel), var->varattno - 1)->attgenerated)
+						TupleDescCompactAttr(RelationGetDescr(rel), var->varattno - 1)->attgenerated)
 						ereport(ERROR,
 								(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
 								 errmsg("BEFORE trigger's WHEN condition cannot reference NEW generated columns"),
diff --git a/src/pl/plpython/plpy_exec.c b/src/pl/plpython/plpy_exec.c
index 0117f1e77ef..aafcb832210 100644
--- a/src/pl/plpython/plpy_exec.c
+++ b/src/pl/plpython/plpy_exec.c
@@ -1033,7 +1033,7 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata,
 						(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 						 errmsg("cannot set system attribute \"%s\"",
 								plattstr)));
-			if (TupleDescAttr(tupdesc, attn - 1)->attgenerated)
+			if (TupleDescCompactAttr(tupdesc, attn - 1)->attgenerated)
 				ereport(ERROR,
 						(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
 						 errmsg("cannot set generated column \"%s\"",
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 44491de669a..6cc4b3d3025 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -3324,7 +3324,7 @@ pltcl_build_tuple_result(Tcl_Interp *interp, Tcl_Obj **kvObjv, int kvObjc,
 					 errmsg("cannot set system attribute \"%s\"",
 							fieldName)));
 
-		if (TupleDescAttr(tupdesc, attn - 1)->attgenerated)
+		if (TupleDescCompactAttr(tupdesc, attn - 1)->attgenerated)
 			ereport(ERROR,
 					(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
 					 errmsg("cannot set generated column \"%s\"",
-- 
2.41.0

