Is there any difference between (XYZ)-[:XYZ]-{1,5}(XYZ) and (XYZ)-[:XYZ*1..5]-(XYZ)?
if you run each and preface with profile
for example
profile match (XYZ)-[:XYZ*1..5]-(XYZ) return *;
and
profile match (XYZ)-[:XYZ]-{1,5}(XYZ) return *;
they result in the same query plan. For example
I find the 2nd form more readable.
But why? Are you getting error? different results? different performance?
If so? for what version of Neo4j?
The first one is using qualified path syntax while the later one is using variable length path syntax. I think in this case they are functionally equivalent, as @dana_canzano demonstrated. I am new to qualified path syntax and am working on upping my game in this area. Where I believe it has the advantage is when you add where conditions within the qualified part, as these get evaluated during the path’s expansion; therefore, expansion can terminate immediately if the condition is false. This is in contrast to when you use variable length patterns and you place a where clause following the match to test some characteristic of the path. In this cause all paths have to be determined then filtered out afterwards. I imagine this would have great performance benefit when the potential paths are complex and many.
Hi Dana,
no, I'm getting the same result...and that's why I am confused! I try to find the reason why at one time its written like this and at other times like that...
(a)<-[s]-(b) (c)-[t]->(d) //this is not allowed
A simple path pattern with more than one element:
(a:A)<-[{p: 30}]-(b)-[t WHERE t.q > 0]->(c:C)
A quantified path pattern can have a lower bound of zero in its quantifier as long as it abuts other patterns that have at least one element:
(:A) ((:X)-[:R]-()){0,10} (:B)
A quantified relationship can also have a lower bound of zero as long as the overall path pattern has at least one element:
(:A)-[:R]->{0,10}(:B)
A concatenation of simple and quantified path patterns:
(a)<-[s]-(b)-[t]->(c) ((n)-[r]->(m)){0,10} (:X)
I'm studying to take the exam.
The examples in the video courses were easy! But then: In the manual - stuff like this! Yes, it's interesting and useful - but "too much"
Hi Gary,
thank you! Yes, now I understand the reasoning why
(a)<-[s]-(b) (c)-[t]->(d) //this is not allowed
A concatenation of simple and quantified path patterns:
(a)<-[s]-(b)-[t]->(c) ((n)-[r]->(m)){0,10} (:X)
[my comment: valid]
from Syntax and semantics - Cypher Manual are different - it's not a combination of simple and quantified...but I'm worried that I might miss sth. like this in the exam.
And then there's nesting: MATCH ((n:A)-[:R]->({p: 30}) WHERE EXISTS { (n)-->+(:X) }){2,3}
The "+" isn't explained - at least not here. I'm still unsure wheter it has to do with Cypher expressions - Cypher Manual or with quantified patterns...
I'll ask more questions in the forum in the future ... I beg forgiveness...
The symbol ->+
means a directed relationship with 1 or more hops. Its shorthand for -[*]->
. I believe there is also an asterisk version, ->*
, which is shorthand for -[*0..]->
Maybe this will help.
One other thing to note (if I'm not mistaken) is that the {1,5} syntax is the GQL standard way to do this, and so from a compatibility-with-the-standard approach, it's probably the preferred way.
Much like Oracle (as an example) has their own syntax for outer joins (with the (+) syntax) and also supports the ANSI standard syntax .