From: Michael Paquier Date: Thu, 7 May 2026 01:18:49 +0000 (+0900) Subject: Simplify code in objectaddress.c for some property graph objects X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6827de95ee094f8a2cb892a40e6f154491e78496;p=thirdparty%2Fpostgresql.git Simplify code in objectaddress.c for some property graph objects Property graph element labels and label properties relied on a direct systable scan when retrieving their object descriptions. These can be simplified with get_catalog_object_by_oid(). This offers the benefit to do a direct syscache lookup, if available. The same logic will be used in a follow-up patch when retrieving the object identity parts, applying the same rule across the board for these object types. Extracted from a larger patch by the author. Author: Bertrand Drouvot Reviewed-by: Ashutosh Bapat Reviewed-by: Alex Guo Discussion: https://postgr.es/m/aej1DkLwhyZWmtxJ@bdtpg --- diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index c1862809577..050b7829eb0 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -4106,26 +4106,19 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) case PropgraphElementLabelRelationId: { Relation rel; - SysScanDesc scan; - ScanKeyData key[1]; HeapTuple tuple; Form_pg_propgraph_element_label pgelform; ObjectAddress oa; rel = table_open(PropgraphElementLabelRelationId, AccessShareLock); - ScanKeyInit(&key[0], - Anum_pg_propgraph_element_label_oid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); - - scan = systable_beginscan(rel, PropgraphElementLabelObjectIndexId, true, NULL, 1, key); - tuple = systable_getnext(scan); + tuple = get_catalog_object_by_oid(rel, + Anum_pg_propgraph_element_label_oid, + object->objectId); if (!HeapTupleIsValid(tuple)) { if (!missing_ok) elog(ERROR, "could not find tuple for element label %u", object->objectId); - systable_endscan(scan); table_close(rel, AccessShareLock); break; } @@ -4136,7 +4129,6 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) ObjectAddressSet(oa, PropgraphElementRelationId, pgelform->pgelelid); appendStringInfoString(&buffer, getObjectDescription(&oa, false)); - systable_endscan(scan); table_close(rel, AccessShareLock); break; } @@ -4166,26 +4158,19 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) case PropgraphLabelPropertyRelationId: { Relation rel; - SysScanDesc scan; - ScanKeyData key[1]; HeapTuple tuple; Form_pg_propgraph_label_property plpform; ObjectAddress oa; rel = table_open(PropgraphLabelPropertyRelationId, AccessShareLock); - ScanKeyInit(&key[0], - Anum_pg_propgraph_label_property_oid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); - - scan = systable_beginscan(rel, PropgraphLabelPropertyObjectIndexId, true, NULL, 1, key); - tuple = systable_getnext(scan); + tuple = get_catalog_object_by_oid(rel, + Anum_pg_propgraph_label_property_oid, + object->objectId); if (!HeapTupleIsValid(tuple)) { if (!missing_ok) elog(ERROR, "could not find tuple for label property %u", object->objectId); - systable_endscan(scan); table_close(rel, AccessShareLock); break; } @@ -4196,7 +4181,6 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) ObjectAddressSet(oa, PropgraphElementLabelRelationId, plpform->plpellabelid); appendStringInfoString(&buffer, getObjectDescription(&oa, false)); - systable_endscan(scan); table_close(rel, AccessShareLock); break; }