skip to Main Content

As Apache AGE is an extension to PostgreSQL. I am curious about how and where the data of vertices (nodes) and edges are stored in Apache AGE.
Does it use PostgreSQL for this? If yes, then how.

2

Answers


  1. Yes, the nodes and edges get stored in separate tables. You can see the full list of tables if you do:

    SELECT * FROM information_schema.tables;

    You can see the node/edge data if you do:

    SELECT * FROM <graph_name>.<node/edge_label> LIMIT 10;

    If you are unsure of the name you gave your graph, you can do:

    SELECT * FROM ag_catalog.ag_graph

    … to get a full list of graphs that you’ve stored using AGE.

    Here are examples of two different tables in a test data set that I use comprised of Airports and defined airline routes between Airports. The first table is of vertices where each Airport is a vertex:

    postgresDB=# d airroutes.airport
                                                                        Table "airroutes.airport"
       Column   |  Type   | Collation | Nullable |                                                      Default                                                      
    ------------+---------+-----------+----------+-------------------------------------------------------------------------------------------------------------------
     id         | graphid |           | not null | _graphid((_label_id('airroutes'::name, 'airport'::name))::integer, nextval('airroutes.airport_id_seq'::regclass))
     properties | agtype  |           | not null | agtype_build_map()
    Indexes:
        "airport_prop_idx" btree (agtype_access_operator(VARIADIC ARRAY[properties, '"code"'::agtype]))
    Inherits: airroutes._ag_label_vertex
    

    And then I have edges that define the routes between airports:

    postgresDB=# d airroutes.route
                                                                       Table "airroutes.route"
       Column   |  Type   | Collation | Nullable |                                                    Default                                                    
    ------------+---------+-----------+----------+---------------------------------------------------------------------------------------------------------------
     id         | graphid |           | not null | _graphid((_label_id('airroutes'::name, 'route'::name))::integer, nextval('airroutes.route_id_seq'::regclass))
     start_id   | graphid |           | not null | 
     end_id     | graphid |           | not null | 
     properties | agtype  |           | not null | agtype_build_map()
    Inherits: airroutes._ag_label_edge
    

    A view of the first 5 airports:

    postgresDB=# SELECT * FROM airroutes.airport LIMIT 5;
           id        |                                                                                                                                  properties                                                                                                                    
                   
    -----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     844424930131969 | {"id": "1", "lat": "33.63669968", "lon": "-84.42810059", "city": "Atlanta", "code": "ATL", "desc": "Hartsfield - Jackson Atlanta International Airport", "elev": "1026", "icao": "KATL", "__id__": 1, "region": "US-GA", "country": "US", "longest": "12390", "runways": "5"}
     844424930131970 | {"id": "2", "lat": "61.17440033", "lon": "-149.9960022", "city": "Anchorage", "code": "ANC", "desc": "Anchorage Ted Stevens", "elev": "151", "icao": "PANC", "__id__": 2, "region": "US-AK", "country": "US", "longest": "12400", "runways": "3"}
     844424930131971 | {"id": "3", "lat": "30.19449997", "lon": "-97.66989899", "city": "Austin", "code": "AUS", "desc": "Austin Bergstrom International Airport", "elev": "542", "icao": "KAUS", "__id__": 3, "region": "US-TX", "country": "US", "longest": "12250", "runways": "2"}
     844424930131972 | {"id": "4", "lat": "36.12450027", "lon": "-86.67819977", "city": "Nashville", "code": "BNA", "desc": "Nashville International Airport", "elev": "599", "icao": "KBNA", "__id__": 4, "region": "US-TN", "country": "US", "longest": "11030", "runways": "4"}
     844424930131973 | {"id": "5", "lat": "42.36429977", "lon": "-71.00520325", "city": "Boston", "code": "BOS", "desc": "Boston Logan", "elev": "19", "icao": "KBOS", "__id__": 5, "region": "US-MA", "country": "US", "longest": "10083", "runways": "6"}
    (5 rows)
    

    A view of the first 5 routes:

    postgresDB=# SELECT * FROM airroutes.route LIMIT 5;
            id        |    start_id     |     end_id      |                            properties                             
    ------------------+-----------------+-----------------+-------------------------------------------------------------------
     1688849860263937 | 844424930131969 | 844424930131971 | {"dist": "809", "route_id": "3749", "end_vertex_type": "airport"}
     1688849860263938 | 844424930131969 | 844424930131972 | {"dist": "214", "route_id": "3750", "end_vertex_type": "airport"}
     1688849860263939 | 844424930131969 | 844424930131973 | {"dist": "945", "route_id": "3751", "end_vertex_type": "airport"}
     1688849860263940 | 844424930131969 | 844424930131974 | {"dist": "576", "route_id": "3752", "end_vertex_type": "airport"}
     1688849860263941 | 844424930131969 | 844424930131975 | {"dist": "546", "route_id": "3753", "end_vertex_type": "airport"}
    (5 rows)
    
    Login or Signup to reply.
  2. When you create a graph with SELECT * FROM create_graph('ag_graph') it adds it’s name and namespace to ag_catalog.ag_graph, and also create two tables within this namespace: _ag_label_vertex and _ag_label_edge. These will be the parent tables of any new vertex or edge label you create.

    So then, if you want to see all the vertices or edges in your graph, you can execute the following queries:

    SELECT * FROM "ag_graph"._ag_label_vertex;
    SELECT * FROM "ag_graph"._ag_label_edge;
    

    Then, whenever you add a vertex or edge label, it is going to store them in a new table for the label, like "ag_graph"."new_label" which will inherit from one of these parent labels. Because of this inheritance system which postgres allows, querying for the parent label tables also retrieves the child label tables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search