From 5a28c695ec9218d53a0f9b913bc9d31067104d8c Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Wed, 6 May 2026 06:07:12 +0000
Subject: [PATCH v2] Clean up property graph error messages

Fix a typo in the error message for mismatched property names in
property graph labels.

Also move an unreachable ReleaseSysCache() before ereport(ERROR) in
check_element_properties(), copying the element alias and relation OID first
so the error path does not reference the released syscache tuple.
---
 src/backend/commands/propgraphcmds.c               | 14 +++++++++-----
 .../regress/expected/create_property_graph.out     |  8 ++++----
 src/test/regress/sql/create_property_graph.sql     |  4 ++--
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/backend/commands/propgraphcmds.c b/src/backend/commands/propgraphcmds.c
index 48284b84db9..6a35ba698ee 100644
--- a/src/backend/commands/propgraphcmds.c
+++ b/src/backend/commands/propgraphcmds.c
@@ -1113,6 +1113,8 @@ check_element_properties(Oid peoid)
 						HeapTuple	tuple3;
 						Form_pg_propgraph_element elform;
 						List	   *dpcontext;
+						char	   *element_name;
+						Oid			element_relid;
 						char	   *dpa,
 								   *dpb;
 
@@ -1120,7 +1122,11 @@ check_element_properties(Oid peoid)
 						if (!tuple3)
 							elog(ERROR, "cache lookup failed for property graph element %u", peoid);
 						elform = (Form_pg_propgraph_element) GETSTRUCT(tuple3);
-						dpcontext = deparse_context_for(get_rel_name(elform->pgerelid), elform->pgerelid);
+						element_name = pstrdup(NameStr(elform->pgealias));
+						element_relid = elform->pgerelid;
+						ReleaseSysCache(tuple3);
+
+						dpcontext = deparse_context_for(get_rel_name(element_relid), element_relid);
 
 						dpa = deparse_expression(na, dpcontext, false, false);
 						dpb = deparse_expression(nb, dpcontext, false, false);
@@ -1141,10 +1147,8 @@ check_element_properties(Oid peoid)
 						ereport(ERROR,
 								errcode(ERRCODE_SYNTAX_ERROR),
 								errmsg("element \"%s\" property \"%s\" expression mismatch: %s vs. %s",
-									   NameStr(elform->pgealias), get_propgraph_property_name(propoid), dpa, dpb),
+									   element_name, get_propgraph_property_name(propoid), dpa, dpb),
 								errdetail("In a property graph element, a property of the same name has to have the same expression in each label."));
-
-						ReleaseSysCache(tuple3);
 					}
 
 					break;
@@ -1266,7 +1270,7 @@ check_element_label_properties(Oid ellabeloid)
 	if (diff1 || diff2)
 		ereport(ERROR,
 				errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				errmsg("mismatching properties names in definition of label \"%s\"", get_propgraph_label_name(labelid)));
+				errmsg("mismatched property names in definition of label \"%s\"", get_propgraph_label_name(labelid)));
 }
 
 /*
diff --git a/src/test/regress/expected/create_property_graph.out b/src/test/regress/expected/create_property_graph.out
index 4fc4759f18e..ebb5f70787b 100644
--- a/src/test/regress/expected/create_property_graph.out
+++ b/src/test/regress/expected/create_property_graph.out
@@ -208,13 +208,13 @@ ERROR:  mismatching number of properties in definition of label "l1"
 CREATE PROPERTY GRAPH gx
     VERTEX TABLES (
         t1 KEY (a) LABEL l1 PROPERTIES (a, b),
-        t2 KEY (i) LABEL l1 PROPERTIES (i AS a, j AS j)  -- mismatching property names on label
+        t2 KEY (i) LABEL l1 PROPERTIES (i AS a, j AS j)  -- mismatched property names on label
     );
-ERROR:  mismatching properties names in definition of label "l1"
+ERROR:  mismatched property names in definition of label "l1"
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS yy, b AS zz);  -- mismatching number of properties on label
 ERROR:  mismatching number of properties in definition of label "t3l1"
-ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS zz);  -- mismatching property names on label
-ERROR:  mismatching properties names in definition of label "t3l1"
+ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS zz);  -- mismatched property names on label
+ERROR:  mismatched property names in definition of label "t3l1"
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x);  -- mismatching number of properties on label
 ERROR:  mismatching number of properties in definition of label "t3l1"
 ALTER PROPERTY GRAPH g1 OWNER TO regress_graph_user1;
diff --git a/src/test/regress/sql/create_property_graph.sql b/src/test/regress/sql/create_property_graph.sql
index 241f93df302..d1f93fe94a8 100644
--- a/src/test/regress/sql/create_property_graph.sql
+++ b/src/test/regress/sql/create_property_graph.sql
@@ -163,10 +163,10 @@ CREATE PROPERTY GRAPH gx
 CREATE PROPERTY GRAPH gx
     VERTEX TABLES (
         t1 KEY (a) LABEL l1 PROPERTIES (a, b),
-        t2 KEY (i) LABEL l1 PROPERTIES (i AS a, j AS j)  -- mismatching property names on label
+        t2 KEY (i) LABEL l1 PROPERTIES (i AS a, j AS j)  -- mismatched property names on label
     );
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS yy, b AS zz);  -- mismatching number of properties on label
-ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS zz);  -- mismatching property names on label
+ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS zz);  -- mismatched property names on label
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x);  -- mismatching number of properties on label
 
 ALTER PROPERTY GRAPH g1 OWNER TO regress_graph_user1;
-- 
2.43.0

