From dcbe87c54a68e8ee1546ce26435fbcf40e801b02 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:25:15 -0400 Subject: [PATCH 1/4] test: ephemeral db enables sorter worker threads --- packages/rust/src/db.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/rust/src/db.rs b/packages/rust/src/db.rs index ba2fff932..d6a2cb4f9 100644 --- a/packages/rust/src/db.rs +++ b/packages/rust/src/db.rs @@ -2200,6 +2200,16 @@ mod tests { assert_eq!(pragma("synchronous"), 0); } + #[test] + fn new_lets_the_sorter_use_worker_threads() { + let db = Db::new().unwrap(); + let threads: i64 = db + .conn() + .query_row("PRAGMA threads", [], |row| row.get(0)) + .unwrap(); + assert_eq!(threads, 8); + } + #[test] fn get_rows_by_file_returns_rows_in_row_index_order() { let db = Db::new().unwrap(); From a2a42d2c9ac8c5aa5292f4d4d540296cf1e1ee6c Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:35:42 -0400 Subject: [PATCH 2/4] perf: let SQLite's sorter use worker threads --- .../2026-10-11-sorts-use-worker-threads.md | 3 +++ .../2026-10-11-sorts-use-worker-threads.md | 25 +++++++++++++++++++ packages/rust/src/db.rs | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 packages/rust/changelog.d/2026-10-11-sorts-use-worker-threads.md create mode 100644 packages/rust/migrations.d/2026-10-11-sorts-use-worker-threads.md diff --git a/packages/rust/changelog.d/2026-10-11-sorts-use-worker-threads.md b/packages/rust/changelog.d/2026-10-11-sorts-use-worker-threads.md new file mode 100644 index 000000000..7a9ca84cf --- /dev/null +++ b/packages/rust/changelog.d/2026-10-11-sorts-use-worker-threads.md @@ -0,0 +1,3 @@ +**Changed** + +- **A `GROUP BY` or `ORDER BY` over a large table now sorts on background threads.** A grouped query over a million parsed rows runs about 9% faster. Output is unchanged. diff --git a/packages/rust/migrations.d/2026-10-11-sorts-use-worker-threads.md b/packages/rust/migrations.d/2026-10-11-sorts-use-worker-threads.md new file mode 100644 index 000000000..3b0666e25 --- /dev/null +++ b/packages/rust/migrations.d/2026-10-11-sorts-use-worker-threads.md @@ -0,0 +1,25 @@ +### Faster sorts over large tables + +#### Summary + +SQLite may now sort on up to eight background threads. Query results and their order are unchanged; nothing breaks. + +#### Required changes + +_None._ + +#### Deprecations removed + +_None._ + +#### Behavior changes without code changes + +_None._ + +#### Verification + +```bash +dirsql query "SELECT level, count(*) FROM events GROUP BY level" +``` + +Prints the same rows as before, sooner on a large table. diff --git a/packages/rust/src/db.rs b/packages/rust/src/db.rs index d6a2cb4f9..ca3657546 100644 --- a/packages/rust/src/db.rs +++ b/packages/rust/src/db.rs @@ -393,6 +393,8 @@ impl Db { // The database is a private temp file that dies with the process, so // durability buys nothing. conn.pragma_update(None, "synchronous", "OFF")?; + // Lets a GROUP BY or ORDER BY over a large table sort on background threads. + conn.pragma_update(None, "threads", 8)?; ensure_internal_rows_table(&conn)?; let scope = StatementScope::new(); vtab::load_module(&conn, Arc::clone(&scope))?; From d788240dd87db72c650d341b90c75c99abc602f8 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:48:29 -0400 Subject: [PATCH 3/4] e2e attestation for bot/speed-parse-pragmas-1011 --- .../e2e-attestations/bot-speed-parse-pragmas-1011.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/python/e2e-attestations/bot-speed-parse-pragmas-1011.json diff --git a/packages/python/e2e-attestations/bot-speed-parse-pragmas-1011.json b/packages/python/e2e-attestations/bot-speed-parse-pragmas-1011.json new file mode 100644 index 000000000..ea2512e35 --- /dev/null +++ b/packages/python/e2e-attestations/bot-speed-parse-pragmas-1011.json @@ -0,0 +1,7 @@ +{ + "command": "uv run python -m pytest tests/e2e/jsonl_parse_speed_test.py tests/e2e/frontmatter_parse_speed_test.py tests/e2e/on_file_query_test.py tests/e2e/query_contract_test.py -x -q", + "ran_at": 1791766109, + "exit_code": 0, + "commit": "a2a42d2c9ac8c5aa5292f4d4d540296cf1e1ee6c", + "branch": "bot/speed-parse-pragmas-1011" +} From 92efde45d1477589ba2e54c0a28e12f00c17892c Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:49:46 -0400 Subject: [PATCH 4/4] e2e attestation for bot/speed-parse-pragmas-1011 --- .../ts/e2e-attestations/bot-speed-parse-pragmas-1011.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/ts/e2e-attestations/bot-speed-parse-pragmas-1011.json diff --git a/packages/ts/e2e-attestations/bot-speed-parse-pragmas-1011.json b/packages/ts/e2e-attestations/bot-speed-parse-pragmas-1011.json new file mode 100644 index 000000000..1d283bd9b --- /dev/null +++ b/packages/ts/e2e-attestations/bot-speed-parse-pragmas-1011.json @@ -0,0 +1,7 @@ +{ + "command": "pnpm test:e2e", + "ran_at": 1791766186, + "exit_code": 0, + "commit": "d788240dd87db72c650d341b90c75c99abc602f8", + "branch": "bot/speed-parse-pragmas-1011" +}