From 14fd765f7dfaf48fb94fcb127075bcbb9d995c01 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Mon, 17 Nov 2025 18:10:00 +0000
Subject: [PATCH v1 8/8] Replace literal 0 with InvalidOid for Oid assignments

Use the proper constant InvalidOid instead of literal 0 when assigning Oid
variables and struct fields.

This improves code clarity by making it explicit that these are invalid Oid
values rather than ambiguous zero literals.
---
 contrib/postgres_fdw/deparse.c             |  2 +-
 src/backend/access/common/printtup.c       |  2 +-
 src/backend/commands/extension.c           |  2 +-
 src/backend/storage/smgr/md.c              |  2 +-
 src/backend/utils/adt/like_support.c       |  2 +-
 src/backend/utils/cache/relfilenumbermap.c |  2 +-
 src/bin/pg_dump/common.c                   | 12 ++++++------
 src/bin/pg_dump/pg_dump.c                  |  8 ++++----
 src/bin/pg_resetwal/pg_resetwal.c          |  2 +-
 src/bin/pg_rewind/filemap.c                |  2 +-
 10 files changed, 18 insertions(+), 18 deletions(-)
   4.3% contrib/postgres_fdw/
   3.8% src/backend/access/common/
   4.6% src/backend/commands/
   4.3% src/backend/storage/smgr/
   6.4% src/backend/utils/adt/
   4.1% src/backend/utils/cache/
  63.2% src/bin/pg_dump/
   4.6% src/bin/pg_resetwal/
   4.3% src/bin/pg_rewind/

diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c
index f2b8968c189..22546e0eae7 100644
--- a/contrib/postgres_fdw/deparse.c
+++ b/contrib/postgres_fdw/deparse.c
@@ -2727,7 +2727,7 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte,
 		 * careful; the table could be beneath an outer join, in which case it
 		 * must go to NULL whenever the rest of the row does.
 		 */
