From 809b5f0d28dbc69388ce8e28c12df0ea9573eadb Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Mon, 17 Nov 2025 08:18:18 +0000
Subject: [PATCH v1 4/8] Use OidIsValid() in various places for CATALOG

Let's use OidIsValid() instead of:

- direct comparisons with InvalidOid
- direct comparisons with literal 0
---
 contrib/amcheck/verify_heapam.c               |  4 ++--
 contrib/test_decoding/test_decoding.c         |  2 +-
 src/backend/access/heap/heaptoast.c           |  6 +++---
 src/backend/bootstrap/bootstrap.c             |  2 +-
 src/backend/catalog/pg_constraint.c           |  2 +-
 src/backend/catalog/pg_shdepend.c             |  6 +++---
 src/backend/catalog/toasting.c                |  2 +-
 src/backend/commands/cluster.c                | 18 ++++++++---------
 src/backend/commands/tablecmds.c              | 16 +++++++--------
 src/backend/parser/parse_relation.c           |  2 +-
 .../replication/logical/reorderbuffer.c       |  2 +-
 src/backend/utils/adt/dbsize.c                |  6 +++---
 src/backend/utils/adt/regproc.c               |  8 ++++----
 src/backend/utils/adt/ruleutils.c             |  6 +++---
 src/backend/utils/cache/relcache.c            | 20 +++++++++----------
 15 files changed, 51 insertions(+), 51 deletions(-)
   4.4% contrib/amcheck/
   5.8% src/backend/access/heap/
   8.0% src/backend/catalog/
  35.4% src/backend/commands/
  14.4% src/backend/utils/adt/
  22.6% src/backend/utils/cache/
   7.2% src/backend/

diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index 4963e9245cb..a5b97b0eea0 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -405,7 +405,7 @@ verify_heapam(PG_FUNCTION_ARGS)
 	}
 
 	/* Optionally open the toast relation, if any. */
-	if (ctx.rel->rd_rel->reltoastrelid && check_toast)
+	if (OidIsValid(ctx.rel->rd_rel->reltoastrelid) && check_toast)
 	{
 		int			offset;
 
@@ -1817,7 +1817,7 @@ check_tuple_attribute(HeapCheckContext *ctx)
 	}
 
 	/* The relation better have a toast table */
