Copilot commented on code in PR #2351:
URL: https://github.com/apache/age/pull/2351#discussion_r2879242631
##########
src/backend/catalog/ag_label.c:
##########
@@ -297,46 +298,104 @@ List *get_all_edge_labels_per_graph(EState *estate, Oid
graph_oid)
HeapTuple tuple;
TupleTableSlot *slot;
ResultRelInfo *resultRelInfo;
+ Oid index_oid;
- /* setup scan keys to get all edges for the given graph oid */
- ScanKeyInit(&scan_keys[1], Anum_ag_label_graph, BTEqualStrategyNumber,
- F_OIDEQ, ObjectIdGetDatum(graph_oid));
- ScanKeyInit(&scan_keys[0], Anum_ag_label_kind, BTEqualStrategyNumber,
- F_CHAREQ, CharGetDatum(LABEL_TYPE_EDGE));
+ index_oid = get_relname_relid("ag_label_graph_oid_index",
+ get_namespace_oid("ag_catalog", false));
/* setup the table to be scanned */
ag_label = table_open(ag_label_relation_id(), RowExclusiveLock);
- scan_desc = table_beginscan(ag_label, estate->es_snapshot, 2, scan_keys);
resultRelInfo = create_entity_result_rel_info(estate, "ag_catalog",
"ag_label");
- slot = ExecInitExtraTupleSlot(
- estate, RelationGetDescr(resultRelInfo->ri_RelationDesc),
- &TTSOpsHeapTuple);
-
- /* scan through the results and get all the label names. */
- while(true)
+ if (OidIsValid(index_oid))
+ {
+ Relation index_rel;
+ IndexScanDesc index_scan_desc;
+
+ slot = ExecInitExtraTupleSlot(
+ estate, RelationGetDescr(resultRelInfo->ri_RelationDesc),
+ &TTSOpsBufferHeapTuple);
+
+ index_rel = index_open(index_oid, RowExclusiveLock);
+
+ ScanKeyInit(&scan_keys[0], Anum_ag_label_name, BTEqualStrategyNumber,
+ F_OIDEQ, ObjectIdGetDatum(graph_oid));
+
Review Comment:
In the index-scan setup, ScanKeyInit() uses Anum_ag_label_name as the
scan-key attno. For index scans the attno should be the index column number
(typically 1 for the first index key), not a heap attribute-number macro (even
if it currently happens to be 1). Using the heap Anum macro here is misleading
and easy to break if catalog columns are ever reordered—use an explicit
index-key attno instead (and consider using ag_label_graph_oid_index_id()
rather than name-based lookup).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]