This is an automated email from the ASF dual-hosted git repository.
dehowef pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/age-website.git
The following commit(s) were added to refs/heads/master by this push:
new ba2827fd Updated graphs.md (#181)
ba2827fd is described below
commit ba2827fd62d00d9b4030add7d66cbe643b440eb2
Author: Matheus Farias de Oliveira Matsumoto
<[email protected]>
AuthorDate: Mon Sep 25 21:22:38 2023 -0300
Updated graphs.md (#181)
I've added a clearer explanation on how graphs and their data are stored
within postgres.
---
docs/intro/graphs.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 78 insertions(+), 4 deletions(-)
diff --git a/docs/intro/graphs.md b/docs/intro/graphs.md
index ecc04532..5d53081c 100644
--- a/docs/intro/graphs.md
+++ b/docs/intro/graphs.md
@@ -46,7 +46,7 @@ Considerations
Example:
-```postgresql
+```sql
SELECT * FROM ag_catalog.create_graph('graph_name');
```
@@ -99,13 +99,87 @@ Considerations:
Example:
-```postgresql
+```sql
SELECT * FROM ag_catalog.drop_graph('graph_name', true);
```
-## A Cypher Graph vs A Postgres Namespace
+## How Graphs Are Stored In Postgres
-Cypher uses a Postgres namespace for every individual graph. It is recommended
that no DML or DDL commands are executed in the namespace that is reserved for
the graph.
+When creating graphs with AGE, a Postgres namespace will be generated for
every individual graph.
+The name and namespace of the created graphs can be seen within the `ag_graph`
table from the `ag_catalog` namespace:
+```sql
+SELECT create_graph('new_graph');
+
+NOTICE: graph "new_graph" has been created
+ create_graph
+--------------
+
+(1 row)
+
+SELECT * FROM ag_catalog.ag_graph;
+
+ name | namespace
+-----------+-----------
+ new_graph | new_graph
+(1 row)
+```
+
+After creating the graph, two tables are going to be created under the graph's
namespace to store vertices and edges: `_ag_label_vertex` and `_ag_label_edge`.
+These will be the parent tables of any new vertex or edge label. The query
below shows how to retrieve the edge and vertex labels for all the graphs in
the database.
+
+```sql
+-- Before creating a new vertex label.
+SELECT * FROM ag_catalog.ag_label;
+
+ name | graph | id | kind | relation |
seq_name
+------------------+-------+----+------+----------------------------+-------------------------
+ _ag_label_vertex | 68484 | 1 | v | new_graph._ag_label_vertex |
_ag_label_vertex_id_seq
+ _ag_label_edge | 68484 | 2 | e | new_graph._ag_label_edge |
_ag_label_edge_id_seq
+(2 rows)
+
+-- Creating a new vertex label.
+SELECT create_vlabel('new_graph', 'Person');
+NOTICE: VLabel "Person" has been created
+ create_vlabel
+---------------
+
+(1 row)
+
+-- After creating a new vertex label.
+SELECT * FROM ag_catalog.ag_label;
+ name | graph | id | kind | relation |
seq_name
+------------------+-------+----+------+----------------------------+-------------------------
+ _ag_label_vertex | 68484 | 1 | v | new_graph._ag_label_vertex |
_ag_label_vertex_id_seq
+ _ag_label_edge | 68484 | 2 | e | new_graph._ag_label_edge |
_ag_label_edge_id_seq
+ Person | 68484 | 3 | v | new_graph."Person" |
Person_id_seq
+(3 rows)
+
+```
+
+Whenever a vertex label is created with the `create_vlabel()` function, a new
table is generated within the `new_graph`'s namespace: `new_graph."<label>"`.
+The same works for the `create_elabel()` function for the creation of edge
labels. Creating vertices and edges with Cypher will automatically make these
tables.
+
+```sql
+-- Creating two vertices and one edge.
+SELECT * FROM cypher('new_graph', $$
+CREATE (:Person {name: 'Daedalus'})-[:FATHER_OF]->(:Person {name: 'Icarus'})
+$$) AS (a agtype);
+ a
+---
+(0 rows)
+
+-- Showing the newly created tables.
+SELECT * FROM ag_catalog.ag_label;
+ name | graph | id | kind | relation |
seq_name
+------------------+-------+----+------+----------------------------+-------------------------
+ _ag_label_vertex | 68484 | 1 | v | new_graph._ag_label_vertex |
_ag_label_vertex_id_seq
+ _ag_label_edge | 68484 | 2 | e | new_graph._ag_label_edge |
_ag_label_edge_id_seq
+ Person | 68484 | 3 | v | new_graph."Person" |
Person_id_seq
+ FATHER_OF | 68484 | 4 | e | new_graph."FATHER_OF" |
FATHER_OF_id_seq
+(4 rows)
+```
+
+_Note: It is recommended that no DML or DDL commands are executed in the
namespace that is reserved for the graph._
<!-- Needs clarification. Since search path is set as ag_catalog first in the
searh path, all DML and DDL will happen in the ag_catalog namespace. Also
should we say schema rather than namespace?
-->