driverfor
neo4jfor
python. I have a program that dynamically creates around 10-12 queries . The final result from all queries is collected in a
list` and returned.
Below are 10 such queries:
MATCH (sslc:subSubLocality)-[:CHILD_OF]->(v4)-[:CHILD_OF]->(v3)-[:CHILD_OF]->(v2)-[:CHILD_OF]->(st:state) WHERE (st.name_wr = 'abcState') AND (sslc.name_wr= 'xyzSLC' OR sslc.name_wr= 'abcxyzcolony') RETURN st, sslc, v4, v3, v2
MATCH (slc:subLocality)-[:CHILD_OF]->(v3)-[:CHILD_OF]->(v2)-[:CHILD_OF]->(st:state) WHERE (st.name_wr = 'abcState') AND (slc.name_wr= 'xyzSLC' OR slc.name_wr= 'abcxyzcolony') RETURN st, slc, v3, v2
MATCH (loc:locality)-[:CHILD_OF]->(v2)-[:CHILD_OF]->(st:state) WHERE (st.name_wr = 'abcState') AND (loc.name_wr= 'deltax' OR loc.name_wr= 'xyzSLC' OR loc.name_wr= 'abcxyzcolony') RETURN st, loc, v2
MATCH (ct:city)-[:CHILD_OF]->(st:state) WHERE (st.name_wr = 'abcState') AND (ct.name_wr= 'deltax' OR ct.name_wr= 'abcxyz') RETURN st, ct
MATCH (sslc:subSubLocality)-[:CHILD_OF]->(v3)-[:CHILD_OF]->(v2)-[:CHILD_OF]->(ct:city) WHERE (ct.name_wr = 'deltax' OR ct.name_wr = 'abcxyz') AND (sslc.name_wr= 'xyzSLC' OR sslc.name_wr= 'abcxyzcolony') RETURN ct, sslc, v3, v2
MATCH (slc:subLocality)-[:CHILD_OF]->(v2)-[:CHILD_OF]->(ct:city) WHERE (ct.name_wr = 'deltax' OR ct.name_wr = 'abcxyz') AND (slc.name_wr= 'xyzSLC' OR slc.name_wr= 'abcxyzcolony') RETURN ct, slc, v2
MATCH (loc:locality)-[:CHILD_OF]->(ct:city) WHERE (ct.name_wr = 'deltax' OR ct.name_wr = 'abcxyz') AND (loc.name_wr= 'deltax' OR loc.name_wr= 'xyzSLC' OR loc.name_wr= 'abcxyzcolony') RETURN ct, loc
MATCH (sslc:subSubLocality)-[:CHILD_OF]->(v2)-[:CHILD_OF]->(loc:locality) WHERE (loc.name_wr = 'deltax' OR loc.name_wr = 'xyzSLC' OR loc.name_wr = 'abcxyzcolony') AND (sslc.name_wr= 'xyzSLC' OR sslc.name_wr= 'abcxyzcolony') RETURN loc, sslc, v2
MATCH (slc:subLocality)-[:CHILD_OF]->(loc:locality) WHERE (loc.name_wr = 'deltax' OR loc.name_wr = 'xyzSLC' OR loc.name_wr = 'abcxyzcolony') AND (slc.name_wr= 'xyzSLC' OR slc.name_wr= 'abcxyzcolony') RETURN loc, slc
MATCH (sslc:subSubLocality)-[:CHILD_OF]->(slc:subLocality) WHERE (slc.name_wr = 'xyzSLC' OR slc.name_wr = 'abcxyzcolony') AND (sslc.name_wr= 'xyzSLC' OR sslc.name_wr= 'abcxyzcolony') RETURN slc, sslc
The Queries might change based on the input dictionary (as I mentioned the queries are created at run-time). But the queries share the same structure.
Below is a Query Plan
that I get and it remains the same for all queries just differs in values inside.
Below is my code that fires up these requests:
def get_query_response(query_list: list)-> list:
driver = GraphDatabase.driver(uri, auth=("neo4j", "neo4j"))
with driver.session() as session:
with session.begin_transaction() as tx:
response = [record.values() for query in query_list for record in tx.run(query)]
return response
The query_list
is a collection of str
that has these queries.
The problem is the whole task takes 2 seconds to give a response. Is there any way to optimize the query or make it faster or maybe operate in milliseconds?
Edit:
To answer a few questions:
- Yes the time mentioned is the time it takes to fetch the results. I had narrowed it down before hand.
- The queries take roughly from
3ms
-10ms
to execute. when I fire the query onneo4j
desktop. Is it the driver that's causing the issue? - Yes it's a locally hosted neo4j database and my system is
i7 16GB Memory with 1TB SSD
- No I didn't create
indeices
now I have and I get a performance bump with500ms
but now it's1.5s
is there any way I can push it to work in milliseconds?