Closed MatheusFarias03 closed 9 months ago
@MatheusFarias03 To find the correct query plan for Cypher, prefix the Cypher command, inside the cypher()
function call with EXPLAIN. Something like -
SELECT * FROM cypher('xyz', $$ EXPLAIN MATCH (u) RETURN u $$) AS (node agtype)
@MatheusFarias03 I'm not sure why you want to use this query. You are essentially calling cypher to find the items and then using SQL to get the ones with 'Vegano' in the name.
-- With Cypher syntax.
WITH graph_query as (
SELECT * FROM cypher('TestGraph', $$
MATCH ()-[E:OFFERS]->(P:Product)
RETURN P.name, E.price ORDER BY P.name, E.price
$$) AS (product agtype, price agtype)
)
SELECT * FROM graph_query
WHERE graph_query.product::text LIKE '%Vegano%';
Something like the following should work just the same, but without the wrapping SQL -
SELECT * FROM cypher('TestGraph', $$
MATCH ()-[E:OFFERS]->(P:Product)
WHERE P.name =~ 'Vegano'
RETURN P.name, E.price ORDER BY P.name, E.price
$$) AS (product agtype, price agtype)
Thank you John! This last query is much better (it took the same time as the SQL only). I didn't know or remember using =~
before, that's why I used WHERE graph_query.product::text LIKE '%Vegano%';
.
@MatheusFarias03 Not a problem, it isn't a well known command. It is roughly related to LIKE but more powerful because it uses regex instead -
PG_FUNCTION_INFO_V1(age_eq_tilde);
/*
* Execution function for =~ aka regular expression comparisons
*
* Note: Everything must resolve to 2 agtype strings. All others types are
* errors.
*/
Datum age_eq_tilde(PG_FUNCTION_ARGS)
It calls the PG function textregexeq
@MatheusFarias03 Btw, if this satisfactorily answers your question, consider closing the ticket :)
Sure! Thank you for the help John!
I have a graph with two vertex labels:
Wholesaler
andProduct
; and with one edge label:OFFERS
.There are 3426 vertices with label
Product
, 4 vertices with labelWholesaler
, and 13326 edges with labelOFFERS
.The below queries shows what are the properties of
Product
andOFFERS
(The names of the vertices are all in Portuguese).The following queries are focused on retrieving information about product offerings from wholesalers, filtering for products that contain the word 'Vegano' ( 'Vegan' in Portuguese ) in the name.
Although I find a bit more understandable with the cypher syntax, the SQL syntax returns the same result 7.19 times faster.
The query plan for the SQL syntax only is:
And the query plan for the Cypher syntax is:
I'm building a website with AGE for my final project in college and I wanted to better understand why the SQL query is faster than the one using Cypher.