Slow Cypher Query Help Needed!


I apologise if someone has asked this question out there somewhere, but i've been looking for awhile and cant seem to find the answer as to why my query is so slow.

I am trying to filter a subgraph with a specific start and end point, with certain restrictions on the connecting relationships. My graph is not particularly large (around 40 nodes, 270 relationships). The graph has several parallel edges but I dont think that would be an issue for neo4j.

This is my query:

MATCH paths = (from:COVERAGEAREA{name:'SGPUCAALL'})-[:CONNECTED_TO*]->(to:COVERAGEAREA{name:'PH - Luzon'})
WHERE  ANY (r IN relationships(paths) WHERE NOT 'UA' IN r.restrictedMerchants AND r.paymentType in ['Both', 'prepaid'])
RETURN paths

have you tried using PROFILE to see which part of the query is slow? just checking what you are trying to do aswell, is it any path (no maximum hop limit) between those two nodes as long as they don't use an edge where the restrictedMerchants is UA and the payment type is Both/prepaid.

Hi, philip thanks for your help. Yes you are mostly correct, trying to get the subgraph between 2 points as long as the relationship payment type is either both/prepaid and UA is not in its restrictedmerchants

i have tried prepending profile to the query, but the query itself always crashes without a result

** edits
the relationships between nodes represent a time slot, with around 4 slots between each node
i have reduced the slots/relationships between nodes to 1 and was able to get a result back

when i increase it to 2

seems like a lot of hits to the db, any way my query can be further optimized?

Hmmmm hard to tell, I will have a think. Have you indexed the coverage area nodes on name? You may want to change your data model to have the slots as nodes and then you can either have nodes for restricted merchants, payment types etc...or keep them as properties on the nodes and index that way? That could potentially effect performance. That is one frustration I have had with Neo4J in general, that you can’t index relationship properties as far as I’m aware. But tbf normally I realise I’m trying to fight a non ideal data model

yeah thinking about it now, you are really going to struggle as its basically hitting all the relationships from the nodes and then again to filter. have you tried using any of the path APOC's to help? Neo4j APOC Procedures User Guide

Hi Philip thanks so much for the help! Unfortunately im unable to convert the slots to nodes as we have a need to perform pathfinding between other nodes using these links. Have limited the number of hops per path and this has improved performance slightly.

Will definitely give apoc & indexing a check. Thanks!

no problem, yeah i dont think indexing will help much in this situation as normally helpful for finding the start of your path, but that doesnt seem to be the cost here. Good luck!