Repository navigation
Run ANALYZE on the lobsters in-memory database - #565
Merged
Merged
Conversation
Contributor
Author
|
The red |
k0kubun
approved these changes
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #527. I didn't see a PR from @rubys yet, so I opened this one.
As @alanwu-shopify-inc suggested there,
benchmark.rbnow runsANALYZEon the in-memory copy right after the backup restore, instead of shipping statistics in the fixture.production.sqlite3has nosqlite_stat1, so SQLite runs the hottest-stories query (/,/recent,/rss) throughindex_stories_on_merged_story_idand sorts in a temp B-tree, instead of readinghotness_idxin order and stopping at the LIMIT. With statistics, that query takes 0.08 ms instead of 10.8 ms here (SQLite 3.54.1, the repro from #527).ANALYZEitself takes about 30 ms and runs before warmup.Ruby 4.0.7 on Linux x86_64, average of the 20 iterations after 5 warmups, with the runs interleaved:
The runs without statistics also vary more. All 114 responses are still 200, and each pass still runs 11,198 SQL queries. Every response except the five
/replypages, which differ from run to run anyway, is byte-identical with and without statistics. As with #564, lobsters results from before and after this change are not directly comparable.The other database benchmarks don't get
ANALYZE. In railsbench, activerecord and sequel it changes no query plan, since their tables have no index besides the primary key. In shipit it changes 6 of 23 plans, but saves under 0.02% of an iteration. erubi-rails doesn't load Active Record.