Speeding up a a query with allShorthestPaths

17 views
Skip to first unread message

Alx

unread,
Jul 18, 2014, 3:40:15 PM7/18/14
to ne...@googlegroups.com
I have the following cypher query:

MATCH (n:User{id:'id'}) - [:HAS_FAX_NUMBER] -> () <-[:HAS_FAX_NUMBER]-(m1) MATCH p = allShortestPaths((n)-[*]-(m1))
RETURN m1.fhid AS SuggestedUser, COUNT(*) as Connections
UNION
MATCH (n:User{id:'id'}) - [:HAS_PHONE_NUMBER] ->() < - [:HAS_PHONE_NUMBER] -(m2) MATCH p = allShortestPaths((n)-[*]-(m2))
RETURN m2.fhid AS SuggestedUser, COUNT(*) as Connection
This query is quite slow: 3 mins. Is there a way to speed this up? I am basically try to find the how connected is the user in question with m1 or m2. There might be another approach to this. Any ideas or suggestions? Thanks in advance!


Alx

unread,
Jul 20, 2014, 11:34:57 AM7/20/14
to ne...@googlegroups.com
I rewrote the query by changing the depth to 2 as follows. I am getting a slight speed-up but not significant. I would appreciate any ideas. 

MATCH (n:User{id:'id'}) - [:HAS_FAX_NUMBER] -> () <-[:HAS_FAX_NUMBER]-(m1) MATCH p = allShortestPaths((n)-[*..2]-(m1))
RETURN m1.fhid AS SuggestedUser, COUNT(p) as Connections
UNION
MATCH (n:User{id:'id'}) - [:HAS_PHONE_NUMBER] ->() < - [:HAS_PHONE_NUMBER] -(m2) MATCH p = allShortestPaths((n)-[*..2]-(m2))
RETURN m2.fhid AS SuggestedUser, COUNT(p) as Connection

Michael Hunger

unread,
Jul 20, 2014, 10:41:47 PM7/20/14
to ne...@googlegroups.com
MATCH (n:User{id:'id'}) - [:HAS_FAX_NUMBER] -> () <-[:HAS_FAX_NUMBER]-(m1)
WITH distinct n,m1
MATCH p = allShortestPaths((n)-[*..2]-(m1))
RETURN m1.fhid AS SuggestedUser, COUNT(p) as Connections
UNION
MATCH (n:User{id:'id'}) - [:HAS_PHONE_NUMBER] ->() < - [:HAS_PHONE_NUMBER] -(m2)
WITH distinct n,m2
MATCH p = allShortestPaths((n)-[*..2]-(m2))
RETURN m2.fhid AS SuggestedUser, COUNT(p) as Connection

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.

Reply all
Reply to author
Forward
0 new messages