From 0d8f3ff345d25d3d19ef1e3afb7374c45acef44b Mon Sep 17 00:00:00 2001
From: Rushabh Lathia <rushabh.lathia@enterprisedb.com>
Date: Mon, 10 Mar 2025 16:40:02 +0530
Subject: [PATCH 4/4] Adjust set_attnotnull() API input parameters.

---
 src/backend/commands/tablecmds.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ef9ec42e624..a1730abd318 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -471,8 +471,7 @@ static void add_column_collation_dependency(Oid relid, int32 attnum, Oid collid)
 static ObjectAddress ATExecDropNotNull(Relation rel, const char *colName, bool recurse,
 									   LOCKMODE lockmode);
 static void set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum,
-						   char newvalue, bool queue_validation,
-						   LOCKMODE lockmode);
+						   char newvalue, LOCKMODE lockmode);
 static ObjectAddress ATExecSetNotNull(List **wqueue, Relation rel,
 									  char *constrname, char *colName,
 									  bool recurse, bool recursing,
@@ -1319,8 +1318,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
 	nncols = AddRelationNotNullConstraints(rel, stmt->nnconstraints,
 										   old_notnulls);
 	foreach_int(attrnum, nncols)
-		set_attnotnull(NULL, rel, attrnum, ATTRIBUTE_NOTNULL_TRUE,
-					   false, NoLock);
+		set_attnotnull(NULL, rel, attrnum, ATTRIBUTE_NOTNULL_TRUE, NoLock);
 
 	ObjectAddressSet(address, RelationRelationId, relationId);
 
@@ -7718,13 +7716,11 @@ ATExecDropNotNull(Relation rel, const char *colName, bool recurse,
  */
 static void
 set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum,
-			   char newvalue, bool queue_validation, LOCKMODE lockmode)
+			   char newvalue, LOCKMODE lockmode)
 {
 	Form_pg_attribute attr;
 
 
-	Assert(!queue_validation || wqueue != NULL);
-
 	CheckAlterTableIsSafe(rel);
 
 	/*
@@ -7756,7 +7752,7 @@ set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum,
 		 * Queue later validation of this constraint, if necessary and
 		 * requested by caller.
 		 */
-		if (queue_validation &&
+		if (wqueue &&
 			newvalue == ATTRIBUTE_NOTNULL_TRUE &&
 			!NotNullImpliedByRelConstraints(rel, attr))
 		{
@@ -7940,7 +7936,7 @@ ATExecSetNotNull(List **wqueue, Relation rel, char *conName, char *colName,
 				   constraint->skip_validation ?
 				   ATTRIBUTE_NOTNULL_INVALID :
 				   ATTRIBUTE_NOTNULL_TRUE,
-				   !constraint->skip_validation, lockmode);
+				   lockmode);
 
 	/*
 	 * Recurse to propagate the constraint to children that don't have one.
@@ -9800,7 +9796,6 @@ ATAddCheckNNConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
 						   ccon->skip_validation ?
 						   ATTRIBUTE_NOTNULL_INVALID :
 						   ATTRIBUTE_NOTNULL_TRUE,
-						   !ccon->skip_validation,
 						   lockmode);
 
 		ObjectAddressSet(address, ConstraintRelationId, ccon->conoid);
@@ -12550,8 +12545,7 @@ QueueNNConstraintValidation(List **wqueue, Relation conrel, Relation rel,
 	CatalogTupleUpdate(conrel, &copyTuple->t_self, copyTuple);
 
 	/* Also flip attnotnull */
-	set_attnotnull(wqueue, rel, attnum, ATTRIBUTE_NOTNULL_TRUE, false,
-				   lockmode);
+	set_attnotnull(NULL, rel, attnum, ATTRIBUTE_NOTNULL_TRUE, lockmode);
 
 	InvokeObjectPostAlterHook(ConstraintRelationId, con->oid, 0);
 
-- 
2.43.0

