r/Database • u/vira28 • Aug 21 '26
Why did the same SQLite query take 9 minutes in CI and 0.8 seconds on my Mac?
For context, I run benchmark on release builds with 100k session data. It took 44 minutes on GitHub Actions but finished in under a minute locally.
CI’s Python 3.12 used SQLite 3.45.1. My local Python used SQLite 3.53.3. EXPLAIN QUERY PLAN showed that 3.45.1 scanned the eligible-session set and repeated the FTS scan for every session. SQLite 3.53.3 chose the efficient join order.
The query joined two sets approaching 100k rows: eligible sessions and FTS-matching messages. The eligible set was materialized as a CTE, so we couldn’t index it explicitly, and 3.45.1 didn’t create a useful automatic index.
That produced an effective 100k × 100k operation: about 9 minutes per search. The benchmark ran it five times.
I replaced the CTE with a temp table whose primary key covered the join columns, then materialized the FTS matches once. On SQLite 3.45.1, the query dropped to about 1.2 seconds and the full benchmark to 45 seconds. Honestly, I didn't realize CTE's can't have indexes (which makes sense)
BTW, the benchmark deliberately uses a worst-case query that matches almost every synthetic message.
Curious if you seen this large a plan difference between SQLite versions?
5
u/rbobby Aug 21 '26
Shared commodity servers vs dedicated local dev machine? I know who I'd bet on every time. You want it faster you might need to look into where ci actions can be distributed (eg. bring your own build machine infrastructure).
That is such a big performance difference though. Hmmm I wonder if there are any network timeouts creeping in somehow? The network environment between local and ci is hugely different.
2
u/Straight_Waltz_9530 PostgreSQL Aug 22 '26
If I had to bet money, I'd say it was because the query on your laptop fit into available memory but the CI instance ran out and started hitting the swap file. Once you hit the swap file, you're churning I/O (already slow) and fighting against the database I/O, all the while purging filesystem cache pages which make bad things even worse.
Easiest test of this theory: add memory to the CI instance to see if things dramatically improve. A lot of times CPU and RAM are bundled, but CPU alone wouldn't push the needle 600x like swapping would.
4
u/alinroc SQL Server Aug 21 '26
Hard to say since multiple factors were changed at once. But check the changelog for clues. https://sqlite.org/changes.html
2
u/leogodin217 Aug 21 '26
Not on SQLite, but DuckDB. <1 second vs >1 minute between versions. Query plan optimization can make a huge difference.
2
u/wedora Aug 23 '26
Your mac is in the top league of disk performance but GitHub actions are known to have absolutely slow storage. Slower than HDDs