Report how many changes were done in the interface
This commit is contained in:
1 parent
dc978fd0fd
commit
8258bdc2a3
6 files changed
+140
-23
No files matched your search
@@ -1,5 +1,30 @@
|
||||
# Write statistics
|
||||
|
||||
## Status
|
||||
|
||||
Done. Queries that can write report `stats` in the final `PULL` summary, with the
|
||||
node, relationship and label counters exact, and `properties-set` approximate as
|
||||
described below. `CREATE DATABASE` and `DROP DATABASE` report system updates.
|
||||
|
||||
The spike and testing changed some details below:
|
||||
|
||||
- The counters do **not** reset at commit: they stay until PostgreSQL flushes them,
|
||||
some time later. That makes the difference only reliable within one transaction,
|
||||
which is still why each write runs in its own. Before, query and after are sent as
|
||||
one script, so this costs no extra round trips.
|
||||
- The counters are read with `pg_stat_get_xact_tuples_*`, not the
|
||||
`pg_stat_xact_user_tables` view.
|
||||
- Label tables are found through `pg_class` and `pg_inherits`, not `ag_label`: reading
|
||||
`ag_label` made writes fail for roles without `SELECT` on it.
|
||||
- `labels-removed` is not reported. Deleting a node does not count in Neo4j, and AGE
|
||||
cannot remove a label.
|
||||
- `SET n.a = 1, n.b = 2` is one update per node, so `properties-set` is the number of
|
||||
nodes and relationships changed, not of properties.
|
||||
|
||||
The price is about 1 ms per query that can write (2.1 ms to 3.0 ms for a single-row
|
||||
`CREATE` on a local database). A statement that writes many rows pays this once.
|
||||
Caching a graph's label tables could lower it.
|
||||
|
||||
## Problem
|
||||
|
||||
Neo4j reports what a write query changed in the `stats` entry of the final `PULL`
|
||||
|
||||
+3
-3
@@ -28,9 +28,9 @@ plans small:
|
||||
transaction-local counters, streaming (06) needs a transaction to keep a server-side
|
||||
cursor open, and `PROFILE` (01) needs a savepoint. All three want `Session.run` to
|
||||
wrap auto-commit queries in `BEGIN ... COMMIT` instead of relying on the
|
||||
connection's autocommit mode. Plan 06 only did this for read queries, which run
|
||||
in a cursor's transaction; queries that can write still use autocommit, so 02 still
|
||||
has to add it for them.
|
||||
connection's autocommit mode. This is done: reads run in a cursor's transaction
|
||||
(06), and queries that can write in one around the statistics (02). `Session._script`
|
||||
runs such a transaction in one round trip.
|
||||
3. **Unit tests.** The only test is the end-to-end `tests/smoke_test.py`. Most of
|
||||
this work is text rewriting in `cypher.py`, which is cheap to unit test without a
|
||||
database. Add `tests/test_cypher.py` (pytest) alongside the first plan that
|
||||
|
||||
Reference in new issue
Block a user