-		Oid			fetchval = 0;
+		Oid			fetchval = InvalidOid;
 
 		if (varattno == TableOidAttributeNumber)
 			fetchval = rte->relid;
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c
index 9f05e1d15bd..6734db55226 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -223,7 +223,7 @@ SendRowDescriptionMessage(StringInfo buf, TupleDesc typeinfo,
 		else
 		{
 			/* No info available, so send zeroes */
-			resorigtbl = 0;
+			resorigtbl = InvalidOid;
 			resorigcol = 0;
 		}
 
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index 2c389cf6433..96fd63b628d 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -1072,7 +1072,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
 {
 	bool		switch_to_superuser = false;
 	char	   *filename;
-	Oid			save_userid = 0;
+	Oid			save_userid = InvalidOid;
 	int			save_sec_context = 0;
 	int			save_nestlevel;
 	StringInfoData pathbuf;
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index e3f335a8340..147f168abf3 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -1582,7 +1582,7 @@ ForgetDatabaseSyncRequests(Oid dbid)
 	RelFileLocator rlocator;
 
 	rlocator.dbOid = dbid;
-	rlocator.spcOid = 0;
+	rlocator.spcOid = InvalidOid;
 	rlocator.relNumber = 0;
 
 	INIT_MD_FILETAG(tag, rlocator, InvalidForkNumber, InvalidBlockNumber);
diff --git a/src/backend/utils/adt/like_support.c b/src/backend/utils/adt/like_support.c
index 5dbb2f57b4b..94c9504ba73 100644
--- a/src/backend/utils/adt/like_support.c
+++ b/src/backend/utils/adt/like_support.c
@@ -1594,7 +1594,7 @@ make_greater_string(const Const *str_const, FmgrInfo *ltproc, Oid collation)
 		{
 			/* If first time through, determine the suffix to use */
 			static char suffixchar = 0;
-			static Oid	suffixcollation = 0;
+			static Oid	suffixcollation = InvalidOid;
 
 			if (!suffixchar || suffixcollation != collation)
 			{
diff --git a/src/backend/utils/cache/relfilenumbermap.c b/src/backend/utils/cache/relfilenumbermap.c
index 3abd6f03282..1c9463c451d 100644
--- a/src/backend/utils/cache/relfilenumbermap.c
+++ b/src/backend/utils/cache/relfilenumbermap.c
@@ -153,7 +153,7 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
 
 	/* pg_class will show 0 when the value is actually MyDatabaseTableSpace */
 	if (reltablespace == MyDatabaseTableSpace)
-		reltablespace = 0;
+		reltablespace = InvalidOid;
 
 	MemSet(&key, 0, sizeof(key));
 	key.reltablespace = reltablespace;
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index bc1d3a7adc8..84591220122 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -355,8 +355,8 @@ flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables,
 
 			attachinfo = (TableAttachInfo *) palloc(sizeof(TableAttachInfo));
 			attachinfo->dobj.objType = DO_TABLE_ATTACH;
-			attachinfo->dobj.catId.tableoid = 0;
-			attachinfo->dobj.catId.oid = 0;
+			attachinfo->dobj.catId.tableoid = InvalidOid;
+			attachinfo->dobj.catId.oid = InvalidOid;
 			AssignDumpId(&attachinfo->dobj);
 			attachinfo->dobj.name = pg_strdup(tblinfo[i].dobj.name);
 			attachinfo->dobj.namespace = tblinfo[i].dobj.namespace;
@@ -412,8 +412,8 @@ flagInhIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
 			attachinfo = pg_malloc_object(IndexAttachInfo);
 
 			attachinfo->dobj.objType = DO_INDEX_ATTACH;
-			attachinfo->dobj.catId.tableoid = 0;
-			attachinfo->dobj.catId.oid = 0;
+			attachinfo->dobj.catId.tableoid = InvalidOid;
+			attachinfo->dobj.catId.oid = InvalidOid;
 			AssignDumpId(&attachinfo->dobj);
 			attachinfo->dobj.name = pg_strdup(index->dobj.name);
 			attachinfo->dobj.namespace = index->indextable->dobj.namespace;
@@ -608,8 +608,8 @@ flagInhAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables
 
 				attrDef = pg_malloc_object(AttrDefInfo);
 				attrDef->dobj.objType = DO_ATTRDEF;
-				attrDef->dobj.catId.tableoid = 0;
-				attrDef->dobj.catId.oid = 0;
+				attrDef->dobj.catId.tableoid = InvalidOid;
+				attrDef->dobj.catId.oid = InvalidOid;
 				AssignDumpId(&attrDef->dobj);
 				attrDef->dobj.name = pg_strdup(tbinfo->dobj.name);
 				attrDef->dobj.namespace = tbinfo->dobj.namespace;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 8be4714cd4b..20b3e29b5e9 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -3070,7 +3070,7 @@ makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
 	 * Note: use tableoid 0 so that this object won't be mistaken for
 	 * something that pg_depend entries apply to.
 	 */
-	tdinfo->dobj.catId.tableoid = 0;
+	tdinfo->dobj.catId.tableoid = InvalidOid;
 	tdinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
 	AssignDumpId(&tdinfo->dobj);
 	tdinfo->dobj.name = tbinfo->dobj.name;
@@ -4297,7 +4297,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
 			 */
 			polinfo = pg_malloc(sizeof(PolicyInfo));
 			polinfo->dobj.objType = DO_POLICY;
-			polinfo->dobj.catId.tableoid = 0;
+			polinfo->dobj.catId.tableoid = InvalidOid;
 			polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
 			AssignDumpId(&polinfo->dobj);
 			polinfo->dobj.namespace = tbinfo->dobj.namespace;
@@ -7110,8 +7110,8 @@ getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages,
 		DumpableObject *dobj = &info->dobj;
 
 		dobj->objType = DO_REL_STATS;
-		dobj->catId.tableoid = 0;
-		dobj->catId.oid = 0;
+		dobj->catId.tableoid = InvalidOid;
+		dobj->catId.oid = InvalidOid;
 		AssignDumpId(dobj);
 		dobj->dependencies = (DumpId *) pg_malloc(sizeof(DumpId));
 		dobj->dependencies[0] = rel->dumpId;
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index ebdbffc1336..c30a6c95741 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -69,7 +69,7 @@ static TransactionId set_oldest_xid = 0;
 static TransactionId set_xid = 0;
 static TransactionId set_oldest_commit_ts_xid = 0;
 static TransactionId set_newest_commit_ts_xid = 0;
-static Oid	set_oid = 0;
+static Oid	set_oid = InvalidOid;
 static bool mxid_given = false;
 static MultiXactId set_mxid = 0;
 static bool mxoff_given = false;
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index 467fd97ebcf..a400d487c59 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -619,7 +619,7 @@ getFileContentType(const char *path)
 	if (nmatch == 1 || nmatch == 2)
 	{
 		rlocator.spcOid = GLOBALTABLESPACE_OID;
-		rlocator.dbOid = 0;
+		rlocator.dbOid = InvalidOid;
 		result = FILE_CONTENT_TYPE_RELATION;
 	}
 	else
-- 
2.34.1

