I have two queries: q1 and q2. I use the code below to query my neo4j database.
driver = GraphDatabase.driver("bolt://localhost:7687",auth= neo4j_user,neo4j_password))
neo4j_session = driver.session()
t = time.time()
neo4j_session.run(q1,q1_parameters)
print(time.time()-t)
t = time.time()
neo4j_session.run(q2,q2_parameters)
print(time.time()-t)
both q1 and q2 are performed by neo4j in approximately 10 ms in the web interface (http://localhost:7474/browser/). The code above also executes q1 in approximately 10 ms but q2 is performed in 1s.
Why does neo4j bolt connection not like a specific query (q2) even though the web interface executes it 100 times faster? I believe this is not connection overhead as q1 is executed almost as fast either way
You should not be creating a new driver and session for every query.
The README for the Python Bolt driver has the following "Quick Example" of how to run 4 queries (in 3 write and 1 read transactions) with the same
driver
andsession
: