xref: /netbsd-src/external/public-domain/sqlite/man/SQLITE_CONFIG_SINGLETHREAD.3 (revision 82d56013d7b633d116a93943de88e08335357a7c)
1.Dd December 19, 2018
2.Dt SQLITE_CONFIG_SINGLETHREAD 3
3.Os
4.Sh NAME
5.Nm SQLITE_CONFIG_SINGLETHREAD ,
6.Nm SQLITE_CONFIG_MULTITHREAD ,
7.Nm SQLITE_CONFIG_SERIALIZED ,
8.Nm SQLITE_CONFIG_MALLOC ,
9.Nm SQLITE_CONFIG_GETMALLOC ,
10.Nm SQLITE_CONFIG_SCRATCH ,
11.Nm SQLITE_CONFIG_PAGECACHE ,
12.Nm SQLITE_CONFIG_HEAP ,
13.Nm SQLITE_CONFIG_MEMSTATUS ,
14.Nm SQLITE_CONFIG_MUTEX ,
15.Nm SQLITE_CONFIG_GETMUTEX ,
16.Nm SQLITE_CONFIG_LOOKASIDE ,
17.Nm SQLITE_CONFIG_PCACHE ,
18.Nm SQLITE_CONFIG_GETPCACHE ,
19.Nm SQLITE_CONFIG_LOG ,
20.Nm SQLITE_CONFIG_URI ,
21.Nm SQLITE_CONFIG_PCACHE2 ,
22.Nm SQLITE_CONFIG_GETPCACHE2 ,
23.Nm SQLITE_CONFIG_COVERING_INDEX_SCAN ,
24.Nm SQLITE_CONFIG_SQLLOG ,
25.Nm SQLITE_CONFIG_MMAP_SIZE ,
26.Nm SQLITE_CONFIG_WIN32_HEAPSIZE ,
27.Nm SQLITE_CONFIG_PCACHE_HDRSZ ,
28.Nm SQLITE_CONFIG_PMASZ ,
29.Nm SQLITE_CONFIG_STMTJRNL_SPILL ,
30.Nm SQLITE_CONFIG_SMALL_MALLOC ,
31.Nm SQLITE_CONFIG_SORTERREF_SIZE
32.Nd Configuration Options
33.Sh SYNOPSIS
34.Fd #define SQLITE_CONFIG_SINGLETHREAD
35.Fd #define SQLITE_CONFIG_MULTITHREAD
36.Fd #define SQLITE_CONFIG_SERIALIZED
37.Fd #define SQLITE_CONFIG_MALLOC
38.Fd #define SQLITE_CONFIG_GETMALLOC
39.Fd #define SQLITE_CONFIG_SCRATCH
40.Fd #define SQLITE_CONFIG_PAGECACHE
41.Fd #define SQLITE_CONFIG_HEAP
42.Fd #define SQLITE_CONFIG_MEMSTATUS
43.Fd #define SQLITE_CONFIG_MUTEX
44.Fd #define SQLITE_CONFIG_GETMUTEX
45.Fd #define SQLITE_CONFIG_LOOKASIDE
46.Fd #define SQLITE_CONFIG_PCACHE
47.Fd #define SQLITE_CONFIG_GETPCACHE
48.Fd #define SQLITE_CONFIG_LOG
49.Fd #define SQLITE_CONFIG_URI
50.Fd #define SQLITE_CONFIG_PCACHE2
51.Fd #define SQLITE_CONFIG_GETPCACHE2
52.Fd #define SQLITE_CONFIG_COVERING_INDEX_SCAN
53.Fd #define SQLITE_CONFIG_SQLLOG
54.Fd #define SQLITE_CONFIG_MMAP_SIZE
55.Fd #define SQLITE_CONFIG_WIN32_HEAPSIZE
56.Fd #define SQLITE_CONFIG_PCACHE_HDRSZ
57.Fd #define SQLITE_CONFIG_PMASZ
58.Fd #define SQLITE_CONFIG_STMTJRNL_SPILL
59.Fd #define SQLITE_CONFIG_SMALL_MALLOC
60.Fd #define SQLITE_CONFIG_SORTERREF_SIZE
61.Sh DESCRIPTION
62These constants are the available integer configuration options that
63can be passed as the first argument to the sqlite3_config()
64interface.
65.Pp
66New configuration options may be added in future releases of SQLite.
67Existing configuration options might be discontinued.
68Applications should check the return code from sqlite3_config()
69to make sure that the call worked.
70The sqlite3_config() interface will return a non-zero
71error code if a discontinued or unsupported configuration
72option is invoked.
73.Bl -tag -width Ds
74.It SQLITE_CONFIG_SINGLETHREAD
75There are no arguments to this option.
76This option sets the threading mode to Single-thread.
77In other words, it disables all mutexing and puts SQLite into a mode
78where it can only be used by a single thread.
79If SQLite is compiled with the  SQLITE_THREADSAFE=0
80compile-time option then it is not possible to change the threading mode
81from its default value of Single-thread and so sqlite3_config()
82will return SQLITE_ERROR if called with the SQLITE_CONFIG_SINGLETHREAD
83configuration option.
84.It SQLITE_CONFIG_MULTITHREAD
85There are no arguments to this option.
86This option sets the threading mode to Multi-thread.
87In other words, it disables mutexing on database connection
88and prepared statement objects.
89The application is responsible for serializing access to database connections
90and prepared statements.
91But other mutexes are enabled so that SQLite will be safe to use in
92a multi-threaded environment as long as no two threads attempt to use
93the same database connection at the same time.
94If SQLite is compiled with the  SQLITE_THREADSAFE=0
95compile-time option then it is not possible to set the Multi-thread
96threading mode and sqlite3_config() will
97return SQLITE_ERROR if called with the SQLITE_CONFIG_MULTITHREAD
98configuration option.
99.It SQLITE_CONFIG_SERIALIZED
100There are no arguments to this option.
101This option sets the threading mode to Serialized.
102In other words, this option enables all mutexes including the recursive
103mutexes on database connection and prepared statement
104objects.
105In this mode (which is the default when SQLite is compiled with SQLITE_THREADSAFE=1)
106the SQLite library will itself serialize access to database connections
107and prepared statements so that the application
108is free to use the same database connection or the
109same prepared statement in different threads at the
110same time.
111If SQLite is compiled with the  SQLITE_THREADSAFE=0
112compile-time option then it is not possible to set the Serialized threading mode
113and sqlite3_config() will return SQLITE_ERROR
114if called with the SQLITE_CONFIG_SERIALIZED configuration option.
115.It SQLITE_CONFIG_MALLOC
116The SQLITE_CONFIG_MALLOC option takes a single argument which is a
117pointer to an instance of the sqlite3_mem_methods
118structure.
119The argument specifies alternative low-level memory allocation routines
120to be used in place of the memory allocation routines built into SQLite.
121SQLite makes its own private copy of the content of the sqlite3_mem_methods
122structure before the sqlite3_config() call returns.
123.It SQLITE_CONFIG_GETMALLOC
124The SQLITE_CONFIG_GETMALLOC option takes a single argument which is
125a pointer to an instance of the sqlite3_mem_methods
126structure.
127The sqlite3_mem_methods structure is filled with
128the currently defined memory allocation routines.
129This option can be used to overload the default memory allocation routines
130with a wrapper that simulations memory allocation failure or tracks
131memory usage, for example.
132.It SQLITE_CONFIG_SMALL_MALLOC
133The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of type
134int, interpreted as a boolean, which if true provides a hint to SQLite
135that it should avoid large memory allocations if possible.
136SQLite will run faster if it is free to make large memory allocations,
137but some application might prefer to run slower in exchange for guarantees
138about memory fragmentation that are possible if large allocations are
139avoided.
140This hint is normally off.
141.It SQLITE_CONFIG_MEMSTATUS
142The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
143interpreted as a boolean, which enables or disables the collection
144of memory allocation statistics.
145When memory allocation statistics are disabled, the following SQLite
146interfaces become non-operational:
147.Bl -bullet
148.It
149sqlite3_memory_used()
150.It
151sqlite3_memory_highwater()
152.It
153sqlite3_soft_heap_limit64()
154.It
155sqlite3_status64()
156.El
157.Pp
158Memory allocation statistics are enabled by default unless SQLite is
159compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
160which case memory allocation statistics are disabled by default.
161.It SQLITE_CONFIG_SCRATCH
162The SQLITE_CONFIG_SCRATCH option is no longer used.
163.It SQLITE_CONFIG_PAGECACHE
164The SQLITE_CONFIG_PAGECACHE option specifies a memory pool that SQLite
165can use for the database page cache with the default page cache implementation.
166This configuration option is a no-op if an application-define page
167cache implementation is loaded using the SQLITE_CONFIG_PCACHE2.
168There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1698-byte aligned memory (pMem), the size of each page cache line (sz),
170and the number of cache lines (N).
171The sz argument should be the size of the largest database page (a
172power of two between 512 and 65536) plus some extra bytes for each
173page header.
174The number of extra bytes needed by the page header can be determined
175using SQLITE_CONFIG_PCACHE_HDRSZ.
176It is harmless, apart from the wasted memory, for the sz parameter
177to be larger than necessary.
178The pMem argument must be either a NULL pointer or a pointer to an
1798-byte aligned block of memory of at least sz*N bytes, otherwise subsequent
180behavior is undefined.
181When pMem is not NULL, SQLite will strive to use the memory provided
182to satisfy page cache needs, falling back to sqlite3_malloc()
183if a page cache line is larger than sz bytes or if all of the pMem
184buffer is exhausted.
185If pMem is NULL and N is non-zero, then each database connection does
186an initial bulk allocation for page cache memory from sqlite3_malloc()
187sufficient for N cache lines if N is positive or of -1024*N bytes if
188N is negative, .
189If additional page cache memory is needed beyond what is provided by
190the initial allocation, then SQLite goes to sqlite3_malloc()
191separately for each additional cache line.
192.It SQLITE_CONFIG_HEAP
193The SQLITE_CONFIG_HEAP option specifies a static memory buffer that
194SQLite will use for all of its dynamic memory allocation needs beyond
195those provided for by SQLITE_CONFIG_PAGECACHE.
196The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
197with either SQLITE_ENABLE_MEMSYS3 or SQLITE_ENABLE_MEMSYS5
198and returns SQLITE_ERROR if invoked otherwise.
199There are three arguments to SQLITE_CONFIG_HEAP: An 8-byte aligned
200pointer to the memory, the number of bytes in the memory buffer, and
201the minimum allocation size.
202If the first pointer (the memory pointer) is NULL, then SQLite reverts
203to using its default memory allocator (the system malloc() implementation),
204undoing any prior invocation of SQLITE_CONFIG_MALLOC.
205If the memory pointer is not NULL then the alternative memory allocator
206is engaged to handle all of SQLites memory allocation needs.
207The first pointer (the memory pointer) must be aligned to an 8-byte
208boundary or subsequent behavior of SQLite will be undefined.
209The minimum allocation size is capped at 2**12.
210Reasonable values for the minimum allocation size are 2**5 through
2112**8.
212.It SQLITE_CONFIG_MUTEX
213The SQLITE_CONFIG_MUTEX option takes a single argument which is a pointer
214to an instance of the sqlite3_mutex_methods structure.
215The argument specifies alternative low-level mutex routines to be used
216in place the mutex routines built into SQLite.
217SQLite makes a copy of the content of the sqlite3_mutex_methods
218structure before the call to sqlite3_config() returns.
219If SQLite is compiled with the  SQLITE_THREADSAFE=0
220compile-time option then the entire mutexing subsystem is omitted from
221the build and hence calls to sqlite3_config() with
222the SQLITE_CONFIG_MUTEX configuration option will return SQLITE_ERROR.
223.It SQLITE_CONFIG_GETMUTEX
224The SQLITE_CONFIG_GETMUTEX option takes a single argument which is
225a pointer to an instance of the sqlite3_mutex_methods
226structure.
227The sqlite3_mutex_methods structure is filled
228with the currently defined mutex routines.
229This option can be used to overload the default mutex allocation routines
230with a wrapper used to track mutex usage for performance profiling
231or testing, for example.
232If SQLite is compiled with the  SQLITE_THREADSAFE=0
233compile-time option then the entire mutexing subsystem is omitted from
234the build and hence calls to sqlite3_config() with
235the SQLITE_CONFIG_GETMUTEX configuration option will return SQLITE_ERROR.
236.It SQLITE_CONFIG_LOOKASIDE
237The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
238the default size of lookaside memory on each database connection.
239The first argument is the size of each lookaside buffer slot and the
240second is the number of slots allocated to each database connection.
241SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
242The SQLITE_DBCONFIG_LOOKASIDE option to sqlite3_db_config()
243can be used to change the lookaside configuration on individual connections.
244.It SQLITE_CONFIG_PCACHE2
245The SQLITE_CONFIG_PCACHE2 option takes a single argument which is a
246pointer to an sqlite3_pcache_methods2 object.
247This object specifies the interface to a custom page cache implementation.
248SQLite makes a copy of the sqlite3_pcache_methods2
249object.
250.It SQLITE_CONFIG_GETPCACHE2
251The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which is
252a pointer to an sqlite3_pcache_methods2 object.
253SQLite copies of the current page cache implementation into that object.
254.It SQLITE_CONFIG_LOG
255The SQLITE_CONFIG_LOG option is used to configure the SQLite global
256error log.
257( The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
258function with a call signature of void(*)(void*,int,const char*), and
259a pointer to void.
260If the function pointer is not NULL, it is invoked by sqlite3_log()
261to process each logging event.
262If the function pointer is NULL, the sqlite3_log() interface
263becomes a no-op.
264The void pointer that is the second argument to SQLITE_CONFIG_LOG is
265passed through as the first parameter to the application-defined logger
266function whenever that function is invoked.
267The second parameter to the logger function is a copy of the first
268parameter to the corresponding sqlite3_log() call and
269is intended to be a result code or an extended result code.
270The third parameter passed to the logger is log message after formatting
271via sqlite3_snprintf().
272The SQLite logging interface is not reentrant; the logger function
273supplied by the application must not invoke any SQLite interface.
274In a multi-threaded application, the application-defined logger function
275must be threadsafe.
276.It SQLITE_CONFIG_URI The SQLITE_CONFIG_URI option takes a single argument
277of type int.
278If non-zero, then URI handling is globally enabled.
279If the parameter is zero, then URI handling is globally disabled.
280If URI handling is globally enabled, all filenames passed to sqlite3_open(),
281sqlite3_open_v2(), sqlite3_open16()
282or specified as part of ATTACH commands are interpreted as URIs,
283regardless of whether or not the SQLITE_OPEN_URI flag
284is set when the database connection is opened.
285If it is globally disabled, filenames are only interpreted as URIs
286if the SQLITE_OPEN_URI flag is set when the database connection is
287opened.
288By default, URI handling is globally disabled.
289The default value may be changed by compiling with the SQLITE_USE_URI
290symbol defined.
291.It SQLITE_CONFIG_COVERING_INDEX_SCAN The SQLITE_CONFIG_COVERING_INDEX_SCAN
292option takes a single integer argument which is interpreted as a boolean
293in order to enable or disable the use of covering indices for full
294table scans in the query optimizer.
295The default setting is determined by the SQLITE_ALLOW_COVERING_INDEX_SCAN
296compile-time option, or is "on" if that compile-time option is omitted.
297The ability to disable the use of covering indices for full table scans
298is because some incorrectly coded legacy applications might malfunction
299when the optimization is enabled.
300Providing the ability to disable the optimization allows the older,
301buggy application code to work without change even with newer versions
302of SQLite.
303.It SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE These options are
304obsolete and should not be used by new code.
305They are retained for backwards compatibility but are now no-ops.
306.It SQLITE_CONFIG_SQLLOG This option is only available if sqlite is compiled
307with the SQLITE_ENABLE_SQLLOG pre-processor macro
308defined.
309The first argument should be a pointer to a function of type void(*)(void*,sqlite3*,const
310char*, int).
311The second should be of type (void*).
312The callback is invoked by the library in three separate circumstances,
313identified by the value passed as the fourth parameter.
314If the fourth parameter is 0, then the database connection passed as
315the second argument has just been opened.
316The third argument points to a buffer containing the name of the main
317database file.
318If the fourth parameter is 1, then the SQL statement that the third
319parameter points to has just been executed.
320Or, if the fourth parameter is 2, then the connection being passed
321as the second parameter is being closed.
322The third parameter is passed NULL In this case.
323An example of using this configuration option can be seen in the "test_sqllog.c"
324source file in the canonical SQLite source tree.
325.It SQLITE_CONFIG_MMAP_SIZE SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer
326(sqlite3_int64) values that are the default mmap size limit (the default
327setting for PRAGMA mmap_size) and the maximum allowed
328mmap size limit.
329The default setting can be overridden by each database connection using
330either the PRAGMA mmap_size command, or by using the
331SQLITE_FCNTL_MMAP_SIZE file control.
332The maximum allowed mmap size will be silently truncated if necessary
333so that it does not exceed the compile-time maximum mmap size set by
334the SQLITE_MAX_MMAP_SIZE compile-time option.
335If either argument to this option is negative, then that argument is
336changed to its compile-time default.
337.It SQLITE_CONFIG_WIN32_HEAPSIZE The SQLITE_CONFIG_WIN32_HEAPSIZE option
338is only available if SQLite is compiled for Windows with the SQLITE_WIN32_MALLOC
339pre-processor macro defined.
340SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
341that specifies the maximum size of the created heap.
342.It SQLITE_CONFIG_PCACHE_HDRSZ The SQLITE_CONFIG_PCACHE_HDRSZ option takes
343a single parameter which is a pointer to an integer and writes into
344that integer the number of extra bytes per page required for each page
345in SQLITE_CONFIG_PAGECACHE.
346The amount of extra space required can change depending on the compiler,
347target platform, and SQLite version.
348.It SQLITE_CONFIG_PMASZ The SQLITE_CONFIG_PMASZ option takes a single
349parameter which is an unsigned integer and sets the "Minimum PMA Size"
350for the multithreaded sorter to that integer.
351The default minimum PMA Size is set by the SQLITE_SORTER_PMASZ
352compile-time option.
353New threads are launched to help with sort operations when multithreaded
354sorting is enabled (using the PRAGMA threads command)
355and the amount of content to be sorted exceeds the page size times
356the minimum of the PRAGMA cache_size setting and this
357value.
358.It SQLITE_CONFIG_STMTJRNL_SPILL The SQLITE_CONFIG_STMTJRNL_SPILL option
359takes a single parameter which becomes the statement journal
360spill-to-disk threshold.
361Statement journals are held in memory until their
362size (in bytes) exceeds this threshold, at which point they are written
363to disk.
364Or if the threshold is -1, statement journals are always held exclusively
365in memory.
366Since many statement journals never become large, setting the spill
367threshold to a value such as 64KiB can greatly reduce the amount of
368I/O required to support statement rollback.
369The default value for this setting is controlled by the SQLITE_STMTJRNL_SPILL
370compile-time option.
371.It SQLITE_CONFIG_SORTERREF_SIZE The SQLITE_CONFIG_SORTERREF_SIZE option
372accepts a single parameter of type (int) - the new value of the sorter-reference
373size threshold.
374Usually, when SQLite uses an external sort to order records according
375to an ORDER BY clause, all fields required by the caller are present
376in the sorted records.
377However, if SQLite determines based on the declared type of a table
378column that its values are likely to be very large - larger than the
379configured sorter-reference size threshold - then a reference is stored
380in each sorted record and the required column values loaded from the
381database as records are returned in sorted order.
382The default value for this option is to never use this optimization.
383Specifying a negative value for this option restores the default behaviour.
384This option is only available if SQLite is compiled with the SQLITE_ENABLE_SORTER_REFERENCES
385compile-time option.
386.El
387.Pp
388.Sh SEE ALSO
389.Xr sqlite3 3 ,
390.Xr sqlite3_stmt 3 ,
391.Xr sqlite3_config 3 ,
392.Xr sqlite3_db_config 3 ,
393.Xr sqlite3_log 3 ,
394.Xr sqlite3_malloc 3 ,
395.Xr sqlite3_mem_methods 3 ,
396.Xr sqlite3_memory_used 3 ,
397.Xr sqlite3_mutex_methods 3 ,
398.Xr sqlite3_open 3 ,
399.Xr sqlite3_pcache_methods2 3 ,
400.Xr sqlite3_mprintf 3 ,
401.Xr sqlite3_soft_heap_limit64 3 ,
402.Xr sqlite3_status 3 ,
403.Xr SQLITE_CONFIG_SINGLETHREAD 3 ,
404.Xr SQLITE_DBCONFIG_MAINDBNAME 3 ,
405.Xr SQLITE_OK 3 ,
406.Xr SQLITE_FCNTL_LOCKSTATE 3 ,
407.Xr SQLITE_OPEN_READONLY 3
408