Explore the query execution summary
After all records of a query result have been processed, the server ends the transaction by returning a summary of execution.
It comes as a ResultSummary object, and it contains information among which:
-
Query counters — What changes the query triggered on the server
-
Query execution plan — How the database would execute (or executed) the query
-
Notifications — Extra information raised by the server while running the query
-
Timing information and query request summary
Retrieve the execution summary
When running queries with Driver.execute_query(), the execution summary is part of the default return value, as second object.
records, result_summary, keys = driver.execute_query("""
UNWIND ["Alice", "Bob"] AS name
MERGE (p:Person {name: name})
""", database_="<database-name>",
)
# or result_summary = driver.execute_query('<QUERY>').summary
If you are using transaction functions, or a custom transformer with Driver.execute_query(), you can retrieve the query execution summary with the method Result.consume().
Notice that once you ask for the execution summary, the result stream is exhausted: any record yet to be processed is not available anymore.
def create_people(tx):
result = tx.run("""
UNWIND ["Alice", "Bob"] AS name
MERGE (p:Person {name: name})
""")
return result.consume()
with driver.session(database="<database-name>") as session:
result_summary = session.execute_write(create_people)
Query counters
The property ResultSummary.counters contains counters for the operations that a query triggered (as a SummaryCounters object).
summary = driver.execute_query("""
MERGE (p:Person {name: $name})
MERGE (f:Person {name: $friend})
MERGE (p)-[:KNOWS]->(f)
""", name="Mark", friend="Bob",
database_="<database-name>",
).summary
print(summary.counters)
"""
{'_contains_updates': True, 'labels_added': 2, 'relationships_created': 1,
'nodes_created': 2, 'properties_set': 2}
"""
Two additional boolean properties act as meta-counters:
-
contains_updates— whether the query triggered any write operation on the database on which it ran -
contains_system_updates— whether the query triggered any write operation on thesystemdatabase