| 1 | -- Oak benchmark dashboard schema for Cloudflare D1.
|
| 2 | --
|
| 3 | -- Raw JSONL in R2 is the source of truth. These tables are normalized indexes
|
| 4 | -- for dashboard queries and can be rebuilt by replaying R2 objects.
|
| 5 |
|
| 6 | PRAGMA foreign_keys = ON;
|
| 7 |
|
| 8 | CREATE TABLE IF NOT EXISTS uploads (
|
| 9 | r2_key TEXT PRIMARY KEY,
|
| 10 | sha256 TEXT NOT NULL,
|
| 11 | bench_id TEXT NOT NULL,
|
| 12 | profile TEXT NOT NULL,
|
| 13 | row_count INTEGER NOT NULL,
|
| 14 | byte_count INTEGER NOT NULL,
|
| 15 | content_type TEXT,
|
| 16 | status TEXT NOT NULL DEFAULT 'accepted',
|
| 17 | error TEXT,
|
| 18 | uploaded_at TEXT NOT NULL
|
| 19 | );
|
| 20 |
|
| 21 | CREATE INDEX IF NOT EXISTS idx_uploads_bench_id
|
| 22 | ON uploads (bench_id);
|
| 23 |
|
| 24 | CREATE INDEX IF NOT EXISTS idx_uploads_profile_uploaded
|
| 25 | ON uploads (profile, uploaded_at DESC);
|
| 26 |
|
| 27 | CREATE TABLE IF NOT EXISTS hosts (
|
| 28 | host_id TEXT PRIMARY KEY,
|
| 29 | host TEXT,
|
| 30 | platform TEXT,
|
| 31 | machine TEXT,
|
| 32 | python TEXT,
|
| 33 | runner_id TEXT,
|
| 34 | cpu_model TEXT,
|
| 35 | disk_model TEXT,
|
| 36 | metadata_json TEXT,
|
| 37 | first_seen_at TEXT NOT NULL,
|
| 38 | last_seen_at TEXT NOT NULL
|
| 39 | );
|
| 40 |
|
| 41 | -- Run identity is (bench_id, profile): bench_id is a second-resolution
|
| 42 | -- timestamp, and two lanes (e.g. core smoke + mount) started in the same
|
| 43 | -- second share it. run_key = bench_id || ':' || profile so concurrent lanes
|
| 44 | -- never overwrite each other's run metadata. Raw R2 objects are content-keyed
|
| 45 | -- (sha256) and unaffected.
|
| 46 | CREATE TABLE IF NOT EXISTS benchmark_runs (
|
| 47 | run_key TEXT PRIMARY KEY,
|
| 48 | bench_id TEXT NOT NULL,
|
| 49 | timestamp_utc TEXT NOT NULL,
|
| 50 | profile TEXT NOT NULL,
|
| 51 | source_oak_hash TEXT,
|
| 52 | source_oak_repo TEXT,
|
| 53 | source_oak_status TEXT,
|
| 54 | host_id TEXT,
|
| 55 | raw_r2_key TEXT,
|
| 56 | benchmark_track TEXT,
|
| 57 | command_semantics_version TEXT,
|
| 58 | row_count INTEGER NOT NULL DEFAULT 0,
|
| 59 | subject_versions_json TEXT,
|
| 60 | subject_details_json TEXT,
|
| 61 | uploaded_at TEXT NOT NULL,
|
| 62 | FOREIGN KEY (host_id) REFERENCES hosts (host_id),
|
| 63 | FOREIGN KEY (raw_r2_key) REFERENCES uploads (r2_key)
|
| 64 | );
|
| 65 |
|
| 66 | CREATE INDEX IF NOT EXISTS idx_benchmark_runs_profile_time
|
| 67 | ON benchmark_runs (profile, timestamp_utc DESC);
|
| 68 |
|
| 69 | CREATE INDEX IF NOT EXISTS idx_benchmark_runs_bench_id
|
| 70 | ON benchmark_runs (bench_id);
|
| 71 |
|
| 72 | CREATE INDEX IF NOT EXISTS idx_benchmark_runs_source
|
| 73 | ON benchmark_runs (source_oak_hash);
|
| 74 |
|
| 75 | -- Subject identity is subject_id (deterministic hash of run_key + effective
|
| 76 | -- subject + kind + binary_sha256). The same subject name MAY appear more than
|
| 77 | -- once per run when its binary_sha256 differs — both records are kept so a
|
| 78 | -- mixed-binary run never collapses into one subject. Earlier revisions
|
| 79 | -- carried an inline UNIQUE (run_key, name) here; it is superseded by
|
| 80 | -- subject_id identity (see schema_v2.sql). DBs created with the old inline
|
| 81 | -- constraint can be rebuilt by replaying R2 raw objects (header note above).
|
| 82 | CREATE TABLE IF NOT EXISTS subjects (
|
| 83 | subject_id TEXT PRIMARY KEY,
|
| 84 | run_key TEXT NOT NULL,
|
| 85 | name TEXT NOT NULL,
|
| 86 | kind TEXT NOT NULL,
|
| 87 | label TEXT,
|
| 88 | version TEXT,
|
| 89 | binary_path TEXT,
|
| 90 | metadata_json TEXT,
|
| 91 | FOREIGN KEY (run_key) REFERENCES benchmark_runs (run_key) ON DELETE CASCADE
|
| 92 | );
|
| 93 |
|
| 94 | CREATE INDEX IF NOT EXISTS idx_subjects_name
|
| 95 | ON subjects (name);
|
| 96 |
|
| 97 | CREATE TABLE IF NOT EXISTS measurements (
|
| 98 | measurement_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 99 | run_key TEXT NOT NULL,
|
| 100 | subject_id TEXT NOT NULL,
|
| 101 | scenario TEXT NOT NULL,
|
| 102 | operation TEXT NOT NULL,
|
| 103 | run_index INTEGER NOT NULL,
|
| 104 | is_canonical INTEGER NOT NULL DEFAULT 1,
|
| 105 | elapsed_ms REAL,
|
| 106 | estimated_tokens_total INTEGER,
|
| 107 | estimated_tokens_input INTEGER,
|
| 108 | estimated_tokens_output INTEGER,
|
| 109 | token_source TEXT,
|
| 110 | raw_output_bytes INTEGER,
|
| 111 | stdout_bytes INTEGER,
|
| 112 | stderr_bytes INTEGER,
|
| 113 | output_truncated INTEGER NOT NULL DEFAULT 0,
|
| 114 | tool_call_count INTEGER,
|
| 115 | vcs_tool_call_count INTEGER,
|
| 116 | terminal_tool_call_count INTEGER,
|
| 117 | returncode INTEGER NOT NULL,
|
| 118 | command_json TEXT,
|
| 119 | stderr TEXT,
|
| 120 | row_json TEXT NOT NULL,
|
| 121 | created_at TEXT NOT NULL,
|
| 122 | FOREIGN KEY (run_key) REFERENCES benchmark_runs (run_key) ON DELETE CASCADE,
|
| 123 | FOREIGN KEY (subject_id) REFERENCES subjects (subject_id) ON DELETE CASCADE
|
| 124 | );
|
| 125 |
|
| 126 | CREATE INDEX IF NOT EXISTS idx_measurements_group
|
| 127 | ON measurements (run_key, subject_id, scenario, operation);
|
| 128 |
|
| 129 | CREATE INDEX IF NOT EXISTS idx_measurements_dashboard
|
| 130 | ON measurements (scenario, operation, is_canonical, returncode);
|
| 131 |
|
| 132 | CREATE TABLE IF NOT EXISTS aggregates (
|
| 133 | run_key TEXT NOT NULL,
|
| 134 | subject_id TEXT NOT NULL,
|
| 135 | profile TEXT NOT NULL,
|
| 136 | scenario TEXT NOT NULL,
|
| 137 | operation TEXT NOT NULL,
|
| 138 | is_canonical INTEGER NOT NULL DEFAULT 1,
|
| 139 | sample_count INTEGER NOT NULL,
|
| 140 | failure_count INTEGER NOT NULL,
|
| 141 | failure_rate REAL,
|
| 142 | p50_ms REAL,
|
| 143 | p90_ms REAL,
|
| 144 | p95_ms REAL,
|
| 145 | p99_ms REAL,
|
| 146 | mean_ms REAL,
|
| 147 | min_ms REAL,
|
| 148 | max_ms REAL,
|
| 149 | avg_tokens REAL,
|
| 150 | avg_output_bytes REAL,
|
| 151 | truncated_count INTEGER NOT NULL DEFAULT 0,
|
| 152 | avg_tool_calls REAL,
|
| 153 | updated_at TEXT NOT NULL,
|
| 154 | PRIMARY KEY (run_key, subject_id, scenario, operation),
|
| 155 | FOREIGN KEY (run_key) REFERENCES benchmark_runs (run_key) ON DELETE CASCADE,
|
| 156 | FOREIGN KEY (subject_id) REFERENCES subjects (subject_id) ON DELETE CASCADE
|
| 157 | );
|
| 158 |
|
| 159 | CREATE INDEX IF NOT EXISTS idx_aggregates_dashboard
|
| 160 | ON aggregates (profile, scenario, operation, is_canonical);
|
| 161 |
|
| 162 | CREATE TABLE IF NOT EXISTS comparisons (
|
| 163 | comparison_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 164 | run_key TEXT NOT NULL,
|
| 165 | target_subject_id TEXT NOT NULL,
|
| 166 | baseline_subject_id TEXT NOT NULL,
|
| 167 | baseline_kind TEXT NOT NULL,
|
| 168 | profile TEXT NOT NULL,
|
| 169 | scenario TEXT NOT NULL,
|
| 170 | operation TEXT NOT NULL,
|
| 171 | p50_delta_ms REAL,
|
| 172 | p50_slower_pct REAL,
|
| 173 | p90_delta_ms REAL,
|
| 174 | p90_slower_pct REAL,
|
| 175 | p99_delta_ms REAL,
|
| 176 | p99_slower_pct REAL,
|
| 177 | avg_token_delta REAL,
|
| 178 | token_higher_pct REAL,
|
| 179 | avg_output_byte_delta REAL,
|
| 180 | output_byte_higher_pct REAL,
|
| 181 | avg_tool_call_delta REAL,
|
| 182 | tool_call_higher_pct REAL,
|
| 183 | failure_rate_delta_pp REAL,
|
| 184 | threshold_pct REAL NOT NULL,
|
| 185 | min_delta_ms REAL NOT NULL,
|
| 186 | is_regression INTEGER NOT NULL DEFAULT 0,
|
| 187 | state TEXT NOT NULL DEFAULT 'ok',
|
| 188 | severity_score REAL NOT NULL DEFAULT 0,
|
| 189 | updated_at TEXT NOT NULL,
|
| 190 | FOREIGN KEY (run_key) REFERENCES benchmark_runs (run_key) ON DELETE CASCADE,
|
| 191 | FOREIGN KEY (target_subject_id) REFERENCES subjects (subject_id) ON DELETE CASCADE,
|
| 192 | FOREIGN KEY (baseline_subject_id) REFERENCES subjects (subject_id) ON DELETE CASCADE,
|
| 193 | UNIQUE (run_key, target_subject_id, baseline_subject_id, scenario, operation)
|
| 194 | );
|
| 195 |
|
| 196 | CREATE INDEX IF NOT EXISTS idx_comparisons_dashboard
|
| 197 | ON comparisons (profile, is_regression DESC, severity_score DESC, scenario, operation);
|
| 198 |
|
| 199 | CREATE VIEW IF NOT EXISTS dashboard_comparisons AS
|
| 200 | SELECT
|
| 201 | c.comparison_id,
|
| 202 | c.run_key,
|
| 203 | r.bench_id,
|
| 204 | r.timestamp_utc,
|
| 205 | r.profile,
|
| 206 | r.host_id,
|
| 207 | target.name AS target_subject,
|
| 208 | baseline.name AS baseline_subject,
|
| 209 | c.baseline_kind,
|
| 210 | c.scenario,
|
| 211 | c.operation,
|
| 212 | c.p50_delta_ms,
|
| 213 | c.p50_slower_pct,
|
| 214 | c.p90_delta_ms,
|
| 215 | c.p90_slower_pct,
|
| 216 | c.p99_delta_ms,
|
| 217 | c.p99_slower_pct,
|
| 218 | c.avg_token_delta,
|
| 219 | c.token_higher_pct,
|
| 220 | c.avg_output_byte_delta,
|
| 221 | c.output_byte_higher_pct,
|
| 222 | c.avg_tool_call_delta,
|
| 223 | c.tool_call_higher_pct,
|
| 224 | c.failure_rate_delta_pp,
|
| 225 | c.state,
|
| 226 | c.is_regression,
|
| 227 | c.severity_score
|
| 228 | FROM comparisons c
|
| 229 | JOIN benchmark_runs r ON r.run_key = c.run_key
|
| 230 | JOIN subjects target ON target.subject_id = c.target_subject_id
|
| 231 | JOIN subjects baseline ON baseline.subject_id = c.baseline_subject_id;
|