pub struct QueryStats { /* private fields */ }Implementations§
Source§impl QueryStats
impl QueryStats
pub fn new() -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn get(&self, sql: &str) -> Option<&QueryStat>
pub fn get(&self, sql: &str) -> Option<&QueryStat>
Returns the recorded stat snapshot, if any. Does NOT promote LRU (introspection should be side-effect free).
v7.37.22 (22.6) — sql is normalised before lookup so
callers don’t have to know about the normalisation rules.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &QueryStat)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &QueryStat)>
Iterate every recorded entry in deterministic (BTreeMap)
order. Used by spg_stat_query virtual table.
Sourcepub fn normalize_sql(sql: &str) -> String
pub fn normalize_sql(sql: &str) -> String
v7.37.22 (22.6) — normalise a SQL string for pg_stat_statements
grouping. Replaces literal values with $N placeholders so
SELECT * FROM t WHERE id = 1 and SELECT * FROM t WHERE id = 2 collapse into the same key (matching PG’s behaviour).
Rules:
- Numeric literals (integer + float) →
$N - Single-quoted string literals (with
''escape) →$N - NULL / TRUE / FALSE → preserved (PG also preserves these)
- Whitespace runs → single space
- Comments stripped (
-- …to EOL;/* … */block)
Each replaced literal increments N so multi-literal
queries get $1, $2, $3. Round-trippable enough that DBAs
reading the normalised form can map it back to the original
query template.
Sourcepub fn record(&mut self, sql: &str, elapsed_us: u64, now_us: u64)
pub fn record(&mut self, sql: &str, elapsed_us: u64, now_us: u64)
Record one execution. elapsed_us is the wall-clock micros
between start and end; now_us is the wall-clock micros at
completion (used for last_seen_us).
v7.37.22 (22.6) — the sql key is normalised so distinct literal-bearing instances collapse to a single template.
Row-count is reported via Self::record_with_rows; this
shim defaults to 0 for callers that don’t yet plumb the
affected / produced row count through.
Sourcepub fn record_with_rows(
&mut self,
sql: &str,
elapsed_us: u64,
now_us: u64,
rows: u64,
)
pub fn record_with_rows( &mut self, sql: &str, elapsed_us: u64, now_us: u64, rows: u64, )
v7.37.22 (22.9) — full record path with row count tracking.
rows is the number of rows the executor produced
(SELECT result.len()) or affected (INSERT/UPDATE/DELETE
affected). Aggregates over the normalised template into
total_rows (cumulative) and max_rows (per-call peak).
pub fn cap(&self) -> usize
Trait Implementations§
Source§impl Clone for QueryStats
impl Clone for QueryStats
Source§fn clone(&self) -> QueryStats
fn clone(&self) -> QueryStats
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more