drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 1 | /* |
| 2 | ** 2007 May 7 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
larrybr | bc91738 | 2023-06-07 08:40:31 | [diff] [blame] | 12 | ** |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 13 | ** This file defines various limits of what SQLite can process. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | ** The maximum length of a TEXT or BLOB in bytes. This also |
| 18 | ** limits the size of a row in a table or index. |
| 19 | ** |
| 20 | ** The hard limit is the ability of a 32-bit signed integer |
| 21 | ** to count the size: 2^31-1 or 2147483647. |
| 22 | */ |
| 23 | #ifndef SQLITE_MAX_LENGTH |
| 24 | # define SQLITE_MAX_LENGTH 1000000000 |
| 25 | #endif |
drh | 4ddeccf | 2024-11-08 20:57:45 | [diff] [blame] | 26 | #define SQLITE_MIN_LENGTH 30 /* Minimum value for the length limit */ |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | ** This is the maximum number of |
| 30 | ** |
| 31 | ** * Columns in a table |
| 32 | ** * Columns in an index |
| 33 | ** * Columns in a view |
| 34 | ** * Terms in the SET clause of an UPDATE statement |
| 35 | ** * Terms in the result set of a SELECT statement |
| 36 | ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. |
| 37 | ** * Terms in the VALUES clause of an INSERT statement |
| 38 | ** |
drh | ce25007 | 2025-02-21 17:03:22 | [diff] [blame] | 39 | ** The hard upper limit here is 32767. Most database people will |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 40 | ** tell you that in a well-normalized database, you usually should |
| 41 | ** not have more than a dozen or so columns in any table. And if |
| 42 | ** that is the case, there is no point in having more than a few |
| 43 | ** dozen values in any of the other situations described above. |
drh | cc803b2 | 2025-02-21 20:35:37 | [diff] [blame] | 44 | ** |
| 45 | ** An index can only have SQLITE_MAX_COLUMN columns from the user |
| 46 | ** point of view, but the underlying b-tree that implements the index |
| 47 | ** might have up to twice as many columns in a WITHOUT ROWID table, |
| 48 | ** since must also store the primary key at the end. Hence the |
| 49 | ** column count for Index is u16 instead of i16. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 50 | */ |
drh | ce25007 | 2025-02-21 17:03:22 | [diff] [blame] | 51 | #if !defined(SQLITE_MAX_COLUMN) |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 52 | # define SQLITE_MAX_COLUMN 2000 |
drh | ce25007 | 2025-02-21 17:03:22 | [diff] [blame] | 53 | #elif SQLITE_MAX_COLUMN>32767 |
| 54 | # error SQLITE_MAX_COLUMN may not exceed 32767 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 55 | #endif |
| 56 | |
| 57 | /* |
| 58 | ** The maximum length of a single SQL statement in bytes. |
drh | bb4957f | 2008-03-20 14:03:29 | [diff] [blame] | 59 | ** |
| 60 | ** It used to be the case that setting this value to zero would |
| 61 | ** turn the limit off. That is no longer true. It is not possible |
| 62 | ** to turn this limit off. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 63 | */ |
| 64 | #ifndef SQLITE_MAX_SQL_LENGTH |
drh | bb4957f | 2008-03-20 14:03:29 | [diff] [blame] | 65 | # define SQLITE_MAX_SQL_LENGTH 1000000000 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | /* |
larrybr | bc91738 | 2023-06-07 08:40:31 | [diff] [blame] | 69 | ** The maximum depth of an expression tree. This is limited to |
| 70 | ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might |
| 71 | ** want to place more severe limits on the complexity of an |
dan | 6c3b4b0 | 2020-08-20 16:25:26 | [diff] [blame] | 72 | ** expression. A value of 0 means that there is no limit. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 73 | */ |
| 74 | #ifndef SQLITE_MAX_EXPR_DEPTH |
| 75 | # define SQLITE_MAX_EXPR_DEPTH 1000 |
| 76 | #endif |
| 77 | |
| 78 | /* |
| 79 | ** The maximum number of terms in a compound SELECT statement. |
| 80 | ** The code generator for compound SELECT statements does one |
| 81 | ** level of recursion for each term. A stack overflow can result |
| 82 | ** if the number of terms is too large. In practice, most SQL |
| 83 | ** never has more than 3 or 4 terms. Use a value of 0 to disable |
larrybr | bc91738 | 2023-06-07 08:40:31 | [diff] [blame] | 84 | ** any limit on the number of terms in a compound SELECT. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 85 | */ |
| 86 | #ifndef SQLITE_MAX_COMPOUND_SELECT |
| 87 | # define SQLITE_MAX_COMPOUND_SELECT 500 |
| 88 | #endif |
| 89 | |
| 90 | /* |
| 91 | ** The maximum number of opcodes in a VDBE program. |
| 92 | ** Not currently enforced. |
| 93 | */ |
| 94 | #ifndef SQLITE_MAX_VDBE_OP |
drh | 1cb0266 | 2017-03-17 22:50:16 | [diff] [blame] | 95 | # define SQLITE_MAX_VDBE_OP 250000000 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 96 | #endif |
| 97 | |
| 98 | /* |
| 99 | ** The maximum number of arguments to an SQL function. |
drh | 35d302c | 2024-12-12 15:11:27 | [diff] [blame] | 100 | ** |
| 101 | ** This value has a hard upper limit of 32767 due to storage |
| 102 | ** constraints (it needs to fit inside a i16). We keep it |
| 103 | ** lower than that to prevent abuse. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 104 | */ |
| 105 | #ifndef SQLITE_MAX_FUNCTION_ARG |
drh | 35d302c | 2024-12-12 15:11:27 | [diff] [blame] | 106 | # define SQLITE_MAX_FUNCTION_ARG 1000 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 107 | #endif |
| 108 | |
| 109 | /* |
drh | 9d356fb | 2015-02-27 20:28:08 | [diff] [blame] | 110 | ** The suggested maximum number of in-memory pages to use for |
| 111 | ** the main database table and for temporary tables. |
| 112 | ** |
drh | 3767026 | 2016-03-23 13:46:05 | [diff] [blame] | 113 | ** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000, |
| 114 | ** which means the cache size is limited to 2048000 bytes of memory. |
drh | e0e8429 | 2015-02-27 21:53:35 | [diff] [blame] | 115 | ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be |
| 116 | ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 117 | */ |
| 118 | #ifndef SQLITE_DEFAULT_CACHE_SIZE |
drh | 9458086 | 2016-03-04 04:01:43 | [diff] [blame] | 119 | # define SQLITE_DEFAULT_CACHE_SIZE -2000 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 120 | #endif |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 121 | |
| 122 | /* |
dan | 5a299f9 | 2010-05-03 11:05:08 | [diff] [blame] | 123 | ** The default number of frames to accumulate in the log file before |
| 124 | ** checkpointing the database in WAL mode. |
| 125 | */ |
| 126 | #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 127 | # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 |
| 128 | #endif |
| 129 | |
| 130 | /* |
drh | 083e581 | 2008-03-26 15:56:22 | [diff] [blame] | 131 | ** The maximum number of attached databases. This must be between 0 |
drh | 9878fef | 2016-03-04 03:43:10 | [diff] [blame] | 132 | ** and 125. The upper bound of 125 is because the attached databases are |
| 133 | ** counted using a signed 8-bit integer which has a maximum value of 127 |
| 134 | ** and we have to allow 2 extra counts for the "main" and "temp" databases. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 135 | */ |
| 136 | #ifndef SQLITE_MAX_ATTACHED |
| 137 | # define SQLITE_MAX_ATTACHED 10 |
| 138 | #endif |
| 139 | |
| 140 | |
| 141 | /* |
| 142 | ** The maximum value of a ?nnn wildcard that the parser will accept. |
drh | efdba1a | 2020-02-12 20:50:20 | [diff] [blame] | 143 | ** If the value exceeds 32767 then extra space is required for the Expr |
| 144 | ** structure. But otherwise, we believe that the number can be as large |
| 145 | ** as a signed 32-bit integer can hold. |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 146 | */ |
| 147 | #ifndef SQLITE_MAX_VARIABLE_NUMBER |
drh | efdba1a | 2020-02-12 20:50:20 | [diff] [blame] | 148 | # define SQLITE_MAX_VARIABLE_NUMBER 32766 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 149 | #endif |
| 150 | |
drh | b2eced5 | 2010-08-12 02:41:12 | [diff] [blame] | 151 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 152 | ** imposed by the use of 16-bit offsets within each page. |
danielk1977 | 7cbd589 | 2009-01-10 16:15:09 | [diff] [blame] | 153 | ** |
dan | 5a9e07e | 2010-08-18 15:25:17 | [diff] [blame] | 154 | ** Earlier versions of SQLite allowed the user to change this value at |
| 155 | ** compile time. This is no longer permitted, on the grounds that it creates |
larrybr | bc91738 | 2023-06-07 08:40:31 | [diff] [blame] | 156 | ** a library that is technically incompatible with an SQLite library |
| 157 | ** compiled with a different limit. If a process operating on a database |
| 158 | ** with a page-size of 65536 bytes crashes, then an instance of SQLite |
| 159 | ** compiled with the default page-size limit will not be able to rollback |
dan | 5a9e07e | 2010-08-18 15:25:17 | [diff] [blame] | 160 | ** the aborted transaction. This could lead to database corruption. |
drh | f54cc03 | 2007-11-05 14:30:22 | [diff] [blame] | 161 | */ |
dan | 5a9e07e | 2010-08-18 15:25:17 | [diff] [blame] | 162 | #ifdef SQLITE_MAX_PAGE_SIZE |
| 163 | # undef SQLITE_MAX_PAGE_SIZE |
drh | f54cc03 | 2007-11-05 14:30:22 | [diff] [blame] | 164 | #endif |
dan | 5a9e07e | 2010-08-18 15:25:17 | [diff] [blame] | 165 | #define SQLITE_MAX_PAGE_SIZE 65536 |
drh | f54cc03 | 2007-11-05 14:30:22 | [diff] [blame] | 166 | |
| 167 | |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 168 | /* |
| 169 | ** The default size of a database page. |
| 170 | */ |
| 171 | #ifndef SQLITE_DEFAULT_PAGE_SIZE |
drh | 9878fef | 2016-03-04 03:43:10 | [diff] [blame] | 172 | # define SQLITE_DEFAULT_PAGE_SIZE 4096 |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 173 | #endif |
drh | f54cc03 | 2007-11-05 14:30:22 | [diff] [blame] | 174 | #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 175 | # undef SQLITE_DEFAULT_PAGE_SIZE |
| 176 | # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 177 | #endif |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 178 | |
danielk1977 | 9663b8f | 2007-08-24 11:52:28 | [diff] [blame] | 179 | /* |
| 180 | ** Ordinarily, if no value is explicitly provided, SQLite creates databases |
| 181 | ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain |
| 182 | ** device characteristics (sector-size and atomic write() support), |
| 183 | ** SQLite may choose a larger value. This constant is the maximum value |
drh | 85b623f | 2007-12-13 21:54:09 | [diff] [blame] | 184 | ** SQLite will choose on its own. |
danielk1977 | 9663b8f | 2007-08-24 11:52:28 | [diff] [blame] | 185 | */ |
| 186 | #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 187 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 |
| 188 | #endif |
drh | f54cc03 | 2007-11-05 14:30:22 | [diff] [blame] | 189 | #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 190 | # undef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 191 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 192 | #endif |
| 193 | |
drh | f54cc03 | 2007-11-05 14:30:22 | [diff] [blame] | 194 | |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 195 | /* |
| 196 | ** Maximum number of pages in one database file. |
| 197 | ** |
| 198 | ** This is really just the default value for the max_page_count pragma. |
| 199 | ** This value can be lowered (or raised) at run-time using that the |
| 200 | ** max_page_count macro. |
| 201 | */ |
| 202 | #ifndef SQLITE_MAX_PAGE_COUNT |
drh | 433e904 | 2024-01-03 15:49:04 | [diff] [blame] | 203 | # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */ |
drh | c551dd8 | 2007-06-19 15:23:48 | [diff] [blame] | 204 | #endif |
| 205 | |
| 206 | /* |
| 207 | ** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 208 | ** operator. |
| 209 | */ |
| 210 | #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 211 | # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 |
| 212 | #endif |
drh | 417168a | 2009-09-07 18:14:02 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | ** Maximum depth of recursion for triggers. |
dan | f589450 | 2009-10-07 18:41:19 | [diff] [blame] | 216 | ** |
| 217 | ** A value of 1 means that a trigger program will not be able to itself |
larrybr | bc91738 | 2023-06-07 08:40:31 | [diff] [blame] | 218 | ** fire any triggers. A value of 0 means that no trigger programs at all |
dan | f589450 | 2009-10-07 18:41:19 | [diff] [blame] | 219 | ** may be executed. |
drh | 417168a | 2009-09-07 18:14:02 | [diff] [blame] | 220 | */ |
| 221 | #ifndef SQLITE_MAX_TRIGGER_DEPTH |
| 222 | # define SQLITE_MAX_TRIGGER_DEPTH 1000 |
| 223 | #endif |