pub async fn audit_current(conn: &Connection) -> Result<usize>Expand description
Audit current belief in links_current against latest-belief projection of links (§5.8). Returns Ok(0) if zero drift, or Err(DbError::CurrentDrift { n }) if drift detected.
Drift is the symmetric difference: rows links_current has that the
projection does not (stale or spurious materialisation) plus rows the
projection has that links_current does not (missed materialisation).
Both directions must be counted, or the audit certifies a corrupt table.
The two directions are computed as two independent scalar subqueries and
added, rather than as one compound SELECT. SQLite gives EXCEPT and
UNION equal precedence and evaluates them left-associatively, so writing
the four arms as a flat chain parses as (((A EXCEPT B) UNION B) EXCEPT A),
which reduces to A EXCEPT A — a constant zero that reports “no drift” no
matter how corrupt the table is. That was the pre-0.5.4 defect.
Parentheses cannot fix it: SQLite rejects a parenthesised compound-SELECT
operand outright (near "UNION": syntax error). Putting each EXCEPT alone
inside its own scalar subquery makes the grouping structural instead of
syntactic, so there is no precedence for a future edit to get wrong.