- How do I reduce rows read in Cloudflare D1?
- Find the heavy queries with
wrangler d1 insights <db> --sort-by=reads or each result's meta.rows_read. EXPLAIN QUERY PLAN the worst: SCAN reads the whole table, SEARCH ... USING INDEX reads only matching rows. Index the columns the scanned query filters on, run PRAGMA optimize, and re-read its rows read per call.
- Does adding an index in D1 cost rows written?
- Yes. Every insert, and every update that touches an indexed column, also writes the index, so an index trades rows written for rows read. It pays on a table read far more than written — which is why nlqdb's verify also compares rows read per run after the apply and reverts an index that made things worse.
- Does nlqdb run my queries or change my D1 database to find indexes?
- No. It reads the catalog and D1's query insights, and plans texts with
EXPLAIN QUERY PLAN without executing them. Nothing changes until you apply a proposal, and every proposal carries the DROP INDEX that undoes it.
- What does an applied D1 index look like?
- On a test D1, a lookup by
user_id with no index read 5,000 rows a call; after nlqdb applied its proposed index it read 51. On a second, a lookup by title went from 4,999 rows read per run to 1, and the verify job kept the index with no caller.