From 9c0d71a61d0d604b99fa3ee9b009ab87e2d1e830 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 29 Apr 2026 20:29:00 +0800
Subject: [PATCH v20260429 3/3] Use OidIsValid macro in propgraphcmds.c

Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/1DA5D52A-4AFA-426E-83F7-42ED974D682B@gmail.com
---
 src/backend/commands/propgraphcmds.c | 44 ++++++++++++++--------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/backend/commands/propgraphcmds.c b/src/backend/commands/propgraphcmds.c
index d3c0443c336..04830262a54 100644
--- a/src/backend/commands/propgraphcmds.c
+++ b/src/backend/commands/propgraphcmds.c
@@ -206,16 +206,16 @@ CreatePropGraph(ParseState *pstate, const CreatePropGraphStmt *stmt)
 			if (strcmp(vinfo->aliasname, edge->edestvertex) == 0)
 				destrelid = vinfo->relid;
 
-			if (srcrelid && destrelid)
+			if (OidIsValid(srcrelid) && OidIsValid(destrelid))
 				break;
 		}
-		if (!srcrelid)
+		if (!OidIsValid(srcrelid))
 			ereport(ERROR,
 					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
 					 errmsg("source vertex \"%s\" of edge \"%s\" does not exist",
 							edge->esrcvertex, einfo->aliasname),
 					 parser_errposition(pstate, edge->location)));
-		if (!destrelid)
+		if (!OidIsValid(destrelid))
 			ereport(ERROR,
 					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
 					 errmsg("destination vertex \"%s\" of edge \"%s\" does not exist",
@@ -296,13 +296,13 @@ CreatePropGraph(ParseState *pstate, const CreatePropGraphStmt *stmt)
 				einfo->destvertexid = vinfo->elementid;
 				einfo->destrelid = vinfo->relid;
 			}
-			if (einfo->srcvertexid && einfo->destvertexid)
+			if (OidIsValid(einfo->srcvertexid) && OidIsValid(einfo->destvertexid))
 				break;
 		}
-		Assert(einfo->srcvertexid);
-		Assert(einfo->destvertexid);
-		Assert(einfo->srcrelid);
-		Assert(einfo->destrelid);
+		Assert(OidIsValid(einfo->srcvertexid));
+		Assert(OidIsValid(einfo->destvertexid));
+		Assert(OidIsValid(einfo->srcrelid));
+		Assert(OidIsValid(einfo->destrelid));
 		peoid = insert_element_record(pgaddress, einfo);
 		element_oids = lappend_oid(element_oids, peoid);
 	}
