Cypher shortestPath query - behaviour change between 2.1.xx and 2.2 RC01

24 views
Skip to first unread message

Ziv Unger

unread,
Mar 20, 2015, 8:24:59 AM3/20/15
to ne...@googlegroups.com
Hi

We currently have many rather lengthy, complex Cypher queries running on 2.1.x. I wanted to see the potential performance improvements in 2.2's Cypher query planner, so I imported our DB to 2.2 and ran the queries on it.

However, I immediately noticed that I was only getting a subset of the results I'd gotten on 2.1.x, and in some cases no results. After some investigation, it turns out it has to do with different behaviour (and syntax) of shortestPath in 2.2.

The offending lines in the query are:

match objectives-[:target_region]->regions, oregions<-[:target_region]-oobjectives
match path=shortestPath(regions-[:has_child*..4]-oregions)

Regions are a simple parent > child hierarchy, where a parent region is linked to their child nodes (also regions) via a [:has_child] relationship. objectives and oobjectives are identified and matched earlier in the query. The basic premise is to find objectives belonging to two different companies which target either the same regions, or regions that are connected by virtue of being ancestors / descendants of each other.

In 2.1.x, this returns 4 results for this particular set of criteria. Two are direct region matches (Brazil and Australia match each other directly on both sides) and two are descendants (Australia matches two objectives in New South Whales)

In 2.2, it returns only two - the descendants results (Australia <-> NSW)

After some hair pulling, I wondered if perhaps the reason 2.2 wasn't finding the direct matches was that *..4 didn't specify a minimum length. This turned out to be the case, as replacing the relevant line with:

match path=shortestPath(regions-[:has_child*0..4]-oregions)

produces the same results as 2.1.x.

I thought great, so this is how 2.2 does it, let me back-port it into the app so the switchover will be easier when 2.2 is released. However, attempting to replace this line in 2.1.x gives me this error:

"shortestPath(...) does not support a minimal length"

So my question is - is this intended? Did I miss some release notes with breaking changes for 2.2?

Many thanks

Ziv Unger

unread,
Mar 25, 2015, 1:08:23 AM3/25/15
to ne...@googlegroups.com
Just bumping this in the hopes of an official answer?

Michael Hunger

unread,
Mar 25, 2015, 3:49:20 PM3/25/15
to ne...@googlegroups.com
I talked to our engineers, and they said the old behavior was wrong and fixed in 2.1.7 and 2.2

You have to specify min-lenght of 0 if you want get nodes back that are directly the start / end-node.

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ziv Unger

unread,
Mar 26, 2015, 1:24:35 AM3/26/15
to ne...@googlegroups.com
Thanks Michael - much appreciated. As luck would have it, we went directly from 2.1.6 to 2.2, hence not encountering the issue earlier.
Reply all
Reply to author
Forward
0 new messages