Skip to main content

relate_executor/graph/
query_stats.rs

1//! Per-statement mutation counters (`QueryStats`), split out of the graph
2//! module to keep it under the file-size budget.
3
4/// Generates [`QueryStats`] and its `merge` from one counter list, so a
5/// counter cannot exist without its merge arm (ADR-0309's two families are
6/// documented per field below).
7macro_rules! query_stats {
8    ($($(#[$doc:meta])* $name:ident),+ $(,)?) => {
9        /// A statement's mutation counters. Two families count different things:
10        ///
11        /// - The openCypher graph-diff counters the TCK side effects check:
12        ///   `labels_added`/`labels_removed` count label *names* that appear in or
13        ///   vanish from the graph, and `properties_set`/`properties_removed` count
14        ///   property additions and removals (an overwrite is one of each; a deleted
15        ///   entity's properties are removed).
16        /// - Neo4j's update counters, which drivers read from a result summary
17        ///   (ADR-0309): `node_labels_added`/`node_labels_removed` count labels per
18        ///   node (a `REMOVE`, never a delete), and `properties_written` counts one
19        ///   per property a `CREATE`, `SET` or `REMOVE` writes. The wire rendering
20        ///   (`relate::query_stats_to_wire`) uses these.
21        ///
22        /// The node, relationship, index and constraint counters are shared.
23        #[derive(Debug, Clone, Default, PartialEq, Eq)]
24        pub struct QueryStats {
25            $(
26                $(#[$doc])*
27                pub $name: i64,
28            )+
29        }
30
31        impl QueryStats {
32            /// Merge another statement's counters into this one. Generated
33            /// from the one counter list, so a counter cannot exist without
34            /// its merge arm.
35            pub fn merge(&mut self, other: &QueryStats) {
36                $(
37                    self.$name += other.$name;
38                )+
39            }
40        }
41    };
42}
43
44query_stats! {
45    nodes_created,
46    nodes_deleted,
47    relationships_created,
48    relationships_deleted,
49    properties_set,
50    properties_removed,
51    labels_added,
52    labels_removed,
53    /// Indexes created by index DDL (ADR-0309). The range index backing a
54    /// `UNIQUE`/`KEY` constraint is part of that constraint, not counted here.
55    indexes_added,
56    /// Indexes dropped by index DDL (ADR-0309); a constraint's backing index
57    /// dropped with it is not counted here.
58    indexes_removed,
59    /// Constraints created, by constraint DDL or a graph-type change (ADR-0309).
60    constraints_added,
61    /// Constraints dropped, by constraint DDL or a graph-type change (ADR-0309).
62    constraints_removed,
63    /// Labels added to nodes, counted per node (Neo4j's `labels-added`,
64    /// ADR-0309).
65    node_labels_added,
66    /// Labels removed from nodes by `REMOVE`, counted per node (Neo4j's
67    /// `labels-removed`, ADR-0309); deleting a node counts none.
68    node_labels_removed,
69    /// Property writes: one per property a `CREATE`, `SET` or `REMOVE`
70    /// writes, overwrites and removals included (Neo4j's `properties-set`,
71    /// ADR-0309); deleting an entity counts none.
72    properties_written,
73}