@@ -330,7 +330,7 @@ propgraph_element_get_key(ParseState *pstate, const List *key_clause, Relation e
 	{
 		Oid			pkidx = RelationGetPrimaryKeyIndex(element_rel, false);
 
-		if (!pkidx)
+		if (!OidIsValid(pkidx))
 			ereport(ERROR,
 					errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
 					errmsg("no key specified and no suitable primary key exists for definition of element \"%s\"", aliasname),
@@ -681,7 +681,7 @@ insert_element_record(ObjectAddress pgaddress, struct element_info *einfo)
 	 * Add dependencies on vertices and equality operators used for key
 	 * comparison.
 	 */
-	if (einfo->srcvertexid)
+	if (OidIsValid(einfo->srcvertexid))
 	{
 		ObjectAddressSet(referenced, PropgraphElementRelationId, einfo->srcvertexid);
 		add_exact_object_address(&referenced, addrs);
@@ -689,7 +689,7 @@ insert_element_record(ObjectAddress pgaddress, struct element_info *einfo)
 		array_of_attnums_to_objectaddrs(einfo->srcrelid, einfo->srcref, addrs);
 		array_of_opers_to_objectaddrs(einfo->srceqop, addrs);
 	}
-	if (einfo->destvertexid)
+	if (OidIsValid(einfo->destvertexid))
 	{
 		ObjectAddressSet(referenced, PropgraphElementRelationId, einfo->destvertexid);
 		add_exact_object_address(&referenced, addrs);
@@ -751,7 +751,7 @@ insert_label_record(Oid graphid, Oid peoid, const char *label)
 	 * Insert into pg_propgraph_label if not already existing.
 	 */
 	labeloid = GetSysCacheOid2(PROPGRAPHLABELNAME, Anum_pg_propgraph_label_oid, ObjectIdGetDatum(graphid), CStringGetDatum(label));
-	if (!labeloid)
+	if (!OidIsValid(labeloid))
 	{
 		Relation	rel;
 		Datum		values[Natts_pg_propgraph_label] = {0};
@@ -1239,7 +1239,7 @@ check_element_label_properties(Oid ellabeloid)
 	/*
 	 * If there is no previous definition of this label, then we are done.
 	 */
-	if (!ref_ellabeloid)
+	if (!OidIsValid(ref_ellabeloid))
 		return;
 
 	/*
@@ -1299,7 +1299,7 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt)
 									   stmt->missing_ok ? RVR_MISSING_OK : 0,
 									   RangeVarCallbackOwnsRelation,
 									   NULL);
-	if (pgrelid == InvalidOid)
+	if (!OidIsValid(pgrelid))
 	{
 		ereport(NOTICE,
 				(errmsg("relation \"%s\" does not exist, skipping",
@@ -1509,7 +1509,7 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt)
 								   Anum_pg_propgraph_label_oid,
 								   ObjectIdGetDatum(pgrelid),
 								   CStringGetDatum(stmt->drop_label));
-		if (!labeloid)
+		if (!OidIsValid(labeloid))
 			ereport(ERROR,
 					errcode(ERRCODE_UNDEFINED_OBJECT),
 					errmsg("property graph \"%s\" element \"%s\" has no label \"%s\"",
@@ -1548,7 +1548,7 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt)
 		table_close(elrel, AccessShareLock);
 
 		/* Given label is not associated with the element. */
-		if (!ellabeloid)
+		if (!OidIsValid(ellabeloid))
 			ereport(ERROR,
 					errcode(ERRCODE_UNDEFINED_OBJECT),
 					errmsg("property graph \"%s\" element \"%s\" has no label \"%s\"",
@@ -1593,12 +1593,12 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt)
 								   Anum_pg_propgraph_label_oid,
 								   ObjectIdGetDatum(pgrelid),
 								   CStringGetDatum(stmt->alter_label));
-		if (labeloid)
+		if (OidIsValid(labeloid))
 			ellabeloid = GetSysCacheOid2(PROPGRAPHELEMENTLABELELEMENTLABEL,
 										 Anum_pg_propgraph_element_label_oid,
 										 ObjectIdGetDatum(peoid),
 										 ObjectIdGetDatum(labeloid));
-		if (!ellabeloid)
+		if (!OidIsValid(ellabeloid))
 			ereport(ERROR,
 					errcode(ERRCODE_UNDEFINED_OBJECT),
 					errmsg("property graph \"%s\" element \"%s\" has no label \"%s\"",
@@ -1630,13 +1630,13 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt)
 								   Anum_pg_propgraph_label_oid,
 								   ObjectIdGetDatum(pgrelid),
 								   CStringGetDatum(stmt->alter_label));
-		if (labeloid)
+		if (OidIsValid(labeloid))
 			ellabeloid = GetSysCacheOid2(PROPGRAPHELEMENTLABELELEMENTLABEL,
 										 Anum_pg_propgraph_element_label_oid,
 										 ObjectIdGetDatum(peoid),
 										 ObjectIdGetDatum(labeloid));
 
-		if (!ellabeloid)
+		if (!OidIsValid(ellabeloid))
 			ereport(ERROR,
 					errcode(ERRCODE_UNDEFINED_OBJECT),
 					errmsg("property graph \"%s\" element \"%s\" has no label \"%s\"",
@@ -1653,12 +1653,12 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt)
 									  Anum_pg_propgraph_property_oid,
 									  ObjectIdGetDatum(pgrelid),
 									  CStringGetDatum(propname));
-			if (propoid)
+			if (OidIsValid(propoid))
 				plpoid = GetSysCacheOid2(PROPGRAPHLABELPROP,
 										 Anum_pg_propgraph_label_property_oid,
 										 ObjectIdGetDatum(ellabeloid),
 										 ObjectIdGetDatum(propoid));
-			if (!plpoid)
+			if (!OidIsValid(plpoid))
 				ereport(ERROR,
 						errcode(ERRCODE_UNDEFINED_OBJECT),
 						errmsg("property graph \"%s\" element \"%s\" label \"%s\" has no property \"%s\"",
-- 
2.50.1 (Apple Git-155)

