skip to Main Content

If I understand this correctly, every query that is sent when using the apacheAGE extension is being parsed, analyzed and rewritten and it is finally an SQL statement that is being run in the backed proccess for postgres to actually execute the command. When we use a simple match query like

SELECT * FROM cypher('graph', $$ MATCH (u) return u $$) as (u agtype);

what is the SQL statement that postgres runs to actually fetch the correct vertices?

7

Answers


  1. Yes you’re right about the first part and understood it exactly as well.

    However for the second part I think the statement for the simple query "Match (u) return u" would look something like this:

    SELECT * FROM vertice_table;

    Here the vertice_table is the name of the table in the database of PostgreSQL that contains the vertices of the graph. And Select * will be used to fetch all the columns.

    I Hope it will help!

    Login or Signup to reply.
  2. The sql statement that would be generated depends on how the graph is represented in postgres.

    It can be something like this:

    SELECT * FROM graph_vertices WHERE label = 'u';
    

    This is only a simplified example and the actual statement can of course be quite complex.

    Login or Signup to reply.
  3. Yes you are right actually when we run a query using Apache AGE extension , it parsed the query and analysed it and then rewrite it into a SQL statement.

    The extension translate that cypher query and result

    SELECT graph_properties FROM 'graph_name'  
    

    So when we run this it is actually running SQL query at backend and return properties of graph.

    Login or Signup to reply.
  4. If you want to retrieve the age of a person using a WHERE clause with some criteria, you could write a query like this:

    SELECT * FROM graph_vertices WHERE label = 'u' AND properties->>'age' > '15';
    
    Login or Signup to reply.
  5. The PostgreSQL would look up to the vertex table and then collects (using joins in this case) and return the vertices according to the criteria and query you wanted. For example, for your query, the SQL statement would be similar to something like :

    SELECT * FROM graph._ag_label_vertex AS u
    JOIN graph._ag_label_edges AS e
    ON u.id = e.start
    
    Login or Signup to reply.
  6. The translated SQL statement would look something like this:

    SELECT data FROM vertices
    

    Lets assume the graph is stored in a table called vertices with a column called data that contains the vertex properties.

    The SQL statement would retrieve all rows from the vertices table and return the data column, which contains the vertex properties which matches the output of the cypher query.

    Login or Signup to reply.
  7. Basically uses the normal SQL statements too…

    For example
    MATCH (u:persons) RETURN u

    Is equivalent to

    SELECT * FROM persons
    

    And also where the WHERE clause is used, same idea is done in the SQL statements.. and of course it can get more complicated depending on the relationships..

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