mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
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 <bertranddrouvot.pg@gmail.com> Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Alex Guo <guo.alex.hengchen@gmail.com> Discussion: https://postgr.es/m/aej1DkLwhyZWmtxJ@bdtpg
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user