cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to optimize a query that will be executed millions of times under different parameters

Hi, everyone

I am writing a query that returns a relationship according to the attributes of two nodes.

MATCH (a:nodeLabel)-[r:relationType]-(b:nodeLabel) WHERE a.attribute=nodeA AND b.attribute=nodeB RETURN r

There are about one million pairs of nodes. I used for loop to execute this query for each node pair in python and it took so much long time. I thought I can query relationships between million pairs of nodes in one query. But I did not find a solution. Any suggestions?

Many thanks for any help!

3 REPLIES 3

if you prefix the query with EXPLAIN does this report it using an INDEX scan or is it using a scan by LABEL.

Do you have indexes on :nodeLabel and specifically on property attribute

I have indexes specifically on property attribute. The query does use an INDEX scan.
2X_3_3e483eabeb9097aa07740d9413b524739acf1dd9.png

When I execute one query. it took 5ms. But I have millions of queries.

the query plan looks great and I'm not sure where I see it could be improved. and 5ms for a response/output would appear very fast.

isnt the issue now a matter of not the response time of the individual query but rather the number of times it runs