-	if (!ctx->rel->rd_rel->reltoastrelid)
+	if (!OidIsValid(ctx->rel->rd_rel->reltoastrelid))
 	{
 		report_corruption(ctx,
 						  psprintf("toast value %u is external but relation has no toast relation",
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index 36e77c69e1c..9dcbeb7fc8d 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -630,7 +630,7 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
 	appendStringInfoString(ctx->out, "table ");
 	appendStringInfoString(ctx->out,
 						   quote_qualified_identifier(get_namespace_name(get_rel_namespace(RelationGetRelid(relation))),
-													  class_form->relrewrite ?
+													  OidIsValid(class_form->relrewrite) ?
 													  get_rel_name(class_form->relrewrite) :
 													  NameStr(class_form->relname)));
 	appendStringInfoChar(ctx->out, ':');
diff --git a/src/backend/access/heap/heaptoast.c b/src/backend/access/heap/heaptoast.c
index e148c9be482..23688f8937d 100644
--- a/src/backend/access/heap/heaptoast.c
+++ b/src/backend/access/heap/heaptoast.c
@@ -213,7 +213,7 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
 		 * XXX maybe the threshold should be less than maxDataLen?
 		 */
 		if (toast_attr[biggest_attno].tai_size > maxDataLen &&
-			rel->rd_rel->reltoastrelid != InvalidOid)
+			OidIsValid(rel->rd_rel->reltoastrelid))
 			toast_tuple_externalize(&ttc, biggest_attno, options);
 	}
 
@@ -224,7 +224,7 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
 	 */
 	while (heap_compute_data_size(tupleDesc,
 								  toast_values, toast_isnull) > maxDataLen &&
-		   rel->rd_rel->reltoastrelid != InvalidOid)
+		   OidIsValid(rel->rd_rel->reltoastrelid))
 	{
 		int			biggest_attno;
 
@@ -259,7 +259,7 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
 
 	while (heap_compute_data_size(tupleDesc,
 								  toast_values, toast_isnull) > maxDataLen &&
-		   rel->rd_rel->reltoastrelid != InvalidOid)
+		   OidIsValid(rel->rd_rel->reltoastrelid))
 	{
 		int			biggest_attno;
 
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 60b168e668c..2025a3ac2d2 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -551,7 +551,7 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
 		attrtypes[attnum]->attcompression = InvalidCompressionMethod;
 		attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
 		/* if an array type, assume 1-dimensional attribute */
-		if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
+		if (OidIsValid(Ap->am_typ.typelem) && Ap->am_typ.typlen < 0)
 			attrtypes[attnum]->attndims = 1;
 		else
 			attrtypes[attnum]->attndims = 0;
diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c
index 9944e4bd2d1..5c21167a5a9 100644
--- a/src/backend/catalog/pg_constraint.c
+++ b/src/backend/catalog/pg_constraint.c
@@ -1127,7 +1127,7 @@ ConstraintSetParentConstraint(Oid childConstrId,
 	{
 		/* don't allow setting parent for a constraint that already has one */
 		Assert(constrForm->coninhcount == 0);
-		if (constrForm->conparentid != InvalidOid)
+		if (OidIsValid(constrForm->conparentid))
 			elog(ERROR, "constraint %u already has a parent constraint",
 				 childConstrId);
 
diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c
index 2f0f1ace7a3..ee76d23dd43 100644
--- a/src/backend/catalog/pg_shdepend.c
+++ b/src/backend/catalog/pg_shdepend.c
@@ -752,7 +752,7 @@ checkSharedDependencies(Oid classId, Oid objectId,
 		 * number of them later.
 		 */
 		if (sdepForm->dbid == MyDatabaseId ||
-			sdepForm->dbid == InvalidOid)
+			!OidIsValid(sdepForm->dbid))
 		{
 			if (numobjects >= allocedobjects)
 			{
@@ -1403,7 +1403,7 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
 			 * database
 			 */
 			if (sdepForm->dbid != MyDatabaseId &&
-				sdepForm->dbid != InvalidOid)
+				OidIsValid(sdepForm->dbid))
 				continue;
 
 			switch (sdepForm->deptype)
@@ -1589,7 +1589,7 @@ shdepReassignOwned(List *roleids, Oid newrole)
 			 * database
 			 */
 			if (sdepForm->dbid != MyDatabaseId &&
-				sdepForm->dbid != InvalidOid)
+				OidIsValid(sdepForm->dbid))
 				continue;
 
 			/*
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index e42bb2a2082..ed2e3a8592d 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -149,7 +149,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
 	/*
 	 * Is it already toasted?
 	 */
-	if (rel->rd_rel->reltoastrelid != InvalidOid)
+	if (OidIsValid(rel->rd_rel->reltoastrelid))
 		return false;
 
 	/*
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index d8990930145..3314b253352 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -874,7 +874,7 @@ copy_table_data(Relation NewHeap, Relation OldHeap, Relation OldIndex, bool verb
 	 * We don't need to open the toast relation here, just lock it.  The lock
 	 * will be held till end of transaction.
 	 */
-	if (OldHeap->rd_rel->reltoastrelid)
+	if (OidIsValid(OldHeap->rd_rel->reltoastrelid))
 		LockRelationOid(OldHeap->rd_rel->reltoastrelid, AccessExclusiveLock);
 
 	/*
@@ -884,7 +884,7 @@ copy_table_data(Relation NewHeap, Relation OldHeap, Relation OldIndex, bool verb
 	 * swap by links.  This is okay because swap by content is only essential
 	 * for system catalogs, and we don't support schema changes for them.
 	 */
-	if (OldHeap->rd_rel->reltoastrelid && NewHeap->rd_rel->reltoastrelid)
+	if (OidIsValid(OldHeap->rd_rel->reltoastrelid) && OidIsValid(NewHeap->rd_rel->reltoastrelid))
 	{
 		*pSwapToastByContent = true;
 
@@ -1158,7 +1158,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 			elog(ERROR, "cannot change access method of mapped relation \"%s\"",
 				 NameStr(relform1->relname));
 		if (!swap_toast_by_content &&
-			(relform1->reltoastrelid || relform2->reltoastrelid))
+			(OidIsValid(relform1->reltoastrelid) || OidIsValid(relform2->reltoastrelid)))
 			elog(ERROR, "cannot swap toast by links for mapped relation \"%s\"",
 				 NameStr(relform1->relname));
 
@@ -1310,11 +1310,11 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 	 * If we have toast tables associated with the relations being swapped,
 	 * deal with them too.
 	 */
-	if (relform1->reltoastrelid || relform2->reltoastrelid)
+	if (OidIsValid(relform1->reltoastrelid) || OidIsValid(relform2->reltoastrelid))
 	{
 		if (swap_toast_by_content)
 		{
-			if (relform1->reltoastrelid && relform2->reltoastrelid)
+			if (OidIsValid(relform1->reltoastrelid) && OidIsValid(relform2->reltoastrelid))
 			{
 				/* Recursively swap the contents of the toast tables */
 				swap_relation_files(relform1->reltoastrelid,
@@ -1359,7 +1359,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 				elog(ERROR, "cannot swap toast files by links for system catalogs");
 
 			/* Delete old dependencies */
-			if (relform1->reltoastrelid)
+			if (OidIsValid(relform1->reltoastrelid))
 			{
 				count = deleteDependencyRecordsFor(RelationRelationId,
 												   relform1->reltoastrelid,
@@ -1368,7 +1368,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 					elog(ERROR, "expected one dependency record for TOAST table, found %ld",
 						 count);
 			}
-			if (relform2->reltoastrelid)
+			if (OidIsValid(relform2->reltoastrelid))
 			{
 				count = deleteDependencyRecordsFor(RelationRelationId,
 												   relform2->reltoastrelid,
@@ -1384,7 +1384,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 			toastobject.classId = RelationRelationId;
 			toastobject.objectSubId = 0;
 
-			if (relform1->reltoastrelid)
+			if (OidIsValid(relform1->reltoastrelid))
 			{
 				baseobject.objectId = r1;
 				toastobject.objectId = relform1->reltoastrelid;
@@ -1392,7 +1392,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 								   DEPENDENCY_INTERNAL);
 			}
 
-			if (relform2->reltoastrelid)
+			if (OidIsValid(relform2->reltoastrelid))
 			{
 				baseobject.objectId = r2;
 				toastobject.objectId = relform2->reltoastrelid;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 1118a5fc437..45bcfff23d6 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -3788,7 +3788,7 @@ renameatt_check(Oid myrelid, Form_pg_class classform, bool recursing)
 {
 	char		relkind = classform->relkind;
 
-	if (classform->reloftype && !recursing)
+	if (OidIsValid(classform->reloftype) && !recursing)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("cannot rename column of typed table")));
@@ -4118,7 +4118,7 @@ rename_constraint_internal(Oid myrelid,
 							oldconname)));
 	}
 
-	if (con->conindid
+	if (OidIsValid(con->conindid)
 		&& (con->contype == CONSTRAINT_PRIMARY
 			|| con->contype == CONSTRAINT_UNIQUE
 			|| con->contype == CONSTRAINT_EXCLUSION))
@@ -7186,7 +7186,7 @@ ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
 				bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode,
 				AlterTableUtilityContext *context)
 {
-	if (rel->rd_rel->reloftype && !recursing)
+	if (OidIsValid(rel->rd_rel->reloftype) && !recursing)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("cannot add column to typed table")));
@@ -9249,7 +9249,7 @@ ATPrepDropColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
 				 AlterTableCmd *cmd, LOCKMODE lockmode,
 				 AlterTableUtilityContext *context)
 {
-	if (rel->rd_rel->reloftype && !recursing)
+	if (OidIsValid(rel->rd_rel->reloftype) && !recursing)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("cannot drop column from typed table")));
@@ -14385,7 +14385,7 @@ ATPrepAlterColumnType(List **wqueue,
 
 	pstate->p_sourcetext = context->queryString;
 
-	if (rel->rd_rel->reloftype && !recursing)
+	if (OidIsValid(rel->rd_rel->reloftype) && !recursing)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("cannot alter column type of typed table"),
@@ -16280,7 +16280,7 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock
 		}
 
 		/* If it has a toast table, recurse to change its ownership */
-		if (tuple_class->reltoastrelid != InvalidOid)
+		if (OidIsValid(tuple_class->reltoastrelid))
 			ATExecChangeOwner(tuple_class->reltoastrelid, newOwnerId,
 							  true, lockmode);
 
@@ -17230,7 +17230,7 @@ ATExecEnableDisableRule(Relation rel, const char *rulename,
 static void
 ATPrepAddInherit(Relation child_rel)
 {
-	if (child_rel->rd_rel->reloftype)
+	if (OidIsValid(child_rel->rd_rel->reloftype))
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("cannot change inheritance of typed table")));
@@ -18307,7 +18307,7 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
 	}
 
 	/* If the table was already typed, drop the existing dependency. */
-	if (rel->rd_rel->reloftype)
+	if (OidIsValid(rel->rd_rel->reloftype))
 		drop_parent_dependency(relid, TypeRelationId, rel->rd_rel->reloftype,
 							   DEPENDENCY_NORMAL);
 
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 3c80bf1b9ce..6443b38586d 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -2541,7 +2541,7 @@ addRangeTableEntryForENR(ParseState *pstate,
 		else
 		{
 			/* Let's just make sure we can tell this isn't dropped */
-			if (att->atttypid == InvalidOid)
+			if (!OidIsValid(att->atttypid))
 				elog(ERROR, "atttypid is invalid for non-dropped column in \"%s\"",
 					 rv->relname);
 			rte->coltypes = lappend_oid(rte->coltypes, att->atttypid);
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index c1c13f43918..875b3690f9b 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -2366,7 +2366,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
 					 * Ignore temporary heaps created during DDL unless the
 					 * plugin has asked for them.
 					 */
-					if (relation->rd_rel->relrewrite && !rb->output_rewrites)
+					if (OidIsValid(relation->rd_rel->relrewrite) && !rb->output_rewrites)
 						goto change_done;
 
 					/*
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 894d226541f..09975724d96 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -908,7 +908,7 @@ pg_relation_filenode(PG_FUNCTION_ARGS)
 
 	if (RELKIND_HAS_STORAGE(relform->relkind))
 	{
-		if (relform->relfilenode)
+		if (OidIsValid(relform->relfilenode))
 			result = relform->relfilenode;
 		else					/* Consult the relation mapper */
 			result = RelationMapOidToFilenumber(relid,
@@ -986,7 +986,7 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
 	if (RELKIND_HAS_STORAGE(relform->relkind))
 	{
 		/* This logic should match RelationInitPhysicalAddr */
-		if (relform->reltablespace)
+		if (OidIsValid(relform->reltablespace))
 			rlocator.spcOid = relform->reltablespace;
 		else
 			rlocator.spcOid = MyDatabaseTableSpace;
@@ -994,7 +994,7 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
 			rlocator.dbOid = InvalidOid;
 		else
 			rlocator.dbOid = MyDatabaseId;
-		if (relform->relfilenode)
+		if (OidIsValid(relform->relfilenode))
 			rlocator.relNumber = relform->relfilenode;
 		else					/* Consult the relation mapper */
 			rlocator.relNumber = RelationMapOidToFilenumber(relid,
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 22b0319abdf..7ae1a85a5ab 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -760,7 +760,7 @@ format_operator_extended(Oid operator_oid, bits16 flags)
 
 		appendStringInfo(&buf, "%s(", oprname);
 
-		if (operform->oprleft)
+		if (OidIsValid(operform->oprleft))
 			appendStringInfo(&buf, "%s,",
 							 (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
 							 format_type_be_qualified(operform->oprleft) :
@@ -768,7 +768,7 @@ format_operator_extended(Oid operator_oid, bits16 flags)
 		else
 			appendStringInfoString(&buf, "NONE,");
 
-		if (operform->oprright)
+		if (OidIsValid(operform->oprright))
 			appendStringInfo(&buf, "%s)",
 							 (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
 							 format_type_be_qualified(operform->oprright) :
@@ -830,10 +830,10 @@ format_operator_parts(Oid operator_oid, List **objnames, List **objargs,
 	*objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
 						   pstrdup(NameStr(oprForm->oprname)));
 	*objargs = NIL;
-	if (oprForm->oprleft)
+	if (OidIsValid(oprForm->oprleft))
 		*objargs = lappend(*objargs,
 						   format_type_be_qualified(oprForm->oprleft));
-	if (oprForm->oprright)
+	if (OidIsValid(oprForm->oprright))
 		*objargs = lappend(*objargs,
 						   format_type_be_qualified(oprForm->oprright));
 
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 1e4f57bf245..c8ec2579d9a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2489,7 +2489,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
 				expr = stringToNode(conbin);
 
 				/* Set up deparsing context for Var nodes in constraint */
-				if (conForm->conrelid != InvalidOid)
+				if (OidIsValid(conForm->conrelid))
 				{
 					/* relation constraint */
 					context = deparse_context_for(get_relation_name(conForm->conrelid),
@@ -2523,7 +2523,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
 			}
 		case CONSTRAINT_NOTNULL:
 			{
-				if (conForm->conrelid)
+				if (OidIsValid(conForm->conrelid))
 				{
 					AttrNumber	attnum;
 
@@ -2535,7 +2535,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
 					if (((Form_pg_constraint) GETSTRUCT(tup))->connoinherit)
 						appendStringInfoString(&buf, " NO INHERIT");
 				}
-				else if (conForm->contypid)
+				else if (OidIsValid(conForm->contypid))
 				{
 					/* conkey is null for domain not-null constraints */
 					appendStringInfoString(&buf, "NOT NULL");
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 915d0bc9084..62fe96f32d0 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -535,7 +535,7 @@ RelationBuildTupleDesc(Relation relation)
 
 	/* fill rd_att's type ID fields (compare heap.c's AddNewRelationTuple) */
 	relation->rd_att->tdtypeid =
-		relation->rd_rel->reltype ? relation->rd_rel->reltype : RECORDOID;
+		OidIsValid(relation->rd_rel->reltype) ? relation->rd_rel->reltype : RECORDOID;
 	relation->rd_att->tdtypmod = -1;	/* just to be sure */
 
 	constr = (TupleConstr *) MemoryContextAllocZero(CacheMemoryContext,
@@ -1236,7 +1236,7 @@ retry:
 		 */
 	}
 	else
-		Assert(relation->rd_rel->relam == InvalidOid);
+		Assert(!OidIsValid(relation->rd_rel->relam));
 
 	/* extract reloptions if any */
 	RelationParseRelOptions(relation, pg_class_tuple);
@@ -1344,7 +1344,7 @@ RelationInitPhysicalAddr(Relation relation)
 	if (!RELKIND_HAS_STORAGE(relation->rd_rel->relkind))
 		return;
 
-	if (relation->rd_rel->reltablespace)
+	if (OidIsValid(relation->rd_rel->reltablespace))
 		relation->rd_locator.spcOid = relation->rd_rel->reltablespace;
 	else
 		relation->rd_locator.spcOid = MyDatabaseTableSpace;
@@ -1353,7 +1353,7 @@ RelationInitPhysicalAddr(Relation relation)
 	else
 		relation->rd_locator.dbOid = MyDatabaseId;
 
-	if (relation->rd_rel->relfilenode)
+	if (OidIsValid(relation->rd_rel->relfilenode))
 	{
 		/*
 		 * Even if we are using a decoding snapshot that doesn't represent the
@@ -1478,7 +1478,7 @@ RelationInitIndexAccessInfo(Relation relation)
 	/*
 	 * Look up the index's access method, save the OID of its handler function
 	 */
-	Assert(relation->rd_rel->relam != InvalidOid);
+	Assert(OidIsValid(relation->rd_rel->relam));
 	tuple = SearchSysCache1(AMOID, ObjectIdGetDatum(relation->rd_rel->relam));
 	if (!HeapTupleIsValid(tuple))
 		elog(ERROR, "cache lookup failed for access method %u",
@@ -1838,7 +1838,7 @@ RelationInitTableAccessMethod(Relation relation)
 		 * seem prudent to show that in the catalog. So just overwrite it
 		 * here.
 		 */
-		Assert(relation->rd_rel->relam == InvalidOid);
+		Assert(!OidIsValid(relation->rd_rel->relam));
 		relation->rd_amhandler = F_HEAP_TABLEAM_HANDLER;
 	}
 	else if (IsCatalogRelation(relation))
@@ -1855,7 +1855,7 @@ RelationInitTableAccessMethod(Relation relation)
 		 * Look up the table access method, save the OID of its handler
 		 * function.
 		 */
-		Assert(relation->rd_rel->relam != InvalidOid);
+		Assert(OidIsValid(relation->rd_rel->relam));
 		tuple = SearchSysCache1(AMOID,
 								ObjectIdGetDatum(relation->rd_rel->relam));
 		if (!HeapTupleIsValid(tuple))
@@ -4259,7 +4259,7 @@ RelationCacheInitializePhase3(void)
 		/*
 		 * If it's a faked-up entry, read the real pg_class tuple.
 		 */
-		if (relation->rd_rel->relowner == InvalidOid)
+		if (!OidIsValid(relation->rd_rel->relowner))
 		{
 			HeapTuple	htup;
 			Form_pg_class relp;
@@ -4296,7 +4296,7 @@ RelationCacheInitializePhase3(void)
 			ReleaseSysCache(htup);
 
 			/* relowner had better be OK now, else we'll loop forever */
-			if (relation->rd_rel->relowner == InvalidOid)
+			if (!OidIsValid(relation->rd_rel->relowner))
 				elog(ERROR, "invalid relowner in pg_class entry for \"%s\"",
 					 RelationGetRelationName(relation));
 
@@ -6252,7 +6252,7 @@ load_relcache_init_file(bool shared)
 		rel->rd_att = CreateTemplateTupleDesc(relform->relnatts);
 		rel->rd_att->tdrefcount = 1;	/* mark as refcounted */
 
-		rel->rd_att->tdtypeid = relform->reltype ? relform->reltype : RECORDOID;
+		rel->rd_att->tdtypeid = OidIsValid(relform->reltype) ? relform->reltype : RECORDOID;
 		rel->rd_att->tdtypmod = -1; /* just to be sure */
 
 		/* next read all the attribute tuple form data entries */
-- 
2.34.1

