Graph catalogs#
AgensGraph adds seven tables to pg_catalog. Four of them describe the graph structure, and
those are the ones you will query. Three are the shared parent relations that every label
inherits from. PostgreSQL’s own catalogs are unchanged and are documented in its catalogs
chapter.
Catalog |
What it holds |
|---|---|
One row per graph. |
|
One row per label, vertex and edge alike. |
|
One row per property promoted to a typed column. |
|
Edge counts per (start label, edge label, end label) triple. |
|
|
The parent relation of every vertex or edge label in a graph. One pair exists inside each graph’s schema, not in |
|
The composite that backs the |
Two views present the same information in a readable form: see Graph views.
ag_graph#
One row per graph. A graph is a schema, so nspid points at the schema that carries its
labels.
Column |
Type |
Description |
|---|---|---|
|
|
Row identifier. |
|
|
The graph’s name. Unique across the database. |
|
|
The |
|
|
Whether |
SELECT oid, graphname, nspid, graphmeta_valid FROM pg_catalog.ag_graph;
oid | graphname | nspid | graphmeta_valid
-------+-----------+-------+-----------------
16386 | g | 16385 | t
16434 | moviekb | 16433 | f
graphmeta_valid is set false when the metadata is known to be stale, after a binary
upgrade for example. SELECT regather_graphmeta(); rebuilds it and sets the flag. See
Graph metadata.
ag_label#
One row per label. Both vertex and edge labels live here, distinguished by labkind.
Column |
Type |
Description |
|---|---|---|
|
|
Row identifier. |
|
|
The label’s name. Unique within a graph. |
|
|
The |
|
|
The label’s id within the graph, and the high 16 bits of every |
|
|
The |
|
|
|
SELECT labname, labid, labkind FROM pg_catalog.ag_label
WHERE graphid = (SELECT oid FROM pg_catalog.ag_graph WHERE graphname = 'moviekb')
ORDER BY labid;
labname | labid | labkind
------------+-------+---------
ag_vertex | 1 | v
ag_edge | 2 | e
movie | 3 | v
person | 4 | v
acted_in | 5 | e
directed | 6 | e
related_to | 7 | e
labid 1 and 2 are always the graph’s ag_vertex and ag_edge, which are created with the
graph. Because labid is 16 bits and 0 is not valid, a graph holds at most 65,535 labels.
See Limits.
Joining relid to pg_class gets you from a label to its table. That join is what makes
the ordinary PostgreSQL introspection work on a graph:
SELECT l.labname, pg_size_pretty(pg_total_relation_size(l.relid)) AS size
FROM pg_catalog.ag_label l
JOIN pg_catalog.ag_graph g ON g.oid = l.graphid
WHERE g.graphname = 'moviekb' AND l.labkind = 'v'
ORDER BY 1;
ag_label_property#
One row per property that has been promoted to a typed column. This catalog is new in 2.18.
Column |
Type |
Description |
|---|---|---|
|
|
The |
|
|
The property key the column carries. |
|
|
The column’s attribute number in the label’s table. |
|
|
How the column relates to the property. |
The primary key is (laboid, propname), so a label promotes a given key at most once.
A property read resolves to a promoted column only when a row exists here. That mechanism is
behind the promotion form that surprises people. GENERATED ALWAYS AS (expr) STORED creates
a column but registers no row in this catalog. So the column is readable from SQL and
invisible to a Cypher property read.
ag_graphmeta#
One row per (start label, edge label, end label) triple that actually occurs in a graph, with how many edges make it up. The planner uses it two ways: to estimate a traversal, and to prune scans of labels that cannot participate in a pattern.
Column |
Type |
Description |
|---|---|---|
|
|
The |
|
|
The edge label’s |
|
|
The start vertex label’s |
|
|
The end vertex label’s |
|
|
How many edges of that shape exist. |
Read it through ag_graphmeta_view, which resolves the label
ids to names. The table is maintained only when auto_gather_graphmeta is on, and
regather_graphmeta() rebuilds it from scratch. Graph metadata covers
both.
ag_vertex and ag_edge#
These are not in pg_catalog. Every graph’s schema contains its own pair, and every label
you create inherits from one of them. That inheritance is what gives an unlabelled pattern
its meaning. See How a graph is stored.
<graph>.ag_vertex has the vertex column pair, (id graphid, properties jsonb).
<graph>.ag_edge adds the endpoints, (id, start, end, properties).
ag_graphpath#
The composite type behind graphpath. It is an implementation
detail. Build and read a path with the pattern syntax and the path functions rather than
touching this directly.