Neo4j query using only one core of my machine

Viewed 179

I am novice to Graph Databases and struggling to process 1M relationships using the below query. I have observed that the below query is using only 1 core and is taking too long. Is it possible to run the query in parallel using all cores available? I came across AOPC function apoc.cypher.parallel2 and not sure if it can do the trick. I am using the community version but open to upgrade to Enterprise version if I can get it to run in parallel.

MATCH p=(a:address)-[r*]->(b:address)
WHERE NOT (b)-[]->(:address)
WITH a,b, LAST(nodes(p)) as c,length(p) as depth
RETURN a.add_id, c.add_id,max(depth)
ORDER BY a.add_id
;

Thanks in advance.

1 Answers

You can use CALL apoc.periodic.iterate() to do parallel executions, using the parallel: true parameter that you add to options.

However -- normally these are for write operations, and your query is a read. It's not clear what you want to do in terms of a parallel read here.

Normally, to parallelize a read, you break it into multiple paginated reads, and have multiple different queries executing. Like let's take this bit as the core "body" of your query:

MATCH p=(a:address)-[r*]->(b:address)
WHERE NOT (b)-[]->(:address)
WITH a,b, LAST(nodes(p)) as c,length(p) as depth
RETURN a.add_id, c.add_id,max(depth)

to parallelize reads on this, I would do say 3 different queries, each ending with a different ending:

ORDER BY a.add_id SKIP 0 LIMIT 100

ORDER BY a.add_id SKIP 100 LIMIT 100

ORDER BY a.add_id SKIP 200 LIMIT 100

...and so on. Each gives you a page of 100 results

Related