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!

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.
Screenshot%20from%202019-10-04%2016-09-39

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