chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
Owners' notifications name the index their blocks and hides are read by
Merged Approved
This pins both moderation subqueries in Index::notified to forge_moderation with INDEXED BY. The planner's choice then no longer depends on the order the indexes were created in. The index is created in the schema with IF NOT EXISTS. Its WHERE is the instr pair the subqueries already repeat, so SQLite can use it. listItems already pins the same index this way. I found no problems. I did not run the query or the benchmark; the prod timings come from the description. The tests don't cover the creation-order case, as the description admits.
All checks have passed
8 passed, 2 skipped
Merged as 581c6a4
What changes
The block and hide subqueries in
Index::notified'swatchingandmentionbranches now name their index:FROM forge o INDEXED BY forge_moderation, aslistItems' moderation CTE already does.Why
Owners' notifications check blocks and hides through their index added
forge_moderation's ownWHEREto these subqueries so SQLite could use that index. That worked on an index built fresh. It did nothing on prod: after the deploy, the owner's notifications statement still took 600 to 700 ms on everygetUnreadCountand push round (admin_logs).Prod's index has no
sqlite_stat1.forge_repo_createdandforge_moderationboth match(repo_did = ? AND repo_key = ?)at the same estimated cost, so SQLite breaks the tie by the order the indexes were created. On prod,forge_repo_createdwas made afterforge_moderation, since a later version added it to an existing table. A fresh index, as in the tests, creates them inEXPRESSIONS' order, the other way round. So prod still read every record of the repository, JSON-parsed, once for each row heard of, which is the regression the owner default brought in.Naming the index makes the choice the same however the file was built.
How it was checked
On a read-only snapshot of prod's
index.dbandprivate.sqlite(Python'ssqlite3backup API, copied off the host), I ran the query fromindex.rsas written, for chadtmiller.com, with grain.social as its org and the 20 owned-repository watchesowned_watchesgives, on SQLite 3.53, as the bundledlibsqlite3-sys0.38.2 is:The plan now has both subqueries on
SEARCH o USING INDEX forge_moderation (repo_did=? AND repo_key=?). On both databases, the rows match the query before 3mzt7fogvzsyz for no kind and for each ofcomments,pulls-and-issues,reviews,mentionsandchecks.Shortcomings
plans.rsbuilds its planner's tables inEXPRESSIONS' order, as a fresh index does, so it cannot see a plan that depends on creation order. Another query that leaves SQLite to choose between two indexes with the same leading columns could plan differently on prod in the same way.