when I use an optional match clause in a simple cypher query like the following:
MATCH ()-[R0:relationshipclazz0]-()
OPTIONAL MATCH ()-[R0:relationshipclazz0]->(N0:entityclazz0)
WITH distinct R0, R0.att0 as AR0att0, N0
WITH ID(R0) as i, R0.att0 as O1, (N0.att0) as O2, R0
RETURN O1, O2, count(i)
ORDER BY O1, O2
this query take 381 seconds in a graph database with 50 000 relationships and 6000 nodes
please have you any idea how can I optimize this query knowing that I have to optional match because I have null values that I want to descover in my database because using only match clause I didn't get null values
Thanks in advance