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
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:
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!
The sql statement that would be generated depends on how the graph is represented in postgres.
It can be something like this:
This is only a simplified example and the actual statement can of course be quite complex.
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
So when we run this it is actually running SQL query at backend and return properties of graph.
If you want to retrieve the age of a person using a WHERE clause with some criteria, you could write a query like this:
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 :
The translated SQL statement would look something like this:
Lets assume the graph is stored in a table called
vertices
with a column calleddata
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.Basically uses the normal SQL statements too…
For example
MATCH (u:persons) RETURN u
Is equivalent to
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..