Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/backend/catalog/ag_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#include "catalog/pg_namespace.h"
#include "commands/schemacmds.h"
#include "utils/builtins.h"
#include "utils/graph.h"
#include "utils/guc_hooks.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
#include "catalog/catalog.h"
#include "miscadmin.h"
#include "pgstat.h"

/* a global variable for the GUC variable */
char *graph_path = NULL;
Expand All @@ -36,6 +38,28 @@ bool cypher_allow_unsafe_ddl = false;
/* Potentially set by pg_upgrade_support functions */
Oid binary_upgrade_next_ag_graph_oid = InvalidOid;

/* assign_hook for auto_gather_graphmeta */
static bool prev_auto_gather_graphmeta = false;
void auto_gather_graphmeta_assign(bool newval, void *extra)
{
// Only trigger on false->true transition
if (newval && !prev_auto_gather_graphmeta && !IsParallelWorker())
{
if (IsTransactionState())
{
regather_graphmeta_internal();
}
else
{
ereport(WARNING,
(errmsg("auto_gather_graphmeta: cannot gather metadata outside transaction"),
errhint("Metadata will be gathered when set within a transaction.")));
}
}

prev_auto_gather_graphmeta = newval;
}

/* check_hook: validate new graph_path value */
bool
check_graph_path(char **newval, void **extra, GucSource source)
Expand Down
79 changes: 42 additions & 37 deletions src/backend/catalog/ag_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
#include "access/heapam.h"
#include "access/htup_details.h"
#include "catalog/ag_graph_fn.h"
#include "catalog/ag_label_fn.h"
#include "catalog/ag_graphmeta.h"
#include "catalog/ag_label.h"
#include "catalog/ag_label_fn.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "commands/sequence.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
#include "utils/graph.h"
#include "utils/rel.h"
#include "utils/lsyscache.h"
Expand Down Expand Up @@ -164,48 +167,50 @@ GetNewLabelId(char *graphname, Oid graphid)
}

/*
* Retrieves a list of all the names of a graph.
* Retrieves a list of edge label OIDs that are connected to a specific vertex label.
* Finds edges where the given vertex label appears as either start or end vertex.
*/
List *
get_all_edge_labels_per_graph(Snapshot snapshot, Oid graph_oid)
get_connected_edge_labels_for_vertex(Snapshot snapshot, Oid graph_oid, Labid vertex_labid)
{
List *labels = NIL;
ScanKeyData scan_keys[2];
Relation ag_label;
TableScanDesc scan_desc;
HeapTuple tuple;

ScanKeyInit(&scan_keys[0],
Anum_ag_label_graphid,
BTEqualStrategyNumber,
F_OIDEQ,
ObjectIdGetDatum(graph_oid));
ScanKeyInit(&scan_keys[1],
Anum_ag_label_labkind,
BTEqualStrategyNumber,
F_CHAREQ,
CharGetDatum(LABEL_KIND_EDGE));

ag_label = table_open(LabelRelationId, RowExclusiveLock);
scan_desc = table_beginscan(ag_label, snapshot, 2, scan_keys);

while ((tuple = heap_getnext(scan_desc, ForwardScanDirection)) != NULL)
{
Oid label_rel_oid;
bool isnull;
Datum datum;

datum = heap_getattr(tuple,
Anum_ag_label_relid,
RelationGetDescr(ag_label),
&isnull);
label_rel_oid = DatumGetObjectId(datum);
List *edge_labels = NIL;
List *seen_edge_labels = NIL;
int i;
CatCList *tuplist = SearchSysCacheList2(GRAPHMETASTART, graph_oid, vertex_labid);

labels = lappend_oid(labels, label_rel_oid);
for (i = 0; i < tuplist->n_members; i++)
{
HeapTuple tup = &tuplist->members[i]->tuple;
Form_ag_graphmeta metatup = (Form_ag_graphmeta) GETSTRUCT(tup);
Labid edge_labid = metatup->edge;

/* Avoid duplicates */
if (!list_member_int(seen_edge_labels, edge_labid))
{
Oid edge_relid = get_labid_relid(graph_oid, edge_labid);
edge_labels = lappend_oid(edge_labels, edge_relid);
seen_edge_labels = lappend_int(seen_edge_labels, edge_labid);
}
}
ReleaseCatCacheList(tuplist);

table_endscan(scan_desc);
table_close(ag_label, RowExclusiveLock);
tuplist = SearchSysCacheList2(GRAPHMETAEND, graph_oid, vertex_labid);
for (i = 0; i < tuplist->n_members; i++)
{
HeapTuple tup = &tuplist->members[i]->tuple;
Form_ag_graphmeta metatup = (Form_ag_graphmeta) GETSTRUCT(tup);
Labid edge_labid = metatup->edge;

/* Avoid duplicates */
if (!list_member_int(seen_edge_labels, edge_labid))
{
Oid edge_relid = get_labid_relid(graph_oid, edge_labid);
edge_labels = lappend_oid(edge_labels, edge_relid);
seen_edge_labels = lappend_int(seen_edge_labels, edge_labid);
}
}
ReleaseCatCacheList(tuplist);

return labels;
list_free(seen_edge_labels);
return edge_labels;
}
Loading