threads
How many auxiliary worker threads one connection may start to help run a query.
- Predeterminado
0 (no worker threads)- Range
- 0 or more threads
- Restart needed
- No
- Default checked on
- SQLite 3.5x
Lo que hace
The main user is the sorter behind ORDER BY, GROUP BY and CREATE INDEX. 0 keeps everything on the calling thread. The value sets the per-connection SQLITE_LIMIT_WORKER_THREADS limit; SQLITE_DEFAULT_WORKER_THREADS can set the default at compile time and SQLITE_MAX_WORKER_THREADS caps how high it can go.
Valor predeterminado
0 (no worker threads). 0 (a stock SQLite 3.5x build) unless the build sets SQLITE_DEFAULT_WORKER_THREADS.
Check the current value
PRAGMA threads; SELECT * FROM pragma_threads; -- table-valued form, usable in queries
Change it
PRAGMA threads = 4; -- this connection only
No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.
When to change it
On multi-core machines that run big sorts or build large indexes and can spare the cores; small values such as 2 to 4 are the usual starting point.
What can go wrong
Worker threads duplicate sort buffers and compete with the application for CPU, so on a busy server they can worsen overall latency while speeding up one sort. The limit is per connection, so every pooled connection gets its own allowance.
Questions about threads
What is the default value of threads in SQLite?
0 (no worker threads). 0 (a stock SQLite 3.5x build) unless the build sets SQLITE_DEFAULT_WORKER_THREADS.
Does changing threads require a restart?
No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.
When should I change threads?
On multi-core machines that run big sorts or build large indexes and can spare the cores; small values such as 2 to 4 are the usual starting point.
Back to all SQLite settings, or check the SQLite manual for every option.
Related on SQLly
Check threads on your own server
SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.
Texto y datos de esta página: CC BY 4.0, con atribución a SQLly (sqlly.app). Código y fragmentos SQL: MIT. Detalles de la licencia