add metrics and implement the .stats command

This adds basic statement and connection metrics like SQLite (and
libSQL) have.

This is particularly useful to show that materialized views are working:

turso> create table t(a);
turso> insert into t(a) values (1) , (2), (3), (4), (5), (6), (7), (8), (9), (10);
turso> create materialized view v as select count(*) from t;
turso> .stats on
Stats display enabled.
turso> select count(*) from t;
┌───────────┐
│ count (*) │
├───────────┤
│        10 │
└───────────┘

Statement Metrics:
  Row Operations:
    Rows read:        10
    Rows written:     0
    [ ... other metrics ... ]

turso> select * from v;
┌───────────┐
│ count (*) │
├───────────┤
│        10 │
└───────────┘

Statement Metrics:
  Row Operations:
    Rows read:        1
    Rows written:     0
    [ ... other metrics ... ]
This commit is contained in:
Glauber Costa
2025-08-18 07:36:38 -05:00
parent 6e8822792a
commit 36fc8e8fdb
10 changed files with 405 additions and 35 deletions

View File

@@ -3,8 +3,8 @@ pub mod import;
use args::{
CwdArgs, DbConfigArgs, EchoArgs, ExitArgs, HeadersArgs, IndexesArgs, LoadExtensionArgs,
NullValueArgs, OpcodesArgs, OpenArgs, OutputModeArgs, SchemaArgs, SetOutputArgs, TablesArgs,
TimerArgs,
NullValueArgs, OpcodesArgs, OpenArgs, OutputModeArgs, SchemaArgs, SetOutputArgs, StatsArgs,
TablesArgs, TimerArgs,
};
use clap::Parser;
use import::ImportArgs;
@@ -78,6 +78,9 @@ pub enum Command {
/// Print or set the current configuration for the database. Currently ignored.
#[command(name = "dbconfig", display_name = ".dbconfig")]
DbConfig(DbConfigArgs),
/// Display database statistics
#[command(name = "stats", display_name = ".stats")]
Stats(StatsArgs),
/// List vfs modules available
#[command(name = "vfslist", display_name = ".vfslist")]
ListVfs,