xref: /sqlite-3.40.0/src/sqliteLimit.h (revision 6c3b4b07)
1c551dd80Sdrh /*
2c551dd80Sdrh ** 2007 May 7
3c551dd80Sdrh **
4c551dd80Sdrh ** The author disclaims copyright to this source code.  In place of
5c551dd80Sdrh ** a legal notice, here is a blessing:
6c551dd80Sdrh **
7c551dd80Sdrh **    May you do good and not evil.
8c551dd80Sdrh **    May you find forgiveness for yourself and forgive others.
9c551dd80Sdrh **    May you share freely, never taking more than you give.
10c551dd80Sdrh **
11c551dd80Sdrh *************************************************************************
12c551dd80Sdrh **
13c551dd80Sdrh ** This file defines various limits of what SQLite can process.
14c551dd80Sdrh */
15c551dd80Sdrh 
16c551dd80Sdrh /*
17c551dd80Sdrh ** The maximum length of a TEXT or BLOB in bytes.   This also
18c551dd80Sdrh ** limits the size of a row in a table or index.
19c551dd80Sdrh **
20c551dd80Sdrh ** The hard limit is the ability of a 32-bit signed integer
21c551dd80Sdrh ** to count the size: 2^31-1 or 2147483647.
22c551dd80Sdrh */
23c551dd80Sdrh #ifndef SQLITE_MAX_LENGTH
24c551dd80Sdrh # define SQLITE_MAX_LENGTH 1000000000
25c551dd80Sdrh #endif
26c551dd80Sdrh 
27c551dd80Sdrh /*
28c551dd80Sdrh ** This is the maximum number of
29c551dd80Sdrh **
30c551dd80Sdrh **    * Columns in a table
31c551dd80Sdrh **    * Columns in an index
32c551dd80Sdrh **    * Columns in a view
33c551dd80Sdrh **    * Terms in the SET clause of an UPDATE statement
34c551dd80Sdrh **    * Terms in the result set of a SELECT statement
35c551dd80Sdrh **    * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
36c551dd80Sdrh **    * Terms in the VALUES clause of an INSERT statement
37c551dd80Sdrh **
38c551dd80Sdrh ** The hard upper limit here is 32676.  Most database people will
39c551dd80Sdrh ** tell you that in a well-normalized database, you usually should
40c551dd80Sdrh ** not have more than a dozen or so columns in any table.  And if
41c551dd80Sdrh ** that is the case, there is no point in having more than a few
42c551dd80Sdrh ** dozen values in any of the other situations described above.
43c551dd80Sdrh */
44c551dd80Sdrh #ifndef SQLITE_MAX_COLUMN
45c551dd80Sdrh # define SQLITE_MAX_COLUMN 2000
46c551dd80Sdrh #endif
47c551dd80Sdrh 
48c551dd80Sdrh /*
49c551dd80Sdrh ** The maximum length of a single SQL statement in bytes.
50bb4957f8Sdrh **
51bb4957f8Sdrh ** It used to be the case that setting this value to zero would
52bb4957f8Sdrh ** turn the limit off.  That is no longer true.  It is not possible
53bb4957f8Sdrh ** to turn this limit off.
54c551dd80Sdrh */
55c551dd80Sdrh #ifndef SQLITE_MAX_SQL_LENGTH
56bb4957f8Sdrh # define SQLITE_MAX_SQL_LENGTH 1000000000
57c551dd80Sdrh #endif
58c551dd80Sdrh 
59c551dd80Sdrh /*
60c551dd80Sdrh ** The maximum depth of an expression tree. This is limited to
61c551dd80Sdrh ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
62c551dd80Sdrh ** want to place more severe limits on the complexity of an
63*6c3b4b07Sdan ** expression. A value of 0 means that there is no limit.
64c551dd80Sdrh */
65c551dd80Sdrh #ifndef SQLITE_MAX_EXPR_DEPTH
66c551dd80Sdrh # define SQLITE_MAX_EXPR_DEPTH 1000
67c551dd80Sdrh #endif
68c551dd80Sdrh 
69c551dd80Sdrh /*
70c551dd80Sdrh ** The maximum number of terms in a compound SELECT statement.
71c551dd80Sdrh ** The code generator for compound SELECT statements does one
72c551dd80Sdrh ** level of recursion for each term.  A stack overflow can result
73c551dd80Sdrh ** if the number of terms is too large.  In practice, most SQL
74c551dd80Sdrh ** never has more than 3 or 4 terms.  Use a value of 0 to disable
75c551dd80Sdrh ** any limit on the number of terms in a compount SELECT.
76c551dd80Sdrh */
77c551dd80Sdrh #ifndef SQLITE_MAX_COMPOUND_SELECT
78c551dd80Sdrh # define SQLITE_MAX_COMPOUND_SELECT 500
79c551dd80Sdrh #endif
80c551dd80Sdrh 
81c551dd80Sdrh /*
82c551dd80Sdrh ** The maximum number of opcodes in a VDBE program.
83c551dd80Sdrh ** Not currently enforced.
84c551dd80Sdrh */
85c551dd80Sdrh #ifndef SQLITE_MAX_VDBE_OP
861cb0266dSdrh # define SQLITE_MAX_VDBE_OP 250000000
87c551dd80Sdrh #endif
88c551dd80Sdrh 
89c551dd80Sdrh /*
90c551dd80Sdrh ** The maximum number of arguments to an SQL function.
91c551dd80Sdrh */
92c551dd80Sdrh #ifndef SQLITE_MAX_FUNCTION_ARG
93a7c17af6Sdanielk1977 # define SQLITE_MAX_FUNCTION_ARG 127
94c551dd80Sdrh #endif
95c551dd80Sdrh 
96c551dd80Sdrh /*
979d356fbeSdrh ** The suggested maximum number of in-memory pages to use for
989d356fbeSdrh ** the main database table and for temporary tables.
999d356fbeSdrh **
10037670261Sdrh ** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000,
10137670261Sdrh ** which means the cache size is limited to 2048000 bytes of memory.
102e0e84295Sdrh ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
103e0e84295Sdrh ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
104c551dd80Sdrh */
105c551dd80Sdrh #ifndef SQLITE_DEFAULT_CACHE_SIZE
10694580868Sdrh # define SQLITE_DEFAULT_CACHE_SIZE  -2000
107c551dd80Sdrh #endif
108c551dd80Sdrh 
109c551dd80Sdrh /*
1105a299f91Sdan ** The default number of frames to accumulate in the log file before
1115a299f91Sdan ** checkpointing the database in WAL mode.
1125a299f91Sdan */
1135a299f91Sdan #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
1145a299f91Sdan # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT  1000
1155a299f91Sdan #endif
1165a299f91Sdan 
1175a299f91Sdan /*
118083e5819Sdrh ** The maximum number of attached databases.  This must be between 0
1199878fefdSdrh ** and 125.  The upper bound of 125 is because the attached databases are
1209878fefdSdrh ** counted using a signed 8-bit integer which has a maximum value of 127
1219878fefdSdrh ** and we have to allow 2 extra counts for the "main" and "temp" databases.
122c551dd80Sdrh */
123c551dd80Sdrh #ifndef SQLITE_MAX_ATTACHED
124c551dd80Sdrh # define SQLITE_MAX_ATTACHED 10
125c551dd80Sdrh #endif
126c551dd80Sdrh 
127c551dd80Sdrh 
128c551dd80Sdrh /*
129c551dd80Sdrh ** The maximum value of a ?nnn wildcard that the parser will accept.
130efdba1a8Sdrh ** If the value exceeds 32767 then extra space is required for the Expr
131efdba1a8Sdrh ** structure.  But otherwise, we believe that the number can be as large
132efdba1a8Sdrh ** as a signed 32-bit integer can hold.
133c551dd80Sdrh */
134c551dd80Sdrh #ifndef SQLITE_MAX_VARIABLE_NUMBER
135efdba1a8Sdrh # define SQLITE_MAX_VARIABLE_NUMBER 32766
136c551dd80Sdrh #endif
137c551dd80Sdrh 
138b2eced5dSdrh /* Maximum page size.  The upper bound on this value is 65536.  This a limit
139b2eced5dSdrh ** imposed by the use of 16-bit offsets within each page.
1407cbd589dSdanielk1977 **
1415a9e07ebSdan ** Earlier versions of SQLite allowed the user to change this value at
1425a9e07ebSdan ** compile time. This is no longer permitted, on the grounds that it creates
1435a9e07ebSdan ** a library that is technically incompatible with an SQLite library
1445a9e07ebSdan ** compiled with a different limit. If a process operating on a database
1455a9e07ebSdan ** with a page-size of 65536 bytes crashes, then an instance of SQLite
1465a9e07ebSdan ** compiled with the default page-size limit will not be able to rollback
1475a9e07ebSdan ** the aborted transaction. This could lead to database corruption.
148f54cc035Sdrh */
1495a9e07ebSdan #ifdef SQLITE_MAX_PAGE_SIZE
1505a9e07ebSdan # undef SQLITE_MAX_PAGE_SIZE
151f54cc035Sdrh #endif
1525a9e07ebSdan #define SQLITE_MAX_PAGE_SIZE 65536
153f54cc035Sdrh 
154f54cc035Sdrh 
155c551dd80Sdrh /*
156c551dd80Sdrh ** The default size of a database page.
157c551dd80Sdrh */
158c551dd80Sdrh #ifndef SQLITE_DEFAULT_PAGE_SIZE
1599878fefdSdrh # define SQLITE_DEFAULT_PAGE_SIZE 4096
160c551dd80Sdrh #endif
161f54cc035Sdrh #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
162f54cc035Sdrh # undef SQLITE_DEFAULT_PAGE_SIZE
163f54cc035Sdrh # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
164f54cc035Sdrh #endif
165c551dd80Sdrh 
1669663b8f9Sdanielk1977 /*
1679663b8f9Sdanielk1977 ** Ordinarily, if no value is explicitly provided, SQLite creates databases
1689663b8f9Sdanielk1977 ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
1699663b8f9Sdanielk1977 ** device characteristics (sector-size and atomic write() support),
1709663b8f9Sdanielk1977 ** SQLite may choose a larger value. This constant is the maximum value
17185b623f2Sdrh ** SQLite will choose on its own.
1729663b8f9Sdanielk1977 */
1739663b8f9Sdanielk1977 #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE
1749663b8f9Sdanielk1977 # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192
1759663b8f9Sdanielk1977 #endif
176f54cc035Sdrh #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
177f54cc035Sdrh # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
178f54cc035Sdrh # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
179c551dd80Sdrh #endif
180c551dd80Sdrh 
181f54cc035Sdrh 
182c551dd80Sdrh /*
183c551dd80Sdrh ** Maximum number of pages in one database file.
184c551dd80Sdrh **
185c551dd80Sdrh ** This is really just the default value for the max_page_count pragma.
186c551dd80Sdrh ** This value can be lowered (or raised) at run-time using that the
187c551dd80Sdrh ** max_page_count macro.
188c551dd80Sdrh */
189c551dd80Sdrh #ifndef SQLITE_MAX_PAGE_COUNT
190c551dd80Sdrh # define SQLITE_MAX_PAGE_COUNT 1073741823
191c551dd80Sdrh #endif
192c551dd80Sdrh 
193c551dd80Sdrh /*
194c551dd80Sdrh ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
195c551dd80Sdrh ** operator.
196c551dd80Sdrh */
197c551dd80Sdrh #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
198c551dd80Sdrh # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
199c551dd80Sdrh #endif
200417168adSdrh 
201417168adSdrh /*
202417168adSdrh ** Maximum depth of recursion for triggers.
203f589450dSdan **
204f589450dSdan ** A value of 1 means that a trigger program will not be able to itself
205f589450dSdan ** fire any triggers. A value of 0 means that no trigger programs at all
206f589450dSdan ** may be executed.
207417168adSdrh */
208417168adSdrh #ifndef SQLITE_MAX_TRIGGER_DEPTH
209417168adSdrh # define SQLITE_MAX_TRIGGER_DEPTH 1000
210417168adSdrh #endif
211