36 SQLite queries that didn’t use an index
Although indexes existed, 36 queries were scanning every record. Indexes and queries now come from one declaration.
For each kind of record, we build an index on the values of its inner fields. But when we queried, we passed the kind and the field path as SQL variables, and SQLite couldn't use those indexes. 36 lookups by field were checking every record of the same kind.
If we fix the SQL in all 36 places by hand, today's problem goes away. But the code that creates the indexes and the code that queries are still separate. If only one of them changes, we'd again have an index that exists but can't be used. The problem wasn't forgetting an index. It was writing the same condition twice.
So we write the fields to query once, next to the record type. From this declaration, called Indexed, we generate the index and the query together. The kind and the field name go straight into the SQL statement, so SQLite can find the matching index.
Now the index and the query can't state different conditions. How much faster the lookups get is a separate question, though. What we've confirmed goes only as far as SQLite now being able to find the index.
Written from that day’s point of view, using the documents and change history of the time. Published 2026.12.01.
