Expand description
SqliteCostModel — a planner [ConnectionCostModel] backed by real SQLite
statistics (port of zqlite/src/sqlite-cost-model.ts).
For each table scan the planner asks about, we build a single-table SELECT
(constraint columns as = ? placeholders, filters with their literals inlined so
SQLite’s planner sees real values, plus the ORDER BY), prepare it, and read the
query planner’s per-loop estimates via scanstatus:
- rows = the main scan loop’s estimated row count.
- startup_cost =
btree_cost(rows)for each top-levelORDER BYsort loop. - fanout = from
SQLiteStatFanout(stat4/stat1).
This is a faithful logic port, not a byte-for-byte JS differential: the row /
fanout numbers come from this build’s SQLite + ANALYZE stats, which differ from
the JS engine’s. It is validated by real-SQLite integration tests.
Structs§
- Sqlite
Cost Model - A cost model that estimates table-scan cost from a live SQLite connection.
Constants§
- DEFAULT_
FANOUT - SQLite’s default fanout when statistics are unavailable (
SQLiteStatFanout’s default).
Functions§
- btree_
cost btreeCost(sqlite-cost-model.ts):(rows * log2(rows)) / 10— O(n log n) sort,/10because SQLite sorts ~10× faster than pulling rows into the host. Operation order preserved (multiply then divide).