vivace
vivace

Reputation: 59

why is this cypher query so slow with only ~30 nodes and say 50 relationships?

MATCH
  (t:T)-[:Rel]-(o:Espresso)-[:Rel]->(l:Location)<-[:Rel]-(p:Espresso {id:"ttt"})-[:Rel]->t,
  o--(:Rating)--p
RETURN
  distinct o.id AS otherId,
  l.location AS location,
  t.hour AS hour,
  t.day as day

It times out. I tried it as a where clause and using with but no difference. The first part before the , executes quickly...

Upvotes: 2

Views: 91

Answers (3)

vivace
vivace

Reputation: 59

this seems to have fixed it. MATCH (t:Time)-[:Rel]-(o:Espresso)-[:Rel]->(l:Location)<-[:Rel]-(p:Espresso {id:"ttt"})-[:Rel]->t with DISTINCT o,p,t,l MATCH (o)--(rat:Rating)--(p) RETURN DISTINCT o.id as otherId, l.location as location, t.start as start, t.day as day

thanks

Upvotes: 1

Satish Shinde
Satish Shinde

Reputation: 2996

Improvements In your query/structure

  1. Don't use "," in match it will work as a Cartesian Product.
  2. You are using same relationship between all nodes that is :Rel note - Always try to use unique relationship names in different types of nodes.
  3. first go through this doc http://neo4j.com/docs/stable/cypher-query-lang.html
  4. also check this how to write a optimized queries http://www.slideshare.net/neo4j/optimizing-cypher-32550605

Upvotes: 1

Brian Underwood
Brian Underwood

Reputation: 10856

There are only 30 nodes/50 relationships in the whole database? That seems really odd... Have you previously created/deleted a lot of nodes, maybe as part of experimentation? If so, you may want to try restarting the server.

Upvotes: 1

Related Questions