Rindle docs and package mapSkip to main content

Module cost_model

Module cost_model 

Source
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-level ORDER BY sort 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§

SqliteCostModel
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, /10 because SQLite sorts ~10× faster than pulling rows into the host. Operation order preserved (multiply then divide).