简体   繁体   中英

neo4j CYPHER - Relationship Query doesn't finish

in a 14 GB database I have a few CITES relationships:

MATCH p=()-[r:CITES]->() RETURN count(r)

91

However, when I run

MATCH ()-[r:CITES]-() RETURN count(r)

it loads forever and eventually crashes with a browser window reload (neo4j desktop)

You can see the differences in how each of those queries will execute if you prefix each query with EXPLAIN .

The pattern used for the first query is such that the planner will find that count in the counts store, a transactionally updated store of counts of various things. This is a fast constant time lookup.

The other pattern, when omitting the direction, will not use the count store lookup and will actually have to traverse the graph (starting from every node in the graph), and that will take a long time as your graph grows.

As for what this gives back, it should actually be twice the number of :CITIES relationships in your graph, since without the direction on the relationship, each individual relationship will be found twice, since the same path with the start and end nodes switched both fit the given pattern.

Neo4j always choose nodes as start points for query execution. In your query, probably the query engine is touching the whole graph, since you are not adding restrictions on node properties, labels, etc.

I think you should specify a label at least in your first node in the pattern.

MATCH (:Article)-[r:CITES]-() RETURN count(r)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM