Session.run() VS transaction.run() in Neo4j Bolt

北战南征 提交于 2019-12-10 11:09:37

问题


What is the difference between the Session.run() and transaction.run() in Neo4j Bolt driver?

My knowledge is:

Session.run() will execute a single statement    
transaction.run() executes multiple statements.

Those are the information I know which are correct. What are the all other differences?


回答1:


Session.run() will actually create a transaction, execute the statement, and commit the transaction. Transaction.run() will leave the transaction open until you commit it, but the statement will still be sent and interpreted and executed, and results will be returned. However, any changes won't actually be persisted into the datastore, and won't be visible to queries outside of the transaction. You have to mark the transaction as successful and commit it or it will be rolled back.

You should try not to use transactions; open transactions prevent changes to indexes and constraints and increase memory usage. The only reason to use transactions is for the rollback potential; if you want to see what the results of the query are, and maybe undo it depending on those results, then use a transaction. Otherwise use a session.



来源:https://stackoverflow.com/questions/39525713/session-run-vs-transaction-run-in-neo4j-bolt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!