diff --git a/db/deno.json b/db/deno.json index e6911ea..331295c 100644 --- a/db/deno.json +++ b/db/deno.json @@ -4,7 +4,7 @@ "@std/assert": "jsr:@std/assert@^1.0.19" }, "name": "@01edu/db", - "version": "0.2.3", + "version": "0.2.4", "license": "MIT", "exports": { ".": "./mod.ts", diff --git a/db/entries.ts b/db/entries.ts index b483b55..ec010d5 100644 --- a/db/entries.ts +++ b/db/entries.ts @@ -257,6 +257,14 @@ export const initEntries = < [name]: { type }, }) + // SQLite only auto-indexes primary keys. fieldId is the PK, so entryId + // needs an explicit index — without it any partial index on entryInternal + // triggers a full table scan of the field table on every join. + sql` + CREATE INDEX IF NOT EXISTS idx_${tableName}_entry_id + ON ${tableName}(entryId) + `.run() + fieldTables[name] = table fields[name] = table }