in src/backend/utils/adt/age_global_graph.c [572:683]
static void load_edge_hashtable(GRAPH_global_context *ggctx)
{
Oid graph_oid;
Oid graph_namespace_oid;
Snapshot snapshot;
List *edge_label_names = NIL;
ListCell *lc;
/* get the specific graph OID and namespace (schema) OID */
graph_oid = ggctx->graph_oid;
graph_namespace_oid = get_namespace_oid(ggctx->graph_name, false);
/* get the active snapshot */
snapshot = GetActiveSnapshot();
/* get the names of all of the edge label tables */
edge_label_names = get_ag_labels_names(snapshot, graph_oid,
LABEL_TYPE_EDGE);
/* go through all edge label tables in list */
foreach (lc, edge_label_names)
{
Relation graph_edge_label;
TableScanDesc scan_desc;
HeapTuple tuple;
char *edge_label_name;
Oid edge_label_table_oid;
TupleDesc tupdesc;
/* get the edge label name */
edge_label_name = lfirst(lc);
/* get the edge label name's OID */
edge_label_table_oid = get_relname_relid(edge_label_name,
graph_namespace_oid);
/* open the relation (table) and begin the scan */
graph_edge_label = table_open(edge_label_table_oid, ShareLock);
scan_desc = table_beginscan(graph_edge_label, snapshot, 0, NULL);
/* get the tupdesc - we don't need to release this one */
tupdesc = RelationGetDescr(graph_edge_label);
/* bail if the number of columns differs */
if (tupdesc->natts != 4)
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("Invalid number of attributes for %s.%s",
ggctx->graph_name, edge_label_name)));
}
/* get all tuples in table and insert them into graph hashtables */
while((tuple = heap_getnext(scan_desc, ForwardScanDirection)) != NULL)
{
graphid edge_id;
graphid edge_vertex_start_id;
graphid edge_vertex_end_id;
Datum edge_properties;
bool inserted = false;
/* something is wrong if this isn't true */
if (!HeapTupleIsValid(tuple))
{
elog(ERROR, "load_edge_hashtable: !HeapTupleIsValid");
}
Assert(HeapTupleIsValid(tuple));
/* get the edge id */
edge_id = DatumGetInt64(column_get_datum(tupdesc, tuple, 0, "id",
GRAPHIDOID, true));
/* get the edge start_id (start vertex id) */
edge_vertex_start_id = DatumGetInt64(column_get_datum(tupdesc,
tuple, 1,
"start_id",
GRAPHIDOID,
true));
/* get the edge end_id (end vertex id)*/
edge_vertex_end_id = DatumGetInt64(column_get_datum(tupdesc, tuple,
2, "end_id",
GRAPHIDOID,
true));
/* get the edge properties datum */
edge_properties = column_get_datum(tupdesc, tuple, 3, "properties",
AGTYPEOID, true);
/* we need to make a copy of the properties datum */
edge_properties = datumCopy(edge_properties, false, -1);
/* insert edge into edge hashtable */
inserted = insert_edge_entry(ggctx, edge_id, edge_properties,
edge_vertex_start_id,
edge_vertex_end_id,
edge_label_table_oid);
/* warn if there is a duplicate */
if (!inserted)
{
ereport(WARNING,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("ignored duplicate edge")));
}
/* insert the edge into the start and end vertices edge lists */
inserted = insert_vertex_edge(ggctx, edge_vertex_start_id,
edge_vertex_end_id, edge_id,
edge_label_name);
if (!inserted)
{
ereport(WARNING,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("ignored malformed or dangling edge")));
}
}
/* end the scan and close the relation */
table_endscan(scan_desc);
table_close(graph_edge_label, ShareLock);
}
}