Fossil SCM

merged in trunk [496edc2176].

stephan 2011-10-11 14:28 UTC json-multitag-test merge
Commit ec76ee16fdb07dfca88d091781d294e90c166567
+3 -3
--- src/allrepo.c
+++ src/allrepo.c
@@ -74,13 +74,13 @@
7474
** rebuild Rebuild on all repositories
7575
**
7676
** sync Run a "sync" on all repositories
7777
**
7878
** Respositories are automatically added to the set of known repositories
79
-** when one of the following commands against the repository: clone, info,
80
-** pull, push, or sync. Even previously ignored repositories are added back
81
-** to the list of repositories by these commands.
79
+** when one of the following commands are run against the repository: clone,
80
+** info, pull, push, or sync. Even previously ignored repositories are
81
+** added back to the list of repositories by these commands.
8282
*/
8383
void all_cmd(void){
8484
int n;
8585
Stmt q;
8686
const char *zCmd;
8787
--- src/allrepo.c
+++ src/allrepo.c
@@ -74,13 +74,13 @@
74 ** rebuild Rebuild on all repositories
75 **
76 ** sync Run a "sync" on all repositories
77 **
78 ** Respositories are automatically added to the set of known repositories
79 ** when one of the following commands against the repository: clone, info,
80 ** pull, push, or sync. Even previously ignored repositories are added back
81 ** to the list of repositories by these commands.
82 */
83 void all_cmd(void){
84 int n;
85 Stmt q;
86 const char *zCmd;
87
--- src/allrepo.c
+++ src/allrepo.c
@@ -74,13 +74,13 @@
74 ** rebuild Rebuild on all repositories
75 **
76 ** sync Run a "sync" on all repositories
77 **
78 ** Respositories are automatically added to the set of known repositories
79 ** when one of the following commands are run against the repository: clone,
80 ** info, pull, push, or sync. Even previously ignored repositories are
81 ** added back to the list of repositories by these commands.
82 */
83 void all_cmd(void){
84 int n;
85 Stmt q;
86 const char *zCmd;
87
+2 -2
--- src/blob.c
+++ src/blob.c
@@ -330,12 +330,12 @@
330330
blob_is_init(pB);
331331
szA = blob_size(pA);
332332
szB = blob_size(pB);
333333
if( szA!=szB || szA==0 ) return 1;
334334
335
- buf1 = blob_buffer(pA);
336
- buf2 = blob_buffer(pB);
335
+ buf1 = (unsigned char*)blob_buffer(pA);
336
+ buf2 = (unsigned char*)blob_buffer(pB);
337337
338338
for( i=0; i<szA; i++ ){
339339
rc = rc | (buf1[i] ^ buf2[i]);
340340
}
341341
342342
--- src/blob.c
+++ src/blob.c
@@ -330,12 +330,12 @@
330 blob_is_init(pB);
331 szA = blob_size(pA);
332 szB = blob_size(pB);
333 if( szA!=szB || szA==0 ) return 1;
334
335 buf1 = blob_buffer(pA);
336 buf2 = blob_buffer(pB);
337
338 for( i=0; i<szA; i++ ){
339 rc = rc | (buf1[i] ^ buf2[i]);
340 }
341
342
--- src/blob.c
+++ src/blob.c
@@ -330,12 +330,12 @@
330 blob_is_init(pB);
331 szA = blob_size(pA);
332 szB = blob_size(pB);
333 if( szA!=szB || szA==0 ) return 1;
334
335 buf1 = (unsigned char*)blob_buffer(pA);
336 buf2 = (unsigned char*)blob_buffer(pB);
337
338 for( i=0; i<szA; i++ ){
339 rc = rc | (buf1[i] ^ buf2[i]);
340 }
341
342
+2 -2
--- src/blob.c
+++ src/blob.c
@@ -330,12 +330,12 @@
330330
blob_is_init(pB);
331331
szA = blob_size(pA);
332332
szB = blob_size(pB);
333333
if( szA!=szB || szA==0 ) return 1;
334334
335
- buf1 = blob_buffer(pA);
336
- buf2 = blob_buffer(pB);
335
+ buf1 = (unsigned char*)blob_buffer(pA);
336
+ buf2 = (unsigned char*)blob_buffer(pB);
337337
338338
for( i=0; i<szA; i++ ){
339339
rc = rc | (buf1[i] ^ buf2[i]);
340340
}
341341
342342
--- src/blob.c
+++ src/blob.c
@@ -330,12 +330,12 @@
330 blob_is_init(pB);
331 szA = blob_size(pA);
332 szB = blob_size(pB);
333 if( szA!=szB || szA==0 ) return 1;
334
335 buf1 = blob_buffer(pA);
336 buf2 = blob_buffer(pB);
337
338 for( i=0; i<szA; i++ ){
339 rc = rc | (buf1[i] ^ buf2[i]);
340 }
341
342
--- src/blob.c
+++ src/blob.c
@@ -330,12 +330,12 @@
330 blob_is_init(pB);
331 szA = blob_size(pA);
332 szB = blob_size(pB);
333 if( szA!=szB || szA==0 ) return 1;
334
335 buf1 = (unsigned char*)blob_buffer(pA);
336 buf2 = (unsigned char*)blob_buffer(pB);
337
338 for( i=0; i<szA; i++ ){
339 rc = rc | (buf1[i] ^ buf2[i]);
340 }
341
342
+49 -23
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -97,10 +97,11 @@
9797
** Call this routine once before any other use of the SSL interface.
9898
** This routine does initial configuration of the SSL module.
9999
*/
100100
void ssl_global_init(void){
101101
const char *zCaSetting = 0, *zCaFile = 0, *zCaDirectory = 0;
102
+ const char *identityFile;
102103
103104
if( sslIsInit==0 ){
104105
SSL_library_init();
105106
SSL_load_error_strings();
106107
ERR_load_BIO_strings();
@@ -135,19 +136,26 @@
135136
fossil_fatal("Failed to use CA root certificates from "
136137
"ssl-ca-location '%s'", zCaSetting);
137138
}
138139
}
139140
140
- /* Load client SSL identity, preferring the filename specified on the command line */
141
- const char *identityFile = ( g.zSSLIdentity!= 0) ? g.zSSLIdentity : db_get("ssl-identity", 0);
141
+ /* Load client SSL identity, preferring the filename specified on the
142
+ ** command line */
143
+ if( g.zSSLIdentity!=0 ){
144
+ identityFile = g.zSSLIdentity;
145
+ }else{
146
+ identityFile = db_get("ssl-identity", 0);
147
+ }
142148
if( identityFile!=0 && identityFile[0]!='\0' ){
143
- if( SSL_CTX_use_certificate_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!= 1
144
- || SSL_CTX_use_PrivateKey_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!=1 ){
149
+ if( SSL_CTX_use_certificate_file(sslCtx,identityFile,SSL_FILETYPE_PEM)!=1
150
+ || SSL_CTX_use_PrivateKey_file(sslCtx,identityFile,SSL_FILETYPE_PEM)!=1
151
+ ){
145152
fossil_fatal("Could not load SSL identity from %s", identityFile);
146153
}
147154
}
148
- /* Register a callback to tell the user what to do when the server asks for a cert */
155
+ /* Register a callback to tell the user what to do when the server asks
156
+ ** for a cert */
149157
SSL_CTX_set_client_cert_cb(sslCtx, ssl_client_cert_callback);
150158
151159
sslIsInit = 1;
152160
}
153161
}
@@ -184,17 +192,18 @@
184192
** Return the number of errors.
185193
*/
186194
int ssl_open(void){
187195
X509 *cert;
188196
int hasSavedCertificate = 0;
189
-char *connStr ;
197
+ int trusted = 0;
198
+ char *connStr ;
190199
ssl_global_init();
191200
192201
/* Get certificate for current server from global config and
193202
* (if we have it in config) add it to certificate store.
194203
*/
195
- cert = ssl_get_certificate();
204
+ cert = ssl_get_certificate(&trusted);
196205
if ( cert!=NULL ){
197206
X509_STORE_add_cert(SSL_CTX_get_cert_store(sslCtx), cert);
198207
X509_free(cert);
199208
hasSavedCertificate = 1;
200209
}
@@ -232,11 +241,11 @@
232241
ssl_set_errmsg("No SSL certificate was presented by the peer");
233242
ssl_close();
234243
return 1;
235244
}
236245
237
- if( SSL_get_verify_result(ssl) != X509_V_OK ){
246
+ if( trusted<=0 && SSL_get_verify_result(ssl) != X509_V_OK ){
238247
char *desc, *prompt;
239248
char *warning = "";
240249
Blob ans;
241250
BIO *mem;
242251
unsigned char md[32];
@@ -258,19 +267,19 @@
258267
259268
if( hasSavedCertificate ){
260269
warning = "WARNING: Certificate doesn't match the "
261270
"saved certificate for this host!";
262271
}
263
- prompt = mprintf("\nUnknown SSL certificate:\n\n%s\n\n%s\n"
264
- "Either:\n"
265
- " * verify the certificate is correct using the "
266
- "SHA1 fingerprint above\n"
267
- " * use the global ssl-ca-location setting to specify your CA root\n"
268
- " certificates list\n\n"
269
- "If you are not expecting this message, answer no and "
270
- "contact your server\nadministrator.\n\n"
271
- "Accept certificate [a=always/y/N]? ", desc, warning);
272
+ prompt = mprintf(
273
+ "\nUnknown SSL certificate:\n\n%s\n\n%s\n"
274
+ "Either:\n"
275
+ " * verify the certificate is correct using the SHA1 fingerprint above\n"
276
+ " * use the global ssl-ca-location setting to specify your CA root\n"
277
+ " certificates list\n\n"
278
+ "If you are not expecting this message, answer no and "
279
+ "contact your server\nadministrator.\n\n"
280
+ "Accept certificate [a=always/y/N]? ", desc, warning);
272281
BIO_free(mem);
273282
274283
prompt_user(prompt, &ans);
275284
free(prompt);
276285
if( blob_str(&ans)[0]!='y' && blob_str(&ans)[0]!='a' ) {
@@ -278,33 +287,40 @@
278287
ssl_set_errmsg("SSL certificate declined");
279288
ssl_close();
280289
return 1;
281290
}
282291
if( blob_str(&ans)[0]=='a' ) {
283
- ssl_save_certificate(cert);
292
+ if ( trusted==0 ){
293
+ Blob ans2;
294
+ prompt_user("\nSave this certificate as fully trusted [a=always/N]? ",
295
+ &ans2);
296
+ trusted = (blob_str(&ans2)[0]=='a');
297
+ blob_reset(&ans2);
298
+ }
299
+ ssl_save_certificate(cert, trusted);
284300
}
285301
blob_reset(&ans);
286302
}
287303
288304
/* Set the Global.zIpAddr variable to the server we are talking to.
289305
** This is used to populate the ipaddr column of the rcvfrom table,
290306
** if any files are received from the server.
291307
*/
292308
{
293
- /* IPv4 only code */
294
- const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
295
- g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
309
+ /* IPv4 only code */
310
+ const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
311
+ g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
296312
}
297313
298314
X509_free(cert);
299315
return 0;
300316
}
301317
302318
/*
303319
** Save certificate to global config.
304320
*/
305
-void ssl_save_certificate(X509 *cert){
321
+void ssl_save_certificate(X509 *cert, int trusted){
306322
BIO *mem;
307323
char *zCert, *zHost;
308324
309325
mem = BIO_new(BIO_s_mem());
310326
PEM_write_bio_X509(mem, cert);
@@ -311,27 +327,37 @@
311327
BIO_write(mem, "", 1); /* nul-terminate mem buffer */
312328
BIO_get_mem_data(mem, &zCert);
313329
zHost = mprintf("cert:%s", g.urlName);
314330
db_set(zHost, zCert, 1);
315331
free(zHost);
332
+ zHost = mprintf("trusted:%s", g.urlName);
333
+ db_set_int(zHost, trusted, 1);
334
+ free(zHost);
316335
BIO_free(mem);
317336
}
318337
319338
/*
320339
** Get certificate for g.urlName from global config.
321340
** Return NULL if no certificate found.
322341
*/
323
-X509 *ssl_get_certificate(void){
342
+X509 *ssl_get_certificate(int *pTrusted){
324343
char *zHost, *zCert;
325344
BIO *mem;
326345
X509 *cert;
327346
328347
zHost = mprintf("cert:%s", g.urlName);
329348
zCert = db_get(zHost, NULL);
330349
free(zHost);
331350
if ( zCert==NULL )
332351
return NULL;
352
+
353
+ if ( pTrusted!=0 ){
354
+ zHost = mprintf("trusted:%s", g.urlName);
355
+ *pTrusted = db_get_int(zHost, 0);
356
+ free(zHost);
357
+ }
358
+
333359
mem = BIO_new(BIO_s_mem());
334360
BIO_puts(mem, zCert);
335361
cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
336362
free(zCert);
337363
BIO_free(mem);
338364
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -97,10 +97,11 @@
97 ** Call this routine once before any other use of the SSL interface.
98 ** This routine does initial configuration of the SSL module.
99 */
100 void ssl_global_init(void){
101 const char *zCaSetting = 0, *zCaFile = 0, *zCaDirectory = 0;
 
102
103 if( sslIsInit==0 ){
104 SSL_library_init();
105 SSL_load_error_strings();
106 ERR_load_BIO_strings();
@@ -135,19 +136,26 @@
135 fossil_fatal("Failed to use CA root certificates from "
136 "ssl-ca-location '%s'", zCaSetting);
137 }
138 }
139
140 /* Load client SSL identity, preferring the filename specified on the command line */
141 const char *identityFile = ( g.zSSLIdentity!= 0) ? g.zSSLIdentity : db_get("ssl-identity", 0);
 
 
 
 
 
142 if( identityFile!=0 && identityFile[0]!='\0' ){
143 if( SSL_CTX_use_certificate_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!= 1
144 || SSL_CTX_use_PrivateKey_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!=1 ){
 
145 fossil_fatal("Could not load SSL identity from %s", identityFile);
146 }
147 }
148 /* Register a callback to tell the user what to do when the server asks for a cert */
 
149 SSL_CTX_set_client_cert_cb(sslCtx, ssl_client_cert_callback);
150
151 sslIsInit = 1;
152 }
153 }
@@ -184,17 +192,18 @@
184 ** Return the number of errors.
185 */
186 int ssl_open(void){
187 X509 *cert;
188 int hasSavedCertificate = 0;
189 char *connStr ;
 
190 ssl_global_init();
191
192 /* Get certificate for current server from global config and
193 * (if we have it in config) add it to certificate store.
194 */
195 cert = ssl_get_certificate();
196 if ( cert!=NULL ){
197 X509_STORE_add_cert(SSL_CTX_get_cert_store(sslCtx), cert);
198 X509_free(cert);
199 hasSavedCertificate = 1;
200 }
@@ -232,11 +241,11 @@
232 ssl_set_errmsg("No SSL certificate was presented by the peer");
233 ssl_close();
234 return 1;
235 }
236
237 if( SSL_get_verify_result(ssl) != X509_V_OK ){
238 char *desc, *prompt;
239 char *warning = "";
240 Blob ans;
241 BIO *mem;
242 unsigned char md[32];
@@ -258,19 +267,19 @@
258
259 if( hasSavedCertificate ){
260 warning = "WARNING: Certificate doesn't match the "
261 "saved certificate for this host!";
262 }
263 prompt = mprintf("\nUnknown SSL certificate:\n\n%s\n\n%s\n"
264 "Either:\n"
265 " * verify the certificate is correct using the "
266 "SHA1 fingerprint above\n"
267 " * use the global ssl-ca-location setting to specify your CA root\n"
268 " certificates list\n\n"
269 "If you are not expecting this message, answer no and "
270 "contact your server\nadministrator.\n\n"
271 "Accept certificate [a=always/y/N]? ", desc, warning);
272 BIO_free(mem);
273
274 prompt_user(prompt, &ans);
275 free(prompt);
276 if( blob_str(&ans)[0]!='y' && blob_str(&ans)[0]!='a' ) {
@@ -278,33 +287,40 @@
278 ssl_set_errmsg("SSL certificate declined");
279 ssl_close();
280 return 1;
281 }
282 if( blob_str(&ans)[0]=='a' ) {
283 ssl_save_certificate(cert);
 
 
 
 
 
 
 
284 }
285 blob_reset(&ans);
286 }
287
288 /* Set the Global.zIpAddr variable to the server we are talking to.
289 ** This is used to populate the ipaddr column of the rcvfrom table,
290 ** if any files are received from the server.
291 */
292 {
293 /* IPv4 only code */
294 const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
295 g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
296 }
297
298 X509_free(cert);
299 return 0;
300 }
301
302 /*
303 ** Save certificate to global config.
304 */
305 void ssl_save_certificate(X509 *cert){
306 BIO *mem;
307 char *zCert, *zHost;
308
309 mem = BIO_new(BIO_s_mem());
310 PEM_write_bio_X509(mem, cert);
@@ -311,27 +327,37 @@
311 BIO_write(mem, "", 1); /* nul-terminate mem buffer */
312 BIO_get_mem_data(mem, &zCert);
313 zHost = mprintf("cert:%s", g.urlName);
314 db_set(zHost, zCert, 1);
315 free(zHost);
 
 
 
316 BIO_free(mem);
317 }
318
319 /*
320 ** Get certificate for g.urlName from global config.
321 ** Return NULL if no certificate found.
322 */
323 X509 *ssl_get_certificate(void){
324 char *zHost, *zCert;
325 BIO *mem;
326 X509 *cert;
327
328 zHost = mprintf("cert:%s", g.urlName);
329 zCert = db_get(zHost, NULL);
330 free(zHost);
331 if ( zCert==NULL )
332 return NULL;
 
 
 
 
 
 
 
333 mem = BIO_new(BIO_s_mem());
334 BIO_puts(mem, zCert);
335 cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
336 free(zCert);
337 BIO_free(mem);
338
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -97,10 +97,11 @@
97 ** Call this routine once before any other use of the SSL interface.
98 ** This routine does initial configuration of the SSL module.
99 */
100 void ssl_global_init(void){
101 const char *zCaSetting = 0, *zCaFile = 0, *zCaDirectory = 0;
102 const char *identityFile;
103
104 if( sslIsInit==0 ){
105 SSL_library_init();
106 SSL_load_error_strings();
107 ERR_load_BIO_strings();
@@ -135,19 +136,26 @@
136 fossil_fatal("Failed to use CA root certificates from "
137 "ssl-ca-location '%s'", zCaSetting);
138 }
139 }
140
141 /* Load client SSL identity, preferring the filename specified on the
142 ** command line */
143 if( g.zSSLIdentity!=0 ){
144 identityFile = g.zSSLIdentity;
145 }else{
146 identityFile = db_get("ssl-identity", 0);
147 }
148 if( identityFile!=0 && identityFile[0]!='\0' ){
149 if( SSL_CTX_use_certificate_file(sslCtx,identityFile,SSL_FILETYPE_PEM)!=1
150 || SSL_CTX_use_PrivateKey_file(sslCtx,identityFile,SSL_FILETYPE_PEM)!=1
151 ){
152 fossil_fatal("Could not load SSL identity from %s", identityFile);
153 }
154 }
155 /* Register a callback to tell the user what to do when the server asks
156 ** for a cert */
157 SSL_CTX_set_client_cert_cb(sslCtx, ssl_client_cert_callback);
158
159 sslIsInit = 1;
160 }
161 }
@@ -184,17 +192,18 @@
192 ** Return the number of errors.
193 */
194 int ssl_open(void){
195 X509 *cert;
196 int hasSavedCertificate = 0;
197 int trusted = 0;
198 char *connStr ;
199 ssl_global_init();
200
201 /* Get certificate for current server from global config and
202 * (if we have it in config) add it to certificate store.
203 */
204 cert = ssl_get_certificate(&trusted);
205 if ( cert!=NULL ){
206 X509_STORE_add_cert(SSL_CTX_get_cert_store(sslCtx), cert);
207 X509_free(cert);
208 hasSavedCertificate = 1;
209 }
@@ -232,11 +241,11 @@
241 ssl_set_errmsg("No SSL certificate was presented by the peer");
242 ssl_close();
243 return 1;
244 }
245
246 if( trusted<=0 && SSL_get_verify_result(ssl) != X509_V_OK ){
247 char *desc, *prompt;
248 char *warning = "";
249 Blob ans;
250 BIO *mem;
251 unsigned char md[32];
@@ -258,19 +267,19 @@
267
268 if( hasSavedCertificate ){
269 warning = "WARNING: Certificate doesn't match the "
270 "saved certificate for this host!";
271 }
272 prompt = mprintf(
273 "\nUnknown SSL certificate:\n\n%s\n\n%s\n"
274 "Either:\n"
275 " * verify the certificate is correct using the SHA1 fingerprint above\n"
276 " * use the global ssl-ca-location setting to specify your CA root\n"
277 " certificates list\n\n"
278 "If you are not expecting this message, answer no and "
279 "contact your server\nadministrator.\n\n"
280 "Accept certificate [a=always/y/N]? ", desc, warning);
281 BIO_free(mem);
282
283 prompt_user(prompt, &ans);
284 free(prompt);
285 if( blob_str(&ans)[0]!='y' && blob_str(&ans)[0]!='a' ) {
@@ -278,33 +287,40 @@
287 ssl_set_errmsg("SSL certificate declined");
288 ssl_close();
289 return 1;
290 }
291 if( blob_str(&ans)[0]=='a' ) {
292 if ( trusted==0 ){
293 Blob ans2;
294 prompt_user("\nSave this certificate as fully trusted [a=always/N]? ",
295 &ans2);
296 trusted = (blob_str(&ans2)[0]=='a');
297 blob_reset(&ans2);
298 }
299 ssl_save_certificate(cert, trusted);
300 }
301 blob_reset(&ans);
302 }
303
304 /* Set the Global.zIpAddr variable to the server we are talking to.
305 ** This is used to populate the ipaddr column of the rcvfrom table,
306 ** if any files are received from the server.
307 */
308 {
309 /* IPv4 only code */
310 const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
311 g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
312 }
313
314 X509_free(cert);
315 return 0;
316 }
317
318 /*
319 ** Save certificate to global config.
320 */
321 void ssl_save_certificate(X509 *cert, int trusted){
322 BIO *mem;
323 char *zCert, *zHost;
324
325 mem = BIO_new(BIO_s_mem());
326 PEM_write_bio_X509(mem, cert);
@@ -311,27 +327,37 @@
327 BIO_write(mem, "", 1); /* nul-terminate mem buffer */
328 BIO_get_mem_data(mem, &zCert);
329 zHost = mprintf("cert:%s", g.urlName);
330 db_set(zHost, zCert, 1);
331 free(zHost);
332 zHost = mprintf("trusted:%s", g.urlName);
333 db_set_int(zHost, trusted, 1);
334 free(zHost);
335 BIO_free(mem);
336 }
337
338 /*
339 ** Get certificate for g.urlName from global config.
340 ** Return NULL if no certificate found.
341 */
342 X509 *ssl_get_certificate(int *pTrusted){
343 char *zHost, *zCert;
344 BIO *mem;
345 X509 *cert;
346
347 zHost = mprintf("cert:%s", g.urlName);
348 zCert = db_get(zHost, NULL);
349 free(zHost);
350 if ( zCert==NULL )
351 return NULL;
352
353 if ( pTrusted!=0 ){
354 zHost = mprintf("trusted:%s", g.urlName);
355 *pTrusted = db_get_int(zHost, 0);
356 free(zHost);
357 }
358
359 mem = BIO_new(BIO_s_mem());
360 BIO_puts(mem, zCert);
361 cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
362 free(zCert);
363 BIO_free(mem);
364
--- src/rebuild.c
+++ src/rebuild.c
@@ -786,10 +786,11 @@
786786
);
787787
if( bVerily ){
788788
db_multi_exec(
789789
"DELETE FROM concealed;"
790790
"UPDATE rcvfrom SET ipaddr='unknown';"
791
+ "DROP TABLE IF EXISTS accesslog;"
791792
"UPDATE user SET photo=NULL, info='';"
792793
);
793794
}
794795
}
795796
if( !bNeedRebuild ){
796797
--- src/rebuild.c
+++ src/rebuild.c
@@ -786,10 +786,11 @@
786 );
787 if( bVerily ){
788 db_multi_exec(
789 "DELETE FROM concealed;"
790 "UPDATE rcvfrom SET ipaddr='unknown';"
 
791 "UPDATE user SET photo=NULL, info='';"
792 );
793 }
794 }
795 if( !bNeedRebuild ){
796
--- src/rebuild.c
+++ src/rebuild.c
@@ -786,10 +786,11 @@
786 );
787 if( bVerily ){
788 db_multi_exec(
789 "DELETE FROM concealed;"
790 "UPDATE rcvfrom SET ipaddr='unknown';"
791 "DROP TABLE IF EXISTS accesslog;"
792 "UPDATE user SET photo=NULL, info='';"
793 );
794 }
795 }
796 if( !bNeedRebuild ){
797
+1 -1
--- src/sha1.c
+++ src/sha1.c
@@ -82,11 +82,11 @@
8282
#define d qq[3]
8383
#define e qq[4]
8484
8585
void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
8686
{
87
- unsigned int qq[5]; // a, b, c, d, e;
87
+ unsigned int qq[5]; /* a, b, c, d, e; */
8888
static int one = 1;
8989
unsigned int block[16];
9090
memcpy(block, buffer, 64);
9191
memcpy(qq,state,5*sizeof(unsigned int));
9292
9393
--- src/sha1.c
+++ src/sha1.c
@@ -82,11 +82,11 @@
82 #define d qq[3]
83 #define e qq[4]
84
85 void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
86 {
87 unsigned int qq[5]; // a, b, c, d, e;
88 static int one = 1;
89 unsigned int block[16];
90 memcpy(block, buffer, 64);
91 memcpy(qq,state,5*sizeof(unsigned int));
92
93
--- src/sha1.c
+++ src/sha1.c
@@ -82,11 +82,11 @@
82 #define d qq[3]
83 #define e qq[4]
84
85 void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
86 {
87 unsigned int qq[5]; /* a, b, c, d, e; */
88 static int one = 1;
89 unsigned int block[16];
90 memcpy(block, buffer, 64);
91 memcpy(qq,state,5*sizeof(unsigned int));
92
93
+1699 -794
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.8. By combining all the individual C code files into this
3
+** version 3.7.9. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -24,10 +24,11 @@
2424
#endif
2525
#ifndef SQLITE_API
2626
# define SQLITE_API
2727
#endif
2828
/************** Begin file sqliteInt.h ***************************************/
29
+#line 1 "tsrc/sqliteInt.h"
2930
/*
3031
** 2001 September 15
3132
**
3233
** The author disclaims copyright to this source code. In place of
3334
** a legal notice, here is a blessing:
@@ -78,10 +79,11 @@
7879
#include "config.h"
7980
#endif
8081
8182
/************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
8283
/************** Begin file sqliteLimit.h *************************************/
84
+#line 1 "tsrc/sqliteLimit.h"
8385
/*
8486
** 2007 May 7
8587
**
8688
** The author disclaims copyright to this source code. In place of
8789
** a legal notice, here is a blessing:
@@ -289,10 +291,11 @@
289291
# define SQLITE_MAX_TRIGGER_DEPTH 1000
290292
#endif
291293
292294
/************** End of sqliteLimit.h *****************************************/
293295
/************** Continuing where we left off in sqliteInt.h ******************/
296
+#line 54 "tsrc/sqliteInt.h"
294297
295298
/* Disable nuisance warnings on Borland compilers */
296299
#if defined(__BORLANDC__)
297300
#pragma warn -rch /* unreachable code */
298301
#pragma warn -ccc /* Condition is always true or false */
@@ -394,11 +397,11 @@
394397
** assert() macro is enabled, each call into the Win32 native heap subsystem
395398
** will cause HeapValidate to be called. If heap validation should fail, an
396399
** assertion will be triggered.
397400
**
398401
** (Historical note: There used to be several other options, but we've
399
-** pared it down to just these two.)
402
+** pared it down to just these three.)
400403
**
401404
** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
402405
** the default.
403406
*/
404407
#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1
@@ -545,10 +548,11 @@
545548
# define unlikely(X) !!(X)
546549
#endif
547550
548551
/************** Include sqlite3.h in the middle of sqliteInt.h ***************/
549552
/************** Begin file sqlite3.h *****************************************/
553
+#line 1 "tsrc/sqlite3.h"
550554
/*
551555
** 2001 September 15
552556
**
553557
** The author disclaims copyright to this source code. In place of
554558
** a legal notice, here is a blessing:
@@ -654,13 +658,13 @@
654658
**
655659
** See also: [sqlite3_libversion()],
656660
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657661
** [sqlite_version()] and [sqlite_source_id()].
658662
*/
659
-#define SQLITE_VERSION "3.7.8"
660
-#define SQLITE_VERSION_NUMBER 3007008
661
-#define SQLITE_SOURCE_ID "2011-09-19 14:49:19 3e0da808d2f5b4d12046e05980ca04578f581177"
663
+#define SQLITE_VERSION "3.7.9"
664
+#define SQLITE_VERSION_NUMBER 3007009
665
+#define SQLITE_SOURCE_ID "2011-10-07 18:24:25 d4f95b3b6e9f4a4072606af5daa17ea7c645382e"
662666
663667
/*
664668
** CAPI3REF: Run-Time Library Version Numbers
665669
** KEYWORDS: sqlite3_version, sqlite3_sourceid
666670
**
@@ -1318,11 +1322,15 @@
13181322
** in order for the database to be readable. The fourth parameter to
13191323
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
13201324
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
13211325
** WAL mode. If the integer is -1, then it is overwritten with the current
13221326
** WAL persistence setting.
1323
-**
1327
+**
1328
+** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
1329
+** a write transaction to indicate that, unless it is rolled back for some
1330
+** reason, the entire database file will be overwritten by the current
1331
+** transaction. This is used by VACUUM operations.
13241332
*/
13251333
#define SQLITE_FCNTL_LOCKSTATE 1
13261334
#define SQLITE_GET_LOCKPROXYFILE 2
13271335
#define SQLITE_SET_LOCKPROXYFILE 3
13281336
#define SQLITE_LAST_ERRNO 4
@@ -1330,10 +1338,11 @@
13301338
#define SQLITE_FCNTL_CHUNK_SIZE 6
13311339
#define SQLITE_FCNTL_FILE_POINTER 7
13321340
#define SQLITE_FCNTL_SYNC_OMITTED 8
13331341
#define SQLITE_FCNTL_WIN32_AV_RETRY 9
13341342
#define SQLITE_FCNTL_PERSIST_WAL 10
1343
+#define SQLITE_FCNTL_OVERWRITE 11
13351344
13361345
/*
13371346
** CAPI3REF: Mutex Handle
13381347
**
13391348
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3397,11 +3406,11 @@
33973406
** a schema change, on the first [sqlite3_step()] call following any change
33983407
** to the [sqlite3_bind_text | bindings] of that [parameter].
33993408
** ^The specific value of WHERE-clause [parameter] might influence the
34003409
** choice of query plan if the parameter is the left-hand side of a [LIKE]
34013410
** or [GLOB] operator or if the parameter is compared to an indexed column
3402
-** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
3411
+** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
34033412
** the
34043413
** </li>
34053414
** </ol>
34063415
*/
34073416
SQLITE_API int sqlite3_prepare(
@@ -3900,10 +3909,16 @@
39003909
** current row of the result set of [prepared statement] P.
39013910
** ^If prepared statement P does not have results ready to return
39023911
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
39033912
** interfaces) then sqlite3_data_count(P) returns 0.
39043913
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3914
+** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
3915
+** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
3916
+** will return non-zero if previous call to [sqlite3_step](P) returned
3917
+** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
3918
+** where it always returns zero since each step of that multi-step
3919
+** pragma returns 0 columns of data.
39053920
**
39063921
** See also: [sqlite3_column_count()]
39073922
*/
39083923
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
39093924
@@ -6362,20 +6377,34 @@
63626377
** <dd>This parameter returns the approximate number of of bytes of heap
63636378
** and lookaside memory used by all prepared statements associated with
63646379
** the database connection.)^
63656380
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
63666381
** </dd>
6382
+**
6383
+** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
6384
+** <dd>This parameter returns the number of pager cache hits that have
6385
+** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
6386
+** is always 0.
6387
+** </dd>
6388
+**
6389
+** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
6390
+** <dd>This parameter returns the number of pager cache misses that have
6391
+** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
6392
+** is always 0.
6393
+** </dd>
63676394
** </dl>
63686395
*/
63696396
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
63706397
#define SQLITE_DBSTATUS_CACHE_USED 1
63716398
#define SQLITE_DBSTATUS_SCHEMA_USED 2
63726399
#define SQLITE_DBSTATUS_STMT_USED 3
63736400
#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
63746401
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
63756402
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6376
-#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
6403
+#define SQLITE_DBSTATUS_CACHE_HIT 7
6404
+#define SQLITE_DBSTATUS_CACHE_MISS 8
6405
+#define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
63776406
63786407
63796408
/*
63806409
** CAPI3REF: Prepared Statement Status
63816410
**
@@ -6425,11 +6454,10 @@
64256454
** <dd>^This is the number of rows inserted into transient indices that
64266455
** were created automatically in order to help joins run faster.
64276456
** A non-zero value in this counter may indicate an opportunity to
64286457
** improvement performance by adding permanent indices that do not
64296458
** need to be reinitialized each time the statement is run.</dd>
6430
-**
64316459
** </dl>
64326460
*/
64336461
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
64346462
#define SQLITE_STMTSTATUS_SORT 2
64356463
#define SQLITE_STMTSTATUS_AUTOINDEX 3
@@ -7305,12 +7333,14 @@
73057333
#endif /* ifndef _SQLITE3RTREE_H_ */
73067334
73077335
73087336
/************** End of sqlite3.h *********************************************/
73097337
/************** Continuing where we left off in sqliteInt.h ******************/
7338
+#line 309 "tsrc/sqliteInt.h"
73107339
/************** Include hash.h in the middle of sqliteInt.h ******************/
73117340
/************** Begin file hash.h ********************************************/
7341
+#line 1 "tsrc/hash.h"
73127342
/*
73137343
** 2001 September 22
73147344
**
73157345
** The author disclaims copyright to this source code. In place of
73167346
** a legal notice, here is a blessing:
@@ -7406,12 +7436,14 @@
74067436
74077437
#endif /* _SQLITE_HASH_H_ */
74087438
74097439
/************** End of hash.h ************************************************/
74107440
/************** Continuing where we left off in sqliteInt.h ******************/
7441
+#line 310 "tsrc/sqliteInt.h"
74117442
/************** Include parse.h in the middle of sqliteInt.h *****************/
74127443
/************** Begin file parse.h *******************************************/
7444
+#line 1 "tsrc/parse.h"
74137445
#define TK_SEMI 1
74147446
#define TK_EXPLAIN 2
74157447
#define TK_QUERY 3
74167448
#define TK_PLAN 4
74177449
#define TK_BEGIN 5
@@ -7568,10 +7600,11 @@
75687600
#define TK_UMINUS 156
75697601
#define TK_UPLUS 157
75707602
75717603
/************** End of parse.h ***********************************************/
75727604
/************** Continuing where we left off in sqliteInt.h ******************/
7605
+#line 311 "tsrc/sqliteInt.h"
75737606
#include <stdio.h>
75747607
#include <stdlib.h>
75757608
#include <string.h>
75767609
#include <assert.h>
75777610
#include <stddef.h>
@@ -7711,10 +7744,22 @@
77117744
** is 0x00000000ffffffff. But because of quirks of some compilers, we
77127745
** have to specify the value in the less intuitive manner shown:
77137746
*/
77147747
#define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
77157748
7749
+/*
7750
+** The datatype used to store estimates of the number of rows in a
7751
+** table or index. This is an unsigned integer type. For 99.9% of
7752
+** the world, a 32-bit integer is sufficient. But a 64-bit integer
7753
+** can be used at compile-time if desired.
7754
+*/
7755
+#ifdef SQLITE_64BIT_STATS
7756
+ typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */
7757
+#else
7758
+ typedef u32 tRowcnt; /* 32-bit is the default */
7759
+#endif
7760
+
77167761
/*
77177762
** Macros to determine whether the machine is big or little endian,
77187763
** evaluated at runtime.
77197764
*/
77207765
#ifdef SQLITE_AMALGAMATION
@@ -7911,10 +7956,11 @@
79117956
** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
79127957
** pointer types (i.e. FuncDef) defined above.
79137958
*/
79147959
/************** Include btree.h in the middle of sqliteInt.h *****************/
79157960
/************** Begin file btree.h *******************************************/
7961
+#line 1 "tsrc/btree.h"
79167962
/*
79177963
** 2001 September 15
79187964
**
79197965
** The author disclaims copyright to this source code. In place of
79207966
** a legal notice, here is a blessing:
@@ -8155,12 +8201,14 @@
81558201
81568202
#endif /* _BTREE_H_ */
81578203
81588204
/************** End of btree.h ***********************************************/
81598205
/************** Continuing where we left off in sqliteInt.h ******************/
8206
+#line 665 "tsrc/sqliteInt.h"
81608207
/************** Include vdbe.h in the middle of sqliteInt.h ******************/
81618208
/************** Begin file vdbe.h ********************************************/
8209
+#line 1 "tsrc/vdbe.h"
81628210
/*
81638211
** 2001 September 15
81648212
**
81658213
** The author disclaims copyright to this source code. In place of
81668214
** a legal notice, here is a blessing:
@@ -8321,10 +8369,11 @@
83218369
** The makefile scans the vdbe.c source file and creates the "opcodes.h"
83228370
** header file that defines a number for each opcode used by the VDBE.
83238371
*/
83248372
/************** Include opcodes.h in the middle of vdbe.h ********************/
83258373
/************** Begin file opcodes.h *****************************************/
8374
+#line 1 "tsrc/opcodes.h"
83268375
/* Automatically generated. Do not edit */
83278376
/* See the mkopcodeh.awk script for details */
83288377
#define OP_Goto 1
83298378
#define OP_Gosub 2
83308379
#define OP_Return 3
@@ -8509,10 +8558,11 @@
85098558
/* 136 */ 0x01, 0x00, 0x01, 0x00, 0x00, 0x04, 0x04, 0x04,\
85108559
/* 144 */ 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00,}
85118560
85128561
/************** End of opcodes.h *********************************************/
85138562
/************** Continuing where we left off in vdbe.h ***********************/
8563
+#line 164 "tsrc/vdbe.h"
85148564
85158565
/*
85168566
** Prototypes for the VDBE interface. See comments on the implementation
85178567
** for a description of what each of these routines does.
85188568
*/
@@ -8583,12 +8633,14 @@
85838633
85848634
#endif
85858635
85868636
/************** End of vdbe.h ************************************************/
85878637
/************** Continuing where we left off in sqliteInt.h ******************/
8638
+#line 666 "tsrc/sqliteInt.h"
85888639
/************** Include pager.h in the middle of sqliteInt.h *****************/
85898640
/************** Begin file pager.h *******************************************/
8641
+#line 1 "tsrc/pager.h"
85908642
/*
85918643
** 2001 September 15
85928644
**
85938645
** The author disclaims copyright to this source code. In place of
85948646
** a legal notice, here is a blessing:
@@ -8742,10 +8794,11 @@
87428794
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
87438795
SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
87448796
SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
87458797
SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
87468798
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
8799
+SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
87478800
87488801
/* Functions used to truncate the database file. */
87498802
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
87508803
87518804
#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
@@ -8769,12 +8822,14 @@
87698822
87708823
#endif /* _PAGER_H_ */
87718824
87728825
/************** End of pager.h ***********************************************/
87738826
/************** Continuing where we left off in sqliteInt.h ******************/
8827
+#line 667 "tsrc/sqliteInt.h"
87748828
/************** Include pcache.h in the middle of sqliteInt.h ****************/
87758829
/************** Begin file pcache.h ******************************************/
8830
+#line 1 "tsrc/pcache.h"
87768831
/*
87778832
** 2008 August 05
87788833
**
87798834
** The author disclaims copyright to this source code. In place of
87808835
** a legal notice, here is a blessing:
@@ -8929,13 +8984,15 @@
89298984
89308985
#endif /* _PCACHE_H_ */
89318986
89328987
/************** End of pcache.h **********************************************/
89338988
/************** Continuing where we left off in sqliteInt.h ******************/
8989
+#line 668 "tsrc/sqliteInt.h"
89348990
89358991
/************** Include os.h in the middle of sqliteInt.h ********************/
89368992
/************** Begin file os.h **********************************************/
8993
+#line 1 "tsrc/os.h"
89378994
/*
89388995
** 2001 September 16
89398996
**
89408997
** The author disclaims copyright to this source code. In place of
89418998
** a legal notice, here is a blessing:
@@ -9214,12 +9271,14 @@
92149271
92159272
#endif /* _SQLITE_OS_H_ */
92169273
92179274
/************** End of os.h **************************************************/
92189275
/************** Continuing where we left off in sqliteInt.h ******************/
9276
+#line 670 "tsrc/sqliteInt.h"
92199277
/************** Include mutex.h in the middle of sqliteInt.h *****************/
92209278
/************** Begin file mutex.h *******************************************/
9279
+#line 1 "tsrc/mutex.h"
92219280
/*
92229281
** 2007 August 28
92239282
**
92249283
** The author disclaims copyright to this source code. In place of
92259284
** a legal notice, here is a blessing:
@@ -9290,10 +9349,11 @@
92909349
#define sqlite3MutexEnd()
92919350
#endif /* defined(SQLITE_MUTEX_OMIT) */
92929351
92939352
/************** End of mutex.h ***********************************************/
92949353
/************** Continuing where we left off in sqliteInt.h ******************/
9354
+#line 671 "tsrc/sqliteInt.h"
92959355
92969356
92979357
/*
92989358
** Each database file to be accessed by the system is an instance
92999359
** of the following structure. There are normally two of these structures
@@ -9918,11 +9978,11 @@
99189978
int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
99199979
int nCol; /* Number of columns in this table */
99209980
Column *aCol; /* Information about each column */
99219981
Index *pIndex; /* List of SQL indexes on this table. */
99229982
int tnum; /* Root BTree node for this table (see note above) */
9923
- unsigned nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
9983
+ tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
99249984
Select *pSelect; /* NULL for tables. Points to definition if a view. */
99259985
u16 nRef; /* Number of pointers to this Table */
99269986
u8 tabFlags; /* Mask of TF_* values */
99279987
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
99289988
FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10117,11 +10177,11 @@
1011710177
*/
1011810178
struct Index {
1011910179
char *zName; /* Name of this index */
1012010180
int nColumn; /* Number of columns in the table used by this index */
1012110181
int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10122
- unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
10182
+ tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
1012310183
Table *pTable; /* The SQL table being indexed */
1012410184
int tnum; /* Page containing root of this index in database file */
1012510185
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
1012610186
u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
1012710187
u8 bUnordered; /* Use this index for == or IN queries only */
@@ -10128,24 +10188,32 @@
1012810188
char *zColAff; /* String defining the affinity of each column */
1012910189
Index *pNext; /* The next index associated with the same table */
1013010190
Schema *pSchema; /* Schema containing this index */
1013110191
u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
1013210192
char **azColl; /* Array of collation sequence names for index */
10133
- IndexSample *aSample; /* Array of SQLITE_INDEX_SAMPLES samples */
10193
+#ifdef SQLITE_ENABLE_STAT3
10194
+ int nSample; /* Number of elements in aSample[] */
10195
+ tRowcnt avgEq; /* Average nEq value for key values not in aSample */
10196
+ IndexSample *aSample; /* Samples of the left-most key */
10197
+#endif
1013410198
};
1013510199
1013610200
/*
1013710201
** Each sample stored in the sqlite_stat2 table is represented in memory
1013810202
** using a structure of this type.
1013910203
*/
1014010204
struct IndexSample {
1014110205
union {
1014210206
char *z; /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */
10143
- double r; /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */
10207
+ double r; /* Value if eType is SQLITE_FLOAT */
10208
+ i64 i; /* Value if eType is SQLITE_INTEGER */
1014410209
} u;
1014510210
u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
10146
- u8 nByte; /* Size in byte of text or blob. */
10211
+ int nByte; /* Size in byte of text or blob. */
10212
+ tRowcnt nEq; /* Est. number of rows where the key equals this sample */
10213
+ tRowcnt nLt; /* Est. number of rows where key is less than this sample */
10214
+ tRowcnt nDLt; /* Est. number of distinct keys less than this sample */
1014710215
};
1014810216
1014910217
/*
1015010218
** Each token coming out of the lexer is an instance of
1015110219
** this structure. Tokens are also used as part of an expression.
@@ -10593,14 +10661,14 @@
1059310661
#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
1059410662
#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
1059510663
#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
1059610664
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
1059710665
#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
10598
-#define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
10599
-#define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
10600
-#define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
10601
-#define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
10666
+#define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
10667
+#define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
10668
+#define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
10669
+#define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
1060210670
1060310671
/*
1060410672
** The WHERE clause processing routine has two halves. The
1060510673
** first part does the start of the WHERE loop and the second
1060610674
** half does the tail of the WHERE loop. An instance of
@@ -11350,10 +11418,11 @@
1135011418
#else
1135111419
# define sqlite3ViewGetColumnNames(A,B) 0
1135211420
#endif
1135311421
1135411422
SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
11423
+SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
1135511424
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
1135611425
#ifndef SQLITE_OMIT_AUTOINCREMENT
1135711426
SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
1135811427
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
1135911428
#else
@@ -11606,11 +11675,11 @@
1160611675
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1160711676
void(*)(void*));
1160811677
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
1160911678
SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
1161011679
SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
11611
-#ifdef SQLITE_ENABLE_STAT2
11680
+#ifdef SQLITE_ENABLE_STAT3
1161211681
SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *);
1161311682
#endif
1161411683
SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
1161511684
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
1161611685
#ifndef SQLITE_AMALGAMATION
@@ -11893,10 +11962,11 @@
1189311962
1189411963
#endif /* _SQLITEINT_H_ */
1189511964
1189611965
/************** End of sqliteInt.h *******************************************/
1189711966
/************** Begin file global.c ******************************************/
11967
+#line 1 "tsrc/global.c"
1189811968
/*
1189911969
** 2008 June 13
1190011970
**
1190111971
** The author disclaims copyright to this source code. In place of
1190211972
** a legal notice, here is a blessing:
@@ -12115,10 +12185,11 @@
1211512185
*/
1211612186
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
1211712187
1211812188
/************** End of global.c **********************************************/
1211912189
/************** Begin file ctime.c *******************************************/
12190
+#line 1 "tsrc/ctime.c"
1212012191
/*
1212112192
** 2010 February 23
1212212193
**
1212312194
** The author disclaims copyright to this source code. In place of
1212412195
** a legal notice, here is a blessing:
@@ -12232,10 +12303,13 @@
1223212303
#ifdef SQLITE_ENABLE_RTREE
1223312304
"ENABLE_RTREE",
1223412305
#endif
1223512306
#ifdef SQLITE_ENABLE_STAT2
1223612307
"ENABLE_STAT2",
12308
+#endif
12309
+#ifdef SQLITE_ENABLE_STAT3
12310
+ "ENABLE_STAT3",
1223712311
#endif
1223812312
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
1223912313
"ENABLE_UNLOCK_NOTIFY",
1224012314
#endif
1224112315
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
@@ -12445,13 +12519,10 @@
1244512519
"OMIT_WSD",
1244612520
#endif
1244712521
#ifdef SQLITE_OMIT_XFER_OPT
1244812522
"OMIT_XFER_OPT",
1244912523
#endif
12450
-#ifdef SQLITE_PAGECACHE_BLOCKALLOC
12451
- "PAGECACHE_BLOCKALLOC",
12452
-#endif
1245312524
#ifdef SQLITE_PERFORMANCE_TRACE
1245412525
"PERFORMANCE_TRACE",
1245512526
#endif
1245612527
#ifdef SQLITE_PROXY_DEBUG
1245712528
"PROXY_DEBUG",
@@ -12519,10 +12590,11 @@
1251912590
1252012591
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
1252112592
1252212593
/************** End of ctime.c ***********************************************/
1252312594
/************** Begin file status.c ******************************************/
12595
+#line 1 "tsrc/status.c"
1252412596
/*
1252512597
** 2008 June 18
1252612598
**
1252712599
** The author disclaims copyright to this source code. In place of
1252812600
** a legal notice, here is a blessing:
@@ -12536,10 +12608,11 @@
1253612608
** This module implements the sqlite3_status() interface and related
1253712609
** functionality.
1253812610
*/
1253912611
/************** Include vdbeInt.h in the middle of status.c ******************/
1254012612
/************** Begin file vdbeInt.h *****************************************/
12613
+#line 1 "tsrc/vdbeInt.h"
1254112614
/*
1254212615
** 2003 September 6
1254312616
**
1254412617
** The author disclaims copyright to this source code. In place of
1254512618
** a legal notice, here is a blessing:
@@ -12987,10 +13060,11 @@
1298713060
1298813061
#endif /* !defined(_VDBEINT_H_) */
1298913062
1299013063
/************** End of vdbeInt.h *********************************************/
1299113064
/************** Continuing where we left off in status.c *********************/
13065
+#line 18 "tsrc/status.c"
1299213066
1299313067
/*
1299413068
** Variables in which to record status information.
1299513069
*/
1299613070
typedef struct sqlite3StatType sqlite3StatType;
@@ -13189,10 +13263,32 @@
1318913263
*pHighwater = 0;
1319013264
*pCurrent = nByte;
1319113265
1319213266
break;
1319313267
}
13268
+
13269
+ /*
13270
+ ** Set *pCurrent to the total cache hits or misses encountered by all
13271
+ ** pagers the database handle is connected to. *pHighwater is always set
13272
+ ** to zero.
13273
+ */
13274
+ case SQLITE_DBSTATUS_CACHE_HIT:
13275
+ case SQLITE_DBSTATUS_CACHE_MISS: {
13276
+ int i;
13277
+ int nRet = 0;
13278
+ assert( SQLITE_DBSTATUS_CACHE_MISS==SQLITE_DBSTATUS_CACHE_HIT+1 );
13279
+
13280
+ for(i=0; i<db->nDb; i++){
13281
+ if( db->aDb[i].pBt ){
13282
+ Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
13283
+ sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
13284
+ }
13285
+ }
13286
+ *pHighwater = 0;
13287
+ *pCurrent = nRet;
13288
+ break;
13289
+ }
1319413290
1319513291
default: {
1319613292
rc = SQLITE_ERROR;
1319713293
}
1319813294
}
@@ -13200,10 +13296,11 @@
1320013296
return rc;
1320113297
}
1320213298
1320313299
/************** End of status.c **********************************************/
1320413300
/************** Begin file date.c ********************************************/
13301
+#line 1 "tsrc/date.c"
1320513302
/*
1320613303
** 2003 October 31
1320713304
**
1320813305
** The author disclaims copyright to this source code. In place of
1320913306
** a legal notice, here is a blessing:
@@ -14327,10 +14424,11 @@
1432714424
}
1432814425
}
1432914426
1433014427
/************** End of date.c ************************************************/
1433114428
/************** Begin file os.c **********************************************/
14429
+#line 1 "tsrc/os.c"
1433214430
/*
1433314431
** 2005 November 29
1433414432
**
1433514433
** The author disclaims copyright to this source code. In place of
1433614434
** a legal notice, here is a blessing:
@@ -14660,10 +14758,11 @@
1466014758
return SQLITE_OK;
1466114759
}
1466214760
1466314761
/************** End of os.c **************************************************/
1466414762
/************** Begin file fault.c *******************************************/
14763
+#line 1 "tsrc/fault.c"
1466514764
/*
1466614765
** 2008 Jan 22
1466714766
**
1466814767
** The author disclaims copyright to this source code. In place of
1466914768
** a legal notice, here is a blessing:
@@ -14749,10 +14848,11 @@
1474914848
1475014849
#endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
1475114850
1475214851
/************** End of fault.c ***********************************************/
1475314852
/************** Begin file mem0.c ********************************************/
14853
+#line 1 "tsrc/mem0.c"
1475414854
/*
1475514855
** 2008 October 28
1475614856
**
1475714857
** The author disclaims copyright to this source code. In place of
1475814858
** a legal notice, here is a blessing:
@@ -14810,10 +14910,11 @@
1481014910
1481114911
#endif /* SQLITE_ZERO_MALLOC */
1481214912
1481314913
/************** End of mem0.c ************************************************/
1481414914
/************** Begin file mem1.c ********************************************/
14915
+#line 1 "tsrc/mem1.c"
1481514916
/*
1481614917
** 2007 August 14
1481714918
**
1481814919
** The author disclaims copyright to this source code. In place of
1481914920
** a legal notice, here is a blessing:
@@ -14962,10 +15063,11 @@
1496215063
1496315064
#endif /* SQLITE_SYSTEM_MALLOC */
1496415065
1496515066
/************** End of mem1.c ************************************************/
1496615067
/************** Begin file mem2.c ********************************************/
15068
+#line 1 "tsrc/mem2.c"
1496715069
/*
1496815070
** 2007 August 15
1496915071
**
1497015072
** The author disclaims copyright to this source code. In place of
1497115073
** a legal notice, here is a blessing:
@@ -15492,10 +15594,11 @@
1549215594
1549315595
#endif /* SQLITE_MEMDEBUG */
1549415596
1549515597
/************** End of mem2.c ************************************************/
1549615598
/************** Begin file mem3.c ********************************************/
15599
+#line 1 "tsrc/mem3.c"
1549715600
/*
1549815601
** 2007 October 14
1549915602
**
1550015603
** The author disclaims copyright to this source code. In place of
1550115604
** a legal notice, here is a blessing:
@@ -16181,10 +16284,11 @@
1618116284
1618216285
#endif /* SQLITE_ENABLE_MEMSYS3 */
1618316286
1618416287
/************** End of mem3.c ************************************************/
1618516288
/************** Begin file mem5.c ********************************************/
16289
+#line 1 "tsrc/mem5.c"
1618616290
/*
1618716291
** 2007 October 14
1618816292
**
1618916293
** The author disclaims copyright to this source code. In place of
1619016294
** a legal notice, here is a blessing:
@@ -16764,10 +16868,11 @@
1676416868
1676516869
#endif /* SQLITE_ENABLE_MEMSYS5 */
1676616870
1676716871
/************** End of mem5.c ************************************************/
1676816872
/************** Begin file mutex.c *******************************************/
16873
+#line 1 "tsrc/mutex.c"
1676916874
/*
1677016875
** 2007 August 14
1677116876
**
1677216877
** The author disclaims copyright to this source code. In place of
1677316878
** a legal notice, here is a blessing:
@@ -16919,10 +17024,11 @@
1691917024
1692017025
#endif /* SQLITE_MUTEX_OMIT */
1692117026
1692217027
/************** End of mutex.c ***********************************************/
1692317028
/************** Begin file mutex_noop.c **************************************/
17029
+#line 1 "tsrc/mutex_noop.c"
1692417030
/*
1692517031
** 2008 October 07
1692617032
**
1692717033
** The author disclaims copyright to this source code. In place of
1692817034
** a legal notice, here is a blessing:
@@ -17127,10 +17233,11 @@
1712717233
#endif /* SQLITE_MUTEX_NOOP */
1712817234
#endif /* SQLITE_MUTEX_OMIT */
1712917235
1713017236
/************** End of mutex_noop.c ******************************************/
1713117237
/************** Begin file mutex_os2.c ***************************************/
17238
+#line 1 "tsrc/mutex_os2.c"
1713217239
/*
1713317240
** 2007 August 28
1713417241
**
1713517242
** The author disclaims copyright to this source code. In place of
1713617243
** a legal notice, here is a blessing:
@@ -17403,10 +17510,11 @@
1740317510
}
1740417511
#endif /* SQLITE_MUTEX_OS2 */
1740517512
1740617513
/************** End of mutex_os2.c *******************************************/
1740717514
/************** Begin file mutex_unix.c **************************************/
17515
+#line 1 "tsrc/mutex_unix.c"
1740817516
/*
1740917517
** 2007 August 28
1741017518
**
1741117519
** The author disclaims copyright to this source code. In place of
1741217520
** a legal notice, here is a blessing:
@@ -17756,10 +17864,11 @@
1775617864
1775717865
#endif /* SQLITE_MUTEX_PTHREAD */
1775817866
1775917867
/************** End of mutex_unix.c ******************************************/
1776017868
/************** Begin file mutex_w32.c ***************************************/
17869
+#line 1 "tsrc/mutex_w32.c"
1776117870
/*
1776217871
** 2007 August 14
1776317872
**
1776417873
** The author disclaims copyright to this source code. In place of
1776517874
** a legal notice, here is a blessing:
@@ -18090,10 +18199,11 @@
1809018199
}
1809118200
#endif /* SQLITE_MUTEX_W32 */
1809218201
1809318202
/************** End of mutex_w32.c *******************************************/
1809418203
/************** Begin file malloc.c ******************************************/
18204
+#line 1 "tsrc/malloc.c"
1809518205
/*
1809618206
** 2001 September 15
1809718207
**
1809818208
** The author disclaims copyright to this source code. In place of
1809918209
** a legal notice, here is a blessing:
@@ -18869,10 +18979,11 @@
1886918979
return rc & (db ? db->errMask : 0xff);
1887018980
}
1887118981
1887218982
/************** End of malloc.c **********************************************/
1887318983
/************** Begin file printf.c ******************************************/
18984
+#line 1 "tsrc/printf.c"
1887418985
/*
1887518986
** The "printf" code that follows dates from the 1980's. It is in
1887618987
** the public domain. The original comments are included here for
1887718988
** completeness. They are very out-of-date but might be useful as
1887818989
** an historical reference. Most of the "enhancements" have been backed
@@ -19900,10 +20011,11 @@
1990020011
}
1990120012
#endif
1990220013
1990320014
/************** End of printf.c **********************************************/
1990420015
/************** Begin file random.c ******************************************/
20016
+#line 1 "tsrc/random.c"
1990520017
/*
1990620018
** 2001 September 15
1990720019
**
1990820020
** The author disclaims copyright to this source code. In place of
1990920021
** a legal notice, here is a blessing:
@@ -20047,10 +20159,11 @@
2004720159
}
2004820160
#endif /* SQLITE_OMIT_BUILTIN_TEST */
2004920161
2005020162
/************** End of random.c **********************************************/
2005120163
/************** Begin file utf.c *********************************************/
20164
+#line 1 "tsrc/utf.c"
2005220165
/*
2005320166
** 2004 April 13
2005420167
**
2005520168
** The author disclaims copyright to this source code. In place of
2005620169
** a legal notice, here is a blessing:
@@ -20511,11 +20624,11 @@
2051120624
** no longer required.
2051220625
**
2051320626
** If a malloc failure occurs, NULL is returned and the db.mallocFailed
2051420627
** flag set.
2051520628
*/
20516
-#ifdef SQLITE_ENABLE_STAT2
20629
+#ifdef SQLITE_ENABLE_STAT3
2051720630
SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
2051820631
Mem m;
2051920632
memset(&m, 0, sizeof(m));
2052020633
m.db = db;
2052120634
sqlite3VdbeMemSetStr(&m, z, n, SQLITE_UTF8, SQLITE_STATIC);
@@ -20608,10 +20721,11 @@
2060820721
#endif /* SQLITE_TEST */
2060920722
#endif /* SQLITE_OMIT_UTF16 */
2061020723
2061120724
/************** End of utf.c *************************************************/
2061220725
/************** Begin file util.c ********************************************/
20726
+#line 1 "tsrc/util.c"
2061320727
/*
2061420728
** 2001 September 15
2061520729
**
2061620730
** The author disclaims copyright to this source code. In place of
2061720731
** a legal notice, here is a blessing:
@@ -21790,10 +21904,11 @@
2179021904
}
2179121905
#endif
2179221906
2179321907
/************** End of util.c ************************************************/
2179421908
/************** Begin file hash.c ********************************************/
21909
+#line 1 "tsrc/hash.c"
2179521910
/*
2179621911
** 2001 September 22
2179721912
**
2179821913
** The author disclaims copyright to this source code. In place of
2179921914
** a legal notice, here is a blessing:
@@ -22069,10 +22184,11 @@
2206922184
return 0;
2207022185
}
2207122186
2207222187
/************** End of hash.c ************************************************/
2207322188
/************** Begin file opcodes.c *****************************************/
22189
+#line 1 "tsrc/opcodes.c"
2207422190
/* Automatically generated. Do not edit */
2207522191
/* See the mkopcodec.awk script for details. */
2207622192
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
2207722193
SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
2207822194
static const char *const azName[] = { "?",
@@ -22231,10 +22347,11 @@
2223122347
}
2223222348
#endif
2223322349
2223422350
/************** End of opcodes.c *********************************************/
2223522351
/************** Begin file os_os2.c ******************************************/
22352
+#line 1 "tsrc/os_os2.c"
2223622353
/*
2223722354
** 2006 Feb 14
2223822355
**
2223922356
** The author disclaims copyright to this source code. In place of
2224022357
** a legal notice, here is a blessing:
@@ -22287,10 +22404,11 @@
2228722404
/*
2228822405
** Include code that is common to all os_*.c files
2228922406
*/
2229022407
/************** Include os_common.h in the middle of os_os2.c ****************/
2229122408
/************** Begin file os_common.h ***************************************/
22409
+#line 1 "tsrc/os_common.h"
2229222410
/*
2229322411
** 2004 May 22
2229422412
**
2229522413
** The author disclaims copyright to this source code. In place of
2229622414
** a legal notice, here is a blessing:
@@ -22340,10 +22458,11 @@
2234022458
** hwtime.h contains inline assembler code for implementing
2234122459
** high-performance timing routines.
2234222460
*/
2234322461
/************** Include hwtime.h in the middle of os_common.h ****************/
2234422462
/************** Begin file hwtime.h ******************************************/
22463
+#line 1 "tsrc/hwtime.h"
2234522464
/*
2234622465
** 2008 May 27
2234722466
**
2234822467
** The author disclaims copyright to this source code. In place of
2234922468
** a legal notice, here is a blessing:
@@ -22428,10 +22547,11 @@
2242822547
2242922548
#endif /* !defined(_HWTIME_H_) */
2243022549
2243122550
/************** End of hwtime.h **********************************************/
2243222551
/************** Continuing where we left off in os_common.h ******************/
22552
+#line 53 "tsrc/os_common.h"
2243322553
2243422554
static sqlite_uint64 g_start;
2243522555
static sqlite_uint64 g_elapsed;
2243622556
#define TIMER_START g_start=sqlite3Hwtime()
2243722557
#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -22494,10 +22614,11 @@
2249422614
2249522615
#endif /* !defined(_OS_COMMON_H_) */
2249622616
2249722617
/************** End of os_common.h *******************************************/
2249822618
/************** Continuing where we left off in os_os2.c *********************/
22619
+#line 57 "tsrc/os_os2.c"
2249922620
2250022621
/* Forward references */
2250122622
typedef struct os2File os2File; /* The file structure */
2250222623
typedef struct os2ShmNode os2ShmNode; /* A shared descritive memory node */
2250322624
typedef struct os2ShmLink os2ShmLink; /* A connection to shared-memory */
@@ -24365,10 +24486,11 @@
2436524486
2436624487
#endif /* SQLITE_OS_OS2 */
2436724488
2436824489
/************** End of os_os2.c **********************************************/
2436924490
/************** Begin file os_unix.c *****************************************/
24491
+#line 1 "tsrc/os_unix.c"
2437024492
/*
2437124493
** 2004 May 22
2437224494
**
2437324495
** The author disclaims copyright to this source code. In place of
2437424496
** a legal notice, here is a blessing:
@@ -24629,10 +24751,11 @@
2462924751
/*
2463024752
** Include code that is common to all os_*.c files
2463124753
*/
2463224754
/************** Include os_common.h in the middle of os_unix.c ***************/
2463324755
/************** Begin file os_common.h ***************************************/
24756
+#line 1 "tsrc/os_common.h"
2463424757
/*
2463524758
** 2004 May 22
2463624759
**
2463724760
** The author disclaims copyright to this source code. In place of
2463824761
** a legal notice, here is a blessing:
@@ -24682,10 +24805,11 @@
2468224805
** hwtime.h contains inline assembler code for implementing
2468324806
** high-performance timing routines.
2468424807
*/
2468524808
/************** Include hwtime.h in the middle of os_common.h ****************/
2468624809
/************** Begin file hwtime.h ******************************************/
24810
+#line 1 "tsrc/hwtime.h"
2468724811
/*
2468824812
** 2008 May 27
2468924813
**
2469024814
** The author disclaims copyright to this source code. In place of
2469124815
** a legal notice, here is a blessing:
@@ -24770,10 +24894,11 @@
2477024894
2477124895
#endif /* !defined(_HWTIME_H_) */
2477224896
2477324897
/************** End of hwtime.h **********************************************/
2477424898
/************** Continuing where we left off in os_common.h ******************/
24899
+#line 53 "tsrc/os_common.h"
2477524900
2477624901
static sqlite_uint64 g_start;
2477724902
static sqlite_uint64 g_elapsed;
2477824903
#define TIMER_START g_start=sqlite3Hwtime()
2477924904
#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -24836,10 +24961,11 @@
2483624961
2483724962
#endif /* !defined(_OS_COMMON_H_) */
2483824963
2483924964
/************** End of os_common.h *******************************************/
2484024965
/************** Continuing where we left off in os_unix.c ********************/
24966
+#line 265 "tsrc/os_unix.c"
2484124967
2484224968
/*
2484324969
** Define various macros that are missing from some systems.
2484424970
*/
2484524971
#ifndef O_LARGEFILE
@@ -29462,12 +29588,20 @@
2946229588
**
2946329589
** where NN is a 4 digit decimal number. The NN naming schemes are
2946429590
** used by the test_multiplex.c module.
2946529591
*/
2946629592
nDb = sqlite3Strlen30(zPath) - 1;
29467
- while( nDb>0 && zPath[nDb]!='-' ) nDb--;
29468
- if( nDb==0 ) return SQLITE_OK;
29593
+#ifdef SQLITE_ENABLE_8_3_NAMES
29594
+ while( nDb>0 && zPath[nDb]!='-' && zPath[nDb]!='/' ) nDb--;
29595
+ if( nDb==0 || zPath[nDb]=='/' ) return SQLITE_OK;
29596
+#else
29597
+ while( zPath[nDb]!='-' ){
29598
+ assert( nDb>0 );
29599
+ assert( zPath[nDb]!='\n' );
29600
+ nDb--;
29601
+ }
29602
+#endif
2946929603
memcpy(zDb, zPath, nDb);
2947029604
zDb[nDb] = '\0';
2947129605
2947229606
if( 0==osStat(zDb, &sStat) ){
2947329607
*pMode = sStat.st_mode & 0777;
@@ -31345,10 +31479,11 @@
3134531479
3134631480
#endif /* SQLITE_OS_UNIX */
3134731481
3134831482
/************** End of os_unix.c *********************************************/
3134931483
/************** Begin file os_win.c ******************************************/
31484
+#line 1 "tsrc/os_win.c"
3135031485
/*
3135131486
** 2004 May 22
3135231487
**
3135331488
** The author disclaims copyright to this source code. In place of
3135431489
** a legal notice, here is a blessing:
@@ -31406,10 +31541,11 @@
3140631541
/*
3140731542
** Include code that is common to all os_*.c files
3140831543
*/
3140931544
/************** Include os_common.h in the middle of os_win.c ****************/
3141031545
/************** Begin file os_common.h ***************************************/
31546
+#line 1 "tsrc/os_common.h"
3141131547
/*
3141231548
** 2004 May 22
3141331549
**
3141431550
** The author disclaims copyright to this source code. In place of
3141531551
** a legal notice, here is a blessing:
@@ -31459,10 +31595,11 @@
3145931595
** hwtime.h contains inline assembler code for implementing
3146031596
** high-performance timing routines.
3146131597
*/
3146231598
/************** Include hwtime.h in the middle of os_common.h ****************/
3146331599
/************** Begin file hwtime.h ******************************************/
31600
+#line 1 "tsrc/hwtime.h"
3146431601
/*
3146531602
** 2008 May 27
3146631603
**
3146731604
** The author disclaims copyright to this source code. In place of
3146831605
** a legal notice, here is a blessing:
@@ -31547,10 +31684,11 @@
3154731684
3154831685
#endif /* !defined(_HWTIME_H_) */
3154931686
3155031687
/************** End of hwtime.h **********************************************/
3155131688
/************** Continuing where we left off in os_common.h ******************/
31689
+#line 53 "tsrc/os_common.h"
3155231690
3155331691
static sqlite_uint64 g_start;
3155431692
static sqlite_uint64 g_elapsed;
3155531693
#define TIMER_START g_start=sqlite3Hwtime()
3155631694
#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -31613,10 +31751,11 @@
3161331751
3161431752
#endif /* !defined(_OS_COMMON_H_) */
3161531753
3161631754
/************** End of os_common.h *******************************************/
3161731755
/************** Continuing where we left off in os_win.c *********************/
31756
+#line 62 "tsrc/os_win.c"
3161831757
3161931758
/*
3162031759
** Some microsoft compilers lack this definition.
3162131760
*/
3162231761
#ifndef INVALID_FILE_ATTRIBUTES
@@ -34169,11 +34308,11 @@
3416934308
3417034309
if( h==INVALID_HANDLE_VALUE ){
3417134310
pFile->lastErrno = GetLastError();
3417234311
winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name);
3417334312
free(zConverted);
34174
- if( isReadWrite ){
34313
+ if( isReadWrite && !isExclusive ){
3417534314
return winOpen(pVfs, zName, id,
3417634315
((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
3417734316
}else{
3417834317
return SQLITE_CANTOPEN_BKPT;
3417934318
}
@@ -34758,10 +34897,11 @@
3475834897
3475934898
#endif /* SQLITE_OS_WIN */
3476034899
3476134900
/************** End of os_win.c **********************************************/
3476234901
/************** Begin file bitvec.c ******************************************/
34902
+#line 1 "tsrc/bitvec.c"
3476334903
/*
3476434904
** 2008 February 16
3476534905
**
3476634906
** The author disclaims copyright to this source code. In place of
3476734907
** a legal notice, here is a blessing:
@@ -35168,10 +35308,11 @@
3516835308
}
3516935309
#endif /* SQLITE_OMIT_BUILTIN_TEST */
3517035310
3517135311
/************** End of bitvec.c **********************************************/
3517235312
/************** Begin file pcache.c ******************************************/
35313
+#line 1 "tsrc/pcache.c"
3517335314
/*
3517435315
** 2008 August 05
3517535316
**
3517635317
** The author disclaims copyright to this source code. In place of
3517735318
** a legal notice, here is a blessing:
@@ -35764,10 +35905,11 @@
3576435905
}
3576535906
#endif
3576635907
3576735908
/************** End of pcache.c **********************************************/
3576835909
/************** Begin file pcache1.c *****************************************/
35910
+#line 1 "tsrc/pcache1.c"
3576935911
/*
3577035912
** 2008 November 05
3577135913
**
3577235914
** The author disclaims copyright to this source code. In place of
3577335915
** a legal notice, here is a blessing:
@@ -35789,12 +35931,10 @@
3578935931
typedef struct PCache1 PCache1;
3579035932
typedef struct PgHdr1 PgHdr1;
3579135933
typedef struct PgFreeslot PgFreeslot;
3579235934
typedef struct PGroup PGroup;
3579335935
35794
-typedef struct PGroupBlock PGroupBlock;
35795
-typedef struct PGroupBlockList PGroupBlockList;
3579635936
3579735937
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
3579835938
** of one or more PCaches that are able to recycle each others unpinned
3579935939
** pages when they are under memory pressure. A PGroup is an instance of
3580035940
** the following object.
@@ -35821,69 +35961,11 @@
3582135961
int nMaxPage; /* Sum of nMax for purgeable caches */
3582235962
int nMinPage; /* Sum of nMin for purgeable caches */
3582335963
int mxPinned; /* nMaxpage + 10 - nMinPage */
3582435964
int nCurrentPage; /* Number of purgeable pages allocated */
3582535965
PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
35826
-#ifdef SQLITE_PAGECACHE_BLOCKALLOC
35827
- int isBusy; /* Do not run ReleaseMemory() if true */
35828
- PGroupBlockList *pBlockList; /* List of block-lists for this group */
35829
-#endif
35830
-};
35831
-
35832
-/*
35833
-** If SQLITE_PAGECACHE_BLOCKALLOC is defined when the library is built,
35834
-** each PGroup structure has a linked list of the the following starting
35835
-** at PGroup.pBlockList. There is one entry for each distinct page-size
35836
-** currently used by members of the PGroup (i.e. 1024 bytes, 4096 bytes
35837
-** etc.). Variable PGroupBlockList.nByte is set to the actual allocation
35838
-** size requested by each pcache, which is the database page-size plus
35839
-** the various header structures used by the pcache, pager and btree layers.
35840
-** Usually around (pgsz+200) bytes.
35841
-**
35842
-** This size (pgsz+200) bytes is not allocated efficiently by some
35843
-** implementations of malloc. In particular, some implementations are only
35844
-** able to allocate blocks of memory chunks of 2^N bytes, where N is some
35845
-** integer value. Since the page-size is a power of 2, this means we
35846
-** end up wasting (pgsz-200) bytes in each allocation.
35847
-**
35848
-** If SQLITE_PAGECACHE_BLOCKALLOC is defined, the (pgsz+200) byte blocks
35849
-** are not allocated directly. Instead, blocks of roughly M*(pgsz+200) bytes
35850
-** are requested from malloc allocator. After a block is returned,
35851
-** sqlite3MallocSize() is used to determine how many (pgsz+200) byte
35852
-** allocations can fit in the space returned by malloc(). This value may
35853
-** be more than M.
35854
-**
35855
-** The blocks are stored in a doubly-linked list. Variable PGroupBlock.nEntry
35856
-** contains the number of allocations that will fit in the aData[] space.
35857
-** nEntry is limited to the number of bits in bitmask mUsed. If a slot
35858
-** within aData is in use, the corresponding bit in mUsed is set. Thus
35859
-** when (mUsed+1==(1 << nEntry)) the block is completely full.
35860
-**
35861
-** Each time a slot within a block is freed, the block is moved to the start
35862
-** of the linked-list. And if a block becomes completely full, then it is
35863
-** moved to the end of the list. As a result, when searching for a free
35864
-** slot, only the first block in the list need be examined. If it is full,
35865
-** then it is guaranteed that all blocks are full.
35866
-*/
35867
-struct PGroupBlockList {
35868
- int nByte; /* Size of each allocation in bytes */
35869
- PGroupBlock *pFirst; /* First PGroupBlock in list */
35870
- PGroupBlock *pLast; /* Last PGroupBlock in list */
35871
- PGroupBlockList *pNext; /* Next block-list attached to group */
35872
-};
35873
-
35874
-struct PGroupBlock {
35875
- Bitmask mUsed; /* Mask of used slots */
35876
- int nEntry; /* Maximum number of allocations in aData[] */
35877
- u8 *aData; /* Pointer to data block */
35878
- PGroupBlock *pNext; /* Next PGroupBlock in list */
35879
- PGroupBlock *pPrev; /* Previous PGroupBlock in list */
35880
- PGroupBlockList *pList; /* Owner list */
35881
-};
35882
-
35883
-/* Minimum value for PGroupBlock.nEntry */
35884
-#define PAGECACHE_BLOCKALLOC_MINENTRY 15
35966
+};
3588535967
3588635968
/* Each page cache is an instance of the following object. Every
3588735969
** open database file (including each in-memory database and each
3588835970
** temporary or transient database) has a single page cache which
3588935971
** is an instance of this object.
@@ -35983,21 +36065,10 @@
3598336065
**
3598436066
** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
3598536067
*/
3598636068
#define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
3598736069
#define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage)
35988
-
35989
-/*
35990
-** Blocks used by the SQLITE_PAGECACHE_BLOCKALLOC blocks to store/retrieve
35991
-** a PGroupBlock pointer based on a pointer to a page buffer.
35992
-*/
35993
-#define PAGE_SET_BLOCKPTR(pCache, pPg, pBlock) \
35994
- ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) = pBlock )
35995
-
35996
-#define PAGE_GET_BLOCKPTR(pCache, pPg) \
35997
- ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) )
35998
-
3599936070
3600036071
/*
3600136072
** Macros to enter and leave the PCache LRU mutex.
3600236073
*/
3600336074
#define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
@@ -36120,159 +36191,32 @@
3612036191
return iSize;
3612136192
}
3612236193
}
3612336194
#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
3612436195
36125
-#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36126
-/*
36127
-** The block pBlock belongs to list pList but is not currently linked in.
36128
-** Insert it into the start of the list.
36129
-*/
36130
-static void addBlockToList(PGroupBlockList *pList, PGroupBlock *pBlock){
36131
- pBlock->pPrev = 0;
36132
- pBlock->pNext = pList->pFirst;
36133
- pList->pFirst = pBlock;
36134
- if( pBlock->pNext ){
36135
- pBlock->pNext->pPrev = pBlock;
36136
- }else{
36137
- assert( pList->pLast==0 );
36138
- pList->pLast = pBlock;
36139
- }
36140
-}
36141
-
36142
-/*
36143
-** If there are no blocks in the list headed by pList, remove pList
36144
-** from the pGroup->pBlockList list and free it with sqlite3_free().
36145
-*/
36146
-static void freeListIfEmpty(PGroup *pGroup, PGroupBlockList *pList){
36147
- assert( sqlite3_mutex_held(pGroup->mutex) );
36148
- if( pList->pFirst==0 ){
36149
- PGroupBlockList **pp;
36150
- for(pp=&pGroup->pBlockList; *pp!=pList; pp=&(*pp)->pNext);
36151
- *pp = (*pp)->pNext;
36152
- sqlite3_free(pList);
36153
- }
36154
-}
36155
-#endif /* SQLITE_PAGECACHE_BLOCKALLOC */
36156
-
3615736196
/*
3615836197
** Allocate a new page object initially associated with cache pCache.
3615936198
*/
3616036199
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
3616136200
int nByte = sizeof(PgHdr1) + pCache->szPage;
36162
- void *pPg = 0;
36163
- PgHdr1 *p;
36164
-
36165
-#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36166
- PGroup *pGroup = pCache->pGroup;
36167
- PGroupBlockList *pList;
36168
- PGroupBlock *pBlock;
36169
- int i;
36170
-
36171
- nByte += sizeof(PGroupBlockList *);
36172
- nByte = ROUND8(nByte);
36173
-
36174
- for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
36175
- if( pList->nByte==nByte ) break;
36176
- }
36177
- if( pList==0 ){
36178
- PGroupBlockList *pNew;
36179
- assert( pGroup->isBusy==0 );
36180
- assert( sqlite3_mutex_held(pGroup->mutex) );
36181
- pGroup->isBusy = 1; /* Disable sqlite3PcacheReleaseMemory() */
36182
- pNew = (PGroupBlockList *)sqlite3MallocZero(sizeof(PGroupBlockList));
36183
- pGroup->isBusy = 0; /* Reenable sqlite3PcacheReleaseMemory() */
36184
- if( pNew==0 ){
36185
- /* malloc() failure. Return early. */
36186
- return 0;
36187
- }
36188
-#ifdef SQLITE_DEBUG
36189
- for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
36190
- assert( pList->nByte!=nByte );
36191
- }
36192
-#endif
36193
- pNew->nByte = nByte;
36194
- pNew->pNext = pGroup->pBlockList;
36195
- pGroup->pBlockList = pNew;
36196
- pList = pNew;
36197
- }
36198
-
36199
- pBlock = pList->pFirst;
36200
- if( pBlock==0 || pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) ){
36201
- int sz;
36202
-
36203
- /* Allocate a new block. Try to allocate enough space for the PGroupBlock
36204
- ** structure and MINENTRY allocations of nByte bytes each. If the
36205
- ** allocator returns more memory than requested, then more than MINENTRY
36206
- ** allocations may fit in it. */
36207
- assert( sqlite3_mutex_held(pGroup->mutex) );
36208
- pcache1LeaveMutex(pCache->pGroup);
36209
- sz = sizeof(PGroupBlock) + PAGECACHE_BLOCKALLOC_MINENTRY * nByte;
36210
- pBlock = (PGroupBlock *)sqlite3Malloc(sz);
36211
- pcache1EnterMutex(pCache->pGroup);
36212
-
36213
- if( !pBlock ){
36214
- freeListIfEmpty(pGroup, pList);
36215
- return 0;
36216
- }
36217
- pBlock->nEntry = (sqlite3MallocSize(pBlock) - sizeof(PGroupBlock)) / nByte;
36218
- if( pBlock->nEntry>=BMS ){
36219
- pBlock->nEntry = BMS-1;
36220
- }
36221
- pBlock->pList = pList;
36222
- pBlock->mUsed = 0;
36223
- pBlock->aData = (u8 *)&pBlock[1];
36224
- addBlockToList(pList, pBlock);
36225
-
36226
- sz = sqlite3MallocSize(pBlock);
36227
- sqlite3_mutex_enter(pcache1.mutex);
36228
- sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
36229
- sqlite3_mutex_leave(pcache1.mutex);
36230
- }
36231
-
36232
- for(i=0; pPg==0 && ALWAYS(i<pBlock->nEntry); i++){
36233
- if( 0==(pBlock->mUsed & ((Bitmask)1<<i)) ){
36234
- pBlock->mUsed |= ((Bitmask)1<<i);
36235
- pPg = (void *)&pBlock->aData[pList->nByte * i];
36236
- }
36237
- }
36238
- assert( pPg );
36239
- PAGE_SET_BLOCKPTR(pCache, pPg, pBlock);
36240
-
36241
- /* If the block is now full, shift it to the end of the list */
36242
- if( pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) && pList->pLast!=pBlock ){
36243
- assert( pList->pFirst==pBlock );
36244
- assert( pBlock->pPrev==0 );
36245
- assert( pList->pLast->pNext==0 );
36246
- pList->pFirst = pBlock->pNext;
36247
- pList->pFirst->pPrev = 0;
36248
- pBlock->pPrev = pList->pLast;
36249
- pBlock->pNext = 0;
36250
- pList->pLast->pNext = pBlock;
36251
- pList->pLast = pBlock;
36252
- }
36253
- p = PAGE_TO_PGHDR1(pCache, pPg);
36254
- if( pCache->bPurgeable ){
36255
- pCache->pGroup->nCurrentPage++;
36256
- }
36257
-#else
36201
+ PgHdr1 *p = 0;
36202
+ void *pPg;
36203
+
3625836204
/* The group mutex must be released before pcache1Alloc() is called. This
3625936205
** is because it may call sqlite3_release_memory(), which assumes that
3626036206
** this mutex is not held. */
3626136207
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
3626236208
pcache1LeaveMutex(pCache->pGroup);
3626336209
pPg = pcache1Alloc(nByte);
3626436210
pcache1EnterMutex(pCache->pGroup);
36211
+
3626536212
if( pPg ){
3626636213
p = PAGE_TO_PGHDR1(pCache, pPg);
3626736214
if( pCache->bPurgeable ){
3626836215
pCache->pGroup->nCurrentPage++;
3626936216
}
36270
- }else{
36271
- p = 0;
3627236217
}
36273
-#endif
3627436218
return p;
3627536219
}
3627636220
3627736221
/*
3627836222
** Free a page object allocated by pcache1AllocPage().
@@ -36282,53 +36226,12 @@
3628236226
** with a NULL pointer, so we mark the NULL test with ALWAYS().
3628336227
*/
3628436228
static void pcache1FreePage(PgHdr1 *p){
3628536229
if( ALWAYS(p) ){
3628636230
PCache1 *pCache = p->pCache;
36287
- void *pPg = PGHDR1_TO_PAGE(p);
36288
-
36289
-#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36290
- PGroupBlock *pBlock = PAGE_GET_BLOCKPTR(pCache, pPg);
36291
- PGroupBlockList *pList = pBlock->pList;
36292
- int i = ((u8 *)pPg - pBlock->aData) / pList->nByte;
36293
-
36294
- assert( pPg==(void *)&pBlock->aData[i*pList->nByte] );
36295
- assert( pBlock->mUsed & ((Bitmask)1<<i) );
36296
- pBlock->mUsed &= ~((Bitmask)1<<i);
36297
-
36298
- /* Remove the block from the list. If it is completely empty, free it.
36299
- ** Or if it is not completely empty, re-insert it at the start of the
36300
- ** list. */
36301
- if( pList->pFirst==pBlock ){
36302
- pList->pFirst = pBlock->pNext;
36303
- if( pList->pFirst ) pList->pFirst->pPrev = 0;
36304
- }else{
36305
- pBlock->pPrev->pNext = pBlock->pNext;
36306
- }
36307
- if( pList->pLast==pBlock ){
36308
- pList->pLast = pBlock->pPrev;
36309
- if( pList->pLast ) pList->pLast->pNext = 0;
36310
- }else{
36311
- pBlock->pNext->pPrev = pBlock->pPrev;
36312
- }
36313
-
36314
- if( pBlock->mUsed==0 ){
36315
- PGroup *pGroup = p->pCache->pGroup;
36316
-
36317
- int sz = sqlite3MallocSize(pBlock);
36318
- sqlite3_mutex_enter(pcache1.mutex);
36319
- sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -sz);
36320
- sqlite3_mutex_leave(pcache1.mutex);
36321
- freeListIfEmpty(pGroup, pList);
36322
- sqlite3_free(pBlock);
36323
- }else{
36324
- addBlockToList(pList, pBlock);
36325
- }
36326
-#else
3632736231
assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
36328
- pcache1Free(pPg);
36329
-#endif
36232
+ pcache1Free(PGHDR1_TO_PAGE(p));
3633036233
if( pCache->bPurgeable ){
3633136234
pCache->pGroup->nCurrentPage--;
3633236235
}
3633336236
}
3633436237
}
@@ -36935,13 +36838,10 @@
3693536838
** been released, the function returns. The return value is the total number
3693636839
** of bytes of memory released.
3693736840
*/
3693836841
SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
3693936842
int nFree = 0;
36940
-#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36941
- if( pcache1.grp.isBusy ) return 0;
36942
-#endif
3694336843
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
3694436844
assert( sqlite3_mutex_notheld(pcache1.mutex) );
3694536845
if( pcache1.pStart==0 ){
3694636846
PgHdr1 *p;
3694736847
pcache1EnterMutex(&pcache1.grp);
@@ -36980,10 +36880,11 @@
3698036880
}
3698136881
#endif
3698236882
3698336883
/************** End of pcache1.c *********************************************/
3698436884
/************** Begin file rowset.c ******************************************/
36885
+#line 1 "tsrc/rowset.c"
3698536886
/*
3698636887
** 2008 December 3
3698736888
**
3698836889
** The author disclaims copyright to this source code. In place of
3698936890
** a legal notice, here is a blessing:
@@ -37404,10 +37305,11 @@
3740437305
return 0;
3740537306
}
3740637307
3740737308
/************** End of rowset.c **********************************************/
3740837309
/************** Begin file pager.c *******************************************/
37310
+#line 1 "tsrc/pager.c"
3740937311
/*
3741037312
** 2001 September 15
3741137313
**
3741237314
** The author disclaims copyright to this source code. In place of
3741337315
** a legal notice, here is a blessing:
@@ -37427,10 +37329,11 @@
3742737329
** another is writing.
3742837330
*/
3742937331
#ifndef SQLITE_OMIT_DISKIO
3743037332
/************** Include wal.h in the middle of pager.c ***********************/
3743137333
/************** Begin file wal.h *********************************************/
37334
+#line 1 "tsrc/wal.h"
3743237335
/*
3743337336
** 2010 February 1
3743437337
**
3743537338
** The author disclaims copyright to this source code. In place of
3743637339
** a legal notice, here is a blessing:
@@ -37551,10 +37454,11 @@
3755137454
#endif /* ifndef SQLITE_OMIT_WAL */
3755237455
#endif /* _WAL_H_ */
3755337456
3755437457
/************** End of wal.h *************************************************/
3755537458
/************** Continuing where we left off in pager.c **********************/
37459
+#line 24 "tsrc/pager.c"
3755637460
3755737461
3755837462
/******************* NOTES ON THE DESIGN OF THE PAGER ************************
3755937463
**
3756037464
** This comment block describes invariants that hold when using a rollback
@@ -38200,12 +38104,12 @@
3820038104
i64 journalSizeLimit; /* Size limit for persistent journal files */
3820138105
char *zFilename; /* Name of the database file */
3820238106
char *zJournal; /* Name of the journal file */
3820338107
int (*xBusyHandler)(void*); /* Function to call when busy */
3820438108
void *pBusyHandlerArg; /* Context argument for xBusyHandler */
38109
+ int nHit, nMiss; /* Total cache hits and misses */
3820538110
#ifdef SQLITE_TEST
38206
- int nHit, nMiss; /* Cache hits and missing */
3820738111
int nRead, nWrite; /* Database pages read/written */
3820838112
#endif
3820938113
void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */
3821038114
#ifdef SQLITE_HAS_CODEC
3821138115
void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
@@ -41699,11 +41603,11 @@
4169941603
** The doNotSpill flag inhibits all cache spilling regardless of whether
4170041604
** or not a sync is required. This is set during a rollback.
4170141605
**
4170241606
** Spilling is also prohibited when in an error state since that could
4170341607
** lead to database corruption. In the current implementaton it
41704
- ** is impossible for sqlite3PCacheFetch() to be called with createFlag==1
41608
+ ** is impossible for sqlite3PcacheFetch() to be called with createFlag==1
4170541609
** while in the error state, hence it is impossible for this routine to
4170641610
** be called in the error state. Nevertheless, we include a NEVER()
4170741611
** test for the error state as a safeguard against future changes.
4170841612
*/
4170941613
if( NEVER(pPager->errCode) ) return SQLITE_OK;
@@ -42535,18 +42439,17 @@
4253542439
4253642440
if( (*ppPage)->pPager && !noContent ){
4253742441
/* In this case the pcache already contains an initialized copy of
4253842442
** the page. Return without further ado. */
4253942443
assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
42540
- PAGER_INCR(pPager->nHit);
42444
+ pPager->nHit++;
4254142445
return SQLITE_OK;
4254242446
4254342447
}else{
4254442448
/* The pager cache has created a new page. Its content needs to
4254542449
** be initialized. */
4254642450
42547
- PAGER_INCR(pPager->nMiss);
4254842451
pPg = *ppPage;
4254942452
pPg->pPager = pPager;
4255042453
4255142454
/* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
4255242455
** number greater than this, or the unused locking-page, is requested. */
@@ -42578,10 +42481,11 @@
4257842481
}
4257942482
memset(pPg->pData, 0, pPager->pageSize);
4258042483
IOTRACE(("ZERO %p %d\n", pPager, pgno));
4258142484
}else{
4258242485
assert( pPg->pPager==pPager );
42486
+ pPager->nMiss++;
4258342487
rc = readDbPage(pPg);
4258442488
if( rc!=SQLITE_OK ){
4258542489
goto pager_acquire_err;
4258642490
}
4258742491
}
@@ -43611,10 +43515,35 @@
4361143515
a[9] = pPager->nRead;
4361243516
a[10] = pPager->nWrite;
4361343517
return a;
4361443518
}
4361543519
#endif
43520
+
43521
+/*
43522
+** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or
43523
+** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the
43524
+** current cache hit or miss count, according to the value of eStat. If the
43525
+** reset parameter is non-zero, the cache hit or miss count is zeroed before
43526
+** returning.
43527
+*/
43528
+SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){
43529
+ int *piStat;
43530
+
43531
+ assert( eStat==SQLITE_DBSTATUS_CACHE_HIT
43532
+ || eStat==SQLITE_DBSTATUS_CACHE_MISS
43533
+ );
43534
+ if( eStat==SQLITE_DBSTATUS_CACHE_HIT ){
43535
+ piStat = &pPager->nHit;
43536
+ }else{
43537
+ piStat = &pPager->nMiss;
43538
+ }
43539
+
43540
+ *pnVal += *piStat;
43541
+ if( reset ){
43542
+ *piStat = 0;
43543
+ }
43544
+}
4361643545
4361743546
/*
4361843547
** Return true if this is an in-memory pager.
4361943548
*/
4362043549
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
@@ -44362,10 +44291,11 @@
4436244291
4436344292
#endif /* SQLITE_OMIT_DISKIO */
4436444293
4436544294
/************** End of pager.c ***********************************************/
4436644295
/************** Begin file wal.c *********************************************/
44296
+#line 1 "tsrc/wal.c"
4436744297
/*
4436844298
** 2010 February 1
4436944299
**
4437044300
** The author disclaims copyright to this source code. In place of
4437144301
** a legal notice, here is a blessing:
@@ -47316,10 +47246,11 @@
4731647246
4731747247
#endif /* #ifndef SQLITE_OMIT_WAL */
4731847248
4731947249
/************** End of wal.c *************************************************/
4732047250
/************** Begin file btmutex.c *****************************************/
47251
+#line 1 "tsrc/btmutex.c"
4732147252
/*
4732247253
** 2007 August 27
4732347254
**
4732447255
** The author disclaims copyright to this source code. In place of
4732547256
** a legal notice, here is a blessing:
@@ -47335,10 +47266,11 @@
4733547266
** big and we want to break it down some. This packaged seemed like
4733647267
** a good breakout.
4733747268
*/
4733847269
/************** Include btreeInt.h in the middle of btmutex.c ****************/
4733947270
/************** Begin file btreeInt.h ****************************************/
47271
+#line 1 "tsrc/btreeInt.h"
4734047272
/*
4734147273
** 2004 April 6
4734247274
**
4734347275
** The author disclaims copyright to this source code. In place of
4734447276
** a legal notice, here is a blessing:
@@ -47980,10 +47912,11 @@
4798047912
#define get4byte sqlite3Get4byte
4798147913
#define put4byte sqlite3Put4byte
4798247914
4798347915
/************** End of btreeInt.h ********************************************/
4798447916
/************** Continuing where we left off in btmutex.c ********************/
47917
+#line 19 "tsrc/btmutex.c"
4798547918
#ifndef SQLITE_OMIT_SHARED_CACHE
4798647919
#if SQLITE_THREADSAFE
4798747920
4798847921
/*
4798947922
** Obtain the BtShared mutex associated with B-Tree handle p. Also,
@@ -48252,10 +48185,11 @@
4825248185
#endif /* if SQLITE_THREADSAFE */
4825348186
#endif /* ifndef SQLITE_OMIT_SHARED_CACHE */
4825448187
4825548188
/************** End of btmutex.c *********************************************/
4825648189
/************** Begin file btree.c *******************************************/
48190
+#line 1 "tsrc/btree.c"
4825748191
/*
4825848192
** 2004 April 6
4825948193
**
4826048194
** The author disclaims copyright to this source code. In place of
4826148195
** a legal notice, here is a blessing:
@@ -56439,10 +56373,11 @@
5643956373
return rc;
5644056374
}
5644156375
5644256376
/************** End of btree.c ***********************************************/
5644356377
/************** Begin file backup.c ******************************************/
56378
+#line 1 "tsrc/backup.c"
5644456379
/*
5644556380
** 2009 January 28
5644656381
**
5644756382
** The author disclaims copyright to this source code. In place of
5644856383
** a legal notice, here is a blessing:
@@ -57108,13 +57043,21 @@
5710857043
** goes wrong, the transaction on pTo is rolled back. If successful, the
5710957044
** transaction is committed before returning.
5711057045
*/
5711157046
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
5711257047
int rc;
57048
+ sqlite3_file *pFd; /* File descriptor for database pTo */
5711357049
sqlite3_backup b;
5711457050
sqlite3BtreeEnter(pTo);
5711557051
sqlite3BtreeEnter(pFrom);
57052
+
57053
+ assert( sqlite3BtreeIsInTrans(pTo) );
57054
+ pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
57055
+ if( pFd->pMethods ){
57056
+ i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
57057
+ sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
57058
+ }
5711657059
5711757060
/* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
5711857061
** to 0. This is used by the implementations of sqlite3_backup_step()
5711957062
** and sqlite3_backup_finish() to detect that they are being called
5712057063
** from this function, not directly by the user.
@@ -57137,18 +57080,20 @@
5713757080
rc = sqlite3_backup_finish(&b);
5713857081
if( rc==SQLITE_OK ){
5713957082
pTo->pBt->pageSizeFixed = 0;
5714057083
}
5714157084
57085
+ assert( sqlite3BtreeIsInTrans(pTo)==0 );
5714257086
sqlite3BtreeLeave(pFrom);
5714357087
sqlite3BtreeLeave(pTo);
5714457088
return rc;
5714557089
}
5714657090
#endif /* SQLITE_OMIT_VACUUM */
5714757091
5714857092
/************** End of backup.c **********************************************/
5714957093
/************** Begin file vdbemem.c *****************************************/
57094
+#line 1 "tsrc/vdbemem.c"
5715057095
/*
5715157096
** 2004 May 26
5715257097
**
5715357098
** The author disclaims copyright to this source code. In place of
5715457099
** a legal notice, here is a blessing:
@@ -58171,15 +58116,15 @@
5817158116
*ppVal = 0;
5817258117
return SQLITE_OK;
5817358118
}
5817458119
op = pExpr->op;
5817558120
58176
- /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT2.
58121
+ /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT3.
5817758122
** The ifdef here is to enable us to achieve 100% branch test coverage even
58178
- ** when SQLITE_ENABLE_STAT2 is omitted.
58123
+ ** when SQLITE_ENABLE_STAT3 is omitted.
5817958124
*/
58180
-#ifdef SQLITE_ENABLE_STAT2
58125
+#ifdef SQLITE_ENABLE_STAT3
5818158126
if( op==TK_REGISTER ) op = pExpr->op2;
5818258127
#else
5818358128
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
5818458129
#endif
5818558130
@@ -58299,10 +58244,11 @@
5829958244
return 0;
5830058245
}
5830158246
5830258247
/************** End of vdbemem.c *********************************************/
5830358248
/************** Begin file vdbeaux.c *****************************************/
58249
+#line 1 "tsrc/vdbeaux.c"
5830458250
/*
5830558251
** 2003 September 6
5830658252
**
5830758253
** The author disclaims copyright to this source code. In place of
5830858254
** a legal notice, here is a blessing:
@@ -58874,12 +58820,12 @@
5887458820
/*
5887558821
** Change the P2 operand of instruction addr so that it points to
5887658822
** the address of the next instruction to be coded.
5887758823
*/
5887858824
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
58879
- assert( addr>=0 );
58880
- sqlite3VdbeChangeP2(p, addr, p->nOp);
58825
+ assert( addr>=0 || p->db->mallocFailed );
58826
+ if( addr>=0 ) sqlite3VdbeChangeP2(p, addr, p->nOp);
5888158827
}
5888258828
5888358829
5888458830
/*
5888558831
** If the input FuncDef structure is ephemeral, then free it. If
@@ -59441,11 +59387,11 @@
5944159387
SubProgram **apSub = 0; /* Array of sub-vdbes */
5944259388
Mem *pSub = 0; /* Memory cell hold array of subprogs */
5944359389
sqlite3 *db = p->db; /* The database connection */
5944459390
int i; /* Loop counter */
5944559391
int rc = SQLITE_OK; /* Return code */
59446
- Mem *pMem = p->pResultSet = &p->aMem[1]; /* First Mem of result set */
59392
+ Mem *pMem = &p->aMem[1]; /* First Mem of result set */
5944759393
5944859394
assert( p->explain );
5944959395
assert( p->magic==VDBE_MAGIC_RUN );
5945059396
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
5945159397
@@ -59452,10 +59398,11 @@
5945259398
/* Even though this opcode does not use dynamic strings for
5945359399
** the result, result columns may become dynamic if the user calls
5945459400
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
5945559401
*/
5945659402
releaseMemArray(pMem, 8);
59403
+ p->pResultSet = 0;
5945759404
5945859405
if( p->rc==SQLITE_NOMEM ){
5945959406
/* This happens if a malloc() inside a call to sqlite3_column_text() or
5946059407
** sqlite3_column_text16() failed. */
5946159408
db->mallocFailed = 1;
@@ -59606,10 +59553,11 @@
5960659553
pMem->type = SQLITE_NULL;
5960759554
}
5960859555
}
5960959556
5961059557
p->nResColumn = 8 - 4*(p->explain-1);
59558
+ p->pResultSet = &p->aMem[1];
5961159559
p->rc = SQLITE_OK;
5961259560
rc = SQLITE_ROW;
5961359561
}
5961459562
return rc;
5961559563
}
@@ -61538,10 +61486,11 @@
6153861486
}
6153961487
}
6154061488
6154161489
/************** End of vdbeaux.c *********************************************/
6154261490
/************** Begin file vdbeapi.c *****************************************/
61491
+#line 1 "tsrc/vdbeapi.c"
6154361492
/*
6154461493
** 2004 May 26
6154561494
**
6154661495
** The author disclaims copyright to this source code. In place of
6154761496
** a legal notice, here is a blessing:
@@ -62845,10 +62794,11 @@
6284562794
return v;
6284662795
}
6284762796
6284862797
/************** End of vdbeapi.c *********************************************/
6284962798
/************** Begin file vdbetrace.c ***************************************/
62799
+#line 1 "tsrc/vdbetrace.c"
6285062800
/*
6285162801
** 2009 November 25
6285262802
**
6285362803
** The author disclaims copyright to this source code. In place of
6285462804
** a legal notice, here is a blessing:
@@ -63000,10 +62950,11 @@
6300062950
6300162951
#endif /* #ifndef SQLITE_OMIT_TRACE */
6300262952
6300362953
/************** End of vdbetrace.c *******************************************/
6300462954
/************** Begin file vdbe.c ********************************************/
62955
+#line 1 "tsrc/vdbe.c"
6300562956
/*
6300662957
** 2001 September 15
6300762958
**
6300862959
** The author disclaims copyright to this source code. In place of
6300962960
** a legal notice, here is a blessing:
@@ -63469,10 +63420,11 @@
6346963420
** hwtime.h contains inline assembler code for implementing
6347063421
** high-performance timing routines.
6347163422
*/
6347263423
/************** Include hwtime.h in the middle of vdbe.c *********************/
6347363424
/************** Begin file hwtime.h ******************************************/
63425
+#line 1 "tsrc/hwtime.h"
6347463426
/*
6347563427
** 2008 May 27
6347663428
**
6347763429
** The author disclaims copyright to this source code. In place of
6347863430
** a legal notice, here is a blessing:
@@ -63557,10 +63509,11 @@
6355763509
6355863510
#endif /* !defined(_HWTIME_H_) */
6355963511
6356063512
/************** End of hwtime.h **********************************************/
6356163513
/************** Continuing where we left off in vdbe.c ***********************/
63514
+#line 471 "tsrc/vdbe.c"
6356263515
6356363516
#endif
6356463517
6356563518
/*
6356663519
** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
@@ -69801,10 +69754,11 @@
6980169754
goto vdbe_error_halt;
6980269755
}
6980369756
6980469757
/************** End of vdbe.c ************************************************/
6980569758
/************** Begin file vdbeblob.c ****************************************/
69759
+#line 1 "tsrc/vdbeblob.c"
6980669760
/*
6980769761
** 2007 May 1
6980869762
**
6980969763
** The author disclaims copyright to this source code. In place of
6981069764
** a legal notice, here is a blessing:
@@ -70271,10 +70225,11 @@
7027170225
7027270226
#endif /* #ifndef SQLITE_OMIT_INCRBLOB */
7027370227
7027470228
/************** End of vdbeblob.c ********************************************/
7027570229
/************** Begin file vdbesort.c ****************************************/
70230
+#line 1 "tsrc/vdbesort.c"
7027670231
/*
7027770232
** 2011 July 9
7027870233
**
7027970234
** The author disclaims copyright to this source code. In place of
7028070235
** a legal notice, here is a blessing:
@@ -71154,10 +71109,11 @@
7115471109
7115571110
#endif /* #ifndef SQLITE_OMIT_MERGE_SORT */
7115671111
7115771112
/************** End of vdbesort.c ********************************************/
7115871113
/************** Begin file journal.c *****************************************/
71114
+#line 1 "tsrc/journal.c"
7115971115
/*
7116071116
** 2007 August 22
7116171117
**
7116271118
** The author disclaims copyright to this source code. In place of
7116371119
** a legal notice, here is a blessing:
@@ -71394,10 +71350,11 @@
7139471350
}
7139571351
#endif
7139671352
7139771353
/************** End of journal.c *********************************************/
7139871354
/************** Begin file memjournal.c **************************************/
71355
+#line 1 "tsrc/memjournal.c"
7139971356
/*
7140071357
** 2008 October 7
7140171358
**
7140271359
** The author disclaims copyright to this source code. In place of
7140371360
** a legal notice, here is a blessing:
@@ -71655,10 +71612,11 @@
7165571612
return sizeof(MemJournal);
7165671613
}
7165771614
7165871615
/************** End of memjournal.c ******************************************/
7165971616
/************** Begin file walker.c ******************************************/
71617
+#line 1 "tsrc/walker.c"
7166071618
/*
7166171619
** 2008 August 16
7166271620
**
7166371621
** The author disclaims copyright to this source code. In place of
7166471622
** a legal notice, here is a blessing:
@@ -71793,10 +71751,11 @@
7179371751
return rc & WRC_Abort;
7179471752
}
7179571753
7179671754
/************** End of walker.c **********************************************/
7179771755
/************** Begin file resolve.c *****************************************/
71756
+#line 1 "tsrc/resolve.c"
7179871757
/*
7179971758
** 2008 August 18
7180071759
**
7180171760
** The author disclaims copyright to this source code. In place of
7180271761
** a legal notice, here is a blessing:
@@ -73013,10 +72972,11 @@
7301372972
sqlite3WalkSelect(&w, p);
7301472973
}
7301572974
7301672975
/************** End of resolve.c *********************************************/
7301772976
/************** Begin file expr.c ********************************************/
72977
+#line 1 "tsrc/expr.c"
7301872978
/*
7301972979
** 2001 September 15
7302072980
**
7302172981
** The author disclaims copyright to this source code. In place of
7302272982
** a legal notice, here is a blessing:
@@ -76770,10 +76730,11 @@
7677076730
}
7677176731
}
7677276732
7677376733
/************** End of expr.c ************************************************/
7677476734
/************** Begin file alter.c *******************************************/
76735
+#line 1 "tsrc/alter.c"
7677576736
/*
7677676737
** 2005 February 15
7677776738
**
7677876739
** The author disclaims copyright to this source code. In place of
7677976740
** a legal notice, here is a blessing:
@@ -77598,10 +77559,11 @@
7759877559
}
7759977560
#endif /* SQLITE_ALTER_TABLE */
7760077561
7760177562
/************** End of alter.c ***********************************************/
7760277563
/************** Begin file analyze.c *****************************************/
77564
+#line 1 "tsrc/analyze.c"
7760377565
/*
7760477566
** 2005 July 8
7760577567
**
7760677568
** The author disclaims copyright to this source code. In place of
7760777569
** a legal notice, here is a blessing:
@@ -77610,10 +77572,112 @@
7761077572
** May you find forgiveness for yourself and forgive others.
7761177573
** May you share freely, never taking more than you give.
7761277574
**
7761377575
*************************************************************************
7761477576
** This file contains code associated with the ANALYZE command.
77577
+**
77578
+** The ANALYZE command gather statistics about the content of tables
77579
+** and indices. These statistics are made available to the query planner
77580
+** to help it make better decisions about how to perform queries.
77581
+**
77582
+** The following system tables are or have been supported:
77583
+**
77584
+** CREATE TABLE sqlite_stat1(tbl, idx, stat);
77585
+** CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
77586
+** CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
77587
+**
77588
+** Additional tables might be added in future releases of SQLite.
77589
+** The sqlite_stat2 table is not created or used unless the SQLite version
77590
+** is between 3.6.18 and 3.7.8, inclusive, and unless SQLite is compiled
77591
+** with SQLITE_ENABLE_STAT2. The sqlite_stat2 table is deprecated.
77592
+** The sqlite_stat2 table is superceded by sqlite_stat3, which is only
77593
+** created and used by SQLite versions 3.7.9 and later and with
77594
+** SQLITE_ENABLE_STAT3 defined. The fucntionality of sqlite_stat3
77595
+** is a superset of sqlite_stat2.
77596
+**
77597
+** Format of sqlite_stat1:
77598
+**
77599
+** There is normally one row per index, with the index identified by the
77600
+** name in the idx column. The tbl column is the name of the table to
77601
+** which the index belongs. In each such row, the stat column will be
77602
+** a string consisting of a list of integers. The first integer in this
77603
+** list is the number of rows in the index and in the table. The second
77604
+** integer is the average number of rows in the index that have the same
77605
+** value in the first column of the index. The third integer is the average
77606
+** number of rows in the index that have the same value for the first two
77607
+** columns. The N-th integer (for N>1) is the average number of rows in
77608
+** the index which have the same value for the first N-1 columns. For
77609
+** a K-column index, there will be K+1 integers in the stat column. If
77610
+** the index is unique, then the last integer will be 1.
77611
+**
77612
+** The list of integers in the stat column can optionally be followed
77613
+** by the keyword "unordered". The "unordered" keyword, if it is present,
77614
+** must be separated from the last integer by a single space. If the
77615
+** "unordered" keyword is present, then the query planner assumes that
77616
+** the index is unordered and will not use the index for a range query.
77617
+**
77618
+** If the sqlite_stat1.idx column is NULL, then the sqlite_stat1.stat
77619
+** column contains a single integer which is the (estimated) number of
77620
+** rows in the table identified by sqlite_stat1.tbl.
77621
+**
77622
+** Format of sqlite_stat2:
77623
+**
77624
+** The sqlite_stat2 is only created and is only used if SQLite is compiled
77625
+** with SQLITE_ENABLE_STAT2 and if the SQLite version number is between
77626
+** 3.6.18 and 3.7.8. The "stat2" table contains additional information
77627
+** about the distribution of keys within an index. The index is identified by
77628
+** the "idx" column and the "tbl" column is the name of the table to which
77629
+** the index belongs. There are usually 10 rows in the sqlite_stat2
77630
+** table for each index.
77631
+**
77632
+** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
77633
+** inclusive are samples of the left-most key value in the index taken at
77634
+** evenly spaced points along the index. Let the number of samples be S
77635
+** (10 in the standard build) and let C be the number of rows in the index.
77636
+** Then the sampled rows are given by:
77637
+**
77638
+** rownumber = (i*C*2 + C)/(S*2)
77639
+**
77640
+** For i between 0 and S-1. Conceptually, the index space is divided into
77641
+** S uniform buckets and the samples are the middle row from each bucket.
77642
+**
77643
+** The format for sqlite_stat2 is recorded here for legacy reference. This
77644
+** version of SQLite does not support sqlite_stat2. It neither reads nor
77645
+** writes the sqlite_stat2 table. This version of SQLite only supports
77646
+** sqlite_stat3.
77647
+**
77648
+** Format for sqlite_stat3:
77649
+**
77650
+** The sqlite_stat3 is an enhancement to sqlite_stat2. A new name is
77651
+** used to avoid compatibility problems.
77652
+**
77653
+** The format of the sqlite_stat3 table is similar to the format of
77654
+** the sqlite_stat2 table. There are multiple entries for each index.
77655
+** The idx column names the index and the tbl column is the table of the
77656
+** index. If the idx and tbl columns are the same, then the sample is
77657
+** of the INTEGER PRIMARY KEY. The sample column is a value taken from
77658
+** the left-most column of the index. The nEq column is the approximate
77659
+** number of entires in the index whose left-most column exactly matches
77660
+** the sample. nLt is the approximate number of entires whose left-most
77661
+** column is less than the sample. The nDLt column is the approximate
77662
+** number of distinct left-most entries in the index that are less than
77663
+** the sample.
77664
+**
77665
+** Future versions of SQLite might change to store a string containing
77666
+** multiple integers values in the nDLt column of sqlite_stat3. The first
77667
+** integer will be the number of prior index entires that are distinct in
77668
+** the left-most column. The second integer will be the number of prior index
77669
+** entries that are distinct in the first two columns. The third integer
77670
+** will be the number of prior index entries that are distinct in the first
77671
+** three columns. And so forth. With that extension, the nDLt field is
77672
+** similar in function to the sqlite_stat1.stat field.
77673
+**
77674
+** There can be an arbitrary number of sqlite_stat3 entries per index.
77675
+** The ANALYZE command will typically generate sqlite_stat3 tables
77676
+** that contain between 10 and 40 samples which are distributed across
77677
+** the key space, though not uniformly, and which include samples with
77678
+** largest possible nEq values.
7761577679
*/
7761677680
#ifndef SQLITE_OMIT_ANALYZE
7761777681
7761877682
/*
7761977683
** This routine generates code that opens the sqlite_stat1 table for
@@ -77641,12 +77705,18 @@
7764177705
static const struct {
7764277706
const char *zName;
7764377707
const char *zCols;
7764477708
} aTable[] = {
7764577709
{ "sqlite_stat1", "tbl,idx,stat" },
77646
-#ifdef SQLITE_ENABLE_STAT2
77647
- { "sqlite_stat2", "tbl,idx,sampleno,sample" },
77710
+#ifdef SQLITE_ENABLE_STAT3
77711
+ { "sqlite_stat3", "tbl,idx,neq,nlt,ndlt,sample" },
77712
+#endif
77713
+ };
77714
+ static const char *azToDrop[] = {
77715
+ "sqlite_stat2",
77716
+#ifndef SQLITE_ENABLE_STAT3
77717
+ "sqlite_stat3",
7764877718
#endif
7764977719
};
7765077720
7765177721
int aRoot[] = {0, 0};
7765277722
u8 aCreateTbl[] = {0, 0};
@@ -77658,10 +77728,24 @@
7765877728
if( v==0 ) return;
7765977729
assert( sqlite3BtreeHoldsAllMutexes(db) );
7766077730
assert( sqlite3VdbeDb(v)==db );
7766177731
pDb = &db->aDb[iDb];
7766277732
77733
+ /* Drop all statistics tables that this version of SQLite does not
77734
+ ** understand.
77735
+ */
77736
+ for(i=0; i<ArraySize(azToDrop); i++){
77737
+ Table *pTab = sqlite3FindTable(db, azToDrop[i], pDb->zName);
77738
+ if( pTab ){
77739
+ sqlite3CodeDropTable(pParse, pTab, iDb, 0);
77740
+ break;
77741
+ }
77742
+ }
77743
+
77744
+ /* Create new statistic tables if they do not exist, or clear them
77745
+ ** if they do already exist.
77746
+ */
7766377747
for(i=0; i<ArraySize(aTable); i++){
7766477748
const char *zTab = aTable[i].zName;
7766577749
Table *pStat;
7766677750
if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
7766777751
/* The sqlite_stat[12] table does not exist. Create it. Note that a
@@ -77688,17 +77772,237 @@
7768877772
sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
7768977773
}
7769077774
}
7769177775
}
7769277776
77693
- /* Open the sqlite_stat[12] tables for writing. */
77777
+ /* Open the sqlite_stat[13] tables for writing. */
7769477778
for(i=0; i<ArraySize(aTable); i++){
7769577779
sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);
7769677780
sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);
7769777781
sqlite3VdbeChangeP5(v, aCreateTbl[i]);
7769877782
}
7769977783
}
77784
+
77785
+/*
77786
+** Recommended number of samples for sqlite_stat3
77787
+*/
77788
+#ifndef SQLITE_STAT3_SAMPLES
77789
+# define SQLITE_STAT3_SAMPLES 24
77790
+#endif
77791
+
77792
+/*
77793
+** Three SQL functions - stat3_init(), stat3_push(), and stat3_pop() -
77794
+** share an instance of the following structure to hold their state
77795
+** information.
77796
+*/
77797
+typedef struct Stat3Accum Stat3Accum;
77798
+struct Stat3Accum {
77799
+ tRowcnt nRow; /* Number of rows in the entire table */
77800
+ tRowcnt nPSample; /* How often to do a periodic sample */
77801
+ int iMin; /* Index of entry with minimum nEq and hash */
77802
+ int mxSample; /* Maximum number of samples to accumulate */
77803
+ int nSample; /* Current number of samples */
77804
+ u32 iPrn; /* Pseudo-random number used for sampling */
77805
+ struct Stat3Sample {
77806
+ i64 iRowid; /* Rowid in main table of the key */
77807
+ tRowcnt nEq; /* sqlite_stat3.nEq */
77808
+ tRowcnt nLt; /* sqlite_stat3.nLt */
77809
+ tRowcnt nDLt; /* sqlite_stat3.nDLt */
77810
+ u8 isPSample; /* True if a periodic sample */
77811
+ u32 iHash; /* Tiebreaker hash */
77812
+ } *a; /* An array of samples */
77813
+};
77814
+
77815
+#ifdef SQLITE_ENABLE_STAT3
77816
+/*
77817
+** Implementation of the stat3_init(C,S) SQL function. The two parameters
77818
+** are the number of rows in the table or index (C) and the number of samples
77819
+** to accumulate (S).
77820
+**
77821
+** This routine allocates the Stat3Accum object.
77822
+**
77823
+** The return value is the Stat3Accum object (P).
77824
+*/
77825
+static void stat3Init(
77826
+ sqlite3_context *context,
77827
+ int argc,
77828
+ sqlite3_value **argv
77829
+){
77830
+ Stat3Accum *p;
77831
+ tRowcnt nRow;
77832
+ int mxSample;
77833
+ int n;
77834
+
77835
+ UNUSED_PARAMETER(argc);
77836
+ nRow = (tRowcnt)sqlite3_value_int64(argv[0]);
77837
+ mxSample = sqlite3_value_int(argv[1]);
77838
+ n = sizeof(*p) + sizeof(p->a[0])*mxSample;
77839
+ p = sqlite3_malloc( n );
77840
+ if( p==0 ){
77841
+ sqlite3_result_error_nomem(context);
77842
+ return;
77843
+ }
77844
+ memset(p, 0, n);
77845
+ p->a = (struct Stat3Sample*)&p[1];
77846
+ p->nRow = nRow;
77847
+ p->mxSample = mxSample;
77848
+ p->nPSample = p->nRow/(mxSample/3+1) + 1;
77849
+ sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
77850
+ sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
77851
+}
77852
+static const FuncDef stat3InitFuncdef = {
77853
+ 2, /* nArg */
77854
+ SQLITE_UTF8, /* iPrefEnc */
77855
+ 0, /* flags */
77856
+ 0, /* pUserData */
77857
+ 0, /* pNext */
77858
+ stat3Init, /* xFunc */
77859
+ 0, /* xStep */
77860
+ 0, /* xFinalize */
77861
+ "stat3_init", /* zName */
77862
+ 0, /* pHash */
77863
+ 0 /* pDestructor */
77864
+};
77865
+
77866
+
77867
+/*
77868
+** Implementation of the stat3_push(nEq,nLt,nDLt,rowid,P) SQL function. The
77869
+** arguments describe a single key instance. This routine makes the
77870
+** decision about whether or not to retain this key for the sqlite_stat3
77871
+** table.
77872
+**
77873
+** The return value is NULL.
77874
+*/
77875
+static void stat3Push(
77876
+ sqlite3_context *context,
77877
+ int argc,
77878
+ sqlite3_value **argv
77879
+){
77880
+ Stat3Accum *p = (Stat3Accum*)sqlite3_value_blob(argv[4]);
77881
+ tRowcnt nEq = sqlite3_value_int64(argv[0]);
77882
+ tRowcnt nLt = sqlite3_value_int64(argv[1]);
77883
+ tRowcnt nDLt = sqlite3_value_int64(argv[2]);
77884
+ i64 rowid = sqlite3_value_int64(argv[3]);
77885
+ u8 isPSample = 0;
77886
+ u8 doInsert = 0;
77887
+ int iMin = p->iMin;
77888
+ struct Stat3Sample *pSample;
77889
+ int i;
77890
+ u32 h;
77891
+
77892
+ UNUSED_PARAMETER(context);
77893
+ UNUSED_PARAMETER(argc);
77894
+ if( nEq==0 ) return;
77895
+ h = p->iPrn = p->iPrn*1103515245 + 12345;
77896
+ if( (nLt/p->nPSample)!=((nEq+nLt)/p->nPSample) ){
77897
+ doInsert = isPSample = 1;
77898
+ }else if( p->nSample<p->mxSample ){
77899
+ doInsert = 1;
77900
+ }else{
77901
+ if( nEq>p->a[iMin].nEq || (nEq==p->a[iMin].nEq && h>p->a[iMin].iHash) ){
77902
+ doInsert = 1;
77903
+ }
77904
+ }
77905
+ if( !doInsert ) return;
77906
+ if( p->nSample==p->mxSample ){
77907
+ assert( p->nSample - iMin - 1 >= 0 );
77908
+ memmove(&p->a[iMin], &p->a[iMin+1], sizeof(p->a[0])*(p->nSample-iMin-1));
77909
+ pSample = &p->a[p->nSample-1];
77910
+ }else{
77911
+ pSample = &p->a[p->nSample++];
77912
+ }
77913
+ pSample->iRowid = rowid;
77914
+ pSample->nEq = nEq;
77915
+ pSample->nLt = nLt;
77916
+ pSample->nDLt = nDLt;
77917
+ pSample->iHash = h;
77918
+ pSample->isPSample = isPSample;
77919
+
77920
+ /* Find the new minimum */
77921
+ if( p->nSample==p->mxSample ){
77922
+ pSample = p->a;
77923
+ i = 0;
77924
+ while( pSample->isPSample ){
77925
+ i++;
77926
+ pSample++;
77927
+ assert( i<p->nSample );
77928
+ }
77929
+ nEq = pSample->nEq;
77930
+ h = pSample->iHash;
77931
+ iMin = i;
77932
+ for(i++, pSample++; i<p->nSample; i++, pSample++){
77933
+ if( pSample->isPSample ) continue;
77934
+ if( pSample->nEq<nEq
77935
+ || (pSample->nEq==nEq && pSample->iHash<h)
77936
+ ){
77937
+ iMin = i;
77938
+ nEq = pSample->nEq;
77939
+ h = pSample->iHash;
77940
+ }
77941
+ }
77942
+ p->iMin = iMin;
77943
+ }
77944
+}
77945
+static const FuncDef stat3PushFuncdef = {
77946
+ 5, /* nArg */
77947
+ SQLITE_UTF8, /* iPrefEnc */
77948
+ 0, /* flags */
77949
+ 0, /* pUserData */
77950
+ 0, /* pNext */
77951
+ stat3Push, /* xFunc */
77952
+ 0, /* xStep */
77953
+ 0, /* xFinalize */
77954
+ "stat3_push", /* zName */
77955
+ 0, /* pHash */
77956
+ 0 /* pDestructor */
77957
+};
77958
+
77959
+/*
77960
+** Implementation of the stat3_get(P,N,...) SQL function. This routine is
77961
+** used to query the results. Content is returned for the Nth sqlite_stat3
77962
+** row where N is between 0 and S-1 and S is the number of samples. The
77963
+** value returned depends on the number of arguments.
77964
+**
77965
+** argc==2 result: rowid
77966
+** argc==3 result: nEq
77967
+** argc==4 result: nLt
77968
+** argc==5 result: nDLt
77969
+*/
77970
+static void stat3Get(
77971
+ sqlite3_context *context,
77972
+ int argc,
77973
+ sqlite3_value **argv
77974
+){
77975
+ int n = sqlite3_value_int(argv[1]);
77976
+ Stat3Accum *p = (Stat3Accum*)sqlite3_value_blob(argv[0]);
77977
+
77978
+ assert( p!=0 );
77979
+ if( p->nSample<=n ) return;
77980
+ switch( argc ){
77981
+ case 2: sqlite3_result_int64(context, p->a[n].iRowid); break;
77982
+ case 3: sqlite3_result_int64(context, p->a[n].nEq); break;
77983
+ case 4: sqlite3_result_int64(context, p->a[n].nLt); break;
77984
+ default: sqlite3_result_int64(context, p->a[n].nDLt); break;
77985
+ }
77986
+}
77987
+static const FuncDef stat3GetFuncdef = {
77988
+ -1, /* nArg */
77989
+ SQLITE_UTF8, /* iPrefEnc */
77990
+ 0, /* flags */
77991
+ 0, /* pUserData */
77992
+ 0, /* pNext */
77993
+ stat3Get, /* xFunc */
77994
+ 0, /* xStep */
77995
+ 0, /* xFinalize */
77996
+ "stat3_get", /* zName */
77997
+ 0, /* pHash */
77998
+ 0 /* pDestructor */
77999
+};
78000
+#endif /* SQLITE_ENABLE_STAT3 */
78001
+
78002
+
78003
+
7770078004
7770178005
/*
7770278006
** Generate code to do an analysis of all indices associated with
7770378007
** a single table.
7770478008
*/
@@ -77718,24 +78022,31 @@
7771878022
int endOfLoop; /* The end of the loop */
7771978023
int jZeroRows = -1; /* Jump from here if number of rows is zero */
7772078024
int iDb; /* Index of database containing pTab */
7772178025
int regTabname = iMem++; /* Register containing table name */
7772278026
int regIdxname = iMem++; /* Register containing index name */
77723
- int regSampleno = iMem++; /* Register containing next sample number */
77724
- int regCol = iMem++; /* Content of a column analyzed table */
78027
+ int regStat1 = iMem++; /* The stat column of sqlite_stat1 */
78028
+#ifdef SQLITE_ENABLE_STAT3
78029
+ int regNumEq = regStat1; /* Number of instances. Same as regStat1 */
78030
+ int regNumLt = iMem++; /* Number of keys less than regSample */
78031
+ int regNumDLt = iMem++; /* Number of distinct keys less than regSample */
78032
+ int regSample = iMem++; /* The next sample value */
78033
+ int regRowid = regSample; /* Rowid of a sample */
78034
+ int regAccum = iMem++; /* Register to hold Stat3Accum object */
78035
+ int regLoop = iMem++; /* Loop counter */
78036
+ int regCount = iMem++; /* Number of rows in the table or index */
78037
+ int regTemp1 = iMem++; /* Intermediate register */
78038
+ int regTemp2 = iMem++; /* Intermediate register */
78039
+ int once = 1; /* One-time initialization */
78040
+ int shortJump = 0; /* Instruction address */
78041
+ int iTabCur = pParse->nTab++; /* Table cursor */
78042
+#endif
78043
+ int regCol = iMem++; /* Content of a column in analyzed table */
7772578044
int regRec = iMem++; /* Register holding completed record */
7772678045
int regTemp = iMem++; /* Temporary use register */
77727
- int regRowid = iMem++; /* Rowid for the inserted record */
77728
-
77729
-#ifdef SQLITE_ENABLE_STAT2
77730
- int addr = 0; /* Instruction address */
77731
- int regTemp2 = iMem++; /* Temporary use register */
77732
- int regSamplerecno = iMem++; /* Index of next sample to record */
77733
- int regRecno = iMem++; /* Current sample index */
77734
- int regLast = iMem++; /* Index of last sample to record */
77735
- int regFirst = iMem++; /* Index of first sample to record */
77736
-#endif
78046
+ int regNewRowid = iMem++; /* Rowid for the inserted record */
78047
+
7773778048
7773878049
v = sqlite3GetVdbe(pParse);
7773978050
if( v==0 || NEVER(pTab==0) ){
7774078051
return;
7774178052
}
@@ -77764,13 +78075,18 @@
7776478075
iIdxCur = pParse->nTab++;
7776578076
sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
7776678077
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
7776778078
int nCol;
7776878079
KeyInfo *pKey;
78080
+ int addrIfNot = 0; /* address of OP_IfNot */
78081
+ int *aChngAddr; /* Array of jump instruction addresses */
7776978082
7777078083
if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
78084
+ VdbeNoopComment((v, "Begin analysis of %s", pIdx->zName));
7777178085
nCol = pIdx->nColumn;
78086
+ aChngAddr = sqlite3DbMallocRaw(db, sizeof(int)*nCol);
78087
+ if( aChngAddr==0 ) continue;
7777278088
pKey = sqlite3IndexKeyinfo(pParse, pIdx);
7777378089
if( iMem+1+(nCol*2)>pParse->nMem ){
7777478090
pParse->nMem = iMem+1+(nCol*2);
7777578091
}
7777678092
@@ -77781,35 +78097,24 @@
7778178097
VdbeComment((v, "%s", pIdx->zName));
7778278098
7778378099
/* Populate the register containing the index name. */
7778478100
sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
7778578101
77786
-#ifdef SQLITE_ENABLE_STAT2
77787
-
77788
- /* If this iteration of the loop is generating code to analyze the
77789
- ** first index in the pTab->pIndex list, then register regLast has
77790
- ** not been populated. In this case populate it now. */
77791
- if( pTab->pIndex==pIdx ){
77792
- sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regSamplerecno);
77793
- sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2-1, regTemp);
77794
- sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2, regTemp2);
77795
-
77796
- sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regLast);
77797
- sqlite3VdbeAddOp2(v, OP_Null, 0, regFirst);
77798
- addr = sqlite3VdbeAddOp3(v, OP_Lt, regSamplerecno, 0, regLast);
77799
- sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regFirst);
77800
- sqlite3VdbeAddOp3(v, OP_Multiply, regLast, regTemp, regLast);
77801
- sqlite3VdbeAddOp2(v, OP_AddImm, regLast, SQLITE_INDEX_SAMPLES*2-2);
77802
- sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regLast);
77803
- sqlite3VdbeJumpHere(v, addr);
77804
- }
77805
-
77806
- /* Zero the regSampleno and regRecno registers. */
77807
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regSampleno);
77808
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regRecno);
77809
- sqlite3VdbeAddOp2(v, OP_Copy, regFirst, regSamplerecno);
77810
-#endif
78102
+#ifdef SQLITE_ENABLE_STAT3
78103
+ if( once ){
78104
+ once = 0;
78105
+ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
78106
+ }
78107
+ sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regCount);
78108
+ sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_STAT3_SAMPLES, regTemp1);
78109
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, regNumEq);
78110
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, regNumLt);
78111
+ sqlite3VdbeAddOp2(v, OP_Integer, -1, regNumDLt);
78112
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regCount, regAccum,
78113
+ (char*)&stat3InitFuncdef, P4_FUNCDEF);
78114
+ sqlite3VdbeChangeP5(v, 2);
78115
+#endif /* SQLITE_ENABLE_STAT3 */
7781178116
7781278117
/* The block of memory cells initialized here is used as follows.
7781378118
**
7781478119
** iMem:
7781578120
** The total number of rows in the table.
@@ -77835,79 +78140,87 @@
7783578140
/* Start the analysis loop. This loop runs through all the entries in
7783678141
** the index b-tree. */
7783778142
endOfLoop = sqlite3VdbeMakeLabel(v);
7783878143
sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
7783978144
topOfLoop = sqlite3VdbeCurrentAddr(v);
77840
- sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
78145
+ sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1); /* Increment row counter */
7784178146
7784278147
for(i=0; i<nCol; i++){
7784378148
CollSeq *pColl;
7784478149
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
7784578150
if( i==0 ){
77846
-#ifdef SQLITE_ENABLE_STAT2
77847
- /* Check if the record that cursor iIdxCur points to contains a
77848
- ** value that should be stored in the sqlite_stat2 table. If so,
77849
- ** store it. */
77850
- int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno);
77851
- assert( regTabname+1==regIdxname
77852
- && regTabname+2==regSampleno
77853
- && regTabname+3==regCol
77854
- );
77855
- sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
77856
- sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 4, regRec, "aaab", 0);
77857
- sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regRowid);
77858
- sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regRowid);
77859
-
77860
- /* Calculate new values for regSamplerecno and regSampleno.
77861
- **
77862
- ** sampleno = sampleno + 1
77863
- ** samplerecno = samplerecno+(remaining records)/(remaining samples)
77864
- */
77865
- sqlite3VdbeAddOp2(v, OP_AddImm, regSampleno, 1);
77866
- sqlite3VdbeAddOp3(v, OP_Subtract, regRecno, regLast, regTemp);
77867
- sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
77868
- sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regTemp2);
77869
- sqlite3VdbeAddOp3(v, OP_Subtract, regSampleno, regTemp2, regTemp2);
77870
- sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp);
77871
- sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno);
77872
-
77873
- sqlite3VdbeJumpHere(v, ne);
77874
- sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
77875
-#endif
77876
-
7787778151
/* Always record the very first row */
77878
- sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
78152
+ addrIfNot = sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
7787978153
}
7788078154
assert( pIdx->azColl!=0 );
7788178155
assert( pIdx->azColl[i]!=0 );
7788278156
pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
77883
- sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
77884
- (char*)pColl, P4_COLLSEQ);
78157
+ aChngAddr[i] = sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
78158
+ (char*)pColl, P4_COLLSEQ);
7788578159
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
77886
- }
77887
- if( db->mallocFailed ){
77888
- /* If a malloc failure has occurred, then the result of the expression
77889
- ** passed as the second argument to the call to sqlite3VdbeJumpHere()
77890
- ** below may be negative. Which causes an assert() to fail (or an
77891
- ** out-of-bounds write if SQLITE_DEBUG is not defined). */
77892
- return;
78160
+ VdbeComment((v, "jump if column %d changed", i));
78161
+#ifdef SQLITE_ENABLE_STAT3
78162
+ if( i==0 ){
78163
+ sqlite3VdbeAddOp2(v, OP_AddImm, regNumEq, 1);
78164
+ VdbeComment((v, "incr repeat count"));
78165
+ }
78166
+#endif
7789378167
}
7789478168
sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
7789578169
for(i=0; i<nCol; i++){
77896
- int addr2 = sqlite3VdbeCurrentAddr(v) - (nCol*2);
78170
+ sqlite3VdbeJumpHere(v, aChngAddr[i]); /* Set jump dest for the OP_Ne */
7789778171
if( i==0 ){
77898
- sqlite3VdbeJumpHere(v, addr2-1); /* Set jump dest for the OP_IfNot */
78172
+ sqlite3VdbeJumpHere(v, addrIfNot); /* Jump dest for OP_IfNot */
78173
+#ifdef SQLITE_ENABLE_STAT3
78174
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regNumEq, regTemp2,
78175
+ (char*)&stat3PushFuncdef, P4_FUNCDEF);
78176
+ sqlite3VdbeChangeP5(v, 5);
78177
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, pIdx->nColumn, regRowid);
78178
+ sqlite3VdbeAddOp3(v, OP_Add, regNumEq, regNumLt, regNumLt);
78179
+ sqlite3VdbeAddOp2(v, OP_AddImm, regNumDLt, 1);
78180
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, regNumEq);
78181
+#endif
7789978182
}
77900
- sqlite3VdbeJumpHere(v, addr2); /* Set jump dest for the OP_Ne */
7790178183
sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
7790278184
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
7790378185
}
78186
+ sqlite3DbFree(db, aChngAddr);
7790478187
77905
- /* End of the analysis loop. */
78188
+ /* Always jump here after updating the iMem+1...iMem+1+nCol counters */
7790678189
sqlite3VdbeResolveLabel(v, endOfLoop);
78190
+
7790778191
sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
7790878192
sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
78193
+#ifdef SQLITE_ENABLE_STAT3
78194
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regNumEq, regTemp2,
78195
+ (char*)&stat3PushFuncdef, P4_FUNCDEF);
78196
+ sqlite3VdbeChangeP5(v, 5);
78197
+ sqlite3VdbeAddOp2(v, OP_Integer, -1, regLoop);
78198
+ shortJump =
78199
+ sqlite3VdbeAddOp2(v, OP_AddImm, regLoop, 1);
78200
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regTemp1,
78201
+ (char*)&stat3GetFuncdef, P4_FUNCDEF);
78202
+ sqlite3VdbeChangeP5(v, 2);
78203
+ sqlite3VdbeAddOp1(v, OP_IsNull, regTemp1);
78204
+ sqlite3VdbeAddOp3(v, OP_NotExists, iTabCur, shortJump, regTemp1);
78205
+ sqlite3VdbeAddOp3(v, OP_Column, iTabCur, pIdx->aiColumn[0], regSample);
78206
+ sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[0], regSample);
78207
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumEq,
78208
+ (char*)&stat3GetFuncdef, P4_FUNCDEF);
78209
+ sqlite3VdbeChangeP5(v, 3);
78210
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumLt,
78211
+ (char*)&stat3GetFuncdef, P4_FUNCDEF);
78212
+ sqlite3VdbeChangeP5(v, 4);
78213
+ sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumDLt,
78214
+ (char*)&stat3GetFuncdef, P4_FUNCDEF);
78215
+ sqlite3VdbeChangeP5(v, 5);
78216
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regRec, "bbbbbb", 0);
78217
+ sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
78218
+ sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regNewRowid);
78219
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, shortJump);
78220
+ sqlite3VdbeJumpHere(v, shortJump+2);
78221
+#endif
7790978222
7791078223
/* Store the results in sqlite_stat1.
7791178224
**
7791278225
** The result is a single row of the sqlite_stat1 table. The first
7791378226
** two columns are the names of the table and index. The third column
@@ -77923,50 +78236,51 @@
7792378236
**
7792478237
** If K==0 then no entry is made into the sqlite_stat1 table.
7792578238
** If K>0 then it is always the case the D>0 so division by zero
7792678239
** is never possible.
7792778240
*/
77928
- sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno);
78241
+ sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regStat1);
7792978242
if( jZeroRows<0 ){
7793078243
jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
7793178244
}
7793278245
for(i=0; i<nCol; i++){
7793378246
sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0);
77934
- sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
78247
+ sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regStat1, regStat1);
7793578248
sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
7793678249
sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
7793778250
sqlite3VdbeAddOp3(v, OP_Divide, iMem+i+1, regTemp, regTemp);
7793878251
sqlite3VdbeAddOp1(v, OP_ToInt, regTemp);
77939
- sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
78252
+ sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regStat1, regStat1);
7794078253
}
7794178254
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
77942
- sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
77943
- sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
78255
+ sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
78256
+ sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
7794478257
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
7794578258
}
7794678259
7794778260
/* If the table has no indices, create a single sqlite_stat1 entry
7794878261
** containing NULL as the index name and the row count as the content.
7794978262
*/
7795078263
if( pTab->pIndex==0 ){
7795178264
sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb);
7795278265
VdbeComment((v, "%s", pTab->zName));
77953
- sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno);
78266
+ sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat1);
7795478267
sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
77955
- jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regSampleno);
78268
+ jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
7795678269
}else{
7795778270
sqlite3VdbeJumpHere(v, jZeroRows);
7795878271
jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto);
7795978272
}
7796078273
sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
7796178274
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
77962
- sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
77963
- sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
78275
+ sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
78276
+ sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
7796478277
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
7796578278
if( pParse->nMem<regRec ) pParse->nMem = regRec;
7796678279
sqlite3VdbeJumpHere(v, jZeroRows);
7796778280
}
78281
+
7796878282
7796978283
/*
7797078284
** Generate code that will cause the most recent index analysis to
7797178285
** be loaded into internal hash tables where is can be used.
7797278286
*/
@@ -77987,11 +78301,11 @@
7798778301
int iStatCur;
7798878302
int iMem;
7798978303
7799078304
sqlite3BeginWriteOperation(pParse, 0, iDb);
7799178305
iStatCur = pParse->nTab;
77992
- pParse->nTab += 2;
78306
+ pParse->nTab += 3;
7799378307
openStatTable(pParse, iDb, iStatCur, 0, 0);
7799478308
iMem = pParse->nMem+1;
7799578309
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7799678310
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
7799778311
Table *pTab = (Table*)sqliteHashData(k);
@@ -78012,11 +78326,11 @@
7801278326
assert( pTab!=0 );
7801378327
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
7801478328
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
7801578329
sqlite3BeginWriteOperation(pParse, 0, iDb);
7801678330
iStatCur = pParse->nTab;
78017
- pParse->nTab += 2;
78331
+ pParse->nTab += 3;
7801878332
if( pOnlyIdx ){
7801978333
openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");
7802078334
}else{
7802178335
openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
7802278336
}
@@ -78117,11 +78431,11 @@
7811778431
static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
7811878432
analysisInfo *pInfo = (analysisInfo*)pData;
7811978433
Index *pIndex;
7812078434
Table *pTable;
7812178435
int i, c, n;
78122
- unsigned int v;
78436
+ tRowcnt v;
7812378437
const char *z;
7812478438
7812578439
assert( argc==3 );
7812678440
UNUSED_PARAMETER2(NotUsed, argc);
7812778441
@@ -78160,40 +78474,172 @@
7816078474
/*
7816178475
** If the Index.aSample variable is not NULL, delete the aSample[] array
7816278476
** and its contents.
7816378477
*/
7816478478
SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
78165
-#ifdef SQLITE_ENABLE_STAT2
78479
+#ifdef SQLITE_ENABLE_STAT3
7816678480
if( pIdx->aSample ){
7816778481
int j;
78168
- for(j=0; j<SQLITE_INDEX_SAMPLES; j++){
78482
+ for(j=0; j<pIdx->nSample; j++){
7816978483
IndexSample *p = &pIdx->aSample[j];
7817078484
if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
7817178485
sqlite3DbFree(db, p->u.z);
7817278486
}
7817378487
}
7817478488
sqlite3DbFree(db, pIdx->aSample);
78489
+ }
78490
+ if( db && db->pnBytesFreed==0 ){
78491
+ pIdx->nSample = 0;
78492
+ pIdx->aSample = 0;
7817578493
}
7817678494
#else
7817778495
UNUSED_PARAMETER(db);
7817878496
UNUSED_PARAMETER(pIdx);
7817978497
#endif
7818078498
}
7818178499
78500
+#ifdef SQLITE_ENABLE_STAT3
7818278501
/*
78183
-** Load the content of the sqlite_stat1 and sqlite_stat2 tables. The
78502
+** Load content from the sqlite_stat3 table into the Index.aSample[]
78503
+** arrays of all indices.
78504
+*/
78505
+static int loadStat3(sqlite3 *db, const char *zDb){
78506
+ int rc; /* Result codes from subroutines */
78507
+ sqlite3_stmt *pStmt = 0; /* An SQL statement being run */
78508
+ char *zSql; /* Text of the SQL statement */
78509
+ Index *pPrevIdx = 0; /* Previous index in the loop */
78510
+ int idx = 0; /* slot in pIdx->aSample[] for next sample */
78511
+ int eType; /* Datatype of a sample */
78512
+ IndexSample *pSample; /* A slot in pIdx->aSample[] */
78513
+
78514
+ if( !sqlite3FindTable(db, "sqlite_stat3", zDb) ){
78515
+ return SQLITE_OK;
78516
+ }
78517
+
78518
+ zSql = sqlite3MPrintf(db,
78519
+ "SELECT idx,count(*) FROM %Q.sqlite_stat3"
78520
+ " GROUP BY idx", zDb);
78521
+ if( !zSql ){
78522
+ return SQLITE_NOMEM;
78523
+ }
78524
+ rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
78525
+ sqlite3DbFree(db, zSql);
78526
+ if( rc ) return rc;
78527
+
78528
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
78529
+ char *zIndex; /* Index name */
78530
+ Index *pIdx; /* Pointer to the index object */
78531
+ int nSample; /* Number of samples */
78532
+
78533
+ zIndex = (char *)sqlite3_column_text(pStmt, 0);
78534
+ if( zIndex==0 ) continue;
78535
+ nSample = sqlite3_column_int(pStmt, 1);
78536
+ pIdx = sqlite3FindIndex(db, zIndex, zDb);
78537
+ if( pIdx==0 ) continue;
78538
+ assert( pIdx->nSample==0 );
78539
+ pIdx->nSample = nSample;
78540
+ pIdx->aSample = sqlite3MallocZero( nSample*sizeof(IndexSample) );
78541
+ pIdx->avgEq = pIdx->aiRowEst[1];
78542
+ if( pIdx->aSample==0 ){
78543
+ db->mallocFailed = 1;
78544
+ sqlite3_finalize(pStmt);
78545
+ return SQLITE_NOMEM;
78546
+ }
78547
+ }
78548
+ rc = sqlite3_finalize(pStmt);
78549
+ if( rc ) return rc;
78550
+
78551
+ zSql = sqlite3MPrintf(db,
78552
+ "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat3", zDb);
78553
+ if( !zSql ){
78554
+ return SQLITE_NOMEM;
78555
+ }
78556
+ rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
78557
+ sqlite3DbFree(db, zSql);
78558
+ if( rc ) return rc;
78559
+
78560
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
78561
+ char *zIndex; /* Index name */
78562
+ Index *pIdx; /* Pointer to the index object */
78563
+ int i; /* Loop counter */
78564
+ tRowcnt sumEq; /* Sum of the nEq values */
78565
+
78566
+ zIndex = (char *)sqlite3_column_text(pStmt, 0);
78567
+ if( zIndex==0 ) continue;
78568
+ pIdx = sqlite3FindIndex(db, zIndex, zDb);
78569
+ if( pIdx==0 ) continue;
78570
+ if( pIdx==pPrevIdx ){
78571
+ idx++;
78572
+ }else{
78573
+ pPrevIdx = pIdx;
78574
+ idx = 0;
78575
+ }
78576
+ assert( idx<pIdx->nSample );
78577
+ pSample = &pIdx->aSample[idx];
78578
+ pSample->nEq = (tRowcnt)sqlite3_column_int64(pStmt, 1);
78579
+ pSample->nLt = (tRowcnt)sqlite3_column_int64(pStmt, 2);
78580
+ pSample->nDLt = (tRowcnt)sqlite3_column_int64(pStmt, 3);
78581
+ if( idx==pIdx->nSample-1 ){
78582
+ if( pSample->nDLt>0 ){
78583
+ for(i=0, sumEq=0; i<=idx-1; i++) sumEq += pIdx->aSample[i].nEq;
78584
+ pIdx->avgEq = (pSample->nLt - sumEq)/pSample->nDLt;
78585
+ }
78586
+ if( pIdx->avgEq<=0 ) pIdx->avgEq = 1;
78587
+ }
78588
+ eType = sqlite3_column_type(pStmt, 4);
78589
+ pSample->eType = (u8)eType;
78590
+ switch( eType ){
78591
+ case SQLITE_INTEGER: {
78592
+ pSample->u.i = sqlite3_column_int64(pStmt, 4);
78593
+ break;
78594
+ }
78595
+ case SQLITE_FLOAT: {
78596
+ pSample->u.r = sqlite3_column_double(pStmt, 4);
78597
+ break;
78598
+ }
78599
+ case SQLITE_NULL: {
78600
+ break;
78601
+ }
78602
+ default: assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB ); {
78603
+ const char *z = (const char *)(
78604
+ (eType==SQLITE_BLOB) ?
78605
+ sqlite3_column_blob(pStmt, 4):
78606
+ sqlite3_column_text(pStmt, 4)
78607
+ );
78608
+ int n = z ? sqlite3_column_bytes(pStmt, 4) : 0;
78609
+ pSample->nByte = n;
78610
+ if( n < 1){
78611
+ pSample->u.z = 0;
78612
+ }else{
78613
+ pSample->u.z = sqlite3Malloc(n);
78614
+ if( pSample->u.z==0 ){
78615
+ db->mallocFailed = 1;
78616
+ sqlite3_finalize(pStmt);
78617
+ return SQLITE_NOMEM;
78618
+ }
78619
+ memcpy(pSample->u.z, z, n);
78620
+ }
78621
+ }
78622
+ }
78623
+ }
78624
+ return sqlite3_finalize(pStmt);
78625
+}
78626
+#endif /* SQLITE_ENABLE_STAT3 */
78627
+
78628
+/*
78629
+** Load the content of the sqlite_stat1 and sqlite_stat3 tables. The
7818478630
** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
78185
-** arrays. The contents of sqlite_stat2 are used to populate the
78631
+** arrays. The contents of sqlite_stat3 are used to populate the
7818678632
** Index.aSample[] arrays.
7818778633
**
7818878634
** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
78189
-** is returned. In this case, even if SQLITE_ENABLE_STAT2 was defined
78190
-** during compilation and the sqlite_stat2 table is present, no data is
78635
+** is returned. In this case, even if SQLITE_ENABLE_STAT3 was defined
78636
+** during compilation and the sqlite_stat3 table is present, no data is
7819178637
** read from it.
7819278638
**
78193
-** If SQLITE_ENABLE_STAT2 was defined during compilation and the
78194
-** sqlite_stat2 table is not present in the database, SQLITE_ERROR is
78639
+** If SQLITE_ENABLE_STAT3 was defined during compilation and the
78640
+** sqlite_stat3 table is not present in the database, SQLITE_ERROR is
7819578641
** returned. However, in this case, data is read from the sqlite_stat1
7819678642
** table (if it is present) before returning.
7819778643
**
7819878644
** If an OOM error occurs, this function always sets db->mallocFailed.
7819978645
** This means if the caller does not care about other errors, the return
@@ -78211,12 +78657,14 @@
7821178657
/* Clear any prior statistics */
7821278658
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7821378659
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
7821478660
Index *pIdx = sqliteHashData(i);
7821578661
sqlite3DefaultRowEst(pIdx);
78662
+#ifdef SQLITE_ENABLE_STAT3
7821678663
sqlite3DeleteIndexSamples(db, pIdx);
7821778664
pIdx->aSample = 0;
78665
+#endif
7821878666
}
7821978667
7822078668
/* Check to make sure the sqlite_stat1 table exists */
7822178669
sInfo.db = db;
7822278670
sInfo.zDatabase = db->aDb[iDb].zName;
@@ -78224,91 +78672,23 @@
7822478672
return SQLITE_ERROR;
7822578673
}
7822678674
7822778675
/* Load new statistics out of the sqlite_stat1 table */
7822878676
zSql = sqlite3MPrintf(db,
78229
- "SELECT tbl, idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
78677
+ "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
7823078678
if( zSql==0 ){
7823178679
rc = SQLITE_NOMEM;
7823278680
}else{
7823378681
rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
7823478682
sqlite3DbFree(db, zSql);
7823578683
}
7823678684
7823778685
78238
- /* Load the statistics from the sqlite_stat2 table. */
78239
-#ifdef SQLITE_ENABLE_STAT2
78240
- if( rc==SQLITE_OK && !sqlite3FindTable(db, "sqlite_stat2", sInfo.zDatabase) ){
78241
- rc = SQLITE_ERROR;
78242
- }
78243
- if( rc==SQLITE_OK ){
78244
- sqlite3_stmt *pStmt = 0;
78245
-
78246
- zSql = sqlite3MPrintf(db,
78247
- "SELECT idx,sampleno,sample FROM %Q.sqlite_stat2", sInfo.zDatabase);
78248
- if( !zSql ){
78249
- rc = SQLITE_NOMEM;
78250
- }else{
78251
- rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
78252
- sqlite3DbFree(db, zSql);
78253
- }
78254
-
78255
- if( rc==SQLITE_OK ){
78256
- while( sqlite3_step(pStmt)==SQLITE_ROW ){
78257
- char *zIndex; /* Index name */
78258
- Index *pIdx; /* Pointer to the index object */
78259
-
78260
- zIndex = (char *)sqlite3_column_text(pStmt, 0);
78261
- pIdx = zIndex ? sqlite3FindIndex(db, zIndex, sInfo.zDatabase) : 0;
78262
- if( pIdx ){
78263
- int iSample = sqlite3_column_int(pStmt, 1);
78264
- if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
78265
- int eType = sqlite3_column_type(pStmt, 2);
78266
-
78267
- if( pIdx->aSample==0 ){
78268
- static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
78269
- pIdx->aSample = (IndexSample *)sqlite3DbMallocRaw(0, sz);
78270
- if( pIdx->aSample==0 ){
78271
- db->mallocFailed = 1;
78272
- break;
78273
- }
78274
- memset(pIdx->aSample, 0, sz);
78275
- }
78276
-
78277
- assert( pIdx->aSample );
78278
- {
78279
- IndexSample *pSample = &pIdx->aSample[iSample];
78280
- pSample->eType = (u8)eType;
78281
- if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
78282
- pSample->u.r = sqlite3_column_double(pStmt, 2);
78283
- }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
78284
- const char *z = (const char *)(
78285
- (eType==SQLITE_BLOB) ?
78286
- sqlite3_column_blob(pStmt, 2):
78287
- sqlite3_column_text(pStmt, 2)
78288
- );
78289
- int n = sqlite3_column_bytes(pStmt, 2);
78290
- if( n>24 ){
78291
- n = 24;
78292
- }
78293
- pSample->nByte = (u8)n;
78294
- if( n < 1){
78295
- pSample->u.z = 0;
78296
- }else{
78297
- pSample->u.z = sqlite3DbStrNDup(0, z, n);
78298
- if( pSample->u.z==0 ){
78299
- db->mallocFailed = 1;
78300
- break;
78301
- }
78302
- }
78303
- }
78304
- }
78305
- }
78306
- }
78307
- }
78308
- rc = sqlite3_finalize(pStmt);
78309
- }
78686
+ /* Load the statistics from the sqlite_stat3 table. */
78687
+#ifdef SQLITE_ENABLE_STAT3
78688
+ if( rc==SQLITE_OK ){
78689
+ rc = loadStat3(db, sInfo.zDatabase);
7831078690
}
7831178691
#endif
7831278692
7831378693
if( rc==SQLITE_NOMEM ){
7831478694
db->mallocFailed = 1;
@@ -78319,10 +78699,11 @@
7831978699
7832078700
#endif /* SQLITE_OMIT_ANALYZE */
7832178701
7832278702
/************** End of analyze.c *********************************************/
7832378703
/************** Begin file attach.c ******************************************/
78704
+#line 1 "tsrc/attach.c"
7832478705
/*
7832578706
** 2003 April 6
7832678707
**
7832778708
** The author disclaims copyright to this source code. In place of
7832878709
** a legal notice, here is a blessing:
@@ -78878,10 +79259,11 @@
7887879259
}
7887979260
#endif
7888079261
7888179262
/************** End of attach.c **********************************************/
7888279263
/************** Begin file auth.c ********************************************/
79264
+#line 1 "tsrc/auth.c"
7888379265
/*
7888479266
** 2003 January 11
7888579267
**
7888679268
** The author disclaims copyright to this source code. In place of
7888779269
** a legal notice, here is a blessing:
@@ -79129,10 +79511,11 @@
7912979511
7913079512
#endif /* SQLITE_OMIT_AUTHORIZATION */
7913179513
7913279514
/************** End of auth.c ************************************************/
7913379515
/************** Begin file build.c *******************************************/
79516
+#line 1 "tsrc/build.c"
7913479517
/*
7913579518
** 2001 September 15
7913679519
**
7913779520
** The author disclaims copyright to this source code. In place of
7913879521
** a legal notice, here is a blessing:
@@ -81120,11 +81503,15 @@
8112081503
Parse *pParse, /* The parsing context */
8112181504
int iDb, /* The database number */
8112281505
const char *zType, /* "idx" or "tbl" */
8112381506
const char *zName /* Name of index or table */
8112481507
){
81125
- static const char *azStatTab[] = { "sqlite_stat1", "sqlite_stat2" };
81508
+ static const char *azStatTab[] = {
81509
+ "sqlite_stat1",
81510
+ "sqlite_stat2",
81511
+ "sqlite_stat3",
81512
+ };
8112681513
int i;
8112781514
const char *zDbName = pParse->db->aDb[iDb].zName;
8112881515
for(i=0; i<ArraySize(azStatTab); i++){
8112981516
if( sqlite3FindTable(pParse->db, azStatTab[i], zDbName) ){
8113081517
sqlite3NestedParse(pParse,
@@ -81132,10 +81519,80 @@
8113281519
zDbName, azStatTab[i], zType, zName
8113381520
);
8113481521
}
8113581522
}
8113681523
}
81524
+
81525
+/*
81526
+** Generate code to drop a table.
81527
+*/
81528
+SQLITE_PRIVATE void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
81529
+ Vdbe *v;
81530
+ sqlite3 *db = pParse->db;
81531
+ Trigger *pTrigger;
81532
+ Db *pDb = &db->aDb[iDb];
81533
+
81534
+ v = sqlite3GetVdbe(pParse);
81535
+ assert( v!=0 );
81536
+ sqlite3BeginWriteOperation(pParse, 1, iDb);
81537
+
81538
+#ifndef SQLITE_OMIT_VIRTUALTABLE
81539
+ if( IsVirtual(pTab) ){
81540
+ sqlite3VdbeAddOp0(v, OP_VBegin);
81541
+ }
81542
+#endif
81543
+
81544
+ /* Drop all triggers associated with the table being dropped. Code
81545
+ ** is generated to remove entries from sqlite_master and/or
81546
+ ** sqlite_temp_master if required.
81547
+ */
81548
+ pTrigger = sqlite3TriggerList(pParse, pTab);
81549
+ while( pTrigger ){
81550
+ assert( pTrigger->pSchema==pTab->pSchema ||
81551
+ pTrigger->pSchema==db->aDb[1].pSchema );
81552
+ sqlite3DropTriggerPtr(pParse, pTrigger);
81553
+ pTrigger = pTrigger->pNext;
81554
+ }
81555
+
81556
+#ifndef SQLITE_OMIT_AUTOINCREMENT
81557
+ /* Remove any entries of the sqlite_sequence table associated with
81558
+ ** the table being dropped. This is done before the table is dropped
81559
+ ** at the btree level, in case the sqlite_sequence table needs to
81560
+ ** move as a result of the drop (can happen in auto-vacuum mode).
81561
+ */
81562
+ if( pTab->tabFlags & TF_Autoincrement ){
81563
+ sqlite3NestedParse(pParse,
81564
+ "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
81565
+ pDb->zName, pTab->zName
81566
+ );
81567
+ }
81568
+#endif
81569
+
81570
+ /* Drop all SQLITE_MASTER table and index entries that refer to the
81571
+ ** table. The program name loops through the master table and deletes
81572
+ ** every row that refers to a table of the same name as the one being
81573
+ ** dropped. Triggers are handled seperately because a trigger can be
81574
+ ** created in the temp database that refers to a table in another
81575
+ ** database.
81576
+ */
81577
+ sqlite3NestedParse(pParse,
81578
+ "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
81579
+ pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
81580
+ if( !isView && !IsVirtual(pTab) ){
81581
+ destroyTable(pParse, pTab);
81582
+ }
81583
+
81584
+ /* Remove the table entry from SQLite's internal schema and modify
81585
+ ** the schema cookie.
81586
+ */
81587
+ if( IsVirtual(pTab) ){
81588
+ sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
81589
+ }
81590
+ sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
81591
+ sqlite3ChangeCookie(pParse, iDb);
81592
+ sqliteViewResetAll(db, iDb);
81593
+}
8113781594
8113881595
/*
8113981596
** This routine is called to do the work of a DROP TABLE statement.
8114081597
** pName is the name of the table to be dropped.
8114181598
*/
@@ -81225,72 +81682,15 @@
8122581682
/* Generate code to remove the table from the master table
8122681683
** on disk.
8122781684
*/
8122881685
v = sqlite3GetVdbe(pParse);
8122981686
if( v ){
81230
- Trigger *pTrigger;
81231
- Db *pDb = &db->aDb[iDb];
8123281687
sqlite3BeginWriteOperation(pParse, 1, iDb);
81233
-
81234
-#ifndef SQLITE_OMIT_VIRTUALTABLE
81235
- if( IsVirtual(pTab) ){
81236
- sqlite3VdbeAddOp0(v, OP_VBegin);
81237
- }
81238
-#endif
81688
+ sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName);
8123981689
sqlite3FkDropTable(pParse, pName, pTab);
81240
-
81241
- /* Drop all triggers associated with the table being dropped. Code
81242
- ** is generated to remove entries from sqlite_master and/or
81243
- ** sqlite_temp_master if required.
81244
- */
81245
- pTrigger = sqlite3TriggerList(pParse, pTab);
81246
- while( pTrigger ){
81247
- assert( pTrigger->pSchema==pTab->pSchema ||
81248
- pTrigger->pSchema==db->aDb[1].pSchema );
81249
- sqlite3DropTriggerPtr(pParse, pTrigger);
81250
- pTrigger = pTrigger->pNext;
81251
- }
81252
-
81253
-#ifndef SQLITE_OMIT_AUTOINCREMENT
81254
- /* Remove any entries of the sqlite_sequence table associated with
81255
- ** the table being dropped. This is done before the table is dropped
81256
- ** at the btree level, in case the sqlite_sequence table needs to
81257
- ** move as a result of the drop (can happen in auto-vacuum mode).
81258
- */
81259
- if( pTab->tabFlags & TF_Autoincrement ){
81260
- sqlite3NestedParse(pParse,
81261
- "DELETE FROM %s.sqlite_sequence WHERE name=%Q",
81262
- pDb->zName, pTab->zName
81263
- );
81264
- }
81265
-#endif
81266
-
81267
- /* Drop all SQLITE_MASTER table and index entries that refer to the
81268
- ** table. The program name loops through the master table and deletes
81269
- ** every row that refers to a table of the same name as the one being
81270
- ** dropped. Triggers are handled seperately because a trigger can be
81271
- ** created in the temp database that refers to a table in another
81272
- ** database.
81273
- */
81274
- sqlite3NestedParse(pParse,
81275
- "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
81276
- pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
81277
- sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName);
81278
- if( !isView && !IsVirtual(pTab) ){
81279
- destroyTable(pParse, pTab);
81280
- }
81281
-
81282
- /* Remove the table entry from SQLite's internal schema and modify
81283
- ** the schema cookie.
81284
- */
81285
- if( IsVirtual(pTab) ){
81286
- sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
81287
- }
81288
- sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
81289
- sqlite3ChangeCookie(pParse, iDb);
81290
- }
81291
- sqliteViewResetAll(db, iDb);
81690
+ sqlite3CodeDropTable(pParse, pTab, iDb, isView);
81691
+ }
8129281692
8129381693
exit_drop_table:
8129481694
sqlite3SrcListDelete(db, pName);
8129581695
}
8129681696
@@ -81769,24 +82169,24 @@
8176982169
*/
8177082170
nName = sqlite3Strlen30(zName);
8177182171
nCol = pList->nExpr;
8177282172
pIndex = sqlite3DbMallocZero(db,
8177382173
sizeof(Index) + /* Index structure */
82174
+ sizeof(tRowcnt)*(nCol+1) + /* Index.aiRowEst */
8177482175
sizeof(int)*nCol + /* Index.aiColumn */
81775
- sizeof(int)*(nCol+1) + /* Index.aiRowEst */
8177682176
sizeof(char *)*nCol + /* Index.azColl */
8177782177
sizeof(u8)*nCol + /* Index.aSortOrder */
8177882178
nName + 1 + /* Index.zName */
8177982179
nExtra /* Collation sequence names */
8178082180
);
8178182181
if( db->mallocFailed ){
8178282182
goto exit_create_index;
8178382183
}
81784
- pIndex->azColl = (char**)(&pIndex[1]);
82184
+ pIndex->aiRowEst = (tRowcnt*)(&pIndex[1]);
82185
+ pIndex->azColl = (char**)(&pIndex->aiRowEst[nCol+1]);
8178582186
pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
81786
- pIndex->aiRowEst = (unsigned *)(&pIndex->aiColumn[nCol]);
81787
- pIndex->aSortOrder = (u8 *)(&pIndex->aiRowEst[nCol+1]);
82187
+ pIndex->aSortOrder = (u8 *)(&pIndex->aiColumn[nCol]);
8178882188
pIndex->zName = (char *)(&pIndex->aSortOrder[nCol]);
8178982189
zExtra = (char *)(&pIndex->zName[nName+1]);
8179082190
memcpy(pIndex->zName, zName, nName+1);
8179182191
pIndex->pTable = pTab;
8179282192
pIndex->nColumn = pList->nExpr;
@@ -82059,13 +82459,13 @@
8205982459
** Apart from that, we have little to go on besides intuition as to
8206082460
** how aiRowEst[] should be initialized. The numbers generated here
8206182461
** are based on typical values found in actual indices.
8206282462
*/
8206382463
SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
82064
- unsigned *a = pIdx->aiRowEst;
82464
+ tRowcnt *a = pIdx->aiRowEst;
8206582465
int i;
82066
- unsigned n;
82466
+ tRowcnt n;
8206782467
assert( a!=0 );
8206882468
a[0] = pIdx->pTable->nRowEst;
8206982469
if( a[0]<10 ) a[0] = 10;
8207082470
n = 10;
8207182471
for(i=1; i<=pIdx->nColumn; i++){
@@ -82932,10 +83332,11 @@
8293283332
return pKey;
8293383333
}
8293483334
8293583335
/************** End of build.c ***********************************************/
8293683336
/************** Begin file callback.c ****************************************/
83337
+#line 1 "tsrc/callback.c"
8293783338
/*
8293883339
** 2005 May 23
8293983340
**
8294083341
** The author disclaims copyright to this source code. In place of
8294183342
** a legal notice, here is a blessing:
@@ -83391,10 +83792,11 @@
8339183792
return p;
8339283793
}
8339383794
8339483795
/************** End of callback.c ********************************************/
8339583796
/************** Begin file delete.c ******************************************/
83797
+#line 1 "tsrc/delete.c"
8339683798
/*
8339783799
** 2001 September 15
8339883800
**
8339983801
** The author disclaims copyright to this source code. In place of
8340083802
** a legal notice, here is a blessing:
@@ -84045,10 +84447,11 @@
8404584447
return regBase;
8404684448
}
8404784449
8404884450
/************** End of delete.c **********************************************/
8404984451
/************** Begin file func.c ********************************************/
84452
+#line 1 "tsrc/func.c"
8405084453
/*
8405184454
** 2002 February 23
8405284455
**
8405384456
** The author disclaims copyright to this source code. In place of
8405484457
** a legal notice, here is a blessing:
@@ -85653,10 +86056,11 @@
8565386056
#endif
8565486057
}
8565586058
8565686059
/************** End of func.c ************************************************/
8565786060
/************** Begin file fkey.c ********************************************/
86061
+#line 1 "tsrc/fkey.c"
8565886062
/*
8565986063
**
8566086064
** The author disclaims copyright to this source code. In place of
8566186065
** a legal notice, here is a blessing:
8566286066
**
@@ -86873,10 +87277,11 @@
8687387277
}
8687487278
#endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */
8687587279
8687687280
/************** End of fkey.c ************************************************/
8687787281
/************** Begin file insert.c ******************************************/
87282
+#line 1 "tsrc/insert.c"
8687887283
/*
8687987284
** 2001 September 15
8688087285
**
8688187286
** The author disclaims copyright to this source code. In place of
8688287287
** a legal notice, here is a blessing:
@@ -88621,10 +89026,13 @@
8862189026
*/
8862289027
if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
8862389028
return 0;
8862489029
}
8862589030
#endif
89031
+ if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
89032
+ return 0;
89033
+ }
8862689034
8862789035
/* If we get this far, it means either:
8862889036
**
8862989037
** * We can always do the transfer if the table contains an
8863089038
** an integer primary key
@@ -88718,10 +89126,11 @@
8871889126
}
8871989127
#endif /* SQLITE_OMIT_XFER_OPT */
8872089128
8872189129
/************** End of insert.c **********************************************/
8872289130
/************** Begin file legacy.c ******************************************/
89131
+#line 1 "tsrc/legacy.c"
8872389132
/*
8872489133
** 2001 September 15
8872589134
**
8872689135
** The author disclaims copyright to this source code. In place of
8872789136
** a legal notice, here is a blessing:
@@ -88865,10 +89274,11 @@
8886589274
return rc;
8886689275
}
8886789276
8886889277
/************** End of legacy.c **********************************************/
8886989278
/************** Begin file loadext.c *****************************************/
89279
+#line 1 "tsrc/loadext.c"
8887089280
/*
8887189281
** 2006 June 7
8887289282
**
8887389283
** The author disclaims copyright to this source code. In place of
8887489284
** a legal notice, here is a blessing:
@@ -88885,10 +89295,11 @@
8888589295
#ifndef SQLITE_CORE
8888689296
#define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
8888789297
#endif
8888889298
/************** Include sqlite3ext.h in the middle of loadext.c **************/
8888989299
/************** Begin file sqlite3ext.h **************************************/
89300
+#line 1 "tsrc/sqlite3ext.h"
8889089301
/*
8889189302
** 2006 June 7
8889289303
**
8889389304
** The author disclaims copyright to this source code. In place of
8889489305
** a legal notice, here is a blessing:
@@ -89313,10 +89724,11 @@
8931389724
8931489725
#endif /* _SQLITE3EXT_H_ */
8931589726
8931689727
/************** End of sqlite3ext.h ******************************************/
8931789728
/************** Continuing where we left off in loadext.c ********************/
89729
+#line 20 "tsrc/loadext.c"
8931889730
/* #include <string.h> */
8931989731
8932089732
#ifndef SQLITE_OMIT_LOAD_EXTENSION
8932189733
8932289734
/*
@@ -89952,10 +90364,11 @@
8995290364
}
8995390365
}
8995490366
8995590367
/************** End of loadext.c *********************************************/
8995690368
/************** Begin file pragma.c ******************************************/
90369
+#line 1 "tsrc/pragma.c"
8995790370
/*
8995890371
** 2003 April 6
8995990372
**
8996090373
** The author disclaims copyright to this source code. In place of
8996190374
** a legal notice, here is a blessing:
@@ -91480,10 +91893,11 @@
9148091893
9148191894
#endif /* SQLITE_OMIT_PRAGMA */
9148291895
9148391896
/************** End of pragma.c **********************************************/
9148491897
/************** Begin file prepare.c *****************************************/
91898
+#line 1 "tsrc/prepare.c"
9148591899
/*
9148691900
** 2005 May 25
9148791901
**
9148891902
** The author disclaims copyright to this source code. In place of
9148991903
** a legal notice, here is a blessing:
@@ -92340,10 +92754,11 @@
9234092754
9234192755
#endif /* SQLITE_OMIT_UTF16 */
9234292756
9234392757
/************** End of prepare.c *********************************************/
9234492758
/************** Begin file select.c ******************************************/
92759
+#line 1 "tsrc/select.c"
9234592760
/*
9234692761
** 2001 September 15
9234792762
**
9234892763
** The author disclaims copyright to this source code. In place of
9234992764
** a legal notice, here is a blessing:
@@ -96928,10 +97343,11 @@
9692897343
*****************************************************************************/
9692997344
#endif /* defined(SQLITE_TEST) || defined(SQLITE_DEBUG) */
9693097345
9693197346
/************** End of select.c **********************************************/
9693297347
/************** Begin file table.c *******************************************/
97348
+#line 1 "tsrc/table.c"
9693397349
/*
9693497350
** 2001 September 15
9693597351
**
9693697352
** The author disclaims copyright to this source code. In place of
9693797353
** a legal notice, here is a blessing:
@@ -97127,10 +97543,11 @@
9712797543
9712897544
#endif /* SQLITE_OMIT_GET_TABLE */
9712997545
9713097546
/************** End of table.c ***********************************************/
9713197547
/************** Begin file trigger.c *****************************************/
97548
+#line 1 "tsrc/trigger.c"
9713297549
/*
9713397550
**
9713497551
** The author disclaims copyright to this source code. In place of
9713597552
** a legal notice, here is a blessing:
9713697553
**
@@ -98252,10 +98669,11 @@
9825298669
9825398670
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
9825498671
9825598672
/************** End of trigger.c *********************************************/
9825698673
/************** Begin file update.c ******************************************/
98674
+#line 1 "tsrc/update.c"
9825798675
/*
9825898676
** 2001 September 15
9825998677
**
9826098678
** The author disclaims copyright to this source code. In place of
9826198679
** a legal notice, here is a blessing:
@@ -98924,10 +99342,11 @@
9892499342
}
9892599343
#endif /* SQLITE_OMIT_VIRTUALTABLE */
9892699344
9892799345
/************** End of update.c **********************************************/
9892899346
/************** Begin file vacuum.c ******************************************/
99347
+#line 1 "tsrc/vacuum.c"
9892999348
/*
9893099349
** 2003 April 6
9893199350
**
9893299351
** The author disclaims copyright to this source code. In place of
9893399352
** a legal notice, here is a blessing:
@@ -98969,11 +99388,11 @@
9896999388
if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
9897099389
sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
9897199390
return sqlite3_errcode(db);
9897299391
}
9897399392
VVA_ONLY( rc = ) sqlite3_step(pStmt);
98974
- assert( rc!=SQLITE_ROW );
99393
+ assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
9897599394
return vacuumFinalize(db, pStmt, pzErrMsg);
9897699395
}
9897799396
9897899397
/*
9897999398
** Execute zSql on database db. The statement returns exactly
@@ -99187,17 +99606,15 @@
9918799606
" WHERE type='view' OR type='trigger'"
9918899607
" OR (type='table' AND rootpage=0)"
9918999608
);
9919099609
if( rc ) goto end_of_vacuum;
9919199610
99192
- /* At this point, unless the main db was completely empty, there is now a
99193
- ** transaction open on the vacuum database, but not on the main database.
99194
- ** Open a btree level transaction on the main database. This allows a
99195
- ** call to sqlite3BtreeCopyFile(). The main database btree level
99196
- ** transaction is then committed, so the SQL level never knows it was
99197
- ** opened for writing. This way, the SQL transaction used to create the
99198
- ** temporary database never needs to be committed.
99611
+ /* At this point, there is a write transaction open on both the
99612
+ ** vacuum database and the main database. Assuming no error occurs,
99613
+ ** both transactions are closed by this block - the main database
99614
+ ** transaction by sqlite3BtreeCopyFile() and the other by an explicit
99615
+ ** call to sqlite3BtreeCommit().
9919999616
*/
9920099617
{
9920199618
u32 meta;
9920299619
int i;
9920399620
@@ -99270,10 +99687,11 @@
9927099687
9927199688
#endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
9927299689
9927399690
/************** End of vacuum.c **********************************************/
9927499691
/************** Begin file vtab.c ********************************************/
99692
+#line 1 "tsrc/vtab.c"
9927599693
/*
9927699694
** 2006 June 10
9927799695
**
9927899696
** The author disclaims copyright to this source code. In place of
9927999697
** a legal notice, here is a blessing:
@@ -100338,10 +100756,11 @@
100338100756
100339100757
#endif /* SQLITE_OMIT_VIRTUALTABLE */
100340100758
100341100759
/************** End of vtab.c ************************************************/
100342100760
/************** Begin file where.c *******************************************/
100761
+#line 1 "tsrc/where.c"
100343100762
/*
100344100763
** 2001 September 15
100345100764
**
100346100765
** The author disclaims copyright to this source code. In place of
100347100766
** a legal notice, here is a blessing:
@@ -100457,25 +100876,35 @@
100457100876
#define TERM_CODED 0x04 /* This term is already coded */
100458100877
#define TERM_COPIED 0x08 /* Has a child */
100459100878
#define TERM_ORINFO 0x10 /* Need to free the WhereTerm.u.pOrInfo object */
100460100879
#define TERM_ANDINFO 0x20 /* Need to free the WhereTerm.u.pAndInfo obj */
100461100880
#define TERM_OR_OK 0x40 /* Used during OR-clause processing */
100462
-#ifdef SQLITE_ENABLE_STAT2
100881
+#ifdef SQLITE_ENABLE_STAT3
100463100882
# define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
100464100883
#else
100465
-# define TERM_VNULL 0x00 /* Disabled if not using stat2 */
100884
+# define TERM_VNULL 0x00 /* Disabled if not using stat3 */
100466100885
#endif
100467100886
100468100887
/*
100469100888
** An instance of the following structure holds all information about a
100470100889
** WHERE clause. Mostly this is a container for one or more WhereTerms.
100890
+**
100891
+** Explanation of pOuter: For a WHERE clause of the form
100892
+**
100893
+** a AND ((b AND c) OR (d AND e)) AND f
100894
+**
100895
+** There are separate WhereClause objects for the whole clause and for
100896
+** the subclauses "(b AND c)" and "(d AND e)". The pOuter field of the
100897
+** subclauses points to the WhereClause object for the whole clause.
100471100898
*/
100472100899
struct WhereClause {
100473100900
Parse *pParse; /* The parser context */
100474100901
WhereMaskSet *pMaskSet; /* Mapping of table cursor numbers to bitmasks */
100475100902
Bitmask vmask; /* Bitmask identifying virtual table cursors */
100903
+ WhereClause *pOuter; /* Outer conjunction */
100476100904
u8 op; /* Split operator. TK_AND or TK_OR */
100905
+ u16 wctrlFlags; /* Might include WHERE_AND_ONLY */
100477100906
int nTerm; /* Number of terms */
100478100907
int nSlot; /* Number of entries in a[] */
100479100908
WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
100480100909
#if defined(SQLITE_SMALL_STACK)
100481100910
WhereTerm aStatic[1]; /* Initial static space for a[] */
@@ -100600,18 +101029,21 @@
100600101029
** Initialize a preallocated WhereClause structure.
100601101030
*/
100602101031
static void whereClauseInit(
100603101032
WhereClause *pWC, /* The WhereClause to be initialized */
100604101033
Parse *pParse, /* The parsing context */
100605
- WhereMaskSet *pMaskSet /* Mapping from table cursor numbers to bitmasks */
101034
+ WhereMaskSet *pMaskSet, /* Mapping from table cursor numbers to bitmasks */
101035
+ u16 wctrlFlags /* Might include WHERE_AND_ONLY */
100606101036
){
100607101037
pWC->pParse = pParse;
100608101038
pWC->pMaskSet = pMaskSet;
101039
+ pWC->pOuter = 0;
100609101040
pWC->nTerm = 0;
100610101041
pWC->nSlot = ArraySize(pWC->aStatic);
100611101042
pWC->a = pWC->aStatic;
100612101043
pWC->vmask = 0;
101044
+ pWC->wctrlFlags = wctrlFlags;
100613101045
}
100614101046
100615101047
/* Forward reference */
100616101048
static void whereClauseClear(WhereClause*);
100617101049
@@ -100923,40 +101355,42 @@
100923101355
){
100924101356
WhereTerm *pTerm;
100925101357
int k;
100926101358
assert( iCur>=0 );
100927101359
op &= WO_ALL;
100928
- for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
100929
- if( pTerm->leftCursor==iCur
100930
- && (pTerm->prereqRight & notReady)==0
100931
- && pTerm->u.leftColumn==iColumn
100932
- && (pTerm->eOperator & op)!=0
100933
- ){
100934
- if( pIdx && pTerm->eOperator!=WO_ISNULL ){
100935
- Expr *pX = pTerm->pExpr;
100936
- CollSeq *pColl;
100937
- char idxaff;
100938
- int j;
100939
- Parse *pParse = pWC->pParse;
100940
-
100941
- idxaff = pIdx->pTable->aCol[iColumn].affinity;
100942
- if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue;
100943
-
100944
- /* Figure out the collation sequence required from an index for
100945
- ** it to be useful for optimising expression pX. Store this
100946
- ** value in variable pColl.
100947
- */
100948
- assert(pX->pLeft);
100949
- pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
100950
- assert(pColl || pParse->nErr);
100951
-
100952
- for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
100953
- if( NEVER(j>=pIdx->nColumn) ) return 0;
100954
- }
100955
- if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
100956
- }
100957
- return pTerm;
101360
+ for(; pWC; pWC=pWC->pOuter){
101361
+ for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
101362
+ if( pTerm->leftCursor==iCur
101363
+ && (pTerm->prereqRight & notReady)==0
101364
+ && pTerm->u.leftColumn==iColumn
101365
+ && (pTerm->eOperator & op)!=0
101366
+ ){
101367
+ if( pIdx && pTerm->eOperator!=WO_ISNULL ){
101368
+ Expr *pX = pTerm->pExpr;
101369
+ CollSeq *pColl;
101370
+ char idxaff;
101371
+ int j;
101372
+ Parse *pParse = pWC->pParse;
101373
+
101374
+ idxaff = pIdx->pTable->aCol[iColumn].affinity;
101375
+ if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue;
101376
+
101377
+ /* Figure out the collation sequence required from an index for
101378
+ ** it to be useful for optimising expression pX. Store this
101379
+ ** value in variable pColl.
101380
+ */
101381
+ assert(pX->pLeft);
101382
+ pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
101383
+ assert(pColl || pParse->nErr);
101384
+
101385
+ for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
101386
+ if( NEVER(j>=pIdx->nColumn) ) return 0;
101387
+ }
101388
+ if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
101389
+ }
101390
+ return pTerm;
101391
+ }
100958101392
}
100959101393
}
100960101394
return 0;
100961101395
}
100962101396
@@ -101216,11 +101650,11 @@
101216101650
assert( pExpr->op==TK_OR );
101217101651
pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
101218101652
if( pOrInfo==0 ) return;
101219101653
pTerm->wtFlags |= TERM_ORINFO;
101220101654
pOrWc = &pOrInfo->wc;
101221
- whereClauseInit(pOrWc, pWC->pParse, pMaskSet);
101655
+ whereClauseInit(pOrWc, pWC->pParse, pMaskSet, pWC->wctrlFlags);
101222101656
whereSplit(pOrWc, pExpr, TK_OR);
101223101657
exprAnalyzeAll(pSrc, pOrWc);
101224101658
if( db->mallocFailed ) return;
101225101659
assert( pOrWc->nTerm>=2 );
101226101660
@@ -101243,13 +101677,14 @@
101243101677
Bitmask b = 0;
101244101678
pOrTerm->u.pAndInfo = pAndInfo;
101245101679
pOrTerm->wtFlags |= TERM_ANDINFO;
101246101680
pOrTerm->eOperator = WO_AND;
101247101681
pAndWC = &pAndInfo->wc;
101248
- whereClauseInit(pAndWC, pWC->pParse, pMaskSet);
101682
+ whereClauseInit(pAndWC, pWC->pParse, pMaskSet, pWC->wctrlFlags);
101249101683
whereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
101250101684
exprAnalyzeAll(pSrc, pAndWC);
101685
+ pAndWC->pOuter = pWC;
101251101686
testcase( db->mallocFailed );
101252101687
if( !db->mallocFailed ){
101253101688
for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
101254101689
assert( pAndTerm->pExpr );
101255101690
if( allowedOp(pAndTerm->pExpr->op) ){
@@ -101679,12 +102114,12 @@
101679102114
pNewTerm->prereqAll = pTerm->prereqAll;
101680102115
}
101681102116
}
101682102117
#endif /* SQLITE_OMIT_VIRTUALTABLE */
101683102118
101684
-#ifdef SQLITE_ENABLE_STAT2
101685
- /* When sqlite_stat2 histogram data is available an operator of the
102119
+#ifdef SQLITE_ENABLE_STAT3
102120
+ /* When sqlite_stat3 histogram data is available an operator of the
101686102121
** form "x IS NOT NULL" can sometimes be evaluated more efficiently
101687102122
** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
101688102123
** virtual term of that form.
101689102124
**
101690102125
** Note that the virtual term must be tagged with TERM_VNULL. This
@@ -101718,11 +102153,11 @@
101718102153
pTerm->nChild = 1;
101719102154
pTerm->wtFlags |= TERM_COPIED;
101720102155
pNewTerm->prereqAll = pTerm->prereqAll;
101721102156
}
101722102157
}
101723
-#endif /* SQLITE_ENABLE_STAT2 */
102158
+#endif /* SQLITE_ENABLE_STAT */
101724102159
101725102160
/* Prevent ON clause terms of a LEFT JOIN from being used to drive
101726102161
** an index for tables to the left of the join.
101727102162
*/
101728102163
pTerm->prereqRight |= extraRight;
@@ -102140,14 +102575,17 @@
102140102575
const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
102141102576
const Bitmask maskSrc = getMask(pWC->pMaskSet, iCur); /* Bitmask for pSrc */
102142102577
WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */
102143102578
WhereTerm *pTerm; /* A single term of the WHERE clause */
102144102579
102145
- /* No OR-clause optimization allowed if the INDEXED BY or NOT INDEXED clauses
102146
- ** are used */
102580
+ /* The OR-clause optimization is disallowed if the INDEXED BY or
102581
+ ** NOT INDEXED clauses are used or if the WHERE_AND_ONLY bit is set. */
102147102582
if( pSrc->notIndexed || pSrc->pIndex!=0 ){
102148102583
return;
102584
+ }
102585
+ if( pWC->wctrlFlags & WHERE_AND_ONLY ){
102586
+ return;
102149102587
}
102150102588
102151102589
/* Search the WHERE clause terms for a usable WO_OR term. */
102152102590
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
102153102591
if( pTerm->eOperator==WO_OR
@@ -102172,10 +102610,11 @@
102172102610
bestIndex(pParse, pAndWC, pSrc, notReady, notValid, 0, &sTermCost);
102173102611
}else if( pOrTerm->leftCursor==iCur ){
102174102612
WhereClause tempWC;
102175102613
tempWC.pParse = pWC->pParse;
102176102614
tempWC.pMaskSet = pWC->pMaskSet;
102615
+ tempWC.pOuter = pWC;
102177102616
tempWC.op = TK_AND;
102178102617
tempWC.a = pOrTerm;
102179102618
tempWC.nTerm = 1;
102180102619
bestIndex(pParse, &tempWC, pSrc, notReady, notValid, 0, &sTermCost);
102181102620
}else{
@@ -102766,71 +103205,90 @@
102766103205
*/
102767103206
bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
102768103207
}
102769103208
#endif /* SQLITE_OMIT_VIRTUALTABLE */
102770103209
103210
+#ifdef SQLITE_ENABLE_STAT3
102771103211
/*
102772
-** Argument pIdx is a pointer to an index structure that has an array of
102773
-** SQLITE_INDEX_SAMPLES evenly spaced samples of the first indexed column
102774
-** stored in Index.aSample. These samples divide the domain of values stored
102775
-** the index into (SQLITE_INDEX_SAMPLES+1) regions.
102776
-** Region 0 contains all values less than the first sample value. Region
102777
-** 1 contains values between the first and second samples. Region 2 contains
102778
-** values between samples 2 and 3. And so on. Region SQLITE_INDEX_SAMPLES
102779
-** contains values larger than the last sample.
102780
-**
102781
-** If the index contains many duplicates of a single value, then it is
102782
-** possible that two or more adjacent samples can hold the same value.
102783
-** When that is the case, the smallest possible region code is returned
102784
-** when roundUp is false and the largest possible region code is returned
102785
-** when roundUp is true.
102786
-**
102787
-** If successful, this function determines which of the regions value
102788
-** pVal lies in, sets *piRegion to the region index (a value between 0
102789
-** and SQLITE_INDEX_SAMPLES+1, inclusive) and returns SQLITE_OK.
102790
-** Or, if an OOM occurs while converting text values between encodings,
102791
-** SQLITE_NOMEM is returned and *piRegion is undefined.
102792
-*/
102793
-#ifdef SQLITE_ENABLE_STAT2
102794
-static int whereRangeRegion(
103212
+** Estimate the location of a particular key among all keys in an
103213
+** index. Store the results in aStat as follows:
103214
+**
103215
+** aStat[0] Est. number of rows less than pVal
103216
+** aStat[1] Est. number of rows equal to pVal
103217
+**
103218
+** Return SQLITE_OK on success.
103219
+*/
103220
+static int whereKeyStats(
102795103221
Parse *pParse, /* Database connection */
102796103222
Index *pIdx, /* Index to consider domain of */
102797103223
sqlite3_value *pVal, /* Value to consider */
102798
- int roundUp, /* Return largest valid region if true */
102799
- int *piRegion /* OUT: Region of domain in which value lies */
103224
+ int roundUp, /* Round up if true. Round down if false */
103225
+ tRowcnt *aStat /* OUT: stats written here */
102800103226
){
103227
+ tRowcnt n;
103228
+ IndexSample *aSample;
103229
+ int i, eType;
103230
+ int isEq = 0;
103231
+ i64 v;
103232
+ double r, rS;
103233
+
102801103234
assert( roundUp==0 || roundUp==1 );
102802
- if( ALWAYS(pVal) ){
102803
- IndexSample *aSample = pIdx->aSample;
102804
- int i = 0;
102805
- int eType = sqlite3_value_type(pVal);
102806
-
102807
- if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
102808
- double r = sqlite3_value_double(pVal);
102809
- for(i=0; i<SQLITE_INDEX_SAMPLES; i++){
102810
- if( aSample[i].eType==SQLITE_NULL ) continue;
102811
- if( aSample[i].eType>=SQLITE_TEXT ) break;
102812
- if( roundUp ){
102813
- if( aSample[i].u.r>r ) break;
102814
- }else{
102815
- if( aSample[i].u.r>=r ) break;
102816
- }
102817
- }
102818
- }else if( eType==SQLITE_NULL ){
102819
- i = 0;
102820
- if( roundUp ){
102821
- while( i<SQLITE_INDEX_SAMPLES && aSample[i].eType==SQLITE_NULL ) i++;
102822
- }
102823
- }else{
103235
+ assert( pIdx->nSample>0 );
103236
+ if( pVal==0 ) return SQLITE_ERROR;
103237
+ n = pIdx->aiRowEst[0];
103238
+ aSample = pIdx->aSample;
103239
+ i = 0;
103240
+ eType = sqlite3_value_type(pVal);
103241
+
103242
+ if( eType==SQLITE_INTEGER ){
103243
+ v = sqlite3_value_int64(pVal);
103244
+ r = (i64)v;
103245
+ for(i=0; i<pIdx->nSample; i++){
103246
+ if( aSample[i].eType==SQLITE_NULL ) continue;
103247
+ if( aSample[i].eType>=SQLITE_TEXT ) break;
103248
+ if( aSample[i].eType==SQLITE_INTEGER ){
103249
+ if( aSample[i].u.i>=v ){
103250
+ isEq = aSample[i].u.i==v;
103251
+ break;
103252
+ }
103253
+ }else{
103254
+ assert( aSample[i].eType==SQLITE_FLOAT );
103255
+ if( aSample[i].u.r>=r ){
103256
+ isEq = aSample[i].u.r==r;
103257
+ break;
103258
+ }
103259
+ }
103260
+ }
103261
+ }else if( eType==SQLITE_FLOAT ){
103262
+ r = sqlite3_value_double(pVal);
103263
+ for(i=0; i<pIdx->nSample; i++){
103264
+ if( aSample[i].eType==SQLITE_NULL ) continue;
103265
+ if( aSample[i].eType>=SQLITE_TEXT ) break;
103266
+ if( aSample[i].eType==SQLITE_FLOAT ){
103267
+ rS = aSample[i].u.r;
103268
+ }else{
103269
+ rS = aSample[i].u.i;
103270
+ }
103271
+ if( rS>=r ){
103272
+ isEq = rS==r;
103273
+ break;
103274
+ }
103275
+ }
103276
+ }else if( eType==SQLITE_NULL ){
103277
+ i = 0;
103278
+ if( aSample[0].eType==SQLITE_NULL ) isEq = 1;
103279
+ }else{
103280
+ assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
103281
+ for(i=0; i<pIdx->nSample; i++){
103282
+ if( aSample[i].eType==SQLITE_TEXT || aSample[i].eType==SQLITE_BLOB ){
103283
+ break;
103284
+ }
103285
+ }
103286
+ if( i<pIdx->nSample ){
102824103287
sqlite3 *db = pParse->db;
102825103288
CollSeq *pColl;
102826103289
const u8 *z;
102827
- int n;
102828
-
102829
- /* pVal comes from sqlite3ValueFromExpr() so the type cannot be NULL */
102830
- assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
102831
-
102832103290
if( eType==SQLITE_BLOB ){
102833103291
z = (const u8 *)sqlite3_value_blob(pVal);
102834103292
pColl = db->pDfltColl;
102835103293
assert( pColl->enc==SQLITE_UTF8 );
102836103294
}else{
@@ -102845,16 +103303,16 @@
102845103303
return SQLITE_NOMEM;
102846103304
}
102847103305
assert( z && pColl && pColl->xCmp );
102848103306
}
102849103307
n = sqlite3ValueBytes(pVal, pColl->enc);
102850
-
102851
- for(i=0; i<SQLITE_INDEX_SAMPLES; i++){
103308
+
103309
+ for(; i<pIdx->nSample; i++){
102852103310
int c;
102853103311
int eSampletype = aSample[i].eType;
102854
- if( eSampletype==SQLITE_NULL || eSampletype<eType ) continue;
102855
- if( (eSampletype!=eType) ) break;
103312
+ if( eSampletype<eType ) continue;
103313
+ if( eSampletype!=eType ) break;
102856103314
#ifndef SQLITE_OMIT_UTF16
102857103315
if( pColl->enc!=SQLITE_UTF8 ){
102858103316
int nSample;
102859103317
char *zSample = sqlite3Utf8to16(
102860103318
db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
@@ -102868,20 +103326,51 @@
102868103326
}else
102869103327
#endif
102870103328
{
102871103329
c = pColl->xCmp(pColl->pUser, aSample[i].nByte, aSample[i].u.z, n, z);
102872103330
}
102873
- if( c-roundUp>=0 ) break;
103331
+ if( c>=0 ){
103332
+ if( c==0 ) isEq = 1;
103333
+ break;
103334
+ }
102874103335
}
102875103336
}
103337
+ }
102876103338
102877
- assert( i>=0 && i<=SQLITE_INDEX_SAMPLES );
102878
- *piRegion = i;
103339
+ /* At this point, aSample[i] is the first sample that is greater than
103340
+ ** or equal to pVal. Or if i==pIdx->nSample, then all samples are less
103341
+ ** than pVal. If aSample[i]==pVal, then isEq==1.
103342
+ */
103343
+ if( isEq ){
103344
+ assert( i<pIdx->nSample );
103345
+ aStat[0] = aSample[i].nLt;
103346
+ aStat[1] = aSample[i].nEq;
103347
+ }else{
103348
+ tRowcnt iLower, iUpper, iGap;
103349
+ if( i==0 ){
103350
+ iLower = 0;
103351
+ iUpper = aSample[0].nLt;
103352
+ }else{
103353
+ iUpper = i>=pIdx->nSample ? n : aSample[i].nLt;
103354
+ iLower = aSample[i-1].nEq + aSample[i-1].nLt;
103355
+ }
103356
+ aStat[1] = pIdx->avgEq;
103357
+ if( iLower>=iUpper ){
103358
+ iGap = 0;
103359
+ }else{
103360
+ iGap = iUpper - iLower;
103361
+ }
103362
+ if( roundUp ){
103363
+ iGap = (iGap*2)/3;
103364
+ }else{
103365
+ iGap = iGap/3;
103366
+ }
103367
+ aStat[0] = iLower + iGap;
102879103368
}
102880103369
return SQLITE_OK;
102881103370
}
102882
-#endif /* #ifdef SQLITE_ENABLE_STAT2 */
103371
+#endif /* SQLITE_ENABLE_STAT3 */
102883103372
102884103373
/*
102885103374
** If expression pExpr represents a literal value, set *pp to point to
102886103375
** an sqlite3_value structure containing the same value, with affinity
102887103376
** aff applied to it, before returning. It is the responsibility of the
@@ -102895,11 +103384,11 @@
102895103384
**
102896103385
** If neither of the above apply, set *pp to NULL.
102897103386
**
102898103387
** If an error occurs, return an error code. Otherwise, SQLITE_OK.
102899103388
*/
102900
-#ifdef SQLITE_ENABLE_STAT2
103389
+#ifdef SQLITE_ENABLE_STAT3
102901103390
static int valueFromExpr(
102902103391
Parse *pParse,
102903103392
Expr *pExpr,
102904103393
u8 aff,
102905103394
sqlite3_value **pp
@@ -102943,106 +103432,92 @@
102943103432
**
102944103433
** ... FROM t1 WHERE a > ? AND a < ? ...
102945103434
**
102946103435
** then nEq should be passed 0.
102947103436
**
102948
-** The returned value is an integer between 1 and 100, inclusive. A return
102949
-** value of 1 indicates that the proposed range scan is expected to visit
102950
-** approximately 1/100th (1%) of the rows selected by the nEq equality
102951
-** constraints (if any). A return value of 100 indicates that it is expected
102952
-** that the range scan will visit every row (100%) selected by the equality
102953
-** constraints.
103437
+** The returned value is an integer divisor to reduce the estimated
103438
+** search space. A return value of 1 means that range constraints are
103439
+** no help at all. A return value of 2 means range constraints are
103440
+** expected to reduce the search space by half. And so forth...
102954103441
**
102955
-** In the absence of sqlite_stat2 ANALYZE data, each range inequality
102956
-** reduces the search space by 3/4ths. Hence a single constraint (x>?)
102957
-** results in a return of 25 and a range constraint (x>? AND x<?) results
102958
-** in a return of 6.
103442
+** In the absence of sqlite_stat3 ANALYZE data, each range inequality
103443
+** reduces the search space by a factor of 4. Hence a single constraint (x>?)
103444
+** results in a return of 4 and a range constraint (x>? AND x<?) results
103445
+** in a return of 16.
102959103446
*/
102960103447
static int whereRangeScanEst(
102961103448
Parse *pParse, /* Parsing & code generating context */
102962103449
Index *p, /* The index containing the range-compared column; "x" */
102963103450
int nEq, /* index into p->aCol[] of the range-compared column */
102964103451
WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */
102965103452
WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
102966
- int *piEst /* OUT: Return value */
103453
+ double *pRangeDiv /* OUT: Reduce search space by this divisor */
102967103454
){
102968103455
int rc = SQLITE_OK;
102969103456
102970
-#ifdef SQLITE_ENABLE_STAT2
102971
-
102972
- if( nEq==0 && p->aSample ){
102973
- sqlite3_value *pLowerVal = 0;
102974
- sqlite3_value *pUpperVal = 0;
102975
- int iEst;
102976
- int iLower = 0;
102977
- int iUpper = SQLITE_INDEX_SAMPLES;
102978
- int roundUpUpper = 0;
102979
- int roundUpLower = 0;
103457
+#ifdef SQLITE_ENABLE_STAT3
103458
+
103459
+ if( nEq==0 && p->nSample ){
103460
+ sqlite3_value *pRangeVal;
103461
+ tRowcnt iLower = 0;
103462
+ tRowcnt iUpper = p->aiRowEst[0];
103463
+ tRowcnt a[2];
102980103464
u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
102981103465
102982103466
if( pLower ){
102983103467
Expr *pExpr = pLower->pExpr->pRight;
102984
- rc = valueFromExpr(pParse, pExpr, aff, &pLowerVal);
103468
+ rc = valueFromExpr(pParse, pExpr, aff, &pRangeVal);
102985103469
assert( pLower->eOperator==WO_GT || pLower->eOperator==WO_GE );
102986
- roundUpLower = (pLower->eOperator==WO_GT) ?1:0;
103470
+ if( rc==SQLITE_OK
103471
+ && whereKeyStats(pParse, p, pRangeVal, 0, a)==SQLITE_OK
103472
+ ){
103473
+ iLower = a[0];
103474
+ if( pLower->eOperator==WO_GT ) iLower += a[1];
103475
+ }
103476
+ sqlite3ValueFree(pRangeVal);
102987103477
}
102988103478
if( rc==SQLITE_OK && pUpper ){
102989103479
Expr *pExpr = pUpper->pExpr->pRight;
102990
- rc = valueFromExpr(pParse, pExpr, aff, &pUpperVal);
103480
+ rc = valueFromExpr(pParse, pExpr, aff, &pRangeVal);
102991103481
assert( pUpper->eOperator==WO_LT || pUpper->eOperator==WO_LE );
102992
- roundUpUpper = (pUpper->eOperator==WO_LE) ?1:0;
102993
- }
102994
-
102995
- if( rc!=SQLITE_OK || (pLowerVal==0 && pUpperVal==0) ){
102996
- sqlite3ValueFree(pLowerVal);
102997
- sqlite3ValueFree(pUpperVal);
102998
- goto range_est_fallback;
102999
- }else if( pLowerVal==0 ){
103000
- rc = whereRangeRegion(pParse, p, pUpperVal, roundUpUpper, &iUpper);
103001
- if( pLower ) iLower = iUpper/2;
103002
- }else if( pUpperVal==0 ){
103003
- rc = whereRangeRegion(pParse, p, pLowerVal, roundUpLower, &iLower);
103004
- if( pUpper ) iUpper = (iLower + SQLITE_INDEX_SAMPLES + 1)/2;
103005
- }else{
103006
- rc = whereRangeRegion(pParse, p, pUpperVal, roundUpUpper, &iUpper);
103007
- if( rc==SQLITE_OK ){
103008
- rc = whereRangeRegion(pParse, p, pLowerVal, roundUpLower, &iLower);
103009
- }
103010
- }
103011
- WHERETRACE(("range scan regions: %d..%d\n", iLower, iUpper));
103012
-
103013
- iEst = iUpper - iLower;
103014
- testcase( iEst==SQLITE_INDEX_SAMPLES );
103015
- assert( iEst<=SQLITE_INDEX_SAMPLES );
103016
- if( iEst<1 ){
103017
- *piEst = 50/SQLITE_INDEX_SAMPLES;
103018
- }else{
103019
- *piEst = (iEst*100)/SQLITE_INDEX_SAMPLES;
103020
- }
103021
- sqlite3ValueFree(pLowerVal);
103022
- sqlite3ValueFree(pUpperVal);
103023
- return rc;
103024
- }
103025
-range_est_fallback:
103482
+ if( rc==SQLITE_OK
103483
+ && whereKeyStats(pParse, p, pRangeVal, 1, a)==SQLITE_OK
103484
+ ){
103485
+ iUpper = a[0];
103486
+ if( pUpper->eOperator==WO_LE ) iUpper += a[1];
103487
+ }
103488
+ sqlite3ValueFree(pRangeVal);
103489
+ }
103490
+ if( rc==SQLITE_OK ){
103491
+ if( iUpper<=iLower ){
103492
+ *pRangeDiv = (double)p->aiRowEst[0];
103493
+ }else{
103494
+ *pRangeDiv = (double)p->aiRowEst[0]/(double)(iUpper - iLower);
103495
+ }
103496
+ WHERETRACE(("range scan regions: %u..%u div=%g\n",
103497
+ (u32)iLower, (u32)iUpper, *pRangeDiv));
103498
+ return SQLITE_OK;
103499
+ }
103500
+ }
103026103501
#else
103027103502
UNUSED_PARAMETER(pParse);
103028103503
UNUSED_PARAMETER(p);
103029103504
UNUSED_PARAMETER(nEq);
103030103505
#endif
103031103506
assert( pLower || pUpper );
103032
- *piEst = 100;
103033
- if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ) *piEst /= 4;
103034
- if( pUpper ) *piEst /= 4;
103507
+ *pRangeDiv = (double)1;
103508
+ if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ) *pRangeDiv *= (double)4;
103509
+ if( pUpper ) *pRangeDiv *= (double)4;
103035103510
return rc;
103036103511
}
103037103512
103038
-#ifdef SQLITE_ENABLE_STAT2
103513
+#ifdef SQLITE_ENABLE_STAT3
103039103514
/*
103040103515
** Estimate the number of rows that will be returned based on
103041103516
** an equality constraint x=VALUE and where that VALUE occurs in
103042103517
** the histogram data. This only works when x is the left-most
103043
-** column of an index and sqlite_stat2 histogram data is available
103518
+** column of an index and sqlite_stat3 histogram data is available
103044103519
** for that index. When pExpr==NULL that means the constraint is
103045103520
** "x IS NULL" instead of "x=VALUE".
103046103521
**
103047103522
** Write the estimated row count into *pnRow and return SQLITE_OK.
103048103523
** If unable to make an estimate, leave *pnRow unchanged and return
@@ -103058,44 +103533,36 @@
103058103533
Index *p, /* The index whose left-most column is pTerm */
103059103534
Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
103060103535
double *pnRow /* Write the revised row estimate here */
103061103536
){
103062103537
sqlite3_value *pRhs = 0; /* VALUE on right-hand side of pTerm */
103063
- int iLower, iUpper; /* Range of histogram regions containing pRhs */
103064103538
u8 aff; /* Column affinity */
103065103539
int rc; /* Subfunction return code */
103066
- double nRowEst; /* New estimate of the number of rows */
103540
+ tRowcnt a[2]; /* Statistics */
103067103541
103068103542
assert( p->aSample!=0 );
103543
+ assert( p->nSample>0 );
103069103544
aff = p->pTable->aCol[p->aiColumn[0]].affinity;
103070103545
if( pExpr ){
103071103546
rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
103072103547
if( rc ) goto whereEqualScanEst_cancel;
103073103548
}else{
103074103549
pRhs = sqlite3ValueNew(pParse->db);
103075103550
}
103076103551
if( pRhs==0 ) return SQLITE_NOTFOUND;
103077
- rc = whereRangeRegion(pParse, p, pRhs, 0, &iLower);
103078
- if( rc ) goto whereEqualScanEst_cancel;
103079
- rc = whereRangeRegion(pParse, p, pRhs, 1, &iUpper);
103080
- if( rc ) goto whereEqualScanEst_cancel;
103081
- WHERETRACE(("equality scan regions: %d..%d\n", iLower, iUpper));
103082
- if( iLower>=iUpper ){
103083
- nRowEst = p->aiRowEst[0]/(SQLITE_INDEX_SAMPLES*2);
103084
- if( nRowEst<*pnRow ) *pnRow = nRowEst;
103085
- }else{
103086
- nRowEst = (iUpper-iLower)*p->aiRowEst[0]/SQLITE_INDEX_SAMPLES;
103087
- *pnRow = nRowEst;
103088
- }
103089
-
103552
+ rc = whereKeyStats(pParse, p, pRhs, 0, a);
103553
+ if( rc==SQLITE_OK ){
103554
+ WHERETRACE(("equality scan regions: %d\n", (int)a[1]));
103555
+ *pnRow = a[1];
103556
+ }
103090103557
whereEqualScanEst_cancel:
103091103558
sqlite3ValueFree(pRhs);
103092103559
return rc;
103093103560
}
103094
-#endif /* defined(SQLITE_ENABLE_STAT2) */
103561
+#endif /* defined(SQLITE_ENABLE_STAT3) */
103095103562
103096
-#ifdef SQLITE_ENABLE_STAT2
103563
+#ifdef SQLITE_ENABLE_STAT3
103097103564
/*
103098103565
** Estimate the number of rows that will be returned based on
103099103566
** an IN constraint where the right-hand side of the IN operator
103100103567
** is a list of values. Example:
103101103568
**
@@ -103114,64 +103581,29 @@
103114103581
Parse *pParse, /* Parsing & code generating context */
103115103582
Index *p, /* The index whose left-most column is pTerm */
103116103583
ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
103117103584
double *pnRow /* Write the revised row estimate here */
103118103585
){
103119
- sqlite3_value *pVal = 0; /* One value from list */
103120
- int iLower, iUpper; /* Range of histogram regions containing pRhs */
103121
- u8 aff; /* Column affinity */
103122
- int rc = SQLITE_OK; /* Subfunction return code */
103123
- double nRowEst; /* New estimate of the number of rows */
103124
- int nSpan = 0; /* Number of histogram regions spanned */
103125
- int nSingle = 0; /* Histogram regions hit by a single value */
103126
- int nNotFound = 0; /* Count of values that are not constants */
103127
- int i; /* Loop counter */
103128
- u8 aSpan[SQLITE_INDEX_SAMPLES+1]; /* Histogram regions that are spanned */
103129
- u8 aSingle[SQLITE_INDEX_SAMPLES+1]; /* Histogram regions hit once */
103586
+ int rc = SQLITE_OK; /* Subfunction return code */
103587
+ double nEst; /* Number of rows for a single term */
103588
+ double nRowEst = (double)0; /* New estimate of the number of rows */
103589
+ int i; /* Loop counter */
103130103590
103131103591
assert( p->aSample!=0 );
103132
- aff = p->pTable->aCol[p->aiColumn[0]].affinity;
103133
- memset(aSpan, 0, sizeof(aSpan));
103134
- memset(aSingle, 0, sizeof(aSingle));
103135
- for(i=0; i<pList->nExpr; i++){
103136
- sqlite3ValueFree(pVal);
103137
- rc = valueFromExpr(pParse, pList->a[i].pExpr, aff, &pVal);
103138
- if( rc ) break;
103139
- if( pVal==0 || sqlite3_value_type(pVal)==SQLITE_NULL ){
103140
- nNotFound++;
103141
- continue;
103142
- }
103143
- rc = whereRangeRegion(pParse, p, pVal, 0, &iLower);
103144
- if( rc ) break;
103145
- rc = whereRangeRegion(pParse, p, pVal, 1, &iUpper);
103146
- if( rc ) break;
103147
- if( iLower>=iUpper ){
103148
- aSingle[iLower] = 1;
103149
- }else{
103150
- assert( iLower>=0 && iUpper<=SQLITE_INDEX_SAMPLES );
103151
- while( iLower<iUpper ) aSpan[iLower++] = 1;
103152
- }
103592
+ for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){
103593
+ nEst = p->aiRowEst[0];
103594
+ rc = whereEqualScanEst(pParse, p, pList->a[i].pExpr, &nEst);
103595
+ nRowEst += nEst;
103153103596
}
103154103597
if( rc==SQLITE_OK ){
103155
- for(i=nSpan=0; i<=SQLITE_INDEX_SAMPLES; i++){
103156
- if( aSpan[i] ){
103157
- nSpan++;
103158
- }else if( aSingle[i] ){
103159
- nSingle++;
103160
- }
103161
- }
103162
- nRowEst = (nSpan*2+nSingle)*p->aiRowEst[0]/(2*SQLITE_INDEX_SAMPLES)
103163
- + nNotFound*p->aiRowEst[1];
103164103598
if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
103165103599
*pnRow = nRowEst;
103166
- WHERETRACE(("IN row estimate: nSpan=%d, nSingle=%d, nNotFound=%d, est=%g\n",
103167
- nSpan, nSingle, nNotFound, nRowEst));
103600
+ WHERETRACE(("IN row estimate: est=%g\n", nRowEst));
103168103601
}
103169
- sqlite3ValueFree(pVal);
103170103602
return rc;
103171103603
}
103172
-#endif /* defined(SQLITE_ENABLE_STAT2) */
103604
+#endif /* defined(SQLITE_ENABLE_STAT3) */
103173103605
103174103606
103175103607
/*
103176103608
** Find the best query plan for accessing a particular table. Write the
103177103609
** best query plan and its cost into the WhereCost object supplied as the
@@ -103214,11 +103646,11 @@
103214103646
Index *pProbe; /* An index we are evaluating */
103215103647
Index *pIdx; /* Copy of pProbe, or zero for IPK index */
103216103648
int eqTermMask; /* Current mask of valid equality operators */
103217103649
int idxEqTermMask; /* Index mask of valid equality operators */
103218103650
Index sPk; /* A fake index object for the primary key */
103219
- unsigned int aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
103651
+ tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
103220103652
int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
103221103653
int wsFlagMask; /* Allowed flags in pCost->plan.wsFlag */
103222103654
103223103655
/* Initialize the cost to a worst-case value */
103224103656
memset(pCost, 0, sizeof(*pCost));
@@ -103269,14 +103701,14 @@
103269103701
}
103270103702
103271103703
/* Loop over all indices looking for the best one to use
103272103704
*/
103273103705
for(; pProbe; pIdx=pProbe=pProbe->pNext){
103274
- const unsigned int * const aiRowEst = pProbe->aiRowEst;
103706
+ const tRowcnt * const aiRowEst = pProbe->aiRowEst;
103275103707
double cost; /* Cost of using pProbe */
103276103708
double nRow; /* Estimated number of rows in result set */
103277
- double log10N; /* base-10 logarithm of nRow (inexact) */
103709
+ double log10N = (double)1; /* base-10 logarithm of nRow (inexact) */
103278103710
int rev; /* True to scan in reverse order */
103279103711
int wsFlags = 0;
103280103712
Bitmask used = 0;
103281103713
103282103714
/* The following variables are populated based on the properties of
@@ -103312,18 +103744,16 @@
103312103744
** Set to true if there was at least one "x IN (SELECT ...)" term used
103313103745
** in determining the value of nInMul. Note that the RHS of the
103314103746
** IN operator must be a SELECT, not a value list, for this variable
103315103747
** to be true.
103316103748
**
103317
- ** estBound:
103318
- ** An estimate on the amount of the table that must be searched. A
103319
- ** value of 100 means the entire table is searched. Range constraints
103320
- ** might reduce this to a value less than 100 to indicate that only
103321
- ** a fraction of the table needs searching. In the absence of
103322
- ** sqlite_stat2 ANALYZE data, a single inequality reduces the search
103323
- ** space to 1/4rd its original size. So an x>? constraint reduces
103324
- ** estBound to 25. Two constraints (x>? AND x<?) reduce estBound to 6.
103749
+ ** rangeDiv:
103750
+ ** An estimate of a divisor by which to reduce the search space due
103751
+ ** to inequality constraints. In the absence of sqlite_stat3 ANALYZE
103752
+ ** data, a single inequality reduces the search space to 1/4rd its
103753
+ ** original size (rangeDiv==4). Two inequalities reduce the search
103754
+ ** space to 1/16th of its original size (rangeDiv==16).
103325103755
**
103326103756
** bSort:
103327103757
** Boolean. True if there is an ORDER BY clause that will require an
103328103758
** external sort (i.e. scanning the index being evaluated will not
103329103759
** correctly order records).
@@ -103344,26 +103774,27 @@
103344103774
** SELECT a, b, c FROM tbl WHERE a = 1;
103345103775
*/
103346103776
int nEq; /* Number of == or IN terms matching index */
103347103777
int bInEst = 0; /* True if "x IN (SELECT...)" seen */
103348103778
int nInMul = 1; /* Number of distinct equalities to lookup */
103349
- int estBound = 100; /* Estimated reduction in search space */
103779
+ double rangeDiv = (double)1; /* Estimated reduction in search space */
103350103780
int nBound = 0; /* Number of range constraints seen */
103351103781
int bSort = !!pOrderBy; /* True if external sort required */
103352103782
int bDist = !!pDistinct; /* True if index cannot help with DISTINCT */
103353103783
int bLookup = 0; /* True if not a covering index */
103354103784
WhereTerm *pTerm; /* A single term of the WHERE clause */
103355
-#ifdef SQLITE_ENABLE_STAT2
103785
+#ifdef SQLITE_ENABLE_STAT3
103356103786
WhereTerm *pFirstTerm = 0; /* First term matching the index */
103357103787
#endif
103358103788
103359103789
/* Determine the values of nEq and nInMul */
103360103790
for(nEq=0; nEq<pProbe->nColumn; nEq++){
103361103791
int j = pProbe->aiColumn[nEq];
103362103792
pTerm = findTerm(pWC, iCur, j, notReady, eqTermMask, pIdx);
103363103793
if( pTerm==0 ) break;
103364103794
wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
103795
+ testcase( pTerm->pWC!=pWC );
103365103796
if( pTerm->eOperator & WO_IN ){
103366103797
Expr *pExpr = pTerm->pExpr;
103367103798
wsFlags |= WHERE_COLUMN_IN;
103368103799
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
103369103800
/* "x IN (SELECT ...)": Assume the SELECT returns 25 rows */
@@ -103374,32 +103805,34 @@
103374103805
nInMul *= pExpr->x.pList->nExpr;
103375103806
}
103376103807
}else if( pTerm->eOperator & WO_ISNULL ){
103377103808
wsFlags |= WHERE_COLUMN_NULL;
103378103809
}
103379
-#ifdef SQLITE_ENABLE_STAT2
103810
+#ifdef SQLITE_ENABLE_STAT3
103380103811
if( nEq==0 && pProbe->aSample ) pFirstTerm = pTerm;
103381103812
#endif
103382103813
used |= pTerm->prereqRight;
103383103814
}
103384103815
103385
- /* Determine the value of estBound. */
103816
+ /* Determine the value of rangeDiv */
103386103817
if( nEq<pProbe->nColumn && pProbe->bUnordered==0 ){
103387103818
int j = pProbe->aiColumn[nEq];
103388103819
if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
103389103820
WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
103390103821
WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
103391
- whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &estBound);
103822
+ whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &rangeDiv);
103392103823
if( pTop ){
103393103824
nBound = 1;
103394103825
wsFlags |= WHERE_TOP_LIMIT;
103395103826
used |= pTop->prereqRight;
103827
+ testcase( pTop->pWC!=pWC );
103396103828
}
103397103829
if( pBtm ){
103398103830
nBound++;
103399103831
wsFlags |= WHERE_BTM_LIMIT;
103400103832
used |= pBtm->prereqRight;
103833
+ testcase( pBtm->pWC!=pWC );
103401103834
}
103402103835
wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
103403103836
}
103404103837
}else if( pProbe->onError!=OE_None ){
103405103838
testcase( wsFlags & WHERE_COLUMN_IN );
@@ -103458,32 +103891,34 @@
103458103891
if( bInEst && nRow*2>aiRowEst[0] ){
103459103892
nRow = aiRowEst[0]/2;
103460103893
nInMul = (int)(nRow / aiRowEst[nEq]);
103461103894
}
103462103895
103463
-#ifdef SQLITE_ENABLE_STAT2
103896
+#ifdef SQLITE_ENABLE_STAT3
103464103897
/* If the constraint is of the form x=VALUE or x IN (E1,E2,...)
103465103898
** and we do not think that values of x are unique and if histogram
103466103899
** data is available for column x, then it might be possible
103467103900
** to get a better estimate on the number of rows based on
103468103901
** VALUE and how common that value is according to the histogram.
103469103902
*/
103470103903
if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 && aiRowEst[1]>1 ){
103904
+ assert( (pFirstTerm->eOperator & (WO_EQ|WO_ISNULL|WO_IN))!=0 );
103471103905
if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){
103472103906
testcase( pFirstTerm->eOperator==WO_EQ );
103473103907
testcase( pFirstTerm->eOperator==WO_ISNULL );
103474103908
whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow);
103475
- }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){
103909
+ }else if( bInEst==0 ){
103910
+ assert( pFirstTerm->eOperator==WO_IN );
103476103911
whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow);
103477103912
}
103478103913
}
103479
-#endif /* SQLITE_ENABLE_STAT2 */
103914
+#endif /* SQLITE_ENABLE_STAT3 */
103480103915
103481103916
/* Adjust the number of output rows and downward to reflect rows
103482103917
** that are excluded by range constraints.
103483103918
*/
103484
- nRow = (nRow * (double)estBound) / (double)100;
103919
+ nRow = nRow/rangeDiv;
103485103920
if( nRow<1 ) nRow = 1;
103486103921
103487103922
/* Experiments run on real SQLite databases show that the time needed
103488103923
** to do a binary search to locate a row in a table or index is roughly
103489103924
** log10(N) times the time to move from one row to the next row within
@@ -103608,14 +104043,14 @@
103608104043
if( nRow<2 ) nRow = 2;
103609104044
}
103610104045
103611104046
103612104047
WHERETRACE((
103613
- "%s(%s): nEq=%d nInMul=%d estBound=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
104048
+ "%s(%s): nEq=%d nInMul=%d rangeDiv=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
103614104049
" notReady=0x%llx log10N=%.1f nRow=%.1f cost=%.1f used=0x%llx\n",
103615104050
pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
103616
- nEq, nInMul, estBound, bSort, bLookup, wsFlags,
104051
+ nEq, nInMul, (int)rangeDiv, bSort, bLookup, wsFlags,
103617104052
notReady, log10N, nRow, cost, used
103618104053
));
103619104054
103620104055
/* If this index is the best we have seen so far, then record this
103621104056
** index and its cost in the pCost structure.
@@ -104115,11 +104550,12 @@
104115104550
*/
104116104551
static Bitmask codeOneLoopStart(
104117104552
WhereInfo *pWInfo, /* Complete information about the WHERE clause */
104118104553
int iLevel, /* Which level of pWInfo->a[] should be coded */
104119104554
u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
104120
- Bitmask notReady /* Which tables are currently available */
104555
+ Bitmask notReady, /* Which tables are currently available */
104556
+ Expr *pWhere /* Complete WHERE clause */
104121104557
){
104122104558
int j, k; /* Loop counters */
104123104559
int iCur; /* The VDBE cursor for the table */
104124104560
int addrNxt; /* Where to jump to continue with the next IN case */
104125104561
int omitTable; /* True if we use the index only */
@@ -104597,11 +105033,12 @@
104597105033
int regRowset = 0; /* Register for RowSet object */
104598105034
int regRowid = 0; /* Register holding rowid */
104599105035
int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
104600105036
int iRetInit; /* Address of regReturn init */
104601105037
int untestedTerms = 0; /* Some terms not completely tested */
104602
- int ii;
105038
+ int ii; /* Loop counter */
105039
+ Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
104603105040
104604105041
pTerm = pLevel->plan.u.pTerm;
104605105042
assert( pTerm!=0 );
104606105043
assert( pTerm->eOperator==WO_OR );
104607105044
assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
@@ -104646,18 +105083,33 @@
104646105083
regRowset = ++pParse->nMem;
104647105084
regRowid = ++pParse->nMem;
104648105085
sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
104649105086
}
104650105087
iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
105088
+
105089
+ /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
105090
+ ** Then for every term xN, evaluate as the subexpression: xN AND z
105091
+ ** That way, terms in y that are factored into the disjunction will
105092
+ ** be picked up by the recursive calls to sqlite3WhereBegin() below.
105093
+ */
105094
+ if( pWC->nTerm>1 ){
105095
+ pAndExpr = sqlite3ExprAlloc(pParse->db, TK_AND, 0, 0);
105096
+ pAndExpr->pRight = pWhere;
105097
+ }
104651105098
104652105099
for(ii=0; ii<pOrWc->nTerm; ii++){
104653105100
WhereTerm *pOrTerm = &pOrWc->a[ii];
104654105101
if( pOrTerm->leftCursor==iCur || pOrTerm->eOperator==WO_AND ){
104655105102
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
105103
+ Expr *pOrExpr = pOrTerm->pExpr;
105104
+ if( pAndExpr ){
105105
+ pAndExpr->pLeft = pOrExpr;
105106
+ pOrExpr = pAndExpr;
105107
+ }
104656105108
/* Loop through table entries that match term pOrTerm. */
104657
- pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrTerm->pExpr, 0, 0,
104658
- WHERE_OMIT_OPEN | WHERE_OMIT_CLOSE |
105109
+ pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
105110
+ WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
104659105111
WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY);
104660105112
if( pSubWInfo ){
104661105113
explainOneScan(
104662105114
pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
104663105115
);
@@ -104681,10 +105133,11 @@
104681105133
/* Finish the loop through table entries that match term pOrTerm. */
104682105134
sqlite3WhereEnd(pSubWInfo);
104683105135
}
104684105136
}
104685105137
}
105138
+ sqlite3DbFree(pParse->db, pAndExpr);
104686105139
sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
104687105140
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
104688105141
sqlite3VdbeResolveLabel(v, iLoopBody);
104689105142
104690105143
if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
@@ -104962,11 +105415,11 @@
104962105415
104963105416
/* Split the WHERE clause into separate subexpressions where each
104964105417
** subexpression is separated by an AND operator.
104965105418
*/
104966105419
initMaskSet(pMaskSet);
104967
- whereClauseInit(pWC, pParse, pMaskSet);
105420
+ whereClauseInit(pWC, pParse, pMaskSet, wctrlFlags);
104968105421
sqlite3ExprCodeConstants(pParse, pWhere);
104969105422
whereSplit(pWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
104970105423
104971105424
/* Special case: a WHERE clause that is constant. Evaluate the
104972105425
** expression and either jump over all of the code or fall thru.
@@ -105290,11 +105743,11 @@
105290105743
int iCur = pTabItem->iCursor;
105291105744
sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
105292105745
}else
105293105746
#endif
105294105747
if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
105295
- && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
105748
+ && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){
105296105749
int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
105297105750
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
105298105751
testcase( pTab->nCol==BMS-1 );
105299105752
testcase( pTab->nCol==BMS );
105300105753
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
@@ -105335,11 +105788,11 @@
105335105788
*/
105336105789
notReady = ~(Bitmask)0;
105337105790
for(i=0; i<nTabList; i++){
105338105791
pLevel = &pWInfo->a[i];
105339105792
explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
105340
- notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
105793
+ notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady, pWhere);
105341105794
pWInfo->iContinue = pLevel->addrCont;
105342105795
}
105343105796
105344105797
#ifdef SQLITE_TEST /* For testing and debugging use only */
105345105798
/* Record in the query plan information about the current table
@@ -105470,11 +105923,11 @@
105470105923
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
105471105924
Table *pTab = pTabItem->pTab;
105472105925
assert( pTab!=0 );
105473105926
if( (pTab->tabFlags & TF_Ephemeral)==0
105474105927
&& pTab->pSelect==0
105475
- && (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0
105928
+ && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
105476105929
){
105477105930
int ws = pLevel->plan.wsFlags;
105478105931
if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
105479105932
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
105480105933
}
@@ -105531,10 +105984,11 @@
105531105984
return;
105532105985
}
105533105986
105534105987
/************** End of where.c ***********************************************/
105535105988
/************** Begin file parse.c *******************************************/
105989
+#line 1 "tsrc/parse.c"
105536105990
/* Driver template for the LEMON parser generator.
105537105991
** The author disclaims copyright to this source code.
105538105992
**
105539105993
** This version of "lempar.c" is modified, slightly, for use by SQLite.
105540105994
** The only modifications are the addition of a couple of NEVER()
@@ -105543,10 +105997,11 @@
105543105997
** specific grammar used by SQLite.
105544105998
*/
105545105999
/* First off, code is included that follows the "include" declaration
105546106000
** in the input grammar file. */
105547106001
/* #include <stdio.h> */
106002
+#line 51 "parse.y"
105548106003
105549106004
105550106005
/*
105551106006
** Disable all error recovery processing in the parser push-down
105552106007
** automaton.
@@ -105590,10 +106045,11 @@
105590106045
/*
105591106046
** An instance of this structure holds the ATTACH key and the key type.
105592106047
*/
105593106048
struct AttachKey { int type; Token key; };
105594106049
106050
+#line 722 "parse.y"
105595106051
105596106052
/* This is a utility routine used to set the ExprSpan.zStart and
105597106053
** ExprSpan.zEnd values of pOut so that the span covers the complete
105598106054
** range of text beginning with pStart and going to the end of pEnd.
105599106055
*/
@@ -105609,10 +106065,11 @@
105609106065
static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token *pValue){
105610106066
pOut->pExpr = sqlite3PExpr(pParse, op, 0, 0, pValue);
105611106067
pOut->zStart = pValue->z;
105612106068
pOut->zEnd = &pValue->z[pValue->n];
105613106069
}
106070
+#line 817 "parse.y"
105614106071
105615106072
/* This routine constructs a binary expression node out of two ExprSpan
105616106073
** objects and uses the result to populate a new ExprSpan object.
105617106074
*/
105618106075
static void spanBinaryExpr(
@@ -105624,10 +106081,11 @@
105624106081
){
105625106082
pOut->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0);
105626106083
pOut->zStart = pLeft->zStart;
105627106084
pOut->zEnd = pRight->zEnd;
105628106085
}
106086
+#line 873 "parse.y"
105629106087
105630106088
/* Construct an expression node for a unary postfix operator
105631106089
*/
105632106090
static void spanUnaryPostfix(
105633106091
ExprSpan *pOut, /* Write the new expression node here */
@@ -105638,10 +106096,11 @@
105638106096
){
105639106097
pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
105640106098
pOut->zStart = pOperand->zStart;
105641106099
pOut->zEnd = &pPostOp->z[pPostOp->n];
105642106100
}
106101
+#line 892 "parse.y"
105643106102
105644106103
/* A routine to convert a binary TK_IS or TK_ISNOT expression into a
105645106104
** unary TK_ISNULL or TK_NOTNULL expression. */
105646106105
static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
105647106106
sqlite3 *db = pParse->db;
@@ -105649,10 +106108,11 @@
105649106108
pA->op = (u8)op;
105650106109
sqlite3ExprDelete(db, pA->pRight);
105651106110
pA->pRight = 0;
105652106111
}
105653106112
}
106113
+#line 920 "parse.y"
105654106114
105655106115
/* Construct an expression node for a unary prefix operator
105656106116
*/
105657106117
static void spanUnaryPrefix(
105658106118
ExprSpan *pOut, /* Write the new expression node here */
@@ -105663,10 +106123,11 @@
105663106123
){
105664106124
pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
105665106125
pOut->zStart = pPreOp->z;
105666106126
pOut->zEnd = pOperand->zEnd;
105667106127
}
106128
+#line 141 "parse.c"
105668106129
/* Next is all token values, in a form suitable for use by makeheaders.
105669106130
** This section will be null unless lemon is run with the -m switch.
105670106131
*/
105671106132
/*
105672106133
** These constants (all generated automatically by the parser generator)
@@ -106918,17 +107379,21 @@
106918107379
** inside the C code.
106919107380
*/
106920107381
case 160: /* select */
106921107382
case 194: /* oneselect */
106922107383
{
107384
+#line 403 "parse.y"
106923107385
sqlite3SelectDelete(pParse->db, (yypminor->yy387));
107386
+#line 1399 "parse.c"
106924107387
}
106925107388
break;
106926107389
case 174: /* term */
106927107390
case 175: /* expr */
106928107391
{
107392
+#line 720 "parse.y"
106929107393
sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
107394
+#line 1407 "parse.c"
106930107395
}
106931107396
break;
106932107397
case 179: /* idxlist_opt */
106933107398
case 187: /* idxlist */
106934107399
case 197: /* selcollist */
@@ -106940,19 +107405,23 @@
106940107405
case 217: /* setlist */
106941107406
case 220: /* itemlist */
106942107407
case 221: /* exprlist */
106943107408
case 226: /* case_exprlist */
106944107409
{
107410
+#line 1103 "parse.y"
106945107411
sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
107412
+#line 1425 "parse.c"
106946107413
}
106947107414
break;
106948107415
case 193: /* fullname */
106949107416
case 198: /* from */
106950107417
case 206: /* seltablist */
106951107418
case 207: /* stl_prefix */
106952107419
{
107420
+#line 534 "parse.y"
106953107421
sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
107422
+#line 1435 "parse.c"
106954107423
}
106955107424
break;
106956107425
case 199: /* where_opt */
106957107426
case 201: /* having_opt */
106958107427
case 210: /* on_opt */
@@ -106960,29 +107429,37 @@
106960107429
case 225: /* case_operand */
106961107430
case 227: /* case_else */
106962107431
case 238: /* when_clause */
106963107432
case 243: /* key_opt */
106964107433
{
107434
+#line 644 "parse.y"
106965107435
sqlite3ExprDelete(pParse->db, (yypminor->yy314));
107436
+#line 1449 "parse.c"
106966107437
}
106967107438
break;
106968107439
case 211: /* using_opt */
106969107440
case 213: /* inscollist */
106970107441
case 219: /* inscollist_opt */
106971107442
{
107443
+#line 566 "parse.y"
106972107444
sqlite3IdListDelete(pParse->db, (yypminor->yy384));
107445
+#line 1458 "parse.c"
106973107446
}
106974107447
break;
106975107448
case 234: /* trigger_cmd_list */
106976107449
case 239: /* trigger_cmd */
106977107450
{
107451
+#line 1210 "parse.y"
106978107452
sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
107453
+#line 1466 "parse.c"
106979107454
}
106980107455
break;
106981107456
case 236: /* trigger_event */
106982107457
{
107458
+#line 1196 "parse.y"
106983107459
sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
107460
+#line 1473 "parse.c"
106984107461
}
106985107462
break;
106986107463
default: break; /* If no destructor action specified: do nothing */
106987107464
}
106988107465
}
@@ -107164,14 +107641,16 @@
107164107641
}
107165107642
#endif
107166107643
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
107167107644
/* Here code is inserted which will execute if the parser
107168107645
** stack every overflows */
107646
+#line 38 "parse.y"
107169107647
107170107648
UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */
107171107649
sqlite3ErrorMsg(pParse, "parser stack overflow");
107172107650
pParse->parseError = 1;
107651
+#line 1664 "parse.c"
107173107652
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
107174107653
}
107175107654
107176107655
/*
107177107656
** Perform a shift action.
@@ -107608,66 +108087,94 @@
107608108087
** { ... } // User supplied code
107609108088
** #line <lineno> <thisfile>
107610108089
** break;
107611108090
*/
107612108091
case 5: /* explain ::= */
108092
+#line 107 "parse.y"
107613108093
{ sqlite3BeginParse(pParse, 0); }
108094
+#line 2107 "parse.c"
107614108095
break;
107615108096
case 6: /* explain ::= EXPLAIN */
108097
+#line 109 "parse.y"
107616108098
{ sqlite3BeginParse(pParse, 1); }
108099
+#line 2112 "parse.c"
107617108100
break;
107618108101
case 7: /* explain ::= EXPLAIN QUERY PLAN */
108102
+#line 110 "parse.y"
107619108103
{ sqlite3BeginParse(pParse, 2); }
108104
+#line 2117 "parse.c"
107620108105
break;
107621108106
case 8: /* cmdx ::= cmd */
108107
+#line 112 "parse.y"
107622108108
{ sqlite3FinishCoding(pParse); }
108109
+#line 2122 "parse.c"
107623108110
break;
107624108111
case 9: /* cmd ::= BEGIN transtype trans_opt */
108112
+#line 117 "parse.y"
107625108113
{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
108114
+#line 2127 "parse.c"
107626108115
break;
107627108116
case 13: /* transtype ::= */
108117
+#line 122 "parse.y"
107628108118
{yygotominor.yy4 = TK_DEFERRED;}
108119
+#line 2132 "parse.c"
107629108120
break;
107630108121
case 14: /* transtype ::= DEFERRED */
107631108122
case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
107632108123
case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
107633108124
case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115);
107634108125
case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117);
108126
+#line 123 "parse.y"
107635108127
{yygotominor.yy4 = yymsp[0].major;}
108128
+#line 2141 "parse.c"
107636108129
break;
107637108130
case 17: /* cmd ::= COMMIT trans_opt */
107638108131
case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
108132
+#line 126 "parse.y"
107639108133
{sqlite3CommitTransaction(pParse);}
108134
+#line 2147 "parse.c"
107640108135
break;
107641108136
case 19: /* cmd ::= ROLLBACK trans_opt */
108137
+#line 128 "parse.y"
107642108138
{sqlite3RollbackTransaction(pParse);}
108139
+#line 2152 "parse.c"
107643108140
break;
107644108141
case 22: /* cmd ::= SAVEPOINT nm */
108142
+#line 132 "parse.y"
107645108143
{
107646108144
sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
107647108145
}
108146
+#line 2159 "parse.c"
107648108147
break;
107649108148
case 23: /* cmd ::= RELEASE savepoint_opt nm */
108149
+#line 135 "parse.y"
107650108150
{
107651108151
sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
107652108152
}
108153
+#line 2166 "parse.c"
107653108154
break;
107654108155
case 24: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
108156
+#line 138 "parse.y"
107655108157
{
107656108158
sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
107657108159
}
108160
+#line 2173 "parse.c"
107658108161
break;
107659108162
case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
108163
+#line 145 "parse.y"
107660108164
{
107661108165
sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
107662108166
}
108167
+#line 2180 "parse.c"
107663108168
break;
107664108169
case 27: /* createkw ::= CREATE */
108170
+#line 148 "parse.y"
107665108171
{
107666108172
pParse->db->lookaside.bEnabled = 0;
107667108173
yygotominor.yy0 = yymsp[0].minor.yy0;
107668108174
}
108175
+#line 2188 "parse.c"
107669108176
break;
107670108177
case 28: /* ifnotexists ::= */
107671108178
case 31: /* temp ::= */ yytestcase(yyruleno==31);
107672108179
case 70: /* autoinc ::= */ yytestcase(yyruleno==70);
107673108180
case 83: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==83);
@@ -107677,44 +108184,56 @@
107677108184
case 109: /* ifexists ::= */ yytestcase(yyruleno==109);
107678108185
case 120: /* distinct ::= ALL */ yytestcase(yyruleno==120);
107679108186
case 121: /* distinct ::= */ yytestcase(yyruleno==121);
107680108187
case 222: /* between_op ::= BETWEEN */ yytestcase(yyruleno==222);
107681108188
case 225: /* in_op ::= IN */ yytestcase(yyruleno==225);
108189
+#line 153 "parse.y"
107682108190
{yygotominor.yy4 = 0;}
108191
+#line 2204 "parse.c"
107683108192
break;
107684108193
case 29: /* ifnotexists ::= IF NOT EXISTS */
107685108194
case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
107686108195
case 71: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==71);
107687108196
case 86: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==86);
107688108197
case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108);
107689108198
case 119: /* distinct ::= DISTINCT */ yytestcase(yyruleno==119);
107690108199
case 223: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==223);
107691108200
case 226: /* in_op ::= NOT IN */ yytestcase(yyruleno==226);
108201
+#line 154 "parse.y"
107692108202
{yygotominor.yy4 = 1;}
108203
+#line 2216 "parse.c"
107693108204
break;
107694108205
case 32: /* create_table_args ::= LP columnlist conslist_opt RP */
108206
+#line 160 "parse.y"
107695108207
{
107696108208
sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
107697108209
}
108210
+#line 2223 "parse.c"
107698108211
break;
107699108212
case 33: /* create_table_args ::= AS select */
108213
+#line 163 "parse.y"
107700108214
{
107701108215
sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy387);
107702108216
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
107703108217
}
108218
+#line 2231 "parse.c"
107704108219
break;
107705108220
case 36: /* column ::= columnid type carglist */
108221
+#line 175 "parse.y"
107706108222
{
107707108223
yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
107708108224
yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
107709108225
}
108226
+#line 2239 "parse.c"
107710108227
break;
107711108228
case 37: /* columnid ::= nm */
108229
+#line 179 "parse.y"
107712108230
{
107713108231
sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
107714108232
yygotominor.yy0 = yymsp[0].minor.yy0;
107715108233
}
108234
+#line 2247 "parse.c"
107716108235
break;
107717108236
case 38: /* id ::= ID */
107718108237
case 39: /* id ::= INDEXED */ yytestcase(yyruleno==39);
107719108238
case 40: /* ids ::= ID|STRING */ yytestcase(yyruleno==40);
107720108239
case 41: /* nm ::= id */ yytestcase(yyruleno==41);
@@ -107734,256 +108253,373 @@
107734108253
case 264: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==264);
107735108254
case 265: /* plus_num ::= plus_opt number */ yytestcase(yyruleno==265);
107736108255
case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266);
107737108256
case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267);
107738108257
case 285: /* trnm ::= nm */ yytestcase(yyruleno==285);
108258
+#line 189 "parse.y"
107739108259
{yygotominor.yy0 = yymsp[0].minor.yy0;}
108260
+#line 2273 "parse.c"
107740108261
break;
107741108262
case 45: /* type ::= typetoken */
108263
+#line 251 "parse.y"
107742108264
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
108265
+#line 2278 "parse.c"
107743108266
break;
107744108267
case 47: /* typetoken ::= typename LP signed RP */
108268
+#line 253 "parse.y"
107745108269
{
107746108270
yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
107747108271
yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
107748108272
}
108273
+#line 2286 "parse.c"
107749108274
break;
107750108275
case 48: /* typetoken ::= typename LP signed COMMA signed RP */
108276
+#line 257 "parse.y"
107751108277
{
107752108278
yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
107753108279
yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
107754108280
}
108281
+#line 2294 "parse.c"
107755108282
break;
107756108283
case 50: /* typename ::= typename ids */
108284
+#line 263 "parse.y"
107757108285
{yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
108286
+#line 2299 "parse.c"
107758108287
break;
107759108288
case 57: /* ccons ::= DEFAULT term */
107760108289
case 59: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==59);
108290
+#line 274 "parse.y"
107761108291
{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy118);}
108292
+#line 2305 "parse.c"
107762108293
break;
107763108294
case 58: /* ccons ::= DEFAULT LP expr RP */
108295
+#line 275 "parse.y"
107764108296
{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy118);}
108297
+#line 2310 "parse.c"
107765108298
break;
107766108299
case 60: /* ccons ::= DEFAULT MINUS term */
108300
+#line 277 "parse.y"
107767108301
{
107768108302
ExprSpan v;
107769108303
v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy118.pExpr, 0, 0);
107770108304
v.zStart = yymsp[-1].minor.yy0.z;
107771108305
v.zEnd = yymsp[0].minor.yy118.zEnd;
107772108306
sqlite3AddDefaultValue(pParse,&v);
107773108307
}
108308
+#line 2321 "parse.c"
107774108309
break;
107775108310
case 61: /* ccons ::= DEFAULT id */
108311
+#line 284 "parse.y"
107776108312
{
107777108313
ExprSpan v;
107778108314
spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
107779108315
sqlite3AddDefaultValue(pParse,&v);
107780108316
}
108317
+#line 2330 "parse.c"
107781108318
break;
107782108319
case 63: /* ccons ::= NOT NULL onconf */
108320
+#line 294 "parse.y"
107783108321
{sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
108322
+#line 2335 "parse.c"
107784108323
break;
107785108324
case 64: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
108325
+#line 296 "parse.y"
107786108326
{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
108327
+#line 2340 "parse.c"
107787108328
break;
107788108329
case 65: /* ccons ::= UNIQUE onconf */
108330
+#line 297 "parse.y"
107789108331
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0);}
108332
+#line 2345 "parse.c"
107790108333
break;
107791108334
case 66: /* ccons ::= CHECK LP expr RP */
108335
+#line 298 "parse.y"
107792108336
{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy118.pExpr);}
108337
+#line 2350 "parse.c"
107793108338
break;
107794108339
case 67: /* ccons ::= REFERENCES nm idxlist_opt refargs */
108340
+#line 300 "parse.y"
107795108341
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
108342
+#line 2355 "parse.c"
107796108343
break;
107797108344
case 68: /* ccons ::= defer_subclause */
108345
+#line 301 "parse.y"
107798108346
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
108347
+#line 2360 "parse.c"
107799108348
break;
107800108349
case 69: /* ccons ::= COLLATE ids */
108350
+#line 302 "parse.y"
107801108351
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
108352
+#line 2365 "parse.c"
107802108353
break;
107803108354
case 72: /* refargs ::= */
108355
+#line 315 "parse.y"
107804108356
{ yygotominor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
108357
+#line 2370 "parse.c"
107805108358
break;
107806108359
case 73: /* refargs ::= refargs refarg */
108360
+#line 316 "parse.y"
107807108361
{ yygotominor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
108362
+#line 2375 "parse.c"
107808108363
break;
107809108364
case 74: /* refarg ::= MATCH nm */
107810108365
case 75: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==75);
108366
+#line 318 "parse.y"
107811108367
{ yygotominor.yy215.value = 0; yygotominor.yy215.mask = 0x000000; }
108368
+#line 2381 "parse.c"
107812108369
break;
107813108370
case 76: /* refarg ::= ON DELETE refact */
108371
+#line 320 "parse.y"
107814108372
{ yygotominor.yy215.value = yymsp[0].minor.yy4; yygotominor.yy215.mask = 0x0000ff; }
108373
+#line 2386 "parse.c"
107815108374
break;
107816108375
case 77: /* refarg ::= ON UPDATE refact */
108376
+#line 321 "parse.y"
107817108377
{ yygotominor.yy215.value = yymsp[0].minor.yy4<<8; yygotominor.yy215.mask = 0x00ff00; }
108378
+#line 2391 "parse.c"
107818108379
break;
107819108380
case 78: /* refact ::= SET NULL */
108381
+#line 323 "parse.y"
107820108382
{ yygotominor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
108383
+#line 2396 "parse.c"
107821108384
break;
107822108385
case 79: /* refact ::= SET DEFAULT */
108386
+#line 324 "parse.y"
107823108387
{ yygotominor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
108388
+#line 2401 "parse.c"
107824108389
break;
107825108390
case 80: /* refact ::= CASCADE */
108391
+#line 325 "parse.y"
107826108392
{ yygotominor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
108393
+#line 2406 "parse.c"
107827108394
break;
107828108395
case 81: /* refact ::= RESTRICT */
108396
+#line 326 "parse.y"
107829108397
{ yygotominor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
108398
+#line 2411 "parse.c"
107830108399
break;
107831108400
case 82: /* refact ::= NO ACTION */
108401
+#line 327 "parse.y"
107832108402
{ yygotominor.yy4 = OE_None; /* EV: R-33326-45252 */}
108403
+#line 2416 "parse.c"
107833108404
break;
107834108405
case 84: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
107835108406
case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99);
107836108407
case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101);
107837108408
case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104);
108409
+#line 330 "parse.y"
107838108410
{yygotominor.yy4 = yymsp[0].minor.yy4;}
108411
+#line 2424 "parse.c"
107839108412
break;
107840108413
case 88: /* conslist_opt ::= */
108414
+#line 339 "parse.y"
107841108415
{yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
108416
+#line 2429 "parse.c"
107842108417
break;
107843108418
case 89: /* conslist_opt ::= COMMA conslist */
108419
+#line 340 "parse.y"
107844108420
{yygotominor.yy0 = yymsp[-1].minor.yy0;}
108421
+#line 2434 "parse.c"
107845108422
break;
107846108423
case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
108424
+#line 346 "parse.y"
107847108425
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
108426
+#line 2439 "parse.c"
107848108427
break;
107849108428
case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */
108429
+#line 348 "parse.y"
107850108430
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0);}
108431
+#line 2444 "parse.c"
107851108432
break;
107852108433
case 96: /* tcons ::= CHECK LP expr RP onconf */
108434
+#line 350 "parse.y"
107853108435
{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy118.pExpr);}
108436
+#line 2449 "parse.c"
107854108437
break;
107855108438
case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
108439
+#line 352 "parse.y"
107856108440
{
107857108441
sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
107858108442
sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
107859108443
}
108444
+#line 2457 "parse.c"
107860108445
break;
107861108446
case 100: /* onconf ::= */
108447
+#line 366 "parse.y"
107862108448
{yygotominor.yy4 = OE_Default;}
108449
+#line 2462 "parse.c"
107863108450
break;
107864108451
case 102: /* orconf ::= */
108452
+#line 368 "parse.y"
107865108453
{yygotominor.yy210 = OE_Default;}
108454
+#line 2467 "parse.c"
107866108455
break;
107867108456
case 103: /* orconf ::= OR resolvetype */
108457
+#line 369 "parse.y"
107868108458
{yygotominor.yy210 = (u8)yymsp[0].minor.yy4;}
108459
+#line 2472 "parse.c"
107869108460
break;
107870108461
case 105: /* resolvetype ::= IGNORE */
108462
+#line 371 "parse.y"
107871108463
{yygotominor.yy4 = OE_Ignore;}
108464
+#line 2477 "parse.c"
107872108465
break;
107873108466
case 106: /* resolvetype ::= REPLACE */
108467
+#line 372 "parse.y"
107874108468
{yygotominor.yy4 = OE_Replace;}
108469
+#line 2482 "parse.c"
107875108470
break;
107876108471
case 107: /* cmd ::= DROP TABLE ifexists fullname */
108472
+#line 376 "parse.y"
107877108473
{
107878108474
sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
107879108475
}
108476
+#line 2489 "parse.c"
107880108477
break;
107881108478
case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
108479
+#line 386 "parse.y"
107882108480
{
107883108481
sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy387, yymsp[-6].minor.yy4, yymsp[-4].minor.yy4);
107884108482
}
108483
+#line 2496 "parse.c"
107885108484
break;
107886108485
case 111: /* cmd ::= DROP VIEW ifexists fullname */
108486
+#line 389 "parse.y"
107887108487
{
107888108488
sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
107889108489
}
108490
+#line 2503 "parse.c"
107890108491
break;
107891108492
case 112: /* cmd ::= select */
108493
+#line 396 "parse.y"
107892108494
{
107893108495
SelectDest dest = {SRT_Output, 0, 0, 0, 0};
107894108496
sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
107895108497
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
107896108498
}
108499
+#line 2512 "parse.c"
107897108500
break;
107898108501
case 113: /* select ::= oneselect */
108502
+#line 407 "parse.y"
107899108503
{yygotominor.yy387 = yymsp[0].minor.yy387;}
108504
+#line 2517 "parse.c"
107900108505
break;
107901108506
case 114: /* select ::= select multiselect_op oneselect */
108507
+#line 409 "parse.y"
107902108508
{
107903108509
if( yymsp[0].minor.yy387 ){
107904108510
yymsp[0].minor.yy387->op = (u8)yymsp[-1].minor.yy4;
107905108511
yymsp[0].minor.yy387->pPrior = yymsp[-2].minor.yy387;
107906108512
}else{
107907108513
sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
107908108514
}
107909108515
yygotominor.yy387 = yymsp[0].minor.yy387;
107910108516
}
108517
+#line 2530 "parse.c"
107911108518
break;
107912108519
case 116: /* multiselect_op ::= UNION ALL */
108520
+#line 420 "parse.y"
107913108521
{yygotominor.yy4 = TK_ALL;}
108522
+#line 2535 "parse.c"
107914108523
break;
107915108524
case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
108525
+#line 424 "parse.y"
107916108526
{
107917108527
yygotominor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy292.pLimit,yymsp[0].minor.yy292.pOffset);
107918108528
}
108529
+#line 2542 "parse.c"
107919108530
break;
107920108531
case 122: /* sclp ::= selcollist COMMA */
107921108532
case 247: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==247);
108533
+#line 445 "parse.y"
107922108534
{yygotominor.yy322 = yymsp[-1].minor.yy322;}
108535
+#line 2548 "parse.c"
107923108536
break;
107924108537
case 123: /* sclp ::= */
107925108538
case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151);
107926108539
case 159: /* groupby_opt ::= */ yytestcase(yyruleno==159);
107927108540
case 240: /* exprlist ::= */ yytestcase(yyruleno==240);
107928108541
case 246: /* idxlist_opt ::= */ yytestcase(yyruleno==246);
108542
+#line 446 "parse.y"
107929108543
{yygotominor.yy322 = 0;}
108544
+#line 2557 "parse.c"
107930108545
break;
107931108546
case 124: /* selcollist ::= sclp expr as */
108547
+#line 447 "parse.y"
107932108548
{
107933108549
yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, yymsp[-1].minor.yy118.pExpr);
107934108550
if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[0].minor.yy0, 1);
107935108551
sqlite3ExprListSetSpan(pParse,yygotominor.yy322,&yymsp[-1].minor.yy118);
107936108552
}
108553
+#line 2566 "parse.c"
107937108554
break;
107938108555
case 125: /* selcollist ::= sclp STAR */
108556
+#line 452 "parse.y"
107939108557
{
107940108558
Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
107941108559
yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy322, p);
107942108560
}
108561
+#line 2574 "parse.c"
107943108562
break;
107944108563
case 126: /* selcollist ::= sclp nm DOT STAR */
108564
+#line 456 "parse.y"
107945108565
{
107946108566
Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
107947108567
Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
107948108568
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
107949108569
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, pDot);
107950108570
}
108571
+#line 2584 "parse.c"
107951108572
break;
107952108573
case 129: /* as ::= */
108574
+#line 469 "parse.y"
107953108575
{yygotominor.yy0.n = 0;}
108576
+#line 2589 "parse.c"
107954108577
break;
107955108578
case 130: /* from ::= */
108579
+#line 481 "parse.y"
107956108580
{yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
108581
+#line 2594 "parse.c"
107957108582
break;
107958108583
case 131: /* from ::= FROM seltablist */
108584
+#line 482 "parse.y"
107959108585
{
107960108586
yygotominor.yy259 = yymsp[0].minor.yy259;
107961108587
sqlite3SrcListShiftJoinType(yygotominor.yy259);
107962108588
}
108589
+#line 2602 "parse.c"
107963108590
break;
107964108591
case 132: /* stl_prefix ::= seltablist joinop */
108592
+#line 490 "parse.y"
107965108593
{
107966108594
yygotominor.yy259 = yymsp[-1].minor.yy259;
107967108595
if( ALWAYS(yygotominor.yy259 && yygotominor.yy259->nSrc>0) ) yygotominor.yy259->a[yygotominor.yy259->nSrc-1].jointype = (u8)yymsp[0].minor.yy4;
107968108596
}
108597
+#line 2610 "parse.c"
107969108598
break;
107970108599
case 133: /* stl_prefix ::= */
108600
+#line 494 "parse.y"
107971108601
{yygotominor.yy259 = 0;}
108602
+#line 2615 "parse.c"
107972108603
break;
107973108604
case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
108605
+#line 495 "parse.y"
107974108606
{
107975108607
yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
107976108608
sqlite3SrcListIndexedBy(pParse, yygotominor.yy259, &yymsp[-2].minor.yy0);
107977108609
}
108610
+#line 2623 "parse.c"
107978108611
break;
107979108612
case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
108613
+#line 501 "parse.y"
107980108614
{
107981108615
yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
107982108616
}
108617
+#line 2630 "parse.c"
107983108618
break;
107984108619
case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
108620
+#line 505 "parse.y"
107985108621
{
107986108622
if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
107987108623
yygotominor.yy259 = yymsp[-4].minor.yy259;
107988108624
}else{
107989108625
Select *pSubquery;
@@ -107990,180 +108626,260 @@
107990108626
sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
107991108627
pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,0,0,0);
107992108628
yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
107993108629
}
107994108630
}
108631
+#line 2644 "parse.c"
107995108632
break;
107996108633
case 137: /* dbnm ::= */
107997108634
case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146);
108635
+#line 530 "parse.y"
107998108636
{yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
108637
+#line 2650 "parse.c"
107999108638
break;
108000108639
case 139: /* fullname ::= nm dbnm */
108640
+#line 535 "parse.y"
108001108641
{yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
108642
+#line 2655 "parse.c"
108002108643
break;
108003108644
case 140: /* joinop ::= COMMA|JOIN */
108645
+#line 539 "parse.y"
108004108646
{ yygotominor.yy4 = JT_INNER; }
108647
+#line 2660 "parse.c"
108005108648
break;
108006108649
case 141: /* joinop ::= JOIN_KW JOIN */
108650
+#line 540 "parse.y"
108007108651
{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
108652
+#line 2665 "parse.c"
108008108653
break;
108009108654
case 142: /* joinop ::= JOIN_KW nm JOIN */
108655
+#line 541 "parse.y"
108010108656
{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
108657
+#line 2670 "parse.c"
108011108658
break;
108012108659
case 143: /* joinop ::= JOIN_KW nm nm JOIN */
108660
+#line 543 "parse.y"
108013108661
{ yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
108662
+#line 2675 "parse.c"
108014108663
break;
108015108664
case 144: /* on_opt ::= ON expr */
108016108665
case 155: /* sortitem ::= expr */ yytestcase(yyruleno==155);
108017108666
case 162: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==162);
108018108667
case 169: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==169);
108019108668
case 235: /* case_else ::= ELSE expr */ yytestcase(yyruleno==235);
108020108669
case 237: /* case_operand ::= expr */ yytestcase(yyruleno==237);
108670
+#line 547 "parse.y"
108021108671
{yygotominor.yy314 = yymsp[0].minor.yy118.pExpr;}
108672
+#line 2685 "parse.c"
108022108673
break;
108023108674
case 145: /* on_opt ::= */
108024108675
case 161: /* having_opt ::= */ yytestcase(yyruleno==161);
108025108676
case 168: /* where_opt ::= */ yytestcase(yyruleno==168);
108026108677
case 236: /* case_else ::= */ yytestcase(yyruleno==236);
108027108678
case 238: /* case_operand ::= */ yytestcase(yyruleno==238);
108679
+#line 548 "parse.y"
108028108680
{yygotominor.yy314 = 0;}
108681
+#line 2694 "parse.c"
108029108682
break;
108030108683
case 148: /* indexed_opt ::= NOT INDEXED */
108684
+#line 563 "parse.y"
108031108685
{yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
108686
+#line 2699 "parse.c"
108032108687
break;
108033108688
case 149: /* using_opt ::= USING LP inscollist RP */
108034108689
case 181: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==181);
108690
+#line 567 "parse.y"
108035108691
{yygotominor.yy384 = yymsp[-1].minor.yy384;}
108692
+#line 2705 "parse.c"
108036108693
break;
108037108694
case 150: /* using_opt ::= */
108038108695
case 180: /* inscollist_opt ::= */ yytestcase(yyruleno==180);
108696
+#line 568 "parse.y"
108039108697
{yygotominor.yy384 = 0;}
108698
+#line 2711 "parse.c"
108040108699
break;
108041108700
case 152: /* orderby_opt ::= ORDER BY sortlist */
108042108701
case 160: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==160);
108043108702
case 239: /* exprlist ::= nexprlist */ yytestcase(yyruleno==239);
108703
+#line 579 "parse.y"
108044108704
{yygotominor.yy322 = yymsp[0].minor.yy322;}
108705
+#line 2718 "parse.c"
108045108706
break;
108046108707
case 153: /* sortlist ::= sortlist COMMA sortitem sortorder */
108708
+#line 580 "parse.y"
108047108709
{
108048108710
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314);
108049108711
if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108050108712
}
108713
+#line 2726 "parse.c"
108051108714
break;
108052108715
case 154: /* sortlist ::= sortitem sortorder */
108716
+#line 584 "parse.y"
108053108717
{
108054108718
yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314);
108055108719
if( yygotominor.yy322 && ALWAYS(yygotominor.yy322->a) ) yygotominor.yy322->a[0].sortOrder = (u8)yymsp[0].minor.yy4;
108056108720
}
108721
+#line 2734 "parse.c"
108057108722
break;
108058108723
case 156: /* sortorder ::= ASC */
108059108724
case 158: /* sortorder ::= */ yytestcase(yyruleno==158);
108725
+#line 592 "parse.y"
108060108726
{yygotominor.yy4 = SQLITE_SO_ASC;}
108727
+#line 2740 "parse.c"
108061108728
break;
108062108729
case 157: /* sortorder ::= DESC */
108730
+#line 593 "parse.y"
108063108731
{yygotominor.yy4 = SQLITE_SO_DESC;}
108732
+#line 2745 "parse.c"
108064108733
break;
108065108734
case 163: /* limit_opt ::= */
108735
+#line 619 "parse.y"
108066108736
{yygotominor.yy292.pLimit = 0; yygotominor.yy292.pOffset = 0;}
108737
+#line 2750 "parse.c"
108067108738
break;
108068108739
case 164: /* limit_opt ::= LIMIT expr */
108740
+#line 620 "parse.y"
108069108741
{yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr; yygotominor.yy292.pOffset = 0;}
108742
+#line 2755 "parse.c"
108070108743
break;
108071108744
case 165: /* limit_opt ::= LIMIT expr OFFSET expr */
108745
+#line 622 "parse.y"
108072108746
{yygotominor.yy292.pLimit = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pOffset = yymsp[0].minor.yy118.pExpr;}
108747
+#line 2760 "parse.c"
108073108748
break;
108074108749
case 166: /* limit_opt ::= LIMIT expr COMMA expr */
108750
+#line 624 "parse.y"
108075108751
{yygotominor.yy292.pOffset = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr;}
108752
+#line 2765 "parse.c"
108076108753
break;
108077108754
case 167: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
108755
+#line 637 "parse.y"
108078108756
{
108079108757
sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
108080108758
sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314);
108081108759
}
108760
+#line 2773 "parse.c"
108082108761
break;
108083108762
case 170: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
108763
+#line 660 "parse.y"
108084108764
{
108085108765
sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
108086108766
sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
108087108767
sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy210);
108088108768
}
108769
+#line 2782 "parse.c"
108089108770
break;
108090108771
case 171: /* setlist ::= setlist COMMA nm EQ expr */
108772
+#line 670 "parse.y"
108091108773
{
108092108774
yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy118.pExpr);
108093108775
sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108094108776
}
108777
+#line 2790 "parse.c"
108095108778
break;
108096108779
case 172: /* setlist ::= nm EQ expr */
108780
+#line 674 "parse.y"
108097108781
{
108098108782
yygotominor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy118.pExpr);
108099108783
sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108100108784
}
108785
+#line 2798 "parse.c"
108101108786
break;
108102108787
case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
108788
+#line 683 "parse.y"
108103108789
{sqlite3Insert(pParse, yymsp[-5].minor.yy259, yymsp[-1].minor.yy322, 0, yymsp[-4].minor.yy384, yymsp[-7].minor.yy210);}
108790
+#line 2803 "parse.c"
108104108791
break;
108105108792
case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
108793
+#line 685 "parse.y"
108106108794
{sqlite3Insert(pParse, yymsp[-2].minor.yy259, 0, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
108795
+#line 2808 "parse.c"
108107108796
break;
108108108797
case 175: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
108798
+#line 687 "parse.y"
108109108799
{sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy210);}
108800
+#line 2813 "parse.c"
108110108801
break;
108111108802
case 176: /* insert_cmd ::= INSERT orconf */
108803
+#line 690 "parse.y"
108112108804
{yygotominor.yy210 = yymsp[0].minor.yy210;}
108805
+#line 2818 "parse.c"
108113108806
break;
108114108807
case 177: /* insert_cmd ::= REPLACE */
108808
+#line 691 "parse.y"
108115108809
{yygotominor.yy210 = OE_Replace;}
108810
+#line 2823 "parse.c"
108116108811
break;
108117108812
case 178: /* itemlist ::= itemlist COMMA expr */
108118108813
case 241: /* nexprlist ::= nexprlist COMMA expr */ yytestcase(yyruleno==241);
108814
+#line 698 "parse.y"
108119108815
{yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy118.pExpr);}
108816
+#line 2829 "parse.c"
108120108817
break;
108121108818
case 179: /* itemlist ::= expr */
108122108819
case 242: /* nexprlist ::= expr */ yytestcase(yyruleno==242);
108820
+#line 700 "parse.y"
108123108821
{yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy118.pExpr);}
108822
+#line 2835 "parse.c"
108124108823
break;
108125108824
case 182: /* inscollist ::= inscollist COMMA nm */
108825
+#line 710 "parse.y"
108126108826
{yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
108827
+#line 2840 "parse.c"
108127108828
break;
108128108829
case 183: /* inscollist ::= nm */
108830
+#line 712 "parse.y"
108129108831
{yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
108832
+#line 2845 "parse.c"
108130108833
break;
108131108834
case 184: /* expr ::= term */
108835
+#line 743 "parse.y"
108132108836
{yygotominor.yy118 = yymsp[0].minor.yy118;}
108837
+#line 2850 "parse.c"
108133108838
break;
108134108839
case 185: /* expr ::= LP expr RP */
108840
+#line 744 "parse.y"
108135108841
{yygotominor.yy118.pExpr = yymsp[-1].minor.yy118.pExpr; spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
108842
+#line 2855 "parse.c"
108136108843
break;
108137108844
case 186: /* term ::= NULL */
108138108845
case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
108139108846
case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
108847
+#line 745 "parse.y"
108140108848
{spanExpr(&yygotominor.yy118, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
108849
+#line 2862 "parse.c"
108141108850
break;
108142108851
case 187: /* expr ::= id */
108143108852
case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
108853
+#line 746 "parse.y"
108144108854
{spanExpr(&yygotominor.yy118, pParse, TK_ID, &yymsp[0].minor.yy0);}
108855
+#line 2868 "parse.c"
108145108856
break;
108146108857
case 189: /* expr ::= nm DOT nm */
108858
+#line 748 "parse.y"
108147108859
{
108148108860
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108149108861
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
108150108862
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
108151108863
spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
108152108864
}
108865
+#line 2878 "parse.c"
108153108866
break;
108154108867
case 190: /* expr ::= nm DOT nm DOT nm */
108868
+#line 754 "parse.y"
108155108869
{
108156108870
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
108157108871
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108158108872
Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
108159108873
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
108160108874
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
108161108875
spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
108162108876
}
108877
+#line 2890 "parse.c"
108163108878
break;
108164108879
case 193: /* expr ::= REGISTER */
108880
+#line 764 "parse.y"
108165108881
{
108166108882
/* When doing a nested parse, one can include terms in an expression
108167108883
** that look like this: #1 #2 ... These terms refer to registers
108168108884
** in the virtual machine. #N is the N-th register. */
108169108885
if( pParse->nested==0 ){
@@ -108173,32 +108889,40 @@
108173108889
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
108174108890
if( yygotominor.yy118.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy118.pExpr->iTable);
108175108891
}
108176108892
spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108177108893
}
108894
+#line 2907 "parse.c"
108178108895
break;
108179108896
case 194: /* expr ::= VARIABLE */
108897
+#line 777 "parse.y"
108180108898
{
108181108899
spanExpr(&yygotominor.yy118, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
108182108900
sqlite3ExprAssignVarNumber(pParse, yygotominor.yy118.pExpr);
108183108901
spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108184108902
}
108903
+#line 2916 "parse.c"
108185108904
break;
108186108905
case 195: /* expr ::= expr COLLATE ids */
108906
+#line 782 "parse.y"
108187108907
{
108188108908
yygotominor.yy118.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
108189108909
yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
108190108910
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108191108911
}
108912
+#line 2925 "parse.c"
108192108913
break;
108193108914
case 196: /* expr ::= CAST LP expr AS typetoken RP */
108915
+#line 788 "parse.y"
108194108916
{
108195108917
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy118.pExpr, 0, &yymsp[-1].minor.yy0);
108196108918
spanSet(&yygotominor.yy118,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
108197108919
}
108920
+#line 2933 "parse.c"
108198108921
break;
108199108922
case 197: /* expr ::= ID LP distinct exprlist RP */
108923
+#line 793 "parse.y"
108200108924
{
108201108925
if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
108202108926
sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
108203108927
}
108204108928
yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
@@ -108205,47 +108929,59 @@
108205108929
spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
108206108930
if( yymsp[-2].minor.yy4 && yygotominor.yy118.pExpr ){
108207108931
yygotominor.yy118.pExpr->flags |= EP_Distinct;
108208108932
}
108209108933
}
108934
+#line 2947 "parse.c"
108210108935
break;
108211108936
case 198: /* expr ::= ID LP STAR RP */
108937
+#line 803 "parse.y"
108212108938
{
108213108939
yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
108214108940
spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
108215108941
}
108942
+#line 2955 "parse.c"
108216108943
break;
108217108944
case 199: /* term ::= CTIME_KW */
108945
+#line 807 "parse.y"
108218108946
{
108219108947
/* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
108220108948
** treated as functions that return constants */
108221108949
yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
108222108950
if( yygotominor.yy118.pExpr ){
108223108951
yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
108224108952
}
108225108953
spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108226108954
}
108955
+#line 2968 "parse.c"
108227108956
break;
108228108957
case 200: /* expr ::= expr AND expr */
108229108958
case 201: /* expr ::= expr OR expr */ yytestcase(yyruleno==201);
108230108959
case 202: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==202);
108231108960
case 203: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==203);
108232108961
case 204: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==204);
108233108962
case 205: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==205);
108234108963
case 206: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==206);
108235108964
case 207: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==207);
108965
+#line 834 "parse.y"
108236108966
{spanBinaryExpr(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);}
108967
+#line 2980 "parse.c"
108237108968
break;
108238108969
case 208: /* likeop ::= LIKE_KW */
108239108970
case 210: /* likeop ::= MATCH */ yytestcase(yyruleno==210);
108971
+#line 847 "parse.y"
108240108972
{yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 0;}
108973
+#line 2986 "parse.c"
108241108974
break;
108242108975
case 209: /* likeop ::= NOT LIKE_KW */
108243108976
case 211: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==211);
108977
+#line 848 "parse.y"
108244108978
{yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 1;}
108979
+#line 2992 "parse.c"
108245108980
break;
108246108981
case 212: /* expr ::= expr likeop expr */
108982
+#line 851 "parse.y"
108247108983
{
108248108984
ExprList *pList;
108249108985
pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy118.pExpr);
108250108986
pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy118.pExpr);
108251108987
yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy342.eOperator);
@@ -108252,12 +108988,14 @@
108252108988
if( yymsp[-1].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108253108989
yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
108254108990
yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108255108991
if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
108256108992
}
108993
+#line 3006 "parse.c"
108257108994
break;
108258108995
case 213: /* expr ::= expr likeop expr ESCAPE expr */
108996
+#line 861 "parse.y"
108259108997
{
108260108998
ExprList *pList;
108261108999
pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
108262109000
pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy118.pExpr);
108263109001
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
@@ -108265,40 +109003,56 @@
108265109003
if( yymsp[-3].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108266109004
yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108267109005
yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108268109006
if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
108269109007
}
109008
+#line 3021 "parse.c"
108270109009
break;
108271109010
case 214: /* expr ::= expr ISNULL|NOTNULL */
109011
+#line 889 "parse.y"
108272109012
{spanUnaryPostfix(&yygotominor.yy118,pParse,yymsp[0].major,&yymsp[-1].minor.yy118,&yymsp[0].minor.yy0);}
109013
+#line 3026 "parse.c"
108273109014
break;
108274109015
case 215: /* expr ::= expr NOT NULL */
109016
+#line 890 "parse.y"
108275109017
{spanUnaryPostfix(&yygotominor.yy118,pParse,TK_NOTNULL,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy0);}
109018
+#line 3031 "parse.c"
108276109019
break;
108277109020
case 216: /* expr ::= expr IS expr */
109021
+#line 911 "parse.y"
108278109022
{
108279109023
spanBinaryExpr(&yygotominor.yy118,pParse,TK_IS,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);
108280109024
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_ISNULL);
108281109025
}
109026
+#line 3039 "parse.c"
108282109027
break;
108283109028
case 217: /* expr ::= expr IS NOT expr */
109029
+#line 915 "parse.y"
108284109030
{
108285109031
spanBinaryExpr(&yygotominor.yy118,pParse,TK_ISNOT,&yymsp[-3].minor.yy118,&yymsp[0].minor.yy118);
108286109032
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_NOTNULL);
108287109033
}
109034
+#line 3047 "parse.c"
108288109035
break;
108289109036
case 218: /* expr ::= NOT expr */
108290109037
case 219: /* expr ::= BITNOT expr */ yytestcase(yyruleno==219);
109038
+#line 938 "parse.y"
108291109039
{spanUnaryPrefix(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
109040
+#line 3053 "parse.c"
108292109041
break;
108293109042
case 220: /* expr ::= MINUS expr */
109043
+#line 941 "parse.y"
108294109044
{spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UMINUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
109045
+#line 3058 "parse.c"
108295109046
break;
108296109047
case 221: /* expr ::= PLUS expr */
109048
+#line 943 "parse.y"
108297109049
{spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UPLUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
109050
+#line 3063 "parse.c"
108298109051
break;
108299109052
case 224: /* expr ::= expr between_op expr AND expr */
109053
+#line 948 "parse.y"
108300109054
{
108301109055
ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
108302109056
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
108303109057
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy118.pExpr, 0, 0);
108304109058
if( yygotominor.yy118.pExpr ){
@@ -108308,12 +109062,14 @@
108308109062
}
108309109063
if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108310109064
yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108311109065
yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108312109066
}
109067
+#line 3080 "parse.c"
108313109068
break;
108314109069
case 227: /* expr ::= expr in_op LP exprlist RP */
109070
+#line 965 "parse.y"
108315109071
{
108316109072
if( yymsp[-1].minor.yy322==0 ){
108317109073
/* Expressions of the form
108318109074
**
108319109075
** expr1 IN ()
@@ -108335,12 +109091,14 @@
108335109091
if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108336109092
}
108337109093
yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108338109094
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108339109095
}
109096
+#line 3109 "parse.c"
108340109097
break;
108341109098
case 228: /* expr ::= LP select RP */
109099
+#line 990 "parse.y"
108342109100
{
108343109101
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
108344109102
if( yygotominor.yy118.pExpr ){
108345109103
yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
108346109104
ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
@@ -108349,12 +109107,14 @@
108349109107
sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
108350109108
}
108351109109
yygotominor.yy118.zStart = yymsp[-2].minor.yy0.z;
108352109110
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108353109111
}
109112
+#line 3125 "parse.c"
108354109113
break;
108355109114
case 229: /* expr ::= expr in_op LP select RP */
109115
+#line 1002 "parse.y"
108356109116
{
108357109117
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
108358109118
if( yygotominor.yy118.pExpr ){
108359109119
yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
108360109120
ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
@@ -108364,12 +109124,14 @@
108364109124
}
108365109125
if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108366109126
yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108367109127
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108368109128
}
109129
+#line 3142 "parse.c"
108369109130
break;
108370109131
case 230: /* expr ::= expr in_op nm dbnm */
109132
+#line 1015 "parse.y"
108371109133
{
108372109134
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
108373109135
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy118.pExpr, 0, 0);
108374109136
if( yygotominor.yy118.pExpr ){
108375109137
yygotominor.yy118.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
@@ -108380,12 +109142,14 @@
108380109142
}
108381109143
if( yymsp[-2].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108382109144
yygotominor.yy118.zStart = yymsp[-3].minor.yy118.zStart;
108383109145
yygotominor.yy118.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
108384109146
}
109147
+#line 3160 "parse.c"
108385109148
break;
108386109149
case 231: /* expr ::= EXISTS LP select RP */
109150
+#line 1029 "parse.y"
108387109151
{
108388109152
Expr *p = yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
108389109153
if( p ){
108390109154
p->x.pSelect = yymsp[-1].minor.yy387;
108391109155
ExprSetProperty(p, EP_xIsSelect);
@@ -108394,12 +109158,14 @@
108394109158
sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
108395109159
}
108396109160
yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
108397109161
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108398109162
}
109163
+#line 3176 "parse.c"
108399109164
break;
108400109165
case 232: /* expr ::= CASE case_operand case_exprlist case_else END */
109166
+#line 1044 "parse.y"
108401109167
{
108402109168
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, 0);
108403109169
if( yygotominor.yy118.pExpr ){
108404109170
yygotominor.yy118.pExpr->x.pList = yymsp[-2].minor.yy322;
108405109171
sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
@@ -108407,38 +109173,50 @@
108407109173
sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
108408109174
}
108409109175
yygotominor.yy118.zStart = yymsp[-4].minor.yy0.z;
108410109176
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108411109177
}
109178
+#line 3191 "parse.c"
108412109179
break;
108413109180
case 233: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
109181
+#line 1057 "parse.y"
108414109182
{
108415109183
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy118.pExpr);
108416109184
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
108417109185
}
109186
+#line 3199 "parse.c"
108418109187
break;
108419109188
case 234: /* case_exprlist ::= WHEN expr THEN expr */
109189
+#line 1061 "parse.y"
108420109190
{
108421109191
yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
108422109192
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
108423109193
}
109194
+#line 3207 "parse.c"
108424109195
break;
108425109196
case 243: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
109197
+#line 1090 "parse.y"
108426109198
{
108427109199
sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0,
108428109200
sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy322, yymsp[-9].minor.yy4,
108429109201
&yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy4);
108430109202
}
109203
+#line 3216 "parse.c"
108431109204
break;
108432109205
case 244: /* uniqueflag ::= UNIQUE */
108433109206
case 298: /* raisetype ::= ABORT */ yytestcase(yyruleno==298);
109207
+#line 1097 "parse.y"
108434109208
{yygotominor.yy4 = OE_Abort;}
109209
+#line 3222 "parse.c"
108435109210
break;
108436109211
case 245: /* uniqueflag ::= */
109212
+#line 1098 "parse.y"
108437109213
{yygotominor.yy4 = OE_None;}
109214
+#line 3227 "parse.c"
108438109215
break;
108439109216
case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
109217
+#line 1107 "parse.y"
108440109218
{
108441109219
Expr *p = 0;
108442109220
if( yymsp[-1].minor.yy0.n>0 ){
108443109221
p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
108444109222
sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
@@ -108446,12 +109224,14 @@
108446109224
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
108447109225
sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
108448109226
sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
108449109227
if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108450109228
}
109229
+#line 3242 "parse.c"
108451109230
break;
108452109231
case 249: /* idxlist ::= nm collate sortorder */
109232
+#line 1118 "parse.y"
108453109233
{
108454109234
Expr *p = 0;
108455109235
if( yymsp[-1].minor.yy0.n>0 ){
108456109236
p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
108457109237
sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
@@ -108459,214 +109239,307 @@
108459109239
yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
108460109240
sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108461109241
sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
108462109242
if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108463109243
}
109244
+#line 3257 "parse.c"
108464109245
break;
108465109246
case 250: /* collate ::= */
109247
+#line 1131 "parse.y"
108466109248
{yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
109249
+#line 3262 "parse.c"
108467109250
break;
108468109251
case 252: /* cmd ::= DROP INDEX ifexists fullname */
109252
+#line 1137 "parse.y"
108469109253
{sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
109254
+#line 3267 "parse.c"
108470109255
break;
108471109256
case 253: /* cmd ::= VACUUM */
108472109257
case 254: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==254);
109258
+#line 1143 "parse.y"
108473109259
{sqlite3Vacuum(pParse);}
109260
+#line 3273 "parse.c"
108474109261
break;
108475109262
case 255: /* cmd ::= PRAGMA nm dbnm */
109263
+#line 1151 "parse.y"
108476109264
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
109265
+#line 3278 "parse.c"
108477109266
break;
108478109267
case 256: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
109268
+#line 1152 "parse.y"
108479109269
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
109270
+#line 3283 "parse.c"
108480109271
break;
108481109272
case 257: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
109273
+#line 1153 "parse.y"
108482109274
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
109275
+#line 3288 "parse.c"
108483109276
break;
108484109277
case 258: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
109278
+#line 1155 "parse.y"
108485109279
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
109280
+#line 3293 "parse.c"
108486109281
break;
108487109282
case 259: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
109283
+#line 1157 "parse.y"
108488109284
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
109285
+#line 3298 "parse.c"
108489109286
break;
108490109287
case 270: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
109288
+#line 1175 "parse.y"
108491109289
{
108492109290
Token all;
108493109291
all.z = yymsp[-3].minor.yy0.z;
108494109292
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
108495109293
sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
108496109294
}
109295
+#line 3308 "parse.c"
108497109296
break;
108498109297
case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
109298
+#line 1184 "parse.y"
108499109299
{
108500109300
sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
108501109301
yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
108502109302
}
109303
+#line 3316 "parse.c"
108503109304
break;
108504109305
case 272: /* trigger_time ::= BEFORE */
108505109306
case 275: /* trigger_time ::= */ yytestcase(yyruleno==275);
109307
+#line 1190 "parse.y"
108506109308
{ yygotominor.yy4 = TK_BEFORE; }
109309
+#line 3322 "parse.c"
108507109310
break;
108508109311
case 273: /* trigger_time ::= AFTER */
109312
+#line 1191 "parse.y"
108509109313
{ yygotominor.yy4 = TK_AFTER; }
109314
+#line 3327 "parse.c"
108510109315
break;
108511109316
case 274: /* trigger_time ::= INSTEAD OF */
109317
+#line 1192 "parse.y"
108512109318
{ yygotominor.yy4 = TK_INSTEAD;}
109319
+#line 3332 "parse.c"
108513109320
break;
108514109321
case 276: /* trigger_event ::= DELETE|INSERT */
108515109322
case 277: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==277);
109323
+#line 1197 "parse.y"
108516109324
{yygotominor.yy90.a = yymsp[0].major; yygotominor.yy90.b = 0;}
109325
+#line 3338 "parse.c"
108517109326
break;
108518109327
case 278: /* trigger_event ::= UPDATE OF inscollist */
109328
+#line 1199 "parse.y"
108519109329
{yygotominor.yy90.a = TK_UPDATE; yygotominor.yy90.b = yymsp[0].minor.yy384;}
109330
+#line 3343 "parse.c"
108520109331
break;
108521109332
case 281: /* when_clause ::= */
108522109333
case 303: /* key_opt ::= */ yytestcase(yyruleno==303);
109334
+#line 1206 "parse.y"
108523109335
{ yygotominor.yy314 = 0; }
109336
+#line 3349 "parse.c"
108524109337
break;
108525109338
case 282: /* when_clause ::= WHEN expr */
108526109339
case 304: /* key_opt ::= KEY expr */ yytestcase(yyruleno==304);
109340
+#line 1207 "parse.y"
108527109341
{ yygotominor.yy314 = yymsp[0].minor.yy118.pExpr; }
109342
+#line 3355 "parse.c"
108528109343
break;
108529109344
case 283: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
109345
+#line 1211 "parse.y"
108530109346
{
108531109347
assert( yymsp[-2].minor.yy203!=0 );
108532109348
yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
108533109349
yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
108534109350
yygotominor.yy203 = yymsp[-2].minor.yy203;
108535109351
}
109352
+#line 3365 "parse.c"
108536109353
break;
108537109354
case 284: /* trigger_cmd_list ::= trigger_cmd SEMI */
109355
+#line 1217 "parse.y"
108538109356
{
108539109357
assert( yymsp[-1].minor.yy203!=0 );
108540109358
yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
108541109359
yygotominor.yy203 = yymsp[-1].minor.yy203;
108542109360
}
109361
+#line 3374 "parse.c"
108543109362
break;
108544109363
case 286: /* trnm ::= nm DOT nm */
109364
+#line 1229 "parse.y"
108545109365
{
108546109366
yygotominor.yy0 = yymsp[0].minor.yy0;
108547109367
sqlite3ErrorMsg(pParse,
108548109368
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
108549109369
"statements within triggers");
108550109370
}
109371
+#line 3384 "parse.c"
108551109372
break;
108552109373
case 288: /* tridxby ::= INDEXED BY nm */
109374
+#line 1241 "parse.y"
108553109375
{
108554109376
sqlite3ErrorMsg(pParse,
108555109377
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
108556109378
"within triggers");
108557109379
}
109380
+#line 3393 "parse.c"
108558109381
break;
108559109382
case 289: /* tridxby ::= NOT INDEXED */
109383
+#line 1246 "parse.y"
108560109384
{
108561109385
sqlite3ErrorMsg(pParse,
108562109386
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
108563109387
"within triggers");
108564109388
}
109389
+#line 3402 "parse.c"
108565109390
break;
108566109391
case 290: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
109392
+#line 1259 "parse.y"
108567109393
{ yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
109394
+#line 3407 "parse.c"
108568109395
break;
108569109396
case 291: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt VALUES LP itemlist RP */
109397
+#line 1264 "parse.y"
108570109398
{yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy384, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy210);}
109399
+#line 3412 "parse.c"
108571109400
break;
108572109401
case 292: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
109402
+#line 1267 "parse.y"
108573109403
{yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
109404
+#line 3417 "parse.c"
108574109405
break;
108575109406
case 293: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
109407
+#line 1271 "parse.y"
108576109408
{yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
109409
+#line 3422 "parse.c"
108577109410
break;
108578109411
case 294: /* trigger_cmd ::= select */
109412
+#line 1274 "parse.y"
108579109413
{yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
109414
+#line 3427 "parse.c"
108580109415
break;
108581109416
case 295: /* expr ::= RAISE LP IGNORE RP */
109417
+#line 1277 "parse.y"
108582109418
{
108583109419
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
108584109420
if( yygotominor.yy118.pExpr ){
108585109421
yygotominor.yy118.pExpr->affinity = OE_Ignore;
108586109422
}
108587109423
yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
108588109424
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108589109425
}
109426
+#line 3439 "parse.c"
108590109427
break;
108591109428
case 296: /* expr ::= RAISE LP raisetype COMMA nm RP */
109429
+#line 1285 "parse.y"
108592109430
{
108593109431
yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
108594109432
if( yygotominor.yy118.pExpr ) {
108595109433
yygotominor.yy118.pExpr->affinity = (char)yymsp[-3].minor.yy4;
108596109434
}
108597109435
yygotominor.yy118.zStart = yymsp[-5].minor.yy0.z;
108598109436
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108599109437
}
109438
+#line 3451 "parse.c"
108600109439
break;
108601109440
case 297: /* raisetype ::= ROLLBACK */
109441
+#line 1296 "parse.y"
108602109442
{yygotominor.yy4 = OE_Rollback;}
109443
+#line 3456 "parse.c"
108603109444
break;
108604109445
case 299: /* raisetype ::= FAIL */
109446
+#line 1298 "parse.y"
108605109447
{yygotominor.yy4 = OE_Fail;}
109448
+#line 3461 "parse.c"
108606109449
break;
108607109450
case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
109451
+#line 1303 "parse.y"
108608109452
{
108609109453
sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
108610109454
}
109455
+#line 3468 "parse.c"
108611109456
break;
108612109457
case 301: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
109458
+#line 1310 "parse.y"
108613109459
{
108614109460
sqlite3Attach(pParse, yymsp[-3].minor.yy118.pExpr, yymsp[-1].minor.yy118.pExpr, yymsp[0].minor.yy314);
108615109461
}
109462
+#line 3475 "parse.c"
108616109463
break;
108617109464
case 302: /* cmd ::= DETACH database_kw_opt expr */
109465
+#line 1313 "parse.y"
108618109466
{
108619109467
sqlite3Detach(pParse, yymsp[0].minor.yy118.pExpr);
108620109468
}
109469
+#line 3482 "parse.c"
108621109470
break;
108622109471
case 307: /* cmd ::= REINDEX */
109472
+#line 1328 "parse.y"
108623109473
{sqlite3Reindex(pParse, 0, 0);}
109474
+#line 3487 "parse.c"
108624109475
break;
108625109476
case 308: /* cmd ::= REINDEX nm dbnm */
109477
+#line 1329 "parse.y"
108626109478
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
109479
+#line 3492 "parse.c"
108627109480
break;
108628109481
case 309: /* cmd ::= ANALYZE */
109482
+#line 1334 "parse.y"
108629109483
{sqlite3Analyze(pParse, 0, 0);}
109484
+#line 3497 "parse.c"
108630109485
break;
108631109486
case 310: /* cmd ::= ANALYZE nm dbnm */
109487
+#line 1335 "parse.y"
108632109488
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
109489
+#line 3502 "parse.c"
108633109490
break;
108634109491
case 311: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
109492
+#line 1340 "parse.y"
108635109493
{
108636109494
sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
108637109495
}
109496
+#line 3509 "parse.c"
108638109497
break;
108639109498
case 312: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
109499
+#line 1343 "parse.y"
108640109500
{
108641109501
sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
108642109502
}
109503
+#line 3516 "parse.c"
108643109504
break;
108644109505
case 313: /* add_column_fullname ::= fullname */
109506
+#line 1346 "parse.y"
108645109507
{
108646109508
pParse->db->lookaside.bEnabled = 0;
108647109509
sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
108648109510
}
109511
+#line 3524 "parse.c"
108649109512
break;
108650109513
case 316: /* cmd ::= create_vtab */
109514
+#line 1356 "parse.y"
108651109515
{sqlite3VtabFinishParse(pParse,0);}
109516
+#line 3529 "parse.c"
108652109517
break;
108653109518
case 317: /* cmd ::= create_vtab LP vtabarglist RP */
109519
+#line 1357 "parse.y"
108654109520
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
109521
+#line 3534 "parse.c"
108655109522
break;
108656109523
case 318: /* create_vtab ::= createkw VIRTUAL TABLE nm dbnm USING nm */
109524
+#line 1358 "parse.y"
108657109525
{
108658109526
sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
108659109527
}
109528
+#line 3541 "parse.c"
108660109529
break;
108661109530
case 321: /* vtabarg ::= */
109531
+#line 1363 "parse.y"
108662109532
{sqlite3VtabArgInit(pParse);}
109533
+#line 3546 "parse.c"
108663109534
break;
108664109535
case 323: /* vtabargtoken ::= ANY */
108665109536
case 324: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==324);
108666109537
case 325: /* lp ::= LP */ yytestcase(yyruleno==325);
109538
+#line 1365 "parse.y"
108667109539
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
109540
+#line 3553 "parse.c"
108668109541
break;
108669109542
default:
108670109543
/* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
108671109544
/* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
108672109545
/* (2) cmdlist ::= ecmd */ yytestcase(yyruleno==2);
@@ -108764,15 +109637,17 @@
108764109637
int yymajor, /* The major type of the error token */
108765109638
YYMINORTYPE yyminor /* The minor type of the error token */
108766109639
){
108767109640
sqlite3ParserARG_FETCH;
108768109641
#define TOKEN (yyminor.yy0)
109642
+#line 32 "parse.y"
108769109643
108770109644
UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
108771109645
assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */
108772109646
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
108773109647
pParse->parseError = 1;
109648
+#line 3661 "parse.c"
108774109649
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
108775109650
}
108776109651
108777109652
/*
108778109653
** The following is executed when the parser accepts
@@ -108962,10 +109837,11 @@
108962109837
return;
108963109838
}
108964109839
108965109840
/************** End of parse.c ***********************************************/
108966109841
/************** Begin file tokenize.c ****************************************/
109842
+#line 1 "tsrc/tokenize.c"
108967109843
/*
108968109844
** 2001 September 15
108969109845
**
108970109846
** The author disclaims copyright to this source code. In place of
108971109847
** a legal notice, here is a blessing:
@@ -109027,10 +109903,11 @@
109027109903
** named keywordhash.h and then included into this source file by
109028109904
** the #include below.
109029109905
*/
109030109906
/************** Include keywordhash.h in the middle of tokenize.c ************/
109031109907
/************** Begin file keywordhash.h *************************************/
109908
+#line 1 "tsrc/keywordhash.h"
109032109909
/***** This file contains automatically generated code ******
109033109910
**
109034109911
** The code in this file has been automatically generated by
109035109912
**
109036109913
** sqlite/tool/mkkeywordhash.c
@@ -109300,10 +110177,11 @@
109300110177
}
109301110178
#define SQLITE_N_KEYWORD 121
109302110179
109303110180
/************** End of keywordhash.h *****************************************/
109304110181
/************** Continuing where we left off in tokenize.c *******************/
110182
+#line 66 "tsrc/tokenize.c"
109305110183
109306110184
109307110185
/*
109308110186
** If X is a character that can be used in an identifier then
109309110187
** IdChar(X) will be true. Otherwise it is false.
@@ -109764,10 +110642,11 @@
109764110642
return nErr;
109765110643
}
109766110644
109767110645
/************** End of tokenize.c ********************************************/
109768110646
/************** Begin file complete.c ****************************************/
110647
+#line 1 "tsrc/complete.c"
109769110648
/*
109770110649
** 2001 September 15
109771110650
**
109772110651
** The author disclaims copyright to this source code. In place of
109773110652
** a legal notice, here is a blessing:
@@ -110049,10 +110928,11 @@
110049110928
#endif /* SQLITE_OMIT_UTF16 */
110050110929
#endif /* SQLITE_OMIT_COMPLETE */
110051110930
110052110931
/************** End of complete.c ********************************************/
110053110932
/************** Begin file main.c ********************************************/
110933
+#line 1 "tsrc/main.c"
110054110934
/*
110055110935
** 2001 September 15
110056110936
**
110057110937
** The author disclaims copyright to this source code. In place of
110058110938
** a legal notice, here is a blessing:
@@ -110069,10 +110949,11 @@
110069110949
*/
110070110950
110071110951
#ifdef SQLITE_ENABLE_FTS3
110072110952
/************** Include fts3.h in the middle of main.c ***********************/
110073110953
/************** Begin file fts3.h ********************************************/
110954
+#line 1 "tsrc/fts3.h"
110074110955
/*
110075110956
** 2006 Oct 10
110076110957
**
110077110958
** The author disclaims copyright to this source code. In place of
110078110959
** a legal notice, here is a blessing:
@@ -110097,14 +110978,16 @@
110097110978
} /* extern "C" */
110098110979
#endif /* __cplusplus */
110099110980
110100110981
/************** End of fts3.h ************************************************/
110101110982
/************** Continuing where we left off in main.c ***********************/
110983
+#line 21 "tsrc/main.c"
110102110984
#endif
110103110985
#ifdef SQLITE_ENABLE_RTREE
110104110986
/************** Include rtree.h in the middle of main.c **********************/
110105110987
/************** Begin file rtree.h *******************************************/
110988
+#line 1 "tsrc/rtree.h"
110106110989
/*
110107110990
** 2008 May 26
110108110991
**
110109110992
** The author disclaims copyright to this source code. In place of
110110110993
** a legal notice, here is a blessing:
@@ -110129,14 +111012,16 @@
110129111012
} /* extern "C" */
110130111013
#endif /* __cplusplus */
110131111014
110132111015
/************** End of rtree.h ***********************************************/
110133111016
/************** Continuing where we left off in main.c ***********************/
111017
+#line 24 "tsrc/main.c"
110134111018
#endif
110135111019
#ifdef SQLITE_ENABLE_ICU
110136111020
/************** Include sqliteicu.h in the middle of main.c ******************/
110137111021
/************** Begin file sqliteicu.h ***************************************/
111022
+#line 1 "tsrc/sqliteicu.h"
110138111023
/*
110139111024
** 2008 May 26
110140111025
**
110141111026
** The author disclaims copyright to this source code. In place of
110142111027
** a legal notice, here is a blessing:
@@ -110162,10 +111047,11 @@
110162111047
#endif /* __cplusplus */
110163111048
110164111049
110165111050
/************** End of sqliteicu.h *******************************************/
110166111051
/************** Continuing where we left off in main.c ***********************/
111052
+#line 27 "tsrc/main.c"
110167111053
#endif
110168111054
110169111055
#ifndef SQLITE_AMALGAMATION
110170111056
/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
110171111057
** contains the text of SQLITE_VERSION macro.
@@ -113092,10 +113978,11 @@
113092113978
return 0;
113093113979
}
113094113980
113095113981
/************** End of main.c ************************************************/
113096113982
/************** Begin file notify.c ******************************************/
113983
+#line 1 "tsrc/notify.c"
113097113984
/*
113098113985
** 2009 March 3
113099113986
**
113100113987
** The author disclaims copyright to this source code. In place of
113101113988
** a legal notice, here is a blessing:
@@ -113425,10 +114312,11 @@
113425114312
}
113426114313
#endif
113427114314
113428114315
/************** End of notify.c **********************************************/
113429114316
/************** Begin file fts3.c ********************************************/
114317
+#line 1 "tsrc/fts3.c"
113430114318
/*
113431114319
** 2006 Oct 10
113432114320
**
113433114321
** The author disclaims copyright to this source code. In place of
113434114322
** a legal notice, here is a blessing:
@@ -113721,10 +114609,11 @@
113721114609
** into a single segment.
113722114610
*/
113723114611
113724114612
/************** Include fts3Int.h in the middle of fts3.c ********************/
113725114613
/************** Begin file fts3Int.h *****************************************/
114614
+#line 1 "tsrc/fts3Int.h"
113726114615
/*
113727114616
** 2009 Nov 12
113728114617
**
113729114618
** The author disclaims copyright to this source code. In place of
113730114619
** a legal notice, here is a blessing:
@@ -113759,10 +114648,11 @@
113759114648
SQLITE_API extern const sqlite3_api_routines *sqlite3_api;
113760114649
#endif
113761114650
113762114651
/************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
113763114652
/************** Begin file fts3_tokenizer.h **********************************/
114653
+#line 1 "tsrc/fts3_tokenizer.h"
113764114654
/*
113765114655
** 2006 July 10
113766114656
**
113767114657
** The author disclaims copyright to this source code.
113768114658
**
@@ -113913,12 +114803,14 @@
113913114803
113914114804
#endif /* _FTS3_TOKENIZER_H_ */
113915114805
113916114806
/************** End of fts3_tokenizer.h **************************************/
113917114807
/************** Continuing where we left off in fts3Int.h ********************/
114808
+#line 40 "tsrc/fts3Int.h"
113918114809
/************** Include fts3_hash.h in the middle of fts3Int.h ***************/
113919114810
/************** Begin file fts3_hash.h ***************************************/
114811
+#line 1 "tsrc/fts3_hash.h"
113920114812
/*
113921114813
** 2001 September 22
113922114814
**
113923114815
** The author disclaims copyright to this source code. In place of
113924114816
** a legal notice, here is a blessing:
@@ -114030,10 +114922,11 @@
114030114922
114031114923
#endif /* _FTS3_HASH_H_ */
114032114924
114033114925
/************** End of fts3_hash.h *******************************************/
114034114926
/************** Continuing where we left off in fts3Int.h ********************/
114927
+#line 41 "tsrc/fts3Int.h"
114035114928
114036114929
/*
114037114930
** This constant controls how often segments are merged. Once there are
114038114931
** FTS3_MERGE_COUNT segments of level N, they are merged into a single
114039114932
** segment of level N+1.
@@ -114506,10 +115399,11 @@
114506115399
#endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
114507115400
#endif /* _FTSINT_H */
114508115401
114509115402
/************** End of fts3Int.h *********************************************/
114510115403
/************** Continuing where we left off in fts3.c ***********************/
115404
+#line 296 "tsrc/fts3.c"
114511115405
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
114512115406
114513115407
#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
114514115408
# define SQLITE_CORE 1
114515115409
#endif
@@ -119055,10 +119949,11 @@
119055119949
119056119950
#endif
119057119951
119058119952
/************** End of fts3.c ************************************************/
119059119953
/************** Begin file fts3_aux.c ****************************************/
119954
+#line 1 "tsrc/fts3_aux.c"
119060119955
/*
119061119956
** 2011 Jan 27
119062119957
**
119063119958
** The author disclaims copyright to this source code. In place of
119064119959
** a legal notice, here is a blessing:
@@ -119531,10 +120426,11 @@
119531120426
119532120427
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
119533120428
119534120429
/************** End of fts3_aux.c ********************************************/
119535120430
/************** Begin file fts3_expr.c ***************************************/
120431
+#line 1 "tsrc/fts3_expr.c"
119536120432
/*
119537120433
** 2008 Nov 28
119538120434
**
119539120435
** The author disclaims copyright to this source code. In place of
119540120436
** a legal notice, here is a blessing:
@@ -120497,10 +121393,11 @@
120497121393
#endif
120498121394
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
120499121395
120500121396
/************** End of fts3_expr.c *******************************************/
120501121397
/************** Begin file fts3_hash.c ***************************************/
121398
+#line 1 "tsrc/fts3_hash.c"
120502121399
/*
120503121400
** 2001 September 22
120504121401
**
120505121402
** The author disclaims copyright to this source code. In place of
120506121403
** a legal notice, here is a blessing:
@@ -120881,10 +121778,11 @@
120881121778
120882121779
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
120883121780
120884121781
/************** End of fts3_hash.c *******************************************/
120885121782
/************** Begin file fts3_porter.c *************************************/
121783
+#line 1 "tsrc/fts3_porter.c"
120886121784
/*
120887121785
** 2006 September 30
120888121786
**
120889121787
** The author disclaims copyright to this source code. In place of
120890121788
** a legal notice, here is a blessing:
@@ -121527,10 +122425,11 @@
121527122425
121528122426
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
121529122427
121530122428
/************** End of fts3_porter.c *****************************************/
121531122429
/************** Begin file fts3_tokenizer.c **********************************/
122430
+#line 1 "tsrc/fts3_tokenizer.c"
121532122431
/*
121533122432
** 2007 June 22
121534122433
**
121535122434
** The author disclaims copyright to this source code. In place of
121536122435
** a legal notice, here is a blessing:
@@ -122018,10 +122917,11 @@
122018122917
122019122918
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
122020122919
122021122920
/************** End of fts3_tokenizer.c **************************************/
122022122921
/************** Begin file fts3_tokenizer1.c *********************************/
122922
+#line 1 "tsrc/fts3_tokenizer1.c"
122023122923
/*
122024122924
** 2006 Oct 10
122025122925
**
122026122926
** The author disclaims copyright to this source code. In place of
122027122927
** a legal notice, here is a blessing:
@@ -122252,10 +123152,11 @@
122252123152
122253123153
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
122254123154
122255123155
/************** End of fts3_tokenizer1.c *************************************/
122256123156
/************** Begin file fts3_write.c **************************************/
123157
+#line 1 "tsrc/fts3_write.c"
122257123158
/*
122258123159
** 2009 Oct 23
122259123160
**
122260123161
** The author disclaims copyright to this source code. In place of
122261123162
** a legal notice, here is a blessing:
@@ -125522,10 +126423,11 @@
125522126423
125523126424
#endif
125524126425
125525126426
/************** End of fts3_write.c ******************************************/
125526126427
/************** Begin file fts3_snippet.c ************************************/
126428
+#line 1 "tsrc/fts3_snippet.c"
125527126429
/*
125528126430
** 2009 Oct 23
125529126431
**
125530126432
** The author disclaims copyright to this source code. In place of
125531126433
** a legal notice, here is a blessing:
@@ -127023,10 +127925,11 @@
127023127925
127024127926
#endif
127025127927
127026127928
/************** End of fts3_snippet.c ****************************************/
127027127929
/************** Begin file rtree.c *******************************************/
127930
+#line 1 "tsrc/rtree.c"
127028127931
/*
127029127932
** 2001 September 15
127030127933
**
127031127934
** The author disclaims copyright to this source code. In place of
127032127935
** a legal notice, here is a blessing:
@@ -130304,10 +131207,11 @@
130304131207
130305131208
#endif
130306131209
130307131210
/************** End of rtree.c ***********************************************/
130308131211
/************** Begin file icu.c *********************************************/
131212
+#line 1 "tsrc/icu.c"
130309131213
/*
130310131214
** 2007 May 6
130311131215
**
130312131216
** The author disclaims copyright to this source code. In place of
130313131217
** a legal notice, here is a blessing:
@@ -130806,10 +131710,11 @@
130806131710
130807131711
#endif
130808131712
130809131713
/************** End of icu.c *************************************************/
130810131714
/************** Begin file fts3_icu.c ****************************************/
131715
+#line 1 "tsrc/fts3_icu.c"
130811131716
/*
130812131717
** 2007 June 22
130813131718
**
130814131719
** The author disclaims copyright to this source code. In place of
130815131720
** a legal notice, here is a blessing:
130816131721
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.8. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -24,10 +24,11 @@
24 #endif
25 #ifndef SQLITE_API
26 # define SQLITE_API
27 #endif
28 /************** Begin file sqliteInt.h ***************************************/
 
29 /*
30 ** 2001 September 15
31 **
32 ** The author disclaims copyright to this source code. In place of
33 ** a legal notice, here is a blessing:
@@ -78,10 +79,11 @@
78 #include "config.h"
79 #endif
80
81 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
82 /************** Begin file sqliteLimit.h *************************************/
 
83 /*
84 ** 2007 May 7
85 **
86 ** The author disclaims copyright to this source code. In place of
87 ** a legal notice, here is a blessing:
@@ -289,10 +291,11 @@
289 # define SQLITE_MAX_TRIGGER_DEPTH 1000
290 #endif
291
292 /************** End of sqliteLimit.h *****************************************/
293 /************** Continuing where we left off in sqliteInt.h ******************/
 
294
295 /* Disable nuisance warnings on Borland compilers */
296 #if defined(__BORLANDC__)
297 #pragma warn -rch /* unreachable code */
298 #pragma warn -ccc /* Condition is always true or false */
@@ -394,11 +397,11 @@
394 ** assert() macro is enabled, each call into the Win32 native heap subsystem
395 ** will cause HeapValidate to be called. If heap validation should fail, an
396 ** assertion will be triggered.
397 **
398 ** (Historical note: There used to be several other options, but we've
399 ** pared it down to just these two.)
400 **
401 ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
402 ** the default.
403 */
404 #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1
@@ -545,10 +548,11 @@
545 # define unlikely(X) !!(X)
546 #endif
547
548 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
549 /************** Begin file sqlite3.h *****************************************/
 
550 /*
551 ** 2001 September 15
552 **
553 ** The author disclaims copyright to this source code. In place of
554 ** a legal notice, here is a blessing:
@@ -654,13 +658,13 @@
654 **
655 ** See also: [sqlite3_libversion()],
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.7.8"
660 #define SQLITE_VERSION_NUMBER 3007008
661 #define SQLITE_SOURCE_ID "2011-09-19 14:49:19 3e0da808d2f5b4d12046e05980ca04578f581177"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -1318,11 +1322,15 @@
1318 ** in order for the database to be readable. The fourth parameter to
1319 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
1320 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
1321 ** WAL mode. If the integer is -1, then it is overwritten with the current
1322 ** WAL persistence setting.
1323 **
 
 
 
 
1324 */
1325 #define SQLITE_FCNTL_LOCKSTATE 1
1326 #define SQLITE_GET_LOCKPROXYFILE 2
1327 #define SQLITE_SET_LOCKPROXYFILE 3
1328 #define SQLITE_LAST_ERRNO 4
@@ -1330,10 +1338,11 @@
1330 #define SQLITE_FCNTL_CHUNK_SIZE 6
1331 #define SQLITE_FCNTL_FILE_POINTER 7
1332 #define SQLITE_FCNTL_SYNC_OMITTED 8
1333 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
1334 #define SQLITE_FCNTL_PERSIST_WAL 10
 
1335
1336 /*
1337 ** CAPI3REF: Mutex Handle
1338 **
1339 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3397,11 +3406,11 @@
3397 ** a schema change, on the first [sqlite3_step()] call following any change
3398 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3399 ** ^The specific value of WHERE-clause [parameter] might influence the
3400 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3401 ** or [GLOB] operator or if the parameter is compared to an indexed column
3402 ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
3403 ** the
3404 ** </li>
3405 ** </ol>
3406 */
3407 SQLITE_API int sqlite3_prepare(
@@ -3900,10 +3909,16 @@
3900 ** current row of the result set of [prepared statement] P.
3901 ** ^If prepared statement P does not have results ready to return
3902 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3903 ** interfaces) then sqlite3_data_count(P) returns 0.
3904 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
 
 
 
 
 
 
3905 **
3906 ** See also: [sqlite3_column_count()]
3907 */
3908 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3909
@@ -6362,20 +6377,34 @@
6362 ** <dd>This parameter returns the approximate number of of bytes of heap
6363 ** and lookaside memory used by all prepared statements associated with
6364 ** the database connection.)^
6365 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6366 ** </dd>
 
 
 
 
 
 
 
 
 
 
 
 
6367 ** </dl>
6368 */
6369 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6370 #define SQLITE_DBSTATUS_CACHE_USED 1
6371 #define SQLITE_DBSTATUS_SCHEMA_USED 2
6372 #define SQLITE_DBSTATUS_STMT_USED 3
6373 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
6374 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6375 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6376 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
 
 
6377
6378
6379 /*
6380 ** CAPI3REF: Prepared Statement Status
6381 **
@@ -6425,11 +6454,10 @@
6425 ** <dd>^This is the number of rows inserted into transient indices that
6426 ** were created automatically in order to help joins run faster.
6427 ** A non-zero value in this counter may indicate an opportunity to
6428 ** improvement performance by adding permanent indices that do not
6429 ** need to be reinitialized each time the statement is run.</dd>
6430 **
6431 ** </dl>
6432 */
6433 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6434 #define SQLITE_STMTSTATUS_SORT 2
6435 #define SQLITE_STMTSTATUS_AUTOINDEX 3
@@ -7305,12 +7333,14 @@
7305 #endif /* ifndef _SQLITE3RTREE_H_ */
7306
7307
7308 /************** End of sqlite3.h *********************************************/
7309 /************** Continuing where we left off in sqliteInt.h ******************/
 
7310 /************** Include hash.h in the middle of sqliteInt.h ******************/
7311 /************** Begin file hash.h ********************************************/
 
7312 /*
7313 ** 2001 September 22
7314 **
7315 ** The author disclaims copyright to this source code. In place of
7316 ** a legal notice, here is a blessing:
@@ -7406,12 +7436,14 @@
7406
7407 #endif /* _SQLITE_HASH_H_ */
7408
7409 /************** End of hash.h ************************************************/
7410 /************** Continuing where we left off in sqliteInt.h ******************/
 
7411 /************** Include parse.h in the middle of sqliteInt.h *****************/
7412 /************** Begin file parse.h *******************************************/
 
7413 #define TK_SEMI 1
7414 #define TK_EXPLAIN 2
7415 #define TK_QUERY 3
7416 #define TK_PLAN 4
7417 #define TK_BEGIN 5
@@ -7568,10 +7600,11 @@
7568 #define TK_UMINUS 156
7569 #define TK_UPLUS 157
7570
7571 /************** End of parse.h ***********************************************/
7572 /************** Continuing where we left off in sqliteInt.h ******************/
 
7573 #include <stdio.h>
7574 #include <stdlib.h>
7575 #include <string.h>
7576 #include <assert.h>
7577 #include <stddef.h>
@@ -7711,10 +7744,22 @@
7711 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
7712 ** have to specify the value in the less intuitive manner shown:
7713 */
7714 #define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
7715
 
 
 
 
 
 
 
 
 
 
 
 
7716 /*
7717 ** Macros to determine whether the machine is big or little endian,
7718 ** evaluated at runtime.
7719 */
7720 #ifdef SQLITE_AMALGAMATION
@@ -7911,10 +7956,11 @@
7911 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
7912 ** pointer types (i.e. FuncDef) defined above.
7913 */
7914 /************** Include btree.h in the middle of sqliteInt.h *****************/
7915 /************** Begin file btree.h *******************************************/
 
7916 /*
7917 ** 2001 September 15
7918 **
7919 ** The author disclaims copyright to this source code. In place of
7920 ** a legal notice, here is a blessing:
@@ -8155,12 +8201,14 @@
8155
8156 #endif /* _BTREE_H_ */
8157
8158 /************** End of btree.h ***********************************************/
8159 /************** Continuing where we left off in sqliteInt.h ******************/
 
8160 /************** Include vdbe.h in the middle of sqliteInt.h ******************/
8161 /************** Begin file vdbe.h ********************************************/
 
8162 /*
8163 ** 2001 September 15
8164 **
8165 ** The author disclaims copyright to this source code. In place of
8166 ** a legal notice, here is a blessing:
@@ -8321,10 +8369,11 @@
8321 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
8322 ** header file that defines a number for each opcode used by the VDBE.
8323 */
8324 /************** Include opcodes.h in the middle of vdbe.h ********************/
8325 /************** Begin file opcodes.h *****************************************/
 
8326 /* Automatically generated. Do not edit */
8327 /* See the mkopcodeh.awk script for details */
8328 #define OP_Goto 1
8329 #define OP_Gosub 2
8330 #define OP_Return 3
@@ -8509,10 +8558,11 @@
8509 /* 136 */ 0x01, 0x00, 0x01, 0x00, 0x00, 0x04, 0x04, 0x04,\
8510 /* 144 */ 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00,}
8511
8512 /************** End of opcodes.h *********************************************/
8513 /************** Continuing where we left off in vdbe.h ***********************/
 
8514
8515 /*
8516 ** Prototypes for the VDBE interface. See comments on the implementation
8517 ** for a description of what each of these routines does.
8518 */
@@ -8583,12 +8633,14 @@
8583
8584 #endif
8585
8586 /************** End of vdbe.h ************************************************/
8587 /************** Continuing where we left off in sqliteInt.h ******************/
 
8588 /************** Include pager.h in the middle of sqliteInt.h *****************/
8589 /************** Begin file pager.h *******************************************/
 
8590 /*
8591 ** 2001 September 15
8592 **
8593 ** The author disclaims copyright to this source code. In place of
8594 ** a legal notice, here is a blessing:
@@ -8742,10 +8794,11 @@
8742 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
8743 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
8744 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
8745 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
8746 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
 
8747
8748 /* Functions used to truncate the database file. */
8749 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
8750
8751 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
@@ -8769,12 +8822,14 @@
8769
8770 #endif /* _PAGER_H_ */
8771
8772 /************** End of pager.h ***********************************************/
8773 /************** Continuing where we left off in sqliteInt.h ******************/
 
8774 /************** Include pcache.h in the middle of sqliteInt.h ****************/
8775 /************** Begin file pcache.h ******************************************/
 
8776 /*
8777 ** 2008 August 05
8778 **
8779 ** The author disclaims copyright to this source code. In place of
8780 ** a legal notice, here is a blessing:
@@ -8929,13 +8984,15 @@
8929
8930 #endif /* _PCACHE_H_ */
8931
8932 /************** End of pcache.h **********************************************/
8933 /************** Continuing where we left off in sqliteInt.h ******************/
 
8934
8935 /************** Include os.h in the middle of sqliteInt.h ********************/
8936 /************** Begin file os.h **********************************************/
 
8937 /*
8938 ** 2001 September 16
8939 **
8940 ** The author disclaims copyright to this source code. In place of
8941 ** a legal notice, here is a blessing:
@@ -9214,12 +9271,14 @@
9214
9215 #endif /* _SQLITE_OS_H_ */
9216
9217 /************** End of os.h **************************************************/
9218 /************** Continuing where we left off in sqliteInt.h ******************/
 
9219 /************** Include mutex.h in the middle of sqliteInt.h *****************/
9220 /************** Begin file mutex.h *******************************************/
 
9221 /*
9222 ** 2007 August 28
9223 **
9224 ** The author disclaims copyright to this source code. In place of
9225 ** a legal notice, here is a blessing:
@@ -9290,10 +9349,11 @@
9290 #define sqlite3MutexEnd()
9291 #endif /* defined(SQLITE_MUTEX_OMIT) */
9292
9293 /************** End of mutex.h ***********************************************/
9294 /************** Continuing where we left off in sqliteInt.h ******************/
 
9295
9296
9297 /*
9298 ** Each database file to be accessed by the system is an instance
9299 ** of the following structure. There are normally two of these structures
@@ -9918,11 +9978,11 @@
9918 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
9919 int nCol; /* Number of columns in this table */
9920 Column *aCol; /* Information about each column */
9921 Index *pIndex; /* List of SQL indexes on this table. */
9922 int tnum; /* Root BTree node for this table (see note above) */
9923 unsigned nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
9924 Select *pSelect; /* NULL for tables. Points to definition if a view. */
9925 u16 nRef; /* Number of pointers to this Table */
9926 u8 tabFlags; /* Mask of TF_* values */
9927 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
9928 FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10117,11 +10177,11 @@
10117 */
10118 struct Index {
10119 char *zName; /* Name of this index */
10120 int nColumn; /* Number of columns in the table used by this index */
10121 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10122 unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
10123 Table *pTable; /* The SQL table being indexed */
10124 int tnum; /* Page containing root of this index in database file */
10125 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10126 u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
10127 u8 bUnordered; /* Use this index for == or IN queries only */
@@ -10128,24 +10188,32 @@
10128 char *zColAff; /* String defining the affinity of each column */
10129 Index *pNext; /* The next index associated with the same table */
10130 Schema *pSchema; /* Schema containing this index */
10131 u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
10132 char **azColl; /* Array of collation sequence names for index */
10133 IndexSample *aSample; /* Array of SQLITE_INDEX_SAMPLES samples */
 
 
 
 
10134 };
10135
10136 /*
10137 ** Each sample stored in the sqlite_stat2 table is represented in memory
10138 ** using a structure of this type.
10139 */
10140 struct IndexSample {
10141 union {
10142 char *z; /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */
10143 double r; /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */
 
10144 } u;
10145 u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
10146 u8 nByte; /* Size in byte of text or blob. */
 
 
 
10147 };
10148
10149 /*
10150 ** Each token coming out of the lexer is an instance of
10151 ** this structure. Tokens are also used as part of an expression.
@@ -10593,14 +10661,14 @@
10593 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
10594 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
10595 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
10596 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
10597 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
10598 #define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
10599 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
10600 #define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
10601 #define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
10602
10603 /*
10604 ** The WHERE clause processing routine has two halves. The
10605 ** first part does the start of the WHERE loop and the second
10606 ** half does the tail of the WHERE loop. An instance of
@@ -11350,10 +11418,11 @@
11350 #else
11351 # define sqlite3ViewGetColumnNames(A,B) 0
11352 #endif
11353
11354 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
 
11355 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
11356 #ifndef SQLITE_OMIT_AUTOINCREMENT
11357 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
11358 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
11359 #else
@@ -11606,11 +11675,11 @@
11606 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11607 void(*)(void*));
11608 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
11609 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
11610 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
11611 #ifdef SQLITE_ENABLE_STAT2
11612 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *);
11613 #endif
11614 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
11615 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
11616 #ifndef SQLITE_AMALGAMATION
@@ -11893,10 +11962,11 @@
11893
11894 #endif /* _SQLITEINT_H_ */
11895
11896 /************** End of sqliteInt.h *******************************************/
11897 /************** Begin file global.c ******************************************/
 
11898 /*
11899 ** 2008 June 13
11900 **
11901 ** The author disclaims copyright to this source code. In place of
11902 ** a legal notice, here is a blessing:
@@ -12115,10 +12185,11 @@
12115 */
12116 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
12117
12118 /************** End of global.c **********************************************/
12119 /************** Begin file ctime.c *******************************************/
 
12120 /*
12121 ** 2010 February 23
12122 **
12123 ** The author disclaims copyright to this source code. In place of
12124 ** a legal notice, here is a blessing:
@@ -12232,10 +12303,13 @@
12232 #ifdef SQLITE_ENABLE_RTREE
12233 "ENABLE_RTREE",
12234 #endif
12235 #ifdef SQLITE_ENABLE_STAT2
12236 "ENABLE_STAT2",
 
 
 
12237 #endif
12238 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
12239 "ENABLE_UNLOCK_NOTIFY",
12240 #endif
12241 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
@@ -12445,13 +12519,10 @@
12445 "OMIT_WSD",
12446 #endif
12447 #ifdef SQLITE_OMIT_XFER_OPT
12448 "OMIT_XFER_OPT",
12449 #endif
12450 #ifdef SQLITE_PAGECACHE_BLOCKALLOC
12451 "PAGECACHE_BLOCKALLOC",
12452 #endif
12453 #ifdef SQLITE_PERFORMANCE_TRACE
12454 "PERFORMANCE_TRACE",
12455 #endif
12456 #ifdef SQLITE_PROXY_DEBUG
12457 "PROXY_DEBUG",
@@ -12519,10 +12590,11 @@
12519
12520 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
12521
12522 /************** End of ctime.c ***********************************************/
12523 /************** Begin file status.c ******************************************/
 
12524 /*
12525 ** 2008 June 18
12526 **
12527 ** The author disclaims copyright to this source code. In place of
12528 ** a legal notice, here is a blessing:
@@ -12536,10 +12608,11 @@
12536 ** This module implements the sqlite3_status() interface and related
12537 ** functionality.
12538 */
12539 /************** Include vdbeInt.h in the middle of status.c ******************/
12540 /************** Begin file vdbeInt.h *****************************************/
 
12541 /*
12542 ** 2003 September 6
12543 **
12544 ** The author disclaims copyright to this source code. In place of
12545 ** a legal notice, here is a blessing:
@@ -12987,10 +13060,11 @@
12987
12988 #endif /* !defined(_VDBEINT_H_) */
12989
12990 /************** End of vdbeInt.h *********************************************/
12991 /************** Continuing where we left off in status.c *********************/
 
12992
12993 /*
12994 ** Variables in which to record status information.
12995 */
12996 typedef struct sqlite3StatType sqlite3StatType;
@@ -13189,10 +13263,32 @@
13189 *pHighwater = 0;
13190 *pCurrent = nByte;
13191
13192 break;
13193 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13194
13195 default: {
13196 rc = SQLITE_ERROR;
13197 }
13198 }
@@ -13200,10 +13296,11 @@
13200 return rc;
13201 }
13202
13203 /************** End of status.c **********************************************/
13204 /************** Begin file date.c ********************************************/
 
13205 /*
13206 ** 2003 October 31
13207 **
13208 ** The author disclaims copyright to this source code. In place of
13209 ** a legal notice, here is a blessing:
@@ -14327,10 +14424,11 @@
14327 }
14328 }
14329
14330 /************** End of date.c ************************************************/
14331 /************** Begin file os.c **********************************************/
 
14332 /*
14333 ** 2005 November 29
14334 **
14335 ** The author disclaims copyright to this source code. In place of
14336 ** a legal notice, here is a blessing:
@@ -14660,10 +14758,11 @@
14660 return SQLITE_OK;
14661 }
14662
14663 /************** End of os.c **************************************************/
14664 /************** Begin file fault.c *******************************************/
 
14665 /*
14666 ** 2008 Jan 22
14667 **
14668 ** The author disclaims copyright to this source code. In place of
14669 ** a legal notice, here is a blessing:
@@ -14749,10 +14848,11 @@
14749
14750 #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
14751
14752 /************** End of fault.c ***********************************************/
14753 /************** Begin file mem0.c ********************************************/
 
14754 /*
14755 ** 2008 October 28
14756 **
14757 ** The author disclaims copyright to this source code. In place of
14758 ** a legal notice, here is a blessing:
@@ -14810,10 +14910,11 @@
14810
14811 #endif /* SQLITE_ZERO_MALLOC */
14812
14813 /************** End of mem0.c ************************************************/
14814 /************** Begin file mem1.c ********************************************/
 
14815 /*
14816 ** 2007 August 14
14817 **
14818 ** The author disclaims copyright to this source code. In place of
14819 ** a legal notice, here is a blessing:
@@ -14962,10 +15063,11 @@
14962
14963 #endif /* SQLITE_SYSTEM_MALLOC */
14964
14965 /************** End of mem1.c ************************************************/
14966 /************** Begin file mem2.c ********************************************/
 
14967 /*
14968 ** 2007 August 15
14969 **
14970 ** The author disclaims copyright to this source code. In place of
14971 ** a legal notice, here is a blessing:
@@ -15492,10 +15594,11 @@
15492
15493 #endif /* SQLITE_MEMDEBUG */
15494
15495 /************** End of mem2.c ************************************************/
15496 /************** Begin file mem3.c ********************************************/
 
15497 /*
15498 ** 2007 October 14
15499 **
15500 ** The author disclaims copyright to this source code. In place of
15501 ** a legal notice, here is a blessing:
@@ -16181,10 +16284,11 @@
16181
16182 #endif /* SQLITE_ENABLE_MEMSYS3 */
16183
16184 /************** End of mem3.c ************************************************/
16185 /************** Begin file mem5.c ********************************************/
 
16186 /*
16187 ** 2007 October 14
16188 **
16189 ** The author disclaims copyright to this source code. In place of
16190 ** a legal notice, here is a blessing:
@@ -16764,10 +16868,11 @@
16764
16765 #endif /* SQLITE_ENABLE_MEMSYS5 */
16766
16767 /************** End of mem5.c ************************************************/
16768 /************** Begin file mutex.c *******************************************/
 
16769 /*
16770 ** 2007 August 14
16771 **
16772 ** The author disclaims copyright to this source code. In place of
16773 ** a legal notice, here is a blessing:
@@ -16919,10 +17024,11 @@
16919
16920 #endif /* SQLITE_MUTEX_OMIT */
16921
16922 /************** End of mutex.c ***********************************************/
16923 /************** Begin file mutex_noop.c **************************************/
 
16924 /*
16925 ** 2008 October 07
16926 **
16927 ** The author disclaims copyright to this source code. In place of
16928 ** a legal notice, here is a blessing:
@@ -17127,10 +17233,11 @@
17127 #endif /* SQLITE_MUTEX_NOOP */
17128 #endif /* SQLITE_MUTEX_OMIT */
17129
17130 /************** End of mutex_noop.c ******************************************/
17131 /************** Begin file mutex_os2.c ***************************************/
 
17132 /*
17133 ** 2007 August 28
17134 **
17135 ** The author disclaims copyright to this source code. In place of
17136 ** a legal notice, here is a blessing:
@@ -17403,10 +17510,11 @@
17403 }
17404 #endif /* SQLITE_MUTEX_OS2 */
17405
17406 /************** End of mutex_os2.c *******************************************/
17407 /************** Begin file mutex_unix.c **************************************/
 
17408 /*
17409 ** 2007 August 28
17410 **
17411 ** The author disclaims copyright to this source code. In place of
17412 ** a legal notice, here is a blessing:
@@ -17756,10 +17864,11 @@
17756
17757 #endif /* SQLITE_MUTEX_PTHREAD */
17758
17759 /************** End of mutex_unix.c ******************************************/
17760 /************** Begin file mutex_w32.c ***************************************/
 
17761 /*
17762 ** 2007 August 14
17763 **
17764 ** The author disclaims copyright to this source code. In place of
17765 ** a legal notice, here is a blessing:
@@ -18090,10 +18199,11 @@
18090 }
18091 #endif /* SQLITE_MUTEX_W32 */
18092
18093 /************** End of mutex_w32.c *******************************************/
18094 /************** Begin file malloc.c ******************************************/
 
18095 /*
18096 ** 2001 September 15
18097 **
18098 ** The author disclaims copyright to this source code. In place of
18099 ** a legal notice, here is a blessing:
@@ -18869,10 +18979,11 @@
18869 return rc & (db ? db->errMask : 0xff);
18870 }
18871
18872 /************** End of malloc.c **********************************************/
18873 /************** Begin file printf.c ******************************************/
 
18874 /*
18875 ** The "printf" code that follows dates from the 1980's. It is in
18876 ** the public domain. The original comments are included here for
18877 ** completeness. They are very out-of-date but might be useful as
18878 ** an historical reference. Most of the "enhancements" have been backed
@@ -19900,10 +20011,11 @@
19900 }
19901 #endif
19902
19903 /************** End of printf.c **********************************************/
19904 /************** Begin file random.c ******************************************/
 
19905 /*
19906 ** 2001 September 15
19907 **
19908 ** The author disclaims copyright to this source code. In place of
19909 ** a legal notice, here is a blessing:
@@ -20047,10 +20159,11 @@
20047 }
20048 #endif /* SQLITE_OMIT_BUILTIN_TEST */
20049
20050 /************** End of random.c **********************************************/
20051 /************** Begin file utf.c *********************************************/
 
20052 /*
20053 ** 2004 April 13
20054 **
20055 ** The author disclaims copyright to this source code. In place of
20056 ** a legal notice, here is a blessing:
@@ -20511,11 +20624,11 @@
20511 ** no longer required.
20512 **
20513 ** If a malloc failure occurs, NULL is returned and the db.mallocFailed
20514 ** flag set.
20515 */
20516 #ifdef SQLITE_ENABLE_STAT2
20517 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
20518 Mem m;
20519 memset(&m, 0, sizeof(m));
20520 m.db = db;
20521 sqlite3VdbeMemSetStr(&m, z, n, SQLITE_UTF8, SQLITE_STATIC);
@@ -20608,10 +20721,11 @@
20608 #endif /* SQLITE_TEST */
20609 #endif /* SQLITE_OMIT_UTF16 */
20610
20611 /************** End of utf.c *************************************************/
20612 /************** Begin file util.c ********************************************/
 
20613 /*
20614 ** 2001 September 15
20615 **
20616 ** The author disclaims copyright to this source code. In place of
20617 ** a legal notice, here is a blessing:
@@ -21790,10 +21904,11 @@
21790 }
21791 #endif
21792
21793 /************** End of util.c ************************************************/
21794 /************** Begin file hash.c ********************************************/
 
21795 /*
21796 ** 2001 September 22
21797 **
21798 ** The author disclaims copyright to this source code. In place of
21799 ** a legal notice, here is a blessing:
@@ -22069,10 +22184,11 @@
22069 return 0;
22070 }
22071
22072 /************** End of hash.c ************************************************/
22073 /************** Begin file opcodes.c *****************************************/
 
22074 /* Automatically generated. Do not edit */
22075 /* See the mkopcodec.awk script for details. */
22076 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
22077 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
22078 static const char *const azName[] = { "?",
@@ -22231,10 +22347,11 @@
22231 }
22232 #endif
22233
22234 /************** End of opcodes.c *********************************************/
22235 /************** Begin file os_os2.c ******************************************/
 
22236 /*
22237 ** 2006 Feb 14
22238 **
22239 ** The author disclaims copyright to this source code. In place of
22240 ** a legal notice, here is a blessing:
@@ -22287,10 +22404,11 @@
22287 /*
22288 ** Include code that is common to all os_*.c files
22289 */
22290 /************** Include os_common.h in the middle of os_os2.c ****************/
22291 /************** Begin file os_common.h ***************************************/
 
22292 /*
22293 ** 2004 May 22
22294 **
22295 ** The author disclaims copyright to this source code. In place of
22296 ** a legal notice, here is a blessing:
@@ -22340,10 +22458,11 @@
22340 ** hwtime.h contains inline assembler code for implementing
22341 ** high-performance timing routines.
22342 */
22343 /************** Include hwtime.h in the middle of os_common.h ****************/
22344 /************** Begin file hwtime.h ******************************************/
 
22345 /*
22346 ** 2008 May 27
22347 **
22348 ** The author disclaims copyright to this source code. In place of
22349 ** a legal notice, here is a blessing:
@@ -22428,10 +22547,11 @@
22428
22429 #endif /* !defined(_HWTIME_H_) */
22430
22431 /************** End of hwtime.h **********************************************/
22432 /************** Continuing where we left off in os_common.h ******************/
 
22433
22434 static sqlite_uint64 g_start;
22435 static sqlite_uint64 g_elapsed;
22436 #define TIMER_START g_start=sqlite3Hwtime()
22437 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -22494,10 +22614,11 @@
22494
22495 #endif /* !defined(_OS_COMMON_H_) */
22496
22497 /************** End of os_common.h *******************************************/
22498 /************** Continuing where we left off in os_os2.c *********************/
 
22499
22500 /* Forward references */
22501 typedef struct os2File os2File; /* The file structure */
22502 typedef struct os2ShmNode os2ShmNode; /* A shared descritive memory node */
22503 typedef struct os2ShmLink os2ShmLink; /* A connection to shared-memory */
@@ -24365,10 +24486,11 @@
24365
24366 #endif /* SQLITE_OS_OS2 */
24367
24368 /************** End of os_os2.c **********************************************/
24369 /************** Begin file os_unix.c *****************************************/
 
24370 /*
24371 ** 2004 May 22
24372 **
24373 ** The author disclaims copyright to this source code. In place of
24374 ** a legal notice, here is a blessing:
@@ -24629,10 +24751,11 @@
24629 /*
24630 ** Include code that is common to all os_*.c files
24631 */
24632 /************** Include os_common.h in the middle of os_unix.c ***************/
24633 /************** Begin file os_common.h ***************************************/
 
24634 /*
24635 ** 2004 May 22
24636 **
24637 ** The author disclaims copyright to this source code. In place of
24638 ** a legal notice, here is a blessing:
@@ -24682,10 +24805,11 @@
24682 ** hwtime.h contains inline assembler code for implementing
24683 ** high-performance timing routines.
24684 */
24685 /************** Include hwtime.h in the middle of os_common.h ****************/
24686 /************** Begin file hwtime.h ******************************************/
 
24687 /*
24688 ** 2008 May 27
24689 **
24690 ** The author disclaims copyright to this source code. In place of
24691 ** a legal notice, here is a blessing:
@@ -24770,10 +24894,11 @@
24770
24771 #endif /* !defined(_HWTIME_H_) */
24772
24773 /************** End of hwtime.h **********************************************/
24774 /************** Continuing where we left off in os_common.h ******************/
 
24775
24776 static sqlite_uint64 g_start;
24777 static sqlite_uint64 g_elapsed;
24778 #define TIMER_START g_start=sqlite3Hwtime()
24779 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -24836,10 +24961,11 @@
24836
24837 #endif /* !defined(_OS_COMMON_H_) */
24838
24839 /************** End of os_common.h *******************************************/
24840 /************** Continuing where we left off in os_unix.c ********************/
 
24841
24842 /*
24843 ** Define various macros that are missing from some systems.
24844 */
24845 #ifndef O_LARGEFILE
@@ -29462,12 +29588,20 @@
29462 **
29463 ** where NN is a 4 digit decimal number. The NN naming schemes are
29464 ** used by the test_multiplex.c module.
29465 */
29466 nDb = sqlite3Strlen30(zPath) - 1;
29467 while( nDb>0 && zPath[nDb]!='-' ) nDb--;
29468 if( nDb==0 ) return SQLITE_OK;
 
 
 
 
 
 
 
 
29469 memcpy(zDb, zPath, nDb);
29470 zDb[nDb] = '\0';
29471
29472 if( 0==osStat(zDb, &sStat) ){
29473 *pMode = sStat.st_mode & 0777;
@@ -31345,10 +31479,11 @@
31345
31346 #endif /* SQLITE_OS_UNIX */
31347
31348 /************** End of os_unix.c *********************************************/
31349 /************** Begin file os_win.c ******************************************/
 
31350 /*
31351 ** 2004 May 22
31352 **
31353 ** The author disclaims copyright to this source code. In place of
31354 ** a legal notice, here is a blessing:
@@ -31406,10 +31541,11 @@
31406 /*
31407 ** Include code that is common to all os_*.c files
31408 */
31409 /************** Include os_common.h in the middle of os_win.c ****************/
31410 /************** Begin file os_common.h ***************************************/
 
31411 /*
31412 ** 2004 May 22
31413 **
31414 ** The author disclaims copyright to this source code. In place of
31415 ** a legal notice, here is a blessing:
@@ -31459,10 +31595,11 @@
31459 ** hwtime.h contains inline assembler code for implementing
31460 ** high-performance timing routines.
31461 */
31462 /************** Include hwtime.h in the middle of os_common.h ****************/
31463 /************** Begin file hwtime.h ******************************************/
 
31464 /*
31465 ** 2008 May 27
31466 **
31467 ** The author disclaims copyright to this source code. In place of
31468 ** a legal notice, here is a blessing:
@@ -31547,10 +31684,11 @@
31547
31548 #endif /* !defined(_HWTIME_H_) */
31549
31550 /************** End of hwtime.h **********************************************/
31551 /************** Continuing where we left off in os_common.h ******************/
 
31552
31553 static sqlite_uint64 g_start;
31554 static sqlite_uint64 g_elapsed;
31555 #define TIMER_START g_start=sqlite3Hwtime()
31556 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -31613,10 +31751,11 @@
31613
31614 #endif /* !defined(_OS_COMMON_H_) */
31615
31616 /************** End of os_common.h *******************************************/
31617 /************** Continuing where we left off in os_win.c *********************/
 
31618
31619 /*
31620 ** Some microsoft compilers lack this definition.
31621 */
31622 #ifndef INVALID_FILE_ATTRIBUTES
@@ -34169,11 +34308,11 @@
34169
34170 if( h==INVALID_HANDLE_VALUE ){
34171 pFile->lastErrno = GetLastError();
34172 winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name);
34173 free(zConverted);
34174 if( isReadWrite ){
34175 return winOpen(pVfs, zName, id,
34176 ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
34177 }else{
34178 return SQLITE_CANTOPEN_BKPT;
34179 }
@@ -34758,10 +34897,11 @@
34758
34759 #endif /* SQLITE_OS_WIN */
34760
34761 /************** End of os_win.c **********************************************/
34762 /************** Begin file bitvec.c ******************************************/
 
34763 /*
34764 ** 2008 February 16
34765 **
34766 ** The author disclaims copyright to this source code. In place of
34767 ** a legal notice, here is a blessing:
@@ -35168,10 +35308,11 @@
35168 }
35169 #endif /* SQLITE_OMIT_BUILTIN_TEST */
35170
35171 /************** End of bitvec.c **********************************************/
35172 /************** Begin file pcache.c ******************************************/
 
35173 /*
35174 ** 2008 August 05
35175 **
35176 ** The author disclaims copyright to this source code. In place of
35177 ** a legal notice, here is a blessing:
@@ -35764,10 +35905,11 @@
35764 }
35765 #endif
35766
35767 /************** End of pcache.c **********************************************/
35768 /************** Begin file pcache1.c *****************************************/
 
35769 /*
35770 ** 2008 November 05
35771 **
35772 ** The author disclaims copyright to this source code. In place of
35773 ** a legal notice, here is a blessing:
@@ -35789,12 +35931,10 @@
35789 typedef struct PCache1 PCache1;
35790 typedef struct PgHdr1 PgHdr1;
35791 typedef struct PgFreeslot PgFreeslot;
35792 typedef struct PGroup PGroup;
35793
35794 typedef struct PGroupBlock PGroupBlock;
35795 typedef struct PGroupBlockList PGroupBlockList;
35796
35797 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
35798 ** of one or more PCaches that are able to recycle each others unpinned
35799 ** pages when they are under memory pressure. A PGroup is an instance of
35800 ** the following object.
@@ -35821,69 +35961,11 @@
35821 int nMaxPage; /* Sum of nMax for purgeable caches */
35822 int nMinPage; /* Sum of nMin for purgeable caches */
35823 int mxPinned; /* nMaxpage + 10 - nMinPage */
35824 int nCurrentPage; /* Number of purgeable pages allocated */
35825 PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
35826 #ifdef SQLITE_PAGECACHE_BLOCKALLOC
35827 int isBusy; /* Do not run ReleaseMemory() if true */
35828 PGroupBlockList *pBlockList; /* List of block-lists for this group */
35829 #endif
35830 };
35831
35832 /*
35833 ** If SQLITE_PAGECACHE_BLOCKALLOC is defined when the library is built,
35834 ** each PGroup structure has a linked list of the the following starting
35835 ** at PGroup.pBlockList. There is one entry for each distinct page-size
35836 ** currently used by members of the PGroup (i.e. 1024 bytes, 4096 bytes
35837 ** etc.). Variable PGroupBlockList.nByte is set to the actual allocation
35838 ** size requested by each pcache, which is the database page-size plus
35839 ** the various header structures used by the pcache, pager and btree layers.
35840 ** Usually around (pgsz+200) bytes.
35841 **
35842 ** This size (pgsz+200) bytes is not allocated efficiently by some
35843 ** implementations of malloc. In particular, some implementations are only
35844 ** able to allocate blocks of memory chunks of 2^N bytes, where N is some
35845 ** integer value. Since the page-size is a power of 2, this means we
35846 ** end up wasting (pgsz-200) bytes in each allocation.
35847 **
35848 ** If SQLITE_PAGECACHE_BLOCKALLOC is defined, the (pgsz+200) byte blocks
35849 ** are not allocated directly. Instead, blocks of roughly M*(pgsz+200) bytes
35850 ** are requested from malloc allocator. After a block is returned,
35851 ** sqlite3MallocSize() is used to determine how many (pgsz+200) byte
35852 ** allocations can fit in the space returned by malloc(). This value may
35853 ** be more than M.
35854 **
35855 ** The blocks are stored in a doubly-linked list. Variable PGroupBlock.nEntry
35856 ** contains the number of allocations that will fit in the aData[] space.
35857 ** nEntry is limited to the number of bits in bitmask mUsed. If a slot
35858 ** within aData is in use, the corresponding bit in mUsed is set. Thus
35859 ** when (mUsed+1==(1 << nEntry)) the block is completely full.
35860 **
35861 ** Each time a slot within a block is freed, the block is moved to the start
35862 ** of the linked-list. And if a block becomes completely full, then it is
35863 ** moved to the end of the list. As a result, when searching for a free
35864 ** slot, only the first block in the list need be examined. If it is full,
35865 ** then it is guaranteed that all blocks are full.
35866 */
35867 struct PGroupBlockList {
35868 int nByte; /* Size of each allocation in bytes */
35869 PGroupBlock *pFirst; /* First PGroupBlock in list */
35870 PGroupBlock *pLast; /* Last PGroupBlock in list */
35871 PGroupBlockList *pNext; /* Next block-list attached to group */
35872 };
35873
35874 struct PGroupBlock {
35875 Bitmask mUsed; /* Mask of used slots */
35876 int nEntry; /* Maximum number of allocations in aData[] */
35877 u8 *aData; /* Pointer to data block */
35878 PGroupBlock *pNext; /* Next PGroupBlock in list */
35879 PGroupBlock *pPrev; /* Previous PGroupBlock in list */
35880 PGroupBlockList *pList; /* Owner list */
35881 };
35882
35883 /* Minimum value for PGroupBlock.nEntry */
35884 #define PAGECACHE_BLOCKALLOC_MINENTRY 15
35885
35886 /* Each page cache is an instance of the following object. Every
35887 ** open database file (including each in-memory database and each
35888 ** temporary or transient database) has a single page cache which
35889 ** is an instance of this object.
@@ -35983,21 +36065,10 @@
35983 **
35984 ** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
35985 */
35986 #define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
35987 #define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage)
35988
35989 /*
35990 ** Blocks used by the SQLITE_PAGECACHE_BLOCKALLOC blocks to store/retrieve
35991 ** a PGroupBlock pointer based on a pointer to a page buffer.
35992 */
35993 #define PAGE_SET_BLOCKPTR(pCache, pPg, pBlock) \
35994 ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) = pBlock )
35995
35996 #define PAGE_GET_BLOCKPTR(pCache, pPg) \
35997 ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) )
35998
35999
36000 /*
36001 ** Macros to enter and leave the PCache LRU mutex.
36002 */
36003 #define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
@@ -36120,159 +36191,32 @@
36120 return iSize;
36121 }
36122 }
36123 #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
36124
36125 #ifdef SQLITE_PAGECACHE_BLOCKALLOC
36126 /*
36127 ** The block pBlock belongs to list pList but is not currently linked in.
36128 ** Insert it into the start of the list.
36129 */
36130 static void addBlockToList(PGroupBlockList *pList, PGroupBlock *pBlock){
36131 pBlock->pPrev = 0;
36132 pBlock->pNext = pList->pFirst;
36133 pList->pFirst = pBlock;
36134 if( pBlock->pNext ){
36135 pBlock->pNext->pPrev = pBlock;
36136 }else{
36137 assert( pList->pLast==0 );
36138 pList->pLast = pBlock;
36139 }
36140 }
36141
36142 /*
36143 ** If there are no blocks in the list headed by pList, remove pList
36144 ** from the pGroup->pBlockList list and free it with sqlite3_free().
36145 */
36146 static void freeListIfEmpty(PGroup *pGroup, PGroupBlockList *pList){
36147 assert( sqlite3_mutex_held(pGroup->mutex) );
36148 if( pList->pFirst==0 ){
36149 PGroupBlockList **pp;
36150 for(pp=&pGroup->pBlockList; *pp!=pList; pp=&(*pp)->pNext);
36151 *pp = (*pp)->pNext;
36152 sqlite3_free(pList);
36153 }
36154 }
36155 #endif /* SQLITE_PAGECACHE_BLOCKALLOC */
36156
36157 /*
36158 ** Allocate a new page object initially associated with cache pCache.
36159 */
36160 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
36161 int nByte = sizeof(PgHdr1) + pCache->szPage;
36162 void *pPg = 0;
36163 PgHdr1 *p;
36164
36165 #ifdef SQLITE_PAGECACHE_BLOCKALLOC
36166 PGroup *pGroup = pCache->pGroup;
36167 PGroupBlockList *pList;
36168 PGroupBlock *pBlock;
36169 int i;
36170
36171 nByte += sizeof(PGroupBlockList *);
36172 nByte = ROUND8(nByte);
36173
36174 for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
36175 if( pList->nByte==nByte ) break;
36176 }
36177 if( pList==0 ){
36178 PGroupBlockList *pNew;
36179 assert( pGroup->isBusy==0 );
36180 assert( sqlite3_mutex_held(pGroup->mutex) );
36181 pGroup->isBusy = 1; /* Disable sqlite3PcacheReleaseMemory() */
36182 pNew = (PGroupBlockList *)sqlite3MallocZero(sizeof(PGroupBlockList));
36183 pGroup->isBusy = 0; /* Reenable sqlite3PcacheReleaseMemory() */
36184 if( pNew==0 ){
36185 /* malloc() failure. Return early. */
36186 return 0;
36187 }
36188 #ifdef SQLITE_DEBUG
36189 for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
36190 assert( pList->nByte!=nByte );
36191 }
36192 #endif
36193 pNew->nByte = nByte;
36194 pNew->pNext = pGroup->pBlockList;
36195 pGroup->pBlockList = pNew;
36196 pList = pNew;
36197 }
36198
36199 pBlock = pList->pFirst;
36200 if( pBlock==0 || pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) ){
36201 int sz;
36202
36203 /* Allocate a new block. Try to allocate enough space for the PGroupBlock
36204 ** structure and MINENTRY allocations of nByte bytes each. If the
36205 ** allocator returns more memory than requested, then more than MINENTRY
36206 ** allocations may fit in it. */
36207 assert( sqlite3_mutex_held(pGroup->mutex) );
36208 pcache1LeaveMutex(pCache->pGroup);
36209 sz = sizeof(PGroupBlock) + PAGECACHE_BLOCKALLOC_MINENTRY * nByte;
36210 pBlock = (PGroupBlock *)sqlite3Malloc(sz);
36211 pcache1EnterMutex(pCache->pGroup);
36212
36213 if( !pBlock ){
36214 freeListIfEmpty(pGroup, pList);
36215 return 0;
36216 }
36217 pBlock->nEntry = (sqlite3MallocSize(pBlock) - sizeof(PGroupBlock)) / nByte;
36218 if( pBlock->nEntry>=BMS ){
36219 pBlock->nEntry = BMS-1;
36220 }
36221 pBlock->pList = pList;
36222 pBlock->mUsed = 0;
36223 pBlock->aData = (u8 *)&pBlock[1];
36224 addBlockToList(pList, pBlock);
36225
36226 sz = sqlite3MallocSize(pBlock);
36227 sqlite3_mutex_enter(pcache1.mutex);
36228 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
36229 sqlite3_mutex_leave(pcache1.mutex);
36230 }
36231
36232 for(i=0; pPg==0 && ALWAYS(i<pBlock->nEntry); i++){
36233 if( 0==(pBlock->mUsed & ((Bitmask)1<<i)) ){
36234 pBlock->mUsed |= ((Bitmask)1<<i);
36235 pPg = (void *)&pBlock->aData[pList->nByte * i];
36236 }
36237 }
36238 assert( pPg );
36239 PAGE_SET_BLOCKPTR(pCache, pPg, pBlock);
36240
36241 /* If the block is now full, shift it to the end of the list */
36242 if( pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) && pList->pLast!=pBlock ){
36243 assert( pList->pFirst==pBlock );
36244 assert( pBlock->pPrev==0 );
36245 assert( pList->pLast->pNext==0 );
36246 pList->pFirst = pBlock->pNext;
36247 pList->pFirst->pPrev = 0;
36248 pBlock->pPrev = pList->pLast;
36249 pBlock->pNext = 0;
36250 pList->pLast->pNext = pBlock;
36251 pList->pLast = pBlock;
36252 }
36253 p = PAGE_TO_PGHDR1(pCache, pPg);
36254 if( pCache->bPurgeable ){
36255 pCache->pGroup->nCurrentPage++;
36256 }
36257 #else
36258 /* The group mutex must be released before pcache1Alloc() is called. This
36259 ** is because it may call sqlite3_release_memory(), which assumes that
36260 ** this mutex is not held. */
36261 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
36262 pcache1LeaveMutex(pCache->pGroup);
36263 pPg = pcache1Alloc(nByte);
36264 pcache1EnterMutex(pCache->pGroup);
 
36265 if( pPg ){
36266 p = PAGE_TO_PGHDR1(pCache, pPg);
36267 if( pCache->bPurgeable ){
36268 pCache->pGroup->nCurrentPage++;
36269 }
36270 }else{
36271 p = 0;
36272 }
36273 #endif
36274 return p;
36275 }
36276
36277 /*
36278 ** Free a page object allocated by pcache1AllocPage().
@@ -36282,53 +36226,12 @@
36282 ** with a NULL pointer, so we mark the NULL test with ALWAYS().
36283 */
36284 static void pcache1FreePage(PgHdr1 *p){
36285 if( ALWAYS(p) ){
36286 PCache1 *pCache = p->pCache;
36287 void *pPg = PGHDR1_TO_PAGE(p);
36288
36289 #ifdef SQLITE_PAGECACHE_BLOCKALLOC
36290 PGroupBlock *pBlock = PAGE_GET_BLOCKPTR(pCache, pPg);
36291 PGroupBlockList *pList = pBlock->pList;
36292 int i = ((u8 *)pPg - pBlock->aData) / pList->nByte;
36293
36294 assert( pPg==(void *)&pBlock->aData[i*pList->nByte] );
36295 assert( pBlock->mUsed & ((Bitmask)1<<i) );
36296 pBlock->mUsed &= ~((Bitmask)1<<i);
36297
36298 /* Remove the block from the list. If it is completely empty, free it.
36299 ** Or if it is not completely empty, re-insert it at the start of the
36300 ** list. */
36301 if( pList->pFirst==pBlock ){
36302 pList->pFirst = pBlock->pNext;
36303 if( pList->pFirst ) pList->pFirst->pPrev = 0;
36304 }else{
36305 pBlock->pPrev->pNext = pBlock->pNext;
36306 }
36307 if( pList->pLast==pBlock ){
36308 pList->pLast = pBlock->pPrev;
36309 if( pList->pLast ) pList->pLast->pNext = 0;
36310 }else{
36311 pBlock->pNext->pPrev = pBlock->pPrev;
36312 }
36313
36314 if( pBlock->mUsed==0 ){
36315 PGroup *pGroup = p->pCache->pGroup;
36316
36317 int sz = sqlite3MallocSize(pBlock);
36318 sqlite3_mutex_enter(pcache1.mutex);
36319 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -sz);
36320 sqlite3_mutex_leave(pcache1.mutex);
36321 freeListIfEmpty(pGroup, pList);
36322 sqlite3_free(pBlock);
36323 }else{
36324 addBlockToList(pList, pBlock);
36325 }
36326 #else
36327 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
36328 pcache1Free(pPg);
36329 #endif
36330 if( pCache->bPurgeable ){
36331 pCache->pGroup->nCurrentPage--;
36332 }
36333 }
36334 }
@@ -36935,13 +36838,10 @@
36935 ** been released, the function returns. The return value is the total number
36936 ** of bytes of memory released.
36937 */
36938 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
36939 int nFree = 0;
36940 #ifdef SQLITE_PAGECACHE_BLOCKALLOC
36941 if( pcache1.grp.isBusy ) return 0;
36942 #endif
36943 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
36944 assert( sqlite3_mutex_notheld(pcache1.mutex) );
36945 if( pcache1.pStart==0 ){
36946 PgHdr1 *p;
36947 pcache1EnterMutex(&pcache1.grp);
@@ -36980,10 +36880,11 @@
36980 }
36981 #endif
36982
36983 /************** End of pcache1.c *********************************************/
36984 /************** Begin file rowset.c ******************************************/
 
36985 /*
36986 ** 2008 December 3
36987 **
36988 ** The author disclaims copyright to this source code. In place of
36989 ** a legal notice, here is a blessing:
@@ -37404,10 +37305,11 @@
37404 return 0;
37405 }
37406
37407 /************** End of rowset.c **********************************************/
37408 /************** Begin file pager.c *******************************************/
 
37409 /*
37410 ** 2001 September 15
37411 **
37412 ** The author disclaims copyright to this source code. In place of
37413 ** a legal notice, here is a blessing:
@@ -37427,10 +37329,11 @@
37427 ** another is writing.
37428 */
37429 #ifndef SQLITE_OMIT_DISKIO
37430 /************** Include wal.h in the middle of pager.c ***********************/
37431 /************** Begin file wal.h *********************************************/
 
37432 /*
37433 ** 2010 February 1
37434 **
37435 ** The author disclaims copyright to this source code. In place of
37436 ** a legal notice, here is a blessing:
@@ -37551,10 +37454,11 @@
37551 #endif /* ifndef SQLITE_OMIT_WAL */
37552 #endif /* _WAL_H_ */
37553
37554 /************** End of wal.h *************************************************/
37555 /************** Continuing where we left off in pager.c **********************/
 
37556
37557
37558 /******************* NOTES ON THE DESIGN OF THE PAGER ************************
37559 **
37560 ** This comment block describes invariants that hold when using a rollback
@@ -38200,12 +38104,12 @@
38200 i64 journalSizeLimit; /* Size limit for persistent journal files */
38201 char *zFilename; /* Name of the database file */
38202 char *zJournal; /* Name of the journal file */
38203 int (*xBusyHandler)(void*); /* Function to call when busy */
38204 void *pBusyHandlerArg; /* Context argument for xBusyHandler */
 
38205 #ifdef SQLITE_TEST
38206 int nHit, nMiss; /* Cache hits and missing */
38207 int nRead, nWrite; /* Database pages read/written */
38208 #endif
38209 void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */
38210 #ifdef SQLITE_HAS_CODEC
38211 void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
@@ -41699,11 +41603,11 @@
41699 ** The doNotSpill flag inhibits all cache spilling regardless of whether
41700 ** or not a sync is required. This is set during a rollback.
41701 **
41702 ** Spilling is also prohibited when in an error state since that could
41703 ** lead to database corruption. In the current implementaton it
41704 ** is impossible for sqlite3PCacheFetch() to be called with createFlag==1
41705 ** while in the error state, hence it is impossible for this routine to
41706 ** be called in the error state. Nevertheless, we include a NEVER()
41707 ** test for the error state as a safeguard against future changes.
41708 */
41709 if( NEVER(pPager->errCode) ) return SQLITE_OK;
@@ -42535,18 +42439,17 @@
42535
42536 if( (*ppPage)->pPager && !noContent ){
42537 /* In this case the pcache already contains an initialized copy of
42538 ** the page. Return without further ado. */
42539 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
42540 PAGER_INCR(pPager->nHit);
42541 return SQLITE_OK;
42542
42543 }else{
42544 /* The pager cache has created a new page. Its content needs to
42545 ** be initialized. */
42546
42547 PAGER_INCR(pPager->nMiss);
42548 pPg = *ppPage;
42549 pPg->pPager = pPager;
42550
42551 /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
42552 ** number greater than this, or the unused locking-page, is requested. */
@@ -42578,10 +42481,11 @@
42578 }
42579 memset(pPg->pData, 0, pPager->pageSize);
42580 IOTRACE(("ZERO %p %d\n", pPager, pgno));
42581 }else{
42582 assert( pPg->pPager==pPager );
 
42583 rc = readDbPage(pPg);
42584 if( rc!=SQLITE_OK ){
42585 goto pager_acquire_err;
42586 }
42587 }
@@ -43611,10 +43515,35 @@
43611 a[9] = pPager->nRead;
43612 a[10] = pPager->nWrite;
43613 return a;
43614 }
43615 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43616
43617 /*
43618 ** Return true if this is an in-memory pager.
43619 */
43620 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
@@ -44362,10 +44291,11 @@
44362
44363 #endif /* SQLITE_OMIT_DISKIO */
44364
44365 /************** End of pager.c ***********************************************/
44366 /************** Begin file wal.c *********************************************/
 
44367 /*
44368 ** 2010 February 1
44369 **
44370 ** The author disclaims copyright to this source code. In place of
44371 ** a legal notice, here is a blessing:
@@ -47316,10 +47246,11 @@
47316
47317 #endif /* #ifndef SQLITE_OMIT_WAL */
47318
47319 /************** End of wal.c *************************************************/
47320 /************** Begin file btmutex.c *****************************************/
 
47321 /*
47322 ** 2007 August 27
47323 **
47324 ** The author disclaims copyright to this source code. In place of
47325 ** a legal notice, here is a blessing:
@@ -47335,10 +47266,11 @@
47335 ** big and we want to break it down some. This packaged seemed like
47336 ** a good breakout.
47337 */
47338 /************** Include btreeInt.h in the middle of btmutex.c ****************/
47339 /************** Begin file btreeInt.h ****************************************/
 
47340 /*
47341 ** 2004 April 6
47342 **
47343 ** The author disclaims copyright to this source code. In place of
47344 ** a legal notice, here is a blessing:
@@ -47980,10 +47912,11 @@
47980 #define get4byte sqlite3Get4byte
47981 #define put4byte sqlite3Put4byte
47982
47983 /************** End of btreeInt.h ********************************************/
47984 /************** Continuing where we left off in btmutex.c ********************/
 
47985 #ifndef SQLITE_OMIT_SHARED_CACHE
47986 #if SQLITE_THREADSAFE
47987
47988 /*
47989 ** Obtain the BtShared mutex associated with B-Tree handle p. Also,
@@ -48252,10 +48185,11 @@
48252 #endif /* if SQLITE_THREADSAFE */
48253 #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */
48254
48255 /************** End of btmutex.c *********************************************/
48256 /************** Begin file btree.c *******************************************/
 
48257 /*
48258 ** 2004 April 6
48259 **
48260 ** The author disclaims copyright to this source code. In place of
48261 ** a legal notice, here is a blessing:
@@ -56439,10 +56373,11 @@
56439 return rc;
56440 }
56441
56442 /************** End of btree.c ***********************************************/
56443 /************** Begin file backup.c ******************************************/
 
56444 /*
56445 ** 2009 January 28
56446 **
56447 ** The author disclaims copyright to this source code. In place of
56448 ** a legal notice, here is a blessing:
@@ -57108,13 +57043,21 @@
57108 ** goes wrong, the transaction on pTo is rolled back. If successful, the
57109 ** transaction is committed before returning.
57110 */
57111 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
57112 int rc;
 
57113 sqlite3_backup b;
57114 sqlite3BtreeEnter(pTo);
57115 sqlite3BtreeEnter(pFrom);
 
 
 
 
 
 
 
57116
57117 /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
57118 ** to 0. This is used by the implementations of sqlite3_backup_step()
57119 ** and sqlite3_backup_finish() to detect that they are being called
57120 ** from this function, not directly by the user.
@@ -57137,18 +57080,20 @@
57137 rc = sqlite3_backup_finish(&b);
57138 if( rc==SQLITE_OK ){
57139 pTo->pBt->pageSizeFixed = 0;
57140 }
57141
 
57142 sqlite3BtreeLeave(pFrom);
57143 sqlite3BtreeLeave(pTo);
57144 return rc;
57145 }
57146 #endif /* SQLITE_OMIT_VACUUM */
57147
57148 /************** End of backup.c **********************************************/
57149 /************** Begin file vdbemem.c *****************************************/
 
57150 /*
57151 ** 2004 May 26
57152 **
57153 ** The author disclaims copyright to this source code. In place of
57154 ** a legal notice, here is a blessing:
@@ -58171,15 +58116,15 @@
58171 *ppVal = 0;
58172 return SQLITE_OK;
58173 }
58174 op = pExpr->op;
58175
58176 /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT2.
58177 ** The ifdef here is to enable us to achieve 100% branch test coverage even
58178 ** when SQLITE_ENABLE_STAT2 is omitted.
58179 */
58180 #ifdef SQLITE_ENABLE_STAT2
58181 if( op==TK_REGISTER ) op = pExpr->op2;
58182 #else
58183 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
58184 #endif
58185
@@ -58299,10 +58244,11 @@
58299 return 0;
58300 }
58301
58302 /************** End of vdbemem.c *********************************************/
58303 /************** Begin file vdbeaux.c *****************************************/
 
58304 /*
58305 ** 2003 September 6
58306 **
58307 ** The author disclaims copyright to this source code. In place of
58308 ** a legal notice, here is a blessing:
@@ -58874,12 +58820,12 @@
58874 /*
58875 ** Change the P2 operand of instruction addr so that it points to
58876 ** the address of the next instruction to be coded.
58877 */
58878 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
58879 assert( addr>=0 );
58880 sqlite3VdbeChangeP2(p, addr, p->nOp);
58881 }
58882
58883
58884 /*
58885 ** If the input FuncDef structure is ephemeral, then free it. If
@@ -59441,11 +59387,11 @@
59441 SubProgram **apSub = 0; /* Array of sub-vdbes */
59442 Mem *pSub = 0; /* Memory cell hold array of subprogs */
59443 sqlite3 *db = p->db; /* The database connection */
59444 int i; /* Loop counter */
59445 int rc = SQLITE_OK; /* Return code */
59446 Mem *pMem = p->pResultSet = &p->aMem[1]; /* First Mem of result set */
59447
59448 assert( p->explain );
59449 assert( p->magic==VDBE_MAGIC_RUN );
59450 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
59451
@@ -59452,10 +59398,11 @@
59452 /* Even though this opcode does not use dynamic strings for
59453 ** the result, result columns may become dynamic if the user calls
59454 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
59455 */
59456 releaseMemArray(pMem, 8);
 
59457
59458 if( p->rc==SQLITE_NOMEM ){
59459 /* This happens if a malloc() inside a call to sqlite3_column_text() or
59460 ** sqlite3_column_text16() failed. */
59461 db->mallocFailed = 1;
@@ -59606,10 +59553,11 @@
59606 pMem->type = SQLITE_NULL;
59607 }
59608 }
59609
59610 p->nResColumn = 8 - 4*(p->explain-1);
 
59611 p->rc = SQLITE_OK;
59612 rc = SQLITE_ROW;
59613 }
59614 return rc;
59615 }
@@ -61538,10 +61486,11 @@
61538 }
61539 }
61540
61541 /************** End of vdbeaux.c *********************************************/
61542 /************** Begin file vdbeapi.c *****************************************/
 
61543 /*
61544 ** 2004 May 26
61545 **
61546 ** The author disclaims copyright to this source code. In place of
61547 ** a legal notice, here is a blessing:
@@ -62845,10 +62794,11 @@
62845 return v;
62846 }
62847
62848 /************** End of vdbeapi.c *********************************************/
62849 /************** Begin file vdbetrace.c ***************************************/
 
62850 /*
62851 ** 2009 November 25
62852 **
62853 ** The author disclaims copyright to this source code. In place of
62854 ** a legal notice, here is a blessing:
@@ -63000,10 +62950,11 @@
63000
63001 #endif /* #ifndef SQLITE_OMIT_TRACE */
63002
63003 /************** End of vdbetrace.c *******************************************/
63004 /************** Begin file vdbe.c ********************************************/
 
63005 /*
63006 ** 2001 September 15
63007 **
63008 ** The author disclaims copyright to this source code. In place of
63009 ** a legal notice, here is a blessing:
@@ -63469,10 +63420,11 @@
63469 ** hwtime.h contains inline assembler code for implementing
63470 ** high-performance timing routines.
63471 */
63472 /************** Include hwtime.h in the middle of vdbe.c *********************/
63473 /************** Begin file hwtime.h ******************************************/
 
63474 /*
63475 ** 2008 May 27
63476 **
63477 ** The author disclaims copyright to this source code. In place of
63478 ** a legal notice, here is a blessing:
@@ -63557,10 +63509,11 @@
63557
63558 #endif /* !defined(_HWTIME_H_) */
63559
63560 /************** End of hwtime.h **********************************************/
63561 /************** Continuing where we left off in vdbe.c ***********************/
 
63562
63563 #endif
63564
63565 /*
63566 ** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
@@ -69801,10 +69754,11 @@
69801 goto vdbe_error_halt;
69802 }
69803
69804 /************** End of vdbe.c ************************************************/
69805 /************** Begin file vdbeblob.c ****************************************/
 
69806 /*
69807 ** 2007 May 1
69808 **
69809 ** The author disclaims copyright to this source code. In place of
69810 ** a legal notice, here is a blessing:
@@ -70271,10 +70225,11 @@
70271
70272 #endif /* #ifndef SQLITE_OMIT_INCRBLOB */
70273
70274 /************** End of vdbeblob.c ********************************************/
70275 /************** Begin file vdbesort.c ****************************************/
 
70276 /*
70277 ** 2011 July 9
70278 **
70279 ** The author disclaims copyright to this source code. In place of
70280 ** a legal notice, here is a blessing:
@@ -71154,10 +71109,11 @@
71154
71155 #endif /* #ifndef SQLITE_OMIT_MERGE_SORT */
71156
71157 /************** End of vdbesort.c ********************************************/
71158 /************** Begin file journal.c *****************************************/
 
71159 /*
71160 ** 2007 August 22
71161 **
71162 ** The author disclaims copyright to this source code. In place of
71163 ** a legal notice, here is a blessing:
@@ -71394,10 +71350,11 @@
71394 }
71395 #endif
71396
71397 /************** End of journal.c *********************************************/
71398 /************** Begin file memjournal.c **************************************/
 
71399 /*
71400 ** 2008 October 7
71401 **
71402 ** The author disclaims copyright to this source code. In place of
71403 ** a legal notice, here is a blessing:
@@ -71655,10 +71612,11 @@
71655 return sizeof(MemJournal);
71656 }
71657
71658 /************** End of memjournal.c ******************************************/
71659 /************** Begin file walker.c ******************************************/
 
71660 /*
71661 ** 2008 August 16
71662 **
71663 ** The author disclaims copyright to this source code. In place of
71664 ** a legal notice, here is a blessing:
@@ -71793,10 +71751,11 @@
71793 return rc & WRC_Abort;
71794 }
71795
71796 /************** End of walker.c **********************************************/
71797 /************** Begin file resolve.c *****************************************/
 
71798 /*
71799 ** 2008 August 18
71800 **
71801 ** The author disclaims copyright to this source code. In place of
71802 ** a legal notice, here is a blessing:
@@ -73013,10 +72972,11 @@
73013 sqlite3WalkSelect(&w, p);
73014 }
73015
73016 /************** End of resolve.c *********************************************/
73017 /************** Begin file expr.c ********************************************/
 
73018 /*
73019 ** 2001 September 15
73020 **
73021 ** The author disclaims copyright to this source code. In place of
73022 ** a legal notice, here is a blessing:
@@ -76770,10 +76730,11 @@
76770 }
76771 }
76772
76773 /************** End of expr.c ************************************************/
76774 /************** Begin file alter.c *******************************************/
 
76775 /*
76776 ** 2005 February 15
76777 **
76778 ** The author disclaims copyright to this source code. In place of
76779 ** a legal notice, here is a blessing:
@@ -77598,10 +77559,11 @@
77598 }
77599 #endif /* SQLITE_ALTER_TABLE */
77600
77601 /************** End of alter.c ***********************************************/
77602 /************** Begin file analyze.c *****************************************/
 
77603 /*
77604 ** 2005 July 8
77605 **
77606 ** The author disclaims copyright to this source code. In place of
77607 ** a legal notice, here is a blessing:
@@ -77610,10 +77572,112 @@
77610 ** May you find forgiveness for yourself and forgive others.
77611 ** May you share freely, never taking more than you give.
77612 **
77613 *************************************************************************
77614 ** This file contains code associated with the ANALYZE command.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77615 */
77616 #ifndef SQLITE_OMIT_ANALYZE
77617
77618 /*
77619 ** This routine generates code that opens the sqlite_stat1 table for
@@ -77641,12 +77705,18 @@
77641 static const struct {
77642 const char *zName;
77643 const char *zCols;
77644 } aTable[] = {
77645 { "sqlite_stat1", "tbl,idx,stat" },
77646 #ifdef SQLITE_ENABLE_STAT2
77647 { "sqlite_stat2", "tbl,idx,sampleno,sample" },
 
 
 
 
 
 
77648 #endif
77649 };
77650
77651 int aRoot[] = {0, 0};
77652 u8 aCreateTbl[] = {0, 0};
@@ -77658,10 +77728,24 @@
77658 if( v==0 ) return;
77659 assert( sqlite3BtreeHoldsAllMutexes(db) );
77660 assert( sqlite3VdbeDb(v)==db );
77661 pDb = &db->aDb[iDb];
77662
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77663 for(i=0; i<ArraySize(aTable); i++){
77664 const char *zTab = aTable[i].zName;
77665 Table *pStat;
77666 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
77667 /* The sqlite_stat[12] table does not exist. Create it. Note that a
@@ -77688,17 +77772,237 @@
77688 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
77689 }
77690 }
77691 }
77692
77693 /* Open the sqlite_stat[12] tables for writing. */
77694 for(i=0; i<ArraySize(aTable); i++){
77695 sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);
77696 sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);
77697 sqlite3VdbeChangeP5(v, aCreateTbl[i]);
77698 }
77699 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77700
77701 /*
77702 ** Generate code to do an analysis of all indices associated with
77703 ** a single table.
77704 */
@@ -77718,24 +78022,31 @@
77718 int endOfLoop; /* The end of the loop */
77719 int jZeroRows = -1; /* Jump from here if number of rows is zero */
77720 int iDb; /* Index of database containing pTab */
77721 int regTabname = iMem++; /* Register containing table name */
77722 int regIdxname = iMem++; /* Register containing index name */
77723 int regSampleno = iMem++; /* Register containing next sample number */
77724 int regCol = iMem++; /* Content of a column analyzed table */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77725 int regRec = iMem++; /* Register holding completed record */
77726 int regTemp = iMem++; /* Temporary use register */
77727 int regRowid = iMem++; /* Rowid for the inserted record */
77728
77729 #ifdef SQLITE_ENABLE_STAT2
77730 int addr = 0; /* Instruction address */
77731 int regTemp2 = iMem++; /* Temporary use register */
77732 int regSamplerecno = iMem++; /* Index of next sample to record */
77733 int regRecno = iMem++; /* Current sample index */
77734 int regLast = iMem++; /* Index of last sample to record */
77735 int regFirst = iMem++; /* Index of first sample to record */
77736 #endif
77737
77738 v = sqlite3GetVdbe(pParse);
77739 if( v==0 || NEVER(pTab==0) ){
77740 return;
77741 }
@@ -77764,13 +78075,18 @@
77764 iIdxCur = pParse->nTab++;
77765 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
77766 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
77767 int nCol;
77768 KeyInfo *pKey;
 
 
77769
77770 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
 
77771 nCol = pIdx->nColumn;
 
 
77772 pKey = sqlite3IndexKeyinfo(pParse, pIdx);
77773 if( iMem+1+(nCol*2)>pParse->nMem ){
77774 pParse->nMem = iMem+1+(nCol*2);
77775 }
77776
@@ -77781,35 +78097,24 @@
77781 VdbeComment((v, "%s", pIdx->zName));
77782
77783 /* Populate the register containing the index name. */
77784 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
77785
77786 #ifdef SQLITE_ENABLE_STAT2
77787
77788 /* If this iteration of the loop is generating code to analyze the
77789 ** first index in the pTab->pIndex list, then register regLast has
77790 ** not been populated. In this case populate it now. */
77791 if( pTab->pIndex==pIdx ){
77792 sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regSamplerecno);
77793 sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2-1, regTemp);
77794 sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2, regTemp2);
77795
77796 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regLast);
77797 sqlite3VdbeAddOp2(v, OP_Null, 0, regFirst);
77798 addr = sqlite3VdbeAddOp3(v, OP_Lt, regSamplerecno, 0, regLast);
77799 sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regFirst);
77800 sqlite3VdbeAddOp3(v, OP_Multiply, regLast, regTemp, regLast);
77801 sqlite3VdbeAddOp2(v, OP_AddImm, regLast, SQLITE_INDEX_SAMPLES*2-2);
77802 sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regLast);
77803 sqlite3VdbeJumpHere(v, addr);
77804 }
77805
77806 /* Zero the regSampleno and regRecno registers. */
77807 sqlite3VdbeAddOp2(v, OP_Integer, 0, regSampleno);
77808 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRecno);
77809 sqlite3VdbeAddOp2(v, OP_Copy, regFirst, regSamplerecno);
77810 #endif
77811
77812 /* The block of memory cells initialized here is used as follows.
77813 **
77814 ** iMem:
77815 ** The total number of rows in the table.
@@ -77835,79 +78140,87 @@
77835 /* Start the analysis loop. This loop runs through all the entries in
77836 ** the index b-tree. */
77837 endOfLoop = sqlite3VdbeMakeLabel(v);
77838 sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
77839 topOfLoop = sqlite3VdbeCurrentAddr(v);
77840 sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
77841
77842 for(i=0; i<nCol; i++){
77843 CollSeq *pColl;
77844 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
77845 if( i==0 ){
77846 #ifdef SQLITE_ENABLE_STAT2
77847 /* Check if the record that cursor iIdxCur points to contains a
77848 ** value that should be stored in the sqlite_stat2 table. If so,
77849 ** store it. */
77850 int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno);
77851 assert( regTabname+1==regIdxname
77852 && regTabname+2==regSampleno
77853 && regTabname+3==regCol
77854 );
77855 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
77856 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 4, regRec, "aaab", 0);
77857 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regRowid);
77858 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regRowid);
77859
77860 /* Calculate new values for regSamplerecno and regSampleno.
77861 **
77862 ** sampleno = sampleno + 1
77863 ** samplerecno = samplerecno+(remaining records)/(remaining samples)
77864 */
77865 sqlite3VdbeAddOp2(v, OP_AddImm, regSampleno, 1);
77866 sqlite3VdbeAddOp3(v, OP_Subtract, regRecno, regLast, regTemp);
77867 sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
77868 sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regTemp2);
77869 sqlite3VdbeAddOp3(v, OP_Subtract, regSampleno, regTemp2, regTemp2);
77870 sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp);
77871 sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno);
77872
77873 sqlite3VdbeJumpHere(v, ne);
77874 sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
77875 #endif
77876
77877 /* Always record the very first row */
77878 sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
77879 }
77880 assert( pIdx->azColl!=0 );
77881 assert( pIdx->azColl[i]!=0 );
77882 pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
77883 sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
77884 (char*)pColl, P4_COLLSEQ);
77885 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
77886 }
77887 if( db->mallocFailed ){
77888 /* If a malloc failure has occurred, then the result of the expression
77889 ** passed as the second argument to the call to sqlite3VdbeJumpHere()
77890 ** below may be negative. Which causes an assert() to fail (or an
77891 ** out-of-bounds write if SQLITE_DEBUG is not defined). */
77892 return;
77893 }
77894 sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
77895 for(i=0; i<nCol; i++){
77896 int addr2 = sqlite3VdbeCurrentAddr(v) - (nCol*2);
77897 if( i==0 ){
77898 sqlite3VdbeJumpHere(v, addr2-1); /* Set jump dest for the OP_IfNot */
 
 
 
 
 
 
 
 
 
77899 }
77900 sqlite3VdbeJumpHere(v, addr2); /* Set jump dest for the OP_Ne */
77901 sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
77902 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
77903 }
 
77904
77905 /* End of the analysis loop. */
77906 sqlite3VdbeResolveLabel(v, endOfLoop);
 
77907 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
77908 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77909
77910 /* Store the results in sqlite_stat1.
77911 **
77912 ** The result is a single row of the sqlite_stat1 table. The first
77913 ** two columns are the names of the table and index. The third column
@@ -77923,50 +78236,51 @@
77923 **
77924 ** If K==0 then no entry is made into the sqlite_stat1 table.
77925 ** If K>0 then it is always the case the D>0 so division by zero
77926 ** is never possible.
77927 */
77928 sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno);
77929 if( jZeroRows<0 ){
77930 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
77931 }
77932 for(i=0; i<nCol; i++){
77933 sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0);
77934 sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
77935 sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
77936 sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
77937 sqlite3VdbeAddOp3(v, OP_Divide, iMem+i+1, regTemp, regTemp);
77938 sqlite3VdbeAddOp1(v, OP_ToInt, regTemp);
77939 sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
77940 }
77941 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
77942 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
77943 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
77944 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
77945 }
77946
77947 /* If the table has no indices, create a single sqlite_stat1 entry
77948 ** containing NULL as the index name and the row count as the content.
77949 */
77950 if( pTab->pIndex==0 ){
77951 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb);
77952 VdbeComment((v, "%s", pTab->zName));
77953 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno);
77954 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
77955 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regSampleno);
77956 }else{
77957 sqlite3VdbeJumpHere(v, jZeroRows);
77958 jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto);
77959 }
77960 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
77961 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
77962 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
77963 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
77964 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
77965 if( pParse->nMem<regRec ) pParse->nMem = regRec;
77966 sqlite3VdbeJumpHere(v, jZeroRows);
77967 }
 
77968
77969 /*
77970 ** Generate code that will cause the most recent index analysis to
77971 ** be loaded into internal hash tables where is can be used.
77972 */
@@ -77987,11 +78301,11 @@
77987 int iStatCur;
77988 int iMem;
77989
77990 sqlite3BeginWriteOperation(pParse, 0, iDb);
77991 iStatCur = pParse->nTab;
77992 pParse->nTab += 2;
77993 openStatTable(pParse, iDb, iStatCur, 0, 0);
77994 iMem = pParse->nMem+1;
77995 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
77996 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
77997 Table *pTab = (Table*)sqliteHashData(k);
@@ -78012,11 +78326,11 @@
78012 assert( pTab!=0 );
78013 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
78014 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78015 sqlite3BeginWriteOperation(pParse, 0, iDb);
78016 iStatCur = pParse->nTab;
78017 pParse->nTab += 2;
78018 if( pOnlyIdx ){
78019 openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");
78020 }else{
78021 openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
78022 }
@@ -78117,11 +78431,11 @@
78117 static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
78118 analysisInfo *pInfo = (analysisInfo*)pData;
78119 Index *pIndex;
78120 Table *pTable;
78121 int i, c, n;
78122 unsigned int v;
78123 const char *z;
78124
78125 assert( argc==3 );
78126 UNUSED_PARAMETER2(NotUsed, argc);
78127
@@ -78160,40 +78474,172 @@
78160 /*
78161 ** If the Index.aSample variable is not NULL, delete the aSample[] array
78162 ** and its contents.
78163 */
78164 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
78165 #ifdef SQLITE_ENABLE_STAT2
78166 if( pIdx->aSample ){
78167 int j;
78168 for(j=0; j<SQLITE_INDEX_SAMPLES; j++){
78169 IndexSample *p = &pIdx->aSample[j];
78170 if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
78171 sqlite3DbFree(db, p->u.z);
78172 }
78173 }
78174 sqlite3DbFree(db, pIdx->aSample);
 
 
 
 
78175 }
78176 #else
78177 UNUSED_PARAMETER(db);
78178 UNUSED_PARAMETER(pIdx);
78179 #endif
78180 }
78181
 
78182 /*
78183 ** Load the content of the sqlite_stat1 and sqlite_stat2 tables. The
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78184 ** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
78185 ** arrays. The contents of sqlite_stat2 are used to populate the
78186 ** Index.aSample[] arrays.
78187 **
78188 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
78189 ** is returned. In this case, even if SQLITE_ENABLE_STAT2 was defined
78190 ** during compilation and the sqlite_stat2 table is present, no data is
78191 ** read from it.
78192 **
78193 ** If SQLITE_ENABLE_STAT2 was defined during compilation and the
78194 ** sqlite_stat2 table is not present in the database, SQLITE_ERROR is
78195 ** returned. However, in this case, data is read from the sqlite_stat1
78196 ** table (if it is present) before returning.
78197 **
78198 ** If an OOM error occurs, this function always sets db->mallocFailed.
78199 ** This means if the caller does not care about other errors, the return
@@ -78211,12 +78657,14 @@
78211 /* Clear any prior statistics */
78212 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
78213 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
78214 Index *pIdx = sqliteHashData(i);
78215 sqlite3DefaultRowEst(pIdx);
 
78216 sqlite3DeleteIndexSamples(db, pIdx);
78217 pIdx->aSample = 0;
 
78218 }
78219
78220 /* Check to make sure the sqlite_stat1 table exists */
78221 sInfo.db = db;
78222 sInfo.zDatabase = db->aDb[iDb].zName;
@@ -78224,91 +78672,23 @@
78224 return SQLITE_ERROR;
78225 }
78226
78227 /* Load new statistics out of the sqlite_stat1 table */
78228 zSql = sqlite3MPrintf(db,
78229 "SELECT tbl, idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
78230 if( zSql==0 ){
78231 rc = SQLITE_NOMEM;
78232 }else{
78233 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
78234 sqlite3DbFree(db, zSql);
78235 }
78236
78237
78238 /* Load the statistics from the sqlite_stat2 table. */
78239 #ifdef SQLITE_ENABLE_STAT2
78240 if( rc==SQLITE_OK && !sqlite3FindTable(db, "sqlite_stat2", sInfo.zDatabase) ){
78241 rc = SQLITE_ERROR;
78242 }
78243 if( rc==SQLITE_OK ){
78244 sqlite3_stmt *pStmt = 0;
78245
78246 zSql = sqlite3MPrintf(db,
78247 "SELECT idx,sampleno,sample FROM %Q.sqlite_stat2", sInfo.zDatabase);
78248 if( !zSql ){
78249 rc = SQLITE_NOMEM;
78250 }else{
78251 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
78252 sqlite3DbFree(db, zSql);
78253 }
78254
78255 if( rc==SQLITE_OK ){
78256 while( sqlite3_step(pStmt)==SQLITE_ROW ){
78257 char *zIndex; /* Index name */
78258 Index *pIdx; /* Pointer to the index object */
78259
78260 zIndex = (char *)sqlite3_column_text(pStmt, 0);
78261 pIdx = zIndex ? sqlite3FindIndex(db, zIndex, sInfo.zDatabase) : 0;
78262 if( pIdx ){
78263 int iSample = sqlite3_column_int(pStmt, 1);
78264 if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
78265 int eType = sqlite3_column_type(pStmt, 2);
78266
78267 if( pIdx->aSample==0 ){
78268 static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
78269 pIdx->aSample = (IndexSample *)sqlite3DbMallocRaw(0, sz);
78270 if( pIdx->aSample==0 ){
78271 db->mallocFailed = 1;
78272 break;
78273 }
78274 memset(pIdx->aSample, 0, sz);
78275 }
78276
78277 assert( pIdx->aSample );
78278 {
78279 IndexSample *pSample = &pIdx->aSample[iSample];
78280 pSample->eType = (u8)eType;
78281 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
78282 pSample->u.r = sqlite3_column_double(pStmt, 2);
78283 }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
78284 const char *z = (const char *)(
78285 (eType==SQLITE_BLOB) ?
78286 sqlite3_column_blob(pStmt, 2):
78287 sqlite3_column_text(pStmt, 2)
78288 );
78289 int n = sqlite3_column_bytes(pStmt, 2);
78290 if( n>24 ){
78291 n = 24;
78292 }
78293 pSample->nByte = (u8)n;
78294 if( n < 1){
78295 pSample->u.z = 0;
78296 }else{
78297 pSample->u.z = sqlite3DbStrNDup(0, z, n);
78298 if( pSample->u.z==0 ){
78299 db->mallocFailed = 1;
78300 break;
78301 }
78302 }
78303 }
78304 }
78305 }
78306 }
78307 }
78308 rc = sqlite3_finalize(pStmt);
78309 }
78310 }
78311 #endif
78312
78313 if( rc==SQLITE_NOMEM ){
78314 db->mallocFailed = 1;
@@ -78319,10 +78699,11 @@
78319
78320 #endif /* SQLITE_OMIT_ANALYZE */
78321
78322 /************** End of analyze.c *********************************************/
78323 /************** Begin file attach.c ******************************************/
 
78324 /*
78325 ** 2003 April 6
78326 **
78327 ** The author disclaims copyright to this source code. In place of
78328 ** a legal notice, here is a blessing:
@@ -78878,10 +79259,11 @@
78878 }
78879 #endif
78880
78881 /************** End of attach.c **********************************************/
78882 /************** Begin file auth.c ********************************************/
 
78883 /*
78884 ** 2003 January 11
78885 **
78886 ** The author disclaims copyright to this source code. In place of
78887 ** a legal notice, here is a blessing:
@@ -79129,10 +79511,11 @@
79129
79130 #endif /* SQLITE_OMIT_AUTHORIZATION */
79131
79132 /************** End of auth.c ************************************************/
79133 /************** Begin file build.c *******************************************/
 
79134 /*
79135 ** 2001 September 15
79136 **
79137 ** The author disclaims copyright to this source code. In place of
79138 ** a legal notice, here is a blessing:
@@ -81120,11 +81503,15 @@
81120 Parse *pParse, /* The parsing context */
81121 int iDb, /* The database number */
81122 const char *zType, /* "idx" or "tbl" */
81123 const char *zName /* Name of index or table */
81124 ){
81125 static const char *azStatTab[] = { "sqlite_stat1", "sqlite_stat2" };
 
 
 
 
81126 int i;
81127 const char *zDbName = pParse->db->aDb[iDb].zName;
81128 for(i=0; i<ArraySize(azStatTab); i++){
81129 if( sqlite3FindTable(pParse->db, azStatTab[i], zDbName) ){
81130 sqlite3NestedParse(pParse,
@@ -81132,10 +81519,80 @@
81132 zDbName, azStatTab[i], zType, zName
81133 );
81134 }
81135 }
81136 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81137
81138 /*
81139 ** This routine is called to do the work of a DROP TABLE statement.
81140 ** pName is the name of the table to be dropped.
81141 */
@@ -81225,72 +81682,15 @@
81225 /* Generate code to remove the table from the master table
81226 ** on disk.
81227 */
81228 v = sqlite3GetVdbe(pParse);
81229 if( v ){
81230 Trigger *pTrigger;
81231 Db *pDb = &db->aDb[iDb];
81232 sqlite3BeginWriteOperation(pParse, 1, iDb);
81233
81234 #ifndef SQLITE_OMIT_VIRTUALTABLE
81235 if( IsVirtual(pTab) ){
81236 sqlite3VdbeAddOp0(v, OP_VBegin);
81237 }
81238 #endif
81239 sqlite3FkDropTable(pParse, pName, pTab);
81240
81241 /* Drop all triggers associated with the table being dropped. Code
81242 ** is generated to remove entries from sqlite_master and/or
81243 ** sqlite_temp_master if required.
81244 */
81245 pTrigger = sqlite3TriggerList(pParse, pTab);
81246 while( pTrigger ){
81247 assert( pTrigger->pSchema==pTab->pSchema ||
81248 pTrigger->pSchema==db->aDb[1].pSchema );
81249 sqlite3DropTriggerPtr(pParse, pTrigger);
81250 pTrigger = pTrigger->pNext;
81251 }
81252
81253 #ifndef SQLITE_OMIT_AUTOINCREMENT
81254 /* Remove any entries of the sqlite_sequence table associated with
81255 ** the table being dropped. This is done before the table is dropped
81256 ** at the btree level, in case the sqlite_sequence table needs to
81257 ** move as a result of the drop (can happen in auto-vacuum mode).
81258 */
81259 if( pTab->tabFlags & TF_Autoincrement ){
81260 sqlite3NestedParse(pParse,
81261 "DELETE FROM %s.sqlite_sequence WHERE name=%Q",
81262 pDb->zName, pTab->zName
81263 );
81264 }
81265 #endif
81266
81267 /* Drop all SQLITE_MASTER table and index entries that refer to the
81268 ** table. The program name loops through the master table and deletes
81269 ** every row that refers to a table of the same name as the one being
81270 ** dropped. Triggers are handled seperately because a trigger can be
81271 ** created in the temp database that refers to a table in another
81272 ** database.
81273 */
81274 sqlite3NestedParse(pParse,
81275 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
81276 pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
81277 sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName);
81278 if( !isView && !IsVirtual(pTab) ){
81279 destroyTable(pParse, pTab);
81280 }
81281
81282 /* Remove the table entry from SQLite's internal schema and modify
81283 ** the schema cookie.
81284 */
81285 if( IsVirtual(pTab) ){
81286 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
81287 }
81288 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
81289 sqlite3ChangeCookie(pParse, iDb);
81290 }
81291 sqliteViewResetAll(db, iDb);
81292
81293 exit_drop_table:
81294 sqlite3SrcListDelete(db, pName);
81295 }
81296
@@ -81769,24 +82169,24 @@
81769 */
81770 nName = sqlite3Strlen30(zName);
81771 nCol = pList->nExpr;
81772 pIndex = sqlite3DbMallocZero(db,
81773 sizeof(Index) + /* Index structure */
 
81774 sizeof(int)*nCol + /* Index.aiColumn */
81775 sizeof(int)*(nCol+1) + /* Index.aiRowEst */
81776 sizeof(char *)*nCol + /* Index.azColl */
81777 sizeof(u8)*nCol + /* Index.aSortOrder */
81778 nName + 1 + /* Index.zName */
81779 nExtra /* Collation sequence names */
81780 );
81781 if( db->mallocFailed ){
81782 goto exit_create_index;
81783 }
81784 pIndex->azColl = (char**)(&pIndex[1]);
 
81785 pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
81786 pIndex->aiRowEst = (unsigned *)(&pIndex->aiColumn[nCol]);
81787 pIndex->aSortOrder = (u8 *)(&pIndex->aiRowEst[nCol+1]);
81788 pIndex->zName = (char *)(&pIndex->aSortOrder[nCol]);
81789 zExtra = (char *)(&pIndex->zName[nName+1]);
81790 memcpy(pIndex->zName, zName, nName+1);
81791 pIndex->pTable = pTab;
81792 pIndex->nColumn = pList->nExpr;
@@ -82059,13 +82459,13 @@
82059 ** Apart from that, we have little to go on besides intuition as to
82060 ** how aiRowEst[] should be initialized. The numbers generated here
82061 ** are based on typical values found in actual indices.
82062 */
82063 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
82064 unsigned *a = pIdx->aiRowEst;
82065 int i;
82066 unsigned n;
82067 assert( a!=0 );
82068 a[0] = pIdx->pTable->nRowEst;
82069 if( a[0]<10 ) a[0] = 10;
82070 n = 10;
82071 for(i=1; i<=pIdx->nColumn; i++){
@@ -82932,10 +83332,11 @@
82932 return pKey;
82933 }
82934
82935 /************** End of build.c ***********************************************/
82936 /************** Begin file callback.c ****************************************/
 
82937 /*
82938 ** 2005 May 23
82939 **
82940 ** The author disclaims copyright to this source code. In place of
82941 ** a legal notice, here is a blessing:
@@ -83391,10 +83792,11 @@
83391 return p;
83392 }
83393
83394 /************** End of callback.c ********************************************/
83395 /************** Begin file delete.c ******************************************/
 
83396 /*
83397 ** 2001 September 15
83398 **
83399 ** The author disclaims copyright to this source code. In place of
83400 ** a legal notice, here is a blessing:
@@ -84045,10 +84447,11 @@
84045 return regBase;
84046 }
84047
84048 /************** End of delete.c **********************************************/
84049 /************** Begin file func.c ********************************************/
 
84050 /*
84051 ** 2002 February 23
84052 **
84053 ** The author disclaims copyright to this source code. In place of
84054 ** a legal notice, here is a blessing:
@@ -85653,10 +86056,11 @@
85653 #endif
85654 }
85655
85656 /************** End of func.c ************************************************/
85657 /************** Begin file fkey.c ********************************************/
 
85658 /*
85659 **
85660 ** The author disclaims copyright to this source code. In place of
85661 ** a legal notice, here is a blessing:
85662 **
@@ -86873,10 +87277,11 @@
86873 }
86874 #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */
86875
86876 /************** End of fkey.c ************************************************/
86877 /************** Begin file insert.c ******************************************/
 
86878 /*
86879 ** 2001 September 15
86880 **
86881 ** The author disclaims copyright to this source code. In place of
86882 ** a legal notice, here is a blessing:
@@ -88621,10 +89026,13 @@
88621 */
88622 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
88623 return 0;
88624 }
88625 #endif
 
 
 
88626
88627 /* If we get this far, it means either:
88628 **
88629 ** * We can always do the transfer if the table contains an
88630 ** an integer primary key
@@ -88718,10 +89126,11 @@
88718 }
88719 #endif /* SQLITE_OMIT_XFER_OPT */
88720
88721 /************** End of insert.c **********************************************/
88722 /************** Begin file legacy.c ******************************************/
 
88723 /*
88724 ** 2001 September 15
88725 **
88726 ** The author disclaims copyright to this source code. In place of
88727 ** a legal notice, here is a blessing:
@@ -88865,10 +89274,11 @@
88865 return rc;
88866 }
88867
88868 /************** End of legacy.c **********************************************/
88869 /************** Begin file loadext.c *****************************************/
 
88870 /*
88871 ** 2006 June 7
88872 **
88873 ** The author disclaims copyright to this source code. In place of
88874 ** a legal notice, here is a blessing:
@@ -88885,10 +89295,11 @@
88885 #ifndef SQLITE_CORE
88886 #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
88887 #endif
88888 /************** Include sqlite3ext.h in the middle of loadext.c **************/
88889 /************** Begin file sqlite3ext.h **************************************/
 
88890 /*
88891 ** 2006 June 7
88892 **
88893 ** The author disclaims copyright to this source code. In place of
88894 ** a legal notice, here is a blessing:
@@ -89313,10 +89724,11 @@
89313
89314 #endif /* _SQLITE3EXT_H_ */
89315
89316 /************** End of sqlite3ext.h ******************************************/
89317 /************** Continuing where we left off in loadext.c ********************/
 
89318 /* #include <string.h> */
89319
89320 #ifndef SQLITE_OMIT_LOAD_EXTENSION
89321
89322 /*
@@ -89952,10 +90364,11 @@
89952 }
89953 }
89954
89955 /************** End of loadext.c *********************************************/
89956 /************** Begin file pragma.c ******************************************/
 
89957 /*
89958 ** 2003 April 6
89959 **
89960 ** The author disclaims copyright to this source code. In place of
89961 ** a legal notice, here is a blessing:
@@ -91480,10 +91893,11 @@
91480
91481 #endif /* SQLITE_OMIT_PRAGMA */
91482
91483 /************** End of pragma.c **********************************************/
91484 /************** Begin file prepare.c *****************************************/
 
91485 /*
91486 ** 2005 May 25
91487 **
91488 ** The author disclaims copyright to this source code. In place of
91489 ** a legal notice, here is a blessing:
@@ -92340,10 +92754,11 @@
92340
92341 #endif /* SQLITE_OMIT_UTF16 */
92342
92343 /************** End of prepare.c *********************************************/
92344 /************** Begin file select.c ******************************************/
 
92345 /*
92346 ** 2001 September 15
92347 **
92348 ** The author disclaims copyright to this source code. In place of
92349 ** a legal notice, here is a blessing:
@@ -96928,10 +97343,11 @@
96928 *****************************************************************************/
96929 #endif /* defined(SQLITE_TEST) || defined(SQLITE_DEBUG) */
96930
96931 /************** End of select.c **********************************************/
96932 /************** Begin file table.c *******************************************/
 
96933 /*
96934 ** 2001 September 15
96935 **
96936 ** The author disclaims copyright to this source code. In place of
96937 ** a legal notice, here is a blessing:
@@ -97127,10 +97543,11 @@
97127
97128 #endif /* SQLITE_OMIT_GET_TABLE */
97129
97130 /************** End of table.c ***********************************************/
97131 /************** Begin file trigger.c *****************************************/
 
97132 /*
97133 **
97134 ** The author disclaims copyright to this source code. In place of
97135 ** a legal notice, here is a blessing:
97136 **
@@ -98252,10 +98669,11 @@
98252
98253 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
98254
98255 /************** End of trigger.c *********************************************/
98256 /************** Begin file update.c ******************************************/
 
98257 /*
98258 ** 2001 September 15
98259 **
98260 ** The author disclaims copyright to this source code. In place of
98261 ** a legal notice, here is a blessing:
@@ -98924,10 +99342,11 @@
98924 }
98925 #endif /* SQLITE_OMIT_VIRTUALTABLE */
98926
98927 /************** End of update.c **********************************************/
98928 /************** Begin file vacuum.c ******************************************/
 
98929 /*
98930 ** 2003 April 6
98931 **
98932 ** The author disclaims copyright to this source code. In place of
98933 ** a legal notice, here is a blessing:
@@ -98969,11 +99388,11 @@
98969 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
98970 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
98971 return sqlite3_errcode(db);
98972 }
98973 VVA_ONLY( rc = ) sqlite3_step(pStmt);
98974 assert( rc!=SQLITE_ROW );
98975 return vacuumFinalize(db, pStmt, pzErrMsg);
98976 }
98977
98978 /*
98979 ** Execute zSql on database db. The statement returns exactly
@@ -99187,17 +99606,15 @@
99187 " WHERE type='view' OR type='trigger'"
99188 " OR (type='table' AND rootpage=0)"
99189 );
99190 if( rc ) goto end_of_vacuum;
99191
99192 /* At this point, unless the main db was completely empty, there is now a
99193 ** transaction open on the vacuum database, but not on the main database.
99194 ** Open a btree level transaction on the main database. This allows a
99195 ** call to sqlite3BtreeCopyFile(). The main database btree level
99196 ** transaction is then committed, so the SQL level never knows it was
99197 ** opened for writing. This way, the SQL transaction used to create the
99198 ** temporary database never needs to be committed.
99199 */
99200 {
99201 u32 meta;
99202 int i;
99203
@@ -99270,10 +99687,11 @@
99270
99271 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
99272
99273 /************** End of vacuum.c **********************************************/
99274 /************** Begin file vtab.c ********************************************/
 
99275 /*
99276 ** 2006 June 10
99277 **
99278 ** The author disclaims copyright to this source code. In place of
99279 ** a legal notice, here is a blessing:
@@ -100338,10 +100756,11 @@
100338
100339 #endif /* SQLITE_OMIT_VIRTUALTABLE */
100340
100341 /************** End of vtab.c ************************************************/
100342 /************** Begin file where.c *******************************************/
 
100343 /*
100344 ** 2001 September 15
100345 **
100346 ** The author disclaims copyright to this source code. In place of
100347 ** a legal notice, here is a blessing:
@@ -100457,25 +100876,35 @@
100457 #define TERM_CODED 0x04 /* This term is already coded */
100458 #define TERM_COPIED 0x08 /* Has a child */
100459 #define TERM_ORINFO 0x10 /* Need to free the WhereTerm.u.pOrInfo object */
100460 #define TERM_ANDINFO 0x20 /* Need to free the WhereTerm.u.pAndInfo obj */
100461 #define TERM_OR_OK 0x40 /* Used during OR-clause processing */
100462 #ifdef SQLITE_ENABLE_STAT2
100463 # define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
100464 #else
100465 # define TERM_VNULL 0x00 /* Disabled if not using stat2 */
100466 #endif
100467
100468 /*
100469 ** An instance of the following structure holds all information about a
100470 ** WHERE clause. Mostly this is a container for one or more WhereTerms.
 
 
 
 
 
 
 
 
100471 */
100472 struct WhereClause {
100473 Parse *pParse; /* The parser context */
100474 WhereMaskSet *pMaskSet; /* Mapping of table cursor numbers to bitmasks */
100475 Bitmask vmask; /* Bitmask identifying virtual table cursors */
 
100476 u8 op; /* Split operator. TK_AND or TK_OR */
 
100477 int nTerm; /* Number of terms */
100478 int nSlot; /* Number of entries in a[] */
100479 WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
100480 #if defined(SQLITE_SMALL_STACK)
100481 WhereTerm aStatic[1]; /* Initial static space for a[] */
@@ -100600,18 +101029,21 @@
100600 ** Initialize a preallocated WhereClause structure.
100601 */
100602 static void whereClauseInit(
100603 WhereClause *pWC, /* The WhereClause to be initialized */
100604 Parse *pParse, /* The parsing context */
100605 WhereMaskSet *pMaskSet /* Mapping from table cursor numbers to bitmasks */
 
100606 ){
100607 pWC->pParse = pParse;
100608 pWC->pMaskSet = pMaskSet;
 
100609 pWC->nTerm = 0;
100610 pWC->nSlot = ArraySize(pWC->aStatic);
100611 pWC->a = pWC->aStatic;
100612 pWC->vmask = 0;
 
100613 }
100614
100615 /* Forward reference */
100616 static void whereClauseClear(WhereClause*);
100617
@@ -100923,40 +101355,42 @@
100923 ){
100924 WhereTerm *pTerm;
100925 int k;
100926 assert( iCur>=0 );
100927 op &= WO_ALL;
100928 for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
100929 if( pTerm->leftCursor==iCur
100930 && (pTerm->prereqRight & notReady)==0
100931 && pTerm->u.leftColumn==iColumn
100932 && (pTerm->eOperator & op)!=0
100933 ){
100934 if( pIdx && pTerm->eOperator!=WO_ISNULL ){
100935 Expr *pX = pTerm->pExpr;
100936 CollSeq *pColl;
100937 char idxaff;
100938 int j;
100939 Parse *pParse = pWC->pParse;
100940
100941 idxaff = pIdx->pTable->aCol[iColumn].affinity;
100942 if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue;
100943
100944 /* Figure out the collation sequence required from an index for
100945 ** it to be useful for optimising expression pX. Store this
100946 ** value in variable pColl.
100947 */
100948 assert(pX->pLeft);
100949 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
100950 assert(pColl || pParse->nErr);
100951
100952 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
100953 if( NEVER(j>=pIdx->nColumn) ) return 0;
100954 }
100955 if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
100956 }
100957 return pTerm;
 
 
100958 }
100959 }
100960 return 0;
100961 }
100962
@@ -101216,11 +101650,11 @@
101216 assert( pExpr->op==TK_OR );
101217 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
101218 if( pOrInfo==0 ) return;
101219 pTerm->wtFlags |= TERM_ORINFO;
101220 pOrWc = &pOrInfo->wc;
101221 whereClauseInit(pOrWc, pWC->pParse, pMaskSet);
101222 whereSplit(pOrWc, pExpr, TK_OR);
101223 exprAnalyzeAll(pSrc, pOrWc);
101224 if( db->mallocFailed ) return;
101225 assert( pOrWc->nTerm>=2 );
101226
@@ -101243,13 +101677,14 @@
101243 Bitmask b = 0;
101244 pOrTerm->u.pAndInfo = pAndInfo;
101245 pOrTerm->wtFlags |= TERM_ANDINFO;
101246 pOrTerm->eOperator = WO_AND;
101247 pAndWC = &pAndInfo->wc;
101248 whereClauseInit(pAndWC, pWC->pParse, pMaskSet);
101249 whereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
101250 exprAnalyzeAll(pSrc, pAndWC);
 
101251 testcase( db->mallocFailed );
101252 if( !db->mallocFailed ){
101253 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
101254 assert( pAndTerm->pExpr );
101255 if( allowedOp(pAndTerm->pExpr->op) ){
@@ -101679,12 +102114,12 @@
101679 pNewTerm->prereqAll = pTerm->prereqAll;
101680 }
101681 }
101682 #endif /* SQLITE_OMIT_VIRTUALTABLE */
101683
101684 #ifdef SQLITE_ENABLE_STAT2
101685 /* When sqlite_stat2 histogram data is available an operator of the
101686 ** form "x IS NOT NULL" can sometimes be evaluated more efficiently
101687 ** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
101688 ** virtual term of that form.
101689 **
101690 ** Note that the virtual term must be tagged with TERM_VNULL. This
@@ -101718,11 +102153,11 @@
101718 pTerm->nChild = 1;
101719 pTerm->wtFlags |= TERM_COPIED;
101720 pNewTerm->prereqAll = pTerm->prereqAll;
101721 }
101722 }
101723 #endif /* SQLITE_ENABLE_STAT2 */
101724
101725 /* Prevent ON clause terms of a LEFT JOIN from being used to drive
101726 ** an index for tables to the left of the join.
101727 */
101728 pTerm->prereqRight |= extraRight;
@@ -102140,14 +102575,17 @@
102140 const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
102141 const Bitmask maskSrc = getMask(pWC->pMaskSet, iCur); /* Bitmask for pSrc */
102142 WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */
102143 WhereTerm *pTerm; /* A single term of the WHERE clause */
102144
102145 /* No OR-clause optimization allowed if the INDEXED BY or NOT INDEXED clauses
102146 ** are used */
102147 if( pSrc->notIndexed || pSrc->pIndex!=0 ){
102148 return;
 
 
 
102149 }
102150
102151 /* Search the WHERE clause terms for a usable WO_OR term. */
102152 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
102153 if( pTerm->eOperator==WO_OR
@@ -102172,10 +102610,11 @@
102172 bestIndex(pParse, pAndWC, pSrc, notReady, notValid, 0, &sTermCost);
102173 }else if( pOrTerm->leftCursor==iCur ){
102174 WhereClause tempWC;
102175 tempWC.pParse = pWC->pParse;
102176 tempWC.pMaskSet = pWC->pMaskSet;
 
102177 tempWC.op = TK_AND;
102178 tempWC.a = pOrTerm;
102179 tempWC.nTerm = 1;
102180 bestIndex(pParse, &tempWC, pSrc, notReady, notValid, 0, &sTermCost);
102181 }else{
@@ -102766,71 +103205,90 @@
102766 */
102767 bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
102768 }
102769 #endif /* SQLITE_OMIT_VIRTUALTABLE */
102770
 
102771 /*
102772 ** Argument pIdx is a pointer to an index structure that has an array of
102773 ** SQLITE_INDEX_SAMPLES evenly spaced samples of the first indexed column
102774 ** stored in Index.aSample. These samples divide the domain of values stored
102775 ** the index into (SQLITE_INDEX_SAMPLES+1) regions.
102776 ** Region 0 contains all values less than the first sample value. Region
102777 ** 1 contains values between the first and second samples. Region 2 contains
102778 ** values between samples 2 and 3. And so on. Region SQLITE_INDEX_SAMPLES
102779 ** contains values larger than the last sample.
102780 **
102781 ** If the index contains many duplicates of a single value, then it is
102782 ** possible that two or more adjacent samples can hold the same value.
102783 ** When that is the case, the smallest possible region code is returned
102784 ** when roundUp is false and the largest possible region code is returned
102785 ** when roundUp is true.
102786 **
102787 ** If successful, this function determines which of the regions value
102788 ** pVal lies in, sets *piRegion to the region index (a value between 0
102789 ** and SQLITE_INDEX_SAMPLES+1, inclusive) and returns SQLITE_OK.
102790 ** Or, if an OOM occurs while converting text values between encodings,
102791 ** SQLITE_NOMEM is returned and *piRegion is undefined.
102792 */
102793 #ifdef SQLITE_ENABLE_STAT2
102794 static int whereRangeRegion(
102795 Parse *pParse, /* Database connection */
102796 Index *pIdx, /* Index to consider domain of */
102797 sqlite3_value *pVal, /* Value to consider */
102798 int roundUp, /* Return largest valid region if true */
102799 int *piRegion /* OUT: Region of domain in which value lies */
102800 ){
 
 
 
 
 
 
 
102801 assert( roundUp==0 || roundUp==1 );
102802 if( ALWAYS(pVal) ){
102803 IndexSample *aSample = pIdx->aSample;
102804 int i = 0;
102805 int eType = sqlite3_value_type(pVal);
102806
102807 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
102808 double r = sqlite3_value_double(pVal);
102809 for(i=0; i<SQLITE_INDEX_SAMPLES; i++){
102810 if( aSample[i].eType==SQLITE_NULL ) continue;
102811 if( aSample[i].eType>=SQLITE_TEXT ) break;
102812 if( roundUp ){
102813 if( aSample[i].u.r>r ) break;
102814 }else{
102815 if( aSample[i].u.r>=r ) break;
102816 }
102817 }
102818 }else if( eType==SQLITE_NULL ){
102819 i = 0;
102820 if( roundUp ){
102821 while( i<SQLITE_INDEX_SAMPLES && aSample[i].eType==SQLITE_NULL ) i++;
102822 }
102823 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102824 sqlite3 *db = pParse->db;
102825 CollSeq *pColl;
102826 const u8 *z;
102827 int n;
102828
102829 /* pVal comes from sqlite3ValueFromExpr() so the type cannot be NULL */
102830 assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
102831
102832 if( eType==SQLITE_BLOB ){
102833 z = (const u8 *)sqlite3_value_blob(pVal);
102834 pColl = db->pDfltColl;
102835 assert( pColl->enc==SQLITE_UTF8 );
102836 }else{
@@ -102845,16 +103303,16 @@
102845 return SQLITE_NOMEM;
102846 }
102847 assert( z && pColl && pColl->xCmp );
102848 }
102849 n = sqlite3ValueBytes(pVal, pColl->enc);
102850
102851 for(i=0; i<SQLITE_INDEX_SAMPLES; i++){
102852 int c;
102853 int eSampletype = aSample[i].eType;
102854 if( eSampletype==SQLITE_NULL || eSampletype<eType ) continue;
102855 if( (eSampletype!=eType) ) break;
102856 #ifndef SQLITE_OMIT_UTF16
102857 if( pColl->enc!=SQLITE_UTF8 ){
102858 int nSample;
102859 char *zSample = sqlite3Utf8to16(
102860 db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
@@ -102868,20 +103326,51 @@
102868 }else
102869 #endif
102870 {
102871 c = pColl->xCmp(pColl->pUser, aSample[i].nByte, aSample[i].u.z, n, z);
102872 }
102873 if( c-roundUp>=0 ) break;
 
 
 
102874 }
102875 }
 
102876
102877 assert( i>=0 && i<=SQLITE_INDEX_SAMPLES );
102878 *piRegion = i;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102879 }
102880 return SQLITE_OK;
102881 }
102882 #endif /* #ifdef SQLITE_ENABLE_STAT2 */
102883
102884 /*
102885 ** If expression pExpr represents a literal value, set *pp to point to
102886 ** an sqlite3_value structure containing the same value, with affinity
102887 ** aff applied to it, before returning. It is the responsibility of the
@@ -102895,11 +103384,11 @@
102895 **
102896 ** If neither of the above apply, set *pp to NULL.
102897 **
102898 ** If an error occurs, return an error code. Otherwise, SQLITE_OK.
102899 */
102900 #ifdef SQLITE_ENABLE_STAT2
102901 static int valueFromExpr(
102902 Parse *pParse,
102903 Expr *pExpr,
102904 u8 aff,
102905 sqlite3_value **pp
@@ -102943,106 +103432,92 @@
102943 **
102944 ** ... FROM t1 WHERE a > ? AND a < ? ...
102945 **
102946 ** then nEq should be passed 0.
102947 **
102948 ** The returned value is an integer between 1 and 100, inclusive. A return
102949 ** value of 1 indicates that the proposed range scan is expected to visit
102950 ** approximately 1/100th (1%) of the rows selected by the nEq equality
102951 ** constraints (if any). A return value of 100 indicates that it is expected
102952 ** that the range scan will visit every row (100%) selected by the equality
102953 ** constraints.
102954 **
102955 ** In the absence of sqlite_stat2 ANALYZE data, each range inequality
102956 ** reduces the search space by 3/4ths. Hence a single constraint (x>?)
102957 ** results in a return of 25 and a range constraint (x>? AND x<?) results
102958 ** in a return of 6.
102959 */
102960 static int whereRangeScanEst(
102961 Parse *pParse, /* Parsing & code generating context */
102962 Index *p, /* The index containing the range-compared column; "x" */
102963 int nEq, /* index into p->aCol[] of the range-compared column */
102964 WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */
102965 WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
102966 int *piEst /* OUT: Return value */
102967 ){
102968 int rc = SQLITE_OK;
102969
102970 #ifdef SQLITE_ENABLE_STAT2
102971
102972 if( nEq==0 && p->aSample ){
102973 sqlite3_value *pLowerVal = 0;
102974 sqlite3_value *pUpperVal = 0;
102975 int iEst;
102976 int iLower = 0;
102977 int iUpper = SQLITE_INDEX_SAMPLES;
102978 int roundUpUpper = 0;
102979 int roundUpLower = 0;
102980 u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
102981
102982 if( pLower ){
102983 Expr *pExpr = pLower->pExpr->pRight;
102984 rc = valueFromExpr(pParse, pExpr, aff, &pLowerVal);
102985 assert( pLower->eOperator==WO_GT || pLower->eOperator==WO_GE );
102986 roundUpLower = (pLower->eOperator==WO_GT) ?1:0;
 
 
 
 
 
 
102987 }
102988 if( rc==SQLITE_OK && pUpper ){
102989 Expr *pExpr = pUpper->pExpr->pRight;
102990 rc = valueFromExpr(pParse, pExpr, aff, &pUpperVal);
102991 assert( pUpper->eOperator==WO_LT || pUpper->eOperator==WO_LE );
102992 roundUpUpper = (pUpper->eOperator==WO_LE) ?1:0;
102993 }
102994
102995 if( rc!=SQLITE_OK || (pLowerVal==0 && pUpperVal==0) ){
102996 sqlite3ValueFree(pLowerVal);
102997 sqlite3ValueFree(pUpperVal);
102998 goto range_est_fallback;
102999 }else if( pLowerVal==0 ){
103000 rc = whereRangeRegion(pParse, p, pUpperVal, roundUpUpper, &iUpper);
103001 if( pLower ) iLower = iUpper/2;
103002 }else if( pUpperVal==0 ){
103003 rc = whereRangeRegion(pParse, p, pLowerVal, roundUpLower, &iLower);
103004 if( pUpper ) iUpper = (iLower + SQLITE_INDEX_SAMPLES + 1)/2;
103005 }else{
103006 rc = whereRangeRegion(pParse, p, pUpperVal, roundUpUpper, &iUpper);
103007 if( rc==SQLITE_OK ){
103008 rc = whereRangeRegion(pParse, p, pLowerVal, roundUpLower, &iLower);
103009 }
103010 }
103011 WHERETRACE(("range scan regions: %d..%d\n", iLower, iUpper));
103012
103013 iEst = iUpper - iLower;
103014 testcase( iEst==SQLITE_INDEX_SAMPLES );
103015 assert( iEst<=SQLITE_INDEX_SAMPLES );
103016 if( iEst<1 ){
103017 *piEst = 50/SQLITE_INDEX_SAMPLES;
103018 }else{
103019 *piEst = (iEst*100)/SQLITE_INDEX_SAMPLES;
103020 }
103021 sqlite3ValueFree(pLowerVal);
103022 sqlite3ValueFree(pUpperVal);
103023 return rc;
103024 }
103025 range_est_fallback:
103026 #else
103027 UNUSED_PARAMETER(pParse);
103028 UNUSED_PARAMETER(p);
103029 UNUSED_PARAMETER(nEq);
103030 #endif
103031 assert( pLower || pUpper );
103032 *piEst = 100;
103033 if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ) *piEst /= 4;
103034 if( pUpper ) *piEst /= 4;
103035 return rc;
103036 }
103037
103038 #ifdef SQLITE_ENABLE_STAT2
103039 /*
103040 ** Estimate the number of rows that will be returned based on
103041 ** an equality constraint x=VALUE and where that VALUE occurs in
103042 ** the histogram data. This only works when x is the left-most
103043 ** column of an index and sqlite_stat2 histogram data is available
103044 ** for that index. When pExpr==NULL that means the constraint is
103045 ** "x IS NULL" instead of "x=VALUE".
103046 **
103047 ** Write the estimated row count into *pnRow and return SQLITE_OK.
103048 ** If unable to make an estimate, leave *pnRow unchanged and return
@@ -103058,44 +103533,36 @@
103058 Index *p, /* The index whose left-most column is pTerm */
103059 Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
103060 double *pnRow /* Write the revised row estimate here */
103061 ){
103062 sqlite3_value *pRhs = 0; /* VALUE on right-hand side of pTerm */
103063 int iLower, iUpper; /* Range of histogram regions containing pRhs */
103064 u8 aff; /* Column affinity */
103065 int rc; /* Subfunction return code */
103066 double nRowEst; /* New estimate of the number of rows */
103067
103068 assert( p->aSample!=0 );
 
103069 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
103070 if( pExpr ){
103071 rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
103072 if( rc ) goto whereEqualScanEst_cancel;
103073 }else{
103074 pRhs = sqlite3ValueNew(pParse->db);
103075 }
103076 if( pRhs==0 ) return SQLITE_NOTFOUND;
103077 rc = whereRangeRegion(pParse, p, pRhs, 0, &iLower);
103078 if( rc ) goto whereEqualScanEst_cancel;
103079 rc = whereRangeRegion(pParse, p, pRhs, 1, &iUpper);
103080 if( rc ) goto whereEqualScanEst_cancel;
103081 WHERETRACE(("equality scan regions: %d..%d\n", iLower, iUpper));
103082 if( iLower>=iUpper ){
103083 nRowEst = p->aiRowEst[0]/(SQLITE_INDEX_SAMPLES*2);
103084 if( nRowEst<*pnRow ) *pnRow = nRowEst;
103085 }else{
103086 nRowEst = (iUpper-iLower)*p->aiRowEst[0]/SQLITE_INDEX_SAMPLES;
103087 *pnRow = nRowEst;
103088 }
103089
103090 whereEqualScanEst_cancel:
103091 sqlite3ValueFree(pRhs);
103092 return rc;
103093 }
103094 #endif /* defined(SQLITE_ENABLE_STAT2) */
103095
103096 #ifdef SQLITE_ENABLE_STAT2
103097 /*
103098 ** Estimate the number of rows that will be returned based on
103099 ** an IN constraint where the right-hand side of the IN operator
103100 ** is a list of values. Example:
103101 **
@@ -103114,64 +103581,29 @@
103114 Parse *pParse, /* Parsing & code generating context */
103115 Index *p, /* The index whose left-most column is pTerm */
103116 ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
103117 double *pnRow /* Write the revised row estimate here */
103118 ){
103119 sqlite3_value *pVal = 0; /* One value from list */
103120 int iLower, iUpper; /* Range of histogram regions containing pRhs */
103121 u8 aff; /* Column affinity */
103122 int rc = SQLITE_OK; /* Subfunction return code */
103123 double nRowEst; /* New estimate of the number of rows */
103124 int nSpan = 0; /* Number of histogram regions spanned */
103125 int nSingle = 0; /* Histogram regions hit by a single value */
103126 int nNotFound = 0; /* Count of values that are not constants */
103127 int i; /* Loop counter */
103128 u8 aSpan[SQLITE_INDEX_SAMPLES+1]; /* Histogram regions that are spanned */
103129 u8 aSingle[SQLITE_INDEX_SAMPLES+1]; /* Histogram regions hit once */
103130
103131 assert( p->aSample!=0 );
103132 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
103133 memset(aSpan, 0, sizeof(aSpan));
103134 memset(aSingle, 0, sizeof(aSingle));
103135 for(i=0; i<pList->nExpr; i++){
103136 sqlite3ValueFree(pVal);
103137 rc = valueFromExpr(pParse, pList->a[i].pExpr, aff, &pVal);
103138 if( rc ) break;
103139 if( pVal==0 || sqlite3_value_type(pVal)==SQLITE_NULL ){
103140 nNotFound++;
103141 continue;
103142 }
103143 rc = whereRangeRegion(pParse, p, pVal, 0, &iLower);
103144 if( rc ) break;
103145 rc = whereRangeRegion(pParse, p, pVal, 1, &iUpper);
103146 if( rc ) break;
103147 if( iLower>=iUpper ){
103148 aSingle[iLower] = 1;
103149 }else{
103150 assert( iLower>=0 && iUpper<=SQLITE_INDEX_SAMPLES );
103151 while( iLower<iUpper ) aSpan[iLower++] = 1;
103152 }
103153 }
103154 if( rc==SQLITE_OK ){
103155 for(i=nSpan=0; i<=SQLITE_INDEX_SAMPLES; i++){
103156 if( aSpan[i] ){
103157 nSpan++;
103158 }else if( aSingle[i] ){
103159 nSingle++;
103160 }
103161 }
103162 nRowEst = (nSpan*2+nSingle)*p->aiRowEst[0]/(2*SQLITE_INDEX_SAMPLES)
103163 + nNotFound*p->aiRowEst[1];
103164 if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
103165 *pnRow = nRowEst;
103166 WHERETRACE(("IN row estimate: nSpan=%d, nSingle=%d, nNotFound=%d, est=%g\n",
103167 nSpan, nSingle, nNotFound, nRowEst));
103168 }
103169 sqlite3ValueFree(pVal);
103170 return rc;
103171 }
103172 #endif /* defined(SQLITE_ENABLE_STAT2) */
103173
103174
103175 /*
103176 ** Find the best query plan for accessing a particular table. Write the
103177 ** best query plan and its cost into the WhereCost object supplied as the
@@ -103214,11 +103646,11 @@
103214 Index *pProbe; /* An index we are evaluating */
103215 Index *pIdx; /* Copy of pProbe, or zero for IPK index */
103216 int eqTermMask; /* Current mask of valid equality operators */
103217 int idxEqTermMask; /* Index mask of valid equality operators */
103218 Index sPk; /* A fake index object for the primary key */
103219 unsigned int aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
103220 int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
103221 int wsFlagMask; /* Allowed flags in pCost->plan.wsFlag */
103222
103223 /* Initialize the cost to a worst-case value */
103224 memset(pCost, 0, sizeof(*pCost));
@@ -103269,14 +103701,14 @@
103269 }
103270
103271 /* Loop over all indices looking for the best one to use
103272 */
103273 for(; pProbe; pIdx=pProbe=pProbe->pNext){
103274 const unsigned int * const aiRowEst = pProbe->aiRowEst;
103275 double cost; /* Cost of using pProbe */
103276 double nRow; /* Estimated number of rows in result set */
103277 double log10N; /* base-10 logarithm of nRow (inexact) */
103278 int rev; /* True to scan in reverse order */
103279 int wsFlags = 0;
103280 Bitmask used = 0;
103281
103282 /* The following variables are populated based on the properties of
@@ -103312,18 +103744,16 @@
103312 ** Set to true if there was at least one "x IN (SELECT ...)" term used
103313 ** in determining the value of nInMul. Note that the RHS of the
103314 ** IN operator must be a SELECT, not a value list, for this variable
103315 ** to be true.
103316 **
103317 ** estBound:
103318 ** An estimate on the amount of the table that must be searched. A
103319 ** value of 100 means the entire table is searched. Range constraints
103320 ** might reduce this to a value less than 100 to indicate that only
103321 ** a fraction of the table needs searching. In the absence of
103322 ** sqlite_stat2 ANALYZE data, a single inequality reduces the search
103323 ** space to 1/4rd its original size. So an x>? constraint reduces
103324 ** estBound to 25. Two constraints (x>? AND x<?) reduce estBound to 6.
103325 **
103326 ** bSort:
103327 ** Boolean. True if there is an ORDER BY clause that will require an
103328 ** external sort (i.e. scanning the index being evaluated will not
103329 ** correctly order records).
@@ -103344,26 +103774,27 @@
103344 ** SELECT a, b, c FROM tbl WHERE a = 1;
103345 */
103346 int nEq; /* Number of == or IN terms matching index */
103347 int bInEst = 0; /* True if "x IN (SELECT...)" seen */
103348 int nInMul = 1; /* Number of distinct equalities to lookup */
103349 int estBound = 100; /* Estimated reduction in search space */
103350 int nBound = 0; /* Number of range constraints seen */
103351 int bSort = !!pOrderBy; /* True if external sort required */
103352 int bDist = !!pDistinct; /* True if index cannot help with DISTINCT */
103353 int bLookup = 0; /* True if not a covering index */
103354 WhereTerm *pTerm; /* A single term of the WHERE clause */
103355 #ifdef SQLITE_ENABLE_STAT2
103356 WhereTerm *pFirstTerm = 0; /* First term matching the index */
103357 #endif
103358
103359 /* Determine the values of nEq and nInMul */
103360 for(nEq=0; nEq<pProbe->nColumn; nEq++){
103361 int j = pProbe->aiColumn[nEq];
103362 pTerm = findTerm(pWC, iCur, j, notReady, eqTermMask, pIdx);
103363 if( pTerm==0 ) break;
103364 wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
 
103365 if( pTerm->eOperator & WO_IN ){
103366 Expr *pExpr = pTerm->pExpr;
103367 wsFlags |= WHERE_COLUMN_IN;
103368 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
103369 /* "x IN (SELECT ...)": Assume the SELECT returns 25 rows */
@@ -103374,32 +103805,34 @@
103374 nInMul *= pExpr->x.pList->nExpr;
103375 }
103376 }else if( pTerm->eOperator & WO_ISNULL ){
103377 wsFlags |= WHERE_COLUMN_NULL;
103378 }
103379 #ifdef SQLITE_ENABLE_STAT2
103380 if( nEq==0 && pProbe->aSample ) pFirstTerm = pTerm;
103381 #endif
103382 used |= pTerm->prereqRight;
103383 }
103384
103385 /* Determine the value of estBound. */
103386 if( nEq<pProbe->nColumn && pProbe->bUnordered==0 ){
103387 int j = pProbe->aiColumn[nEq];
103388 if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
103389 WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
103390 WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
103391 whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &estBound);
103392 if( pTop ){
103393 nBound = 1;
103394 wsFlags |= WHERE_TOP_LIMIT;
103395 used |= pTop->prereqRight;
 
103396 }
103397 if( pBtm ){
103398 nBound++;
103399 wsFlags |= WHERE_BTM_LIMIT;
103400 used |= pBtm->prereqRight;
 
103401 }
103402 wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
103403 }
103404 }else if( pProbe->onError!=OE_None ){
103405 testcase( wsFlags & WHERE_COLUMN_IN );
@@ -103458,32 +103891,34 @@
103458 if( bInEst && nRow*2>aiRowEst[0] ){
103459 nRow = aiRowEst[0]/2;
103460 nInMul = (int)(nRow / aiRowEst[nEq]);
103461 }
103462
103463 #ifdef SQLITE_ENABLE_STAT2
103464 /* If the constraint is of the form x=VALUE or x IN (E1,E2,...)
103465 ** and we do not think that values of x are unique and if histogram
103466 ** data is available for column x, then it might be possible
103467 ** to get a better estimate on the number of rows based on
103468 ** VALUE and how common that value is according to the histogram.
103469 */
103470 if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 && aiRowEst[1]>1 ){
 
103471 if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){
103472 testcase( pFirstTerm->eOperator==WO_EQ );
103473 testcase( pFirstTerm->eOperator==WO_ISNULL );
103474 whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow);
103475 }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){
 
103476 whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow);
103477 }
103478 }
103479 #endif /* SQLITE_ENABLE_STAT2 */
103480
103481 /* Adjust the number of output rows and downward to reflect rows
103482 ** that are excluded by range constraints.
103483 */
103484 nRow = (nRow * (double)estBound) / (double)100;
103485 if( nRow<1 ) nRow = 1;
103486
103487 /* Experiments run on real SQLite databases show that the time needed
103488 ** to do a binary search to locate a row in a table or index is roughly
103489 ** log10(N) times the time to move from one row to the next row within
@@ -103608,14 +104043,14 @@
103608 if( nRow<2 ) nRow = 2;
103609 }
103610
103611
103612 WHERETRACE((
103613 "%s(%s): nEq=%d nInMul=%d estBound=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
103614 " notReady=0x%llx log10N=%.1f nRow=%.1f cost=%.1f used=0x%llx\n",
103615 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
103616 nEq, nInMul, estBound, bSort, bLookup, wsFlags,
103617 notReady, log10N, nRow, cost, used
103618 ));
103619
103620 /* If this index is the best we have seen so far, then record this
103621 ** index and its cost in the pCost structure.
@@ -104115,11 +104550,12 @@
104115 */
104116 static Bitmask codeOneLoopStart(
104117 WhereInfo *pWInfo, /* Complete information about the WHERE clause */
104118 int iLevel, /* Which level of pWInfo->a[] should be coded */
104119 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
104120 Bitmask notReady /* Which tables are currently available */
 
104121 ){
104122 int j, k; /* Loop counters */
104123 int iCur; /* The VDBE cursor for the table */
104124 int addrNxt; /* Where to jump to continue with the next IN case */
104125 int omitTable; /* True if we use the index only */
@@ -104597,11 +105033,12 @@
104597 int regRowset = 0; /* Register for RowSet object */
104598 int regRowid = 0; /* Register holding rowid */
104599 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
104600 int iRetInit; /* Address of regReturn init */
104601 int untestedTerms = 0; /* Some terms not completely tested */
104602 int ii;
 
104603
104604 pTerm = pLevel->plan.u.pTerm;
104605 assert( pTerm!=0 );
104606 assert( pTerm->eOperator==WO_OR );
104607 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
@@ -104646,18 +105083,33 @@
104646 regRowset = ++pParse->nMem;
104647 regRowid = ++pParse->nMem;
104648 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
104649 }
104650 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
 
 
 
 
 
 
 
 
 
 
104651
104652 for(ii=0; ii<pOrWc->nTerm; ii++){
104653 WhereTerm *pOrTerm = &pOrWc->a[ii];
104654 if( pOrTerm->leftCursor==iCur || pOrTerm->eOperator==WO_AND ){
104655 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
 
 
 
 
 
104656 /* Loop through table entries that match term pOrTerm. */
104657 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrTerm->pExpr, 0, 0,
104658 WHERE_OMIT_OPEN | WHERE_OMIT_CLOSE |
104659 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY);
104660 if( pSubWInfo ){
104661 explainOneScan(
104662 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
104663 );
@@ -104681,10 +105133,11 @@
104681 /* Finish the loop through table entries that match term pOrTerm. */
104682 sqlite3WhereEnd(pSubWInfo);
104683 }
104684 }
104685 }
 
104686 sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
104687 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
104688 sqlite3VdbeResolveLabel(v, iLoopBody);
104689
104690 if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
@@ -104962,11 +105415,11 @@
104962
104963 /* Split the WHERE clause into separate subexpressions where each
104964 ** subexpression is separated by an AND operator.
104965 */
104966 initMaskSet(pMaskSet);
104967 whereClauseInit(pWC, pParse, pMaskSet);
104968 sqlite3ExprCodeConstants(pParse, pWhere);
104969 whereSplit(pWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
104970
104971 /* Special case: a WHERE clause that is constant. Evaluate the
104972 ** expression and either jump over all of the code or fall thru.
@@ -105290,11 +105743,11 @@
105290 int iCur = pTabItem->iCursor;
105291 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
105292 }else
105293 #endif
105294 if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
105295 && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
105296 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
105297 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
105298 testcase( pTab->nCol==BMS-1 );
105299 testcase( pTab->nCol==BMS );
105300 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
@@ -105335,11 +105788,11 @@
105335 */
105336 notReady = ~(Bitmask)0;
105337 for(i=0; i<nTabList; i++){
105338 pLevel = &pWInfo->a[i];
105339 explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
105340 notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
105341 pWInfo->iContinue = pLevel->addrCont;
105342 }
105343
105344 #ifdef SQLITE_TEST /* For testing and debugging use only */
105345 /* Record in the query plan information about the current table
@@ -105470,11 +105923,11 @@
105470 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
105471 Table *pTab = pTabItem->pTab;
105472 assert( pTab!=0 );
105473 if( (pTab->tabFlags & TF_Ephemeral)==0
105474 && pTab->pSelect==0
105475 && (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0
105476 ){
105477 int ws = pLevel->plan.wsFlags;
105478 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
105479 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
105480 }
@@ -105531,10 +105984,11 @@
105531 return;
105532 }
105533
105534 /************** End of where.c ***********************************************/
105535 /************** Begin file parse.c *******************************************/
 
105536 /* Driver template for the LEMON parser generator.
105537 ** The author disclaims copyright to this source code.
105538 **
105539 ** This version of "lempar.c" is modified, slightly, for use by SQLite.
105540 ** The only modifications are the addition of a couple of NEVER()
@@ -105543,10 +105997,11 @@
105543 ** specific grammar used by SQLite.
105544 */
105545 /* First off, code is included that follows the "include" declaration
105546 ** in the input grammar file. */
105547 /* #include <stdio.h> */
 
105548
105549
105550 /*
105551 ** Disable all error recovery processing in the parser push-down
105552 ** automaton.
@@ -105590,10 +106045,11 @@
105590 /*
105591 ** An instance of this structure holds the ATTACH key and the key type.
105592 */
105593 struct AttachKey { int type; Token key; };
105594
 
105595
105596 /* This is a utility routine used to set the ExprSpan.zStart and
105597 ** ExprSpan.zEnd values of pOut so that the span covers the complete
105598 ** range of text beginning with pStart and going to the end of pEnd.
105599 */
@@ -105609,10 +106065,11 @@
105609 static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token *pValue){
105610 pOut->pExpr = sqlite3PExpr(pParse, op, 0, 0, pValue);
105611 pOut->zStart = pValue->z;
105612 pOut->zEnd = &pValue->z[pValue->n];
105613 }
 
105614
105615 /* This routine constructs a binary expression node out of two ExprSpan
105616 ** objects and uses the result to populate a new ExprSpan object.
105617 */
105618 static void spanBinaryExpr(
@@ -105624,10 +106081,11 @@
105624 ){
105625 pOut->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0);
105626 pOut->zStart = pLeft->zStart;
105627 pOut->zEnd = pRight->zEnd;
105628 }
 
105629
105630 /* Construct an expression node for a unary postfix operator
105631 */
105632 static void spanUnaryPostfix(
105633 ExprSpan *pOut, /* Write the new expression node here */
@@ -105638,10 +106096,11 @@
105638 ){
105639 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
105640 pOut->zStart = pOperand->zStart;
105641 pOut->zEnd = &pPostOp->z[pPostOp->n];
105642 }
 
105643
105644 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
105645 ** unary TK_ISNULL or TK_NOTNULL expression. */
105646 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
105647 sqlite3 *db = pParse->db;
@@ -105649,10 +106108,11 @@
105649 pA->op = (u8)op;
105650 sqlite3ExprDelete(db, pA->pRight);
105651 pA->pRight = 0;
105652 }
105653 }
 
105654
105655 /* Construct an expression node for a unary prefix operator
105656 */
105657 static void spanUnaryPrefix(
105658 ExprSpan *pOut, /* Write the new expression node here */
@@ -105663,10 +106123,11 @@
105663 ){
105664 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
105665 pOut->zStart = pPreOp->z;
105666 pOut->zEnd = pOperand->zEnd;
105667 }
 
105668 /* Next is all token values, in a form suitable for use by makeheaders.
105669 ** This section will be null unless lemon is run with the -m switch.
105670 */
105671 /*
105672 ** These constants (all generated automatically by the parser generator)
@@ -106918,17 +107379,21 @@
106918 ** inside the C code.
106919 */
106920 case 160: /* select */
106921 case 194: /* oneselect */
106922 {
 
106923 sqlite3SelectDelete(pParse->db, (yypminor->yy387));
 
106924 }
106925 break;
106926 case 174: /* term */
106927 case 175: /* expr */
106928 {
 
106929 sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
 
106930 }
106931 break;
106932 case 179: /* idxlist_opt */
106933 case 187: /* idxlist */
106934 case 197: /* selcollist */
@@ -106940,19 +107405,23 @@
106940 case 217: /* setlist */
106941 case 220: /* itemlist */
106942 case 221: /* exprlist */
106943 case 226: /* case_exprlist */
106944 {
 
106945 sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
 
106946 }
106947 break;
106948 case 193: /* fullname */
106949 case 198: /* from */
106950 case 206: /* seltablist */
106951 case 207: /* stl_prefix */
106952 {
 
106953 sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
 
106954 }
106955 break;
106956 case 199: /* where_opt */
106957 case 201: /* having_opt */
106958 case 210: /* on_opt */
@@ -106960,29 +107429,37 @@
106960 case 225: /* case_operand */
106961 case 227: /* case_else */
106962 case 238: /* when_clause */
106963 case 243: /* key_opt */
106964 {
 
106965 sqlite3ExprDelete(pParse->db, (yypminor->yy314));
 
106966 }
106967 break;
106968 case 211: /* using_opt */
106969 case 213: /* inscollist */
106970 case 219: /* inscollist_opt */
106971 {
 
106972 sqlite3IdListDelete(pParse->db, (yypminor->yy384));
 
106973 }
106974 break;
106975 case 234: /* trigger_cmd_list */
106976 case 239: /* trigger_cmd */
106977 {
 
106978 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
 
106979 }
106980 break;
106981 case 236: /* trigger_event */
106982 {
 
106983 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
 
106984 }
106985 break;
106986 default: break; /* If no destructor action specified: do nothing */
106987 }
106988 }
@@ -107164,14 +107641,16 @@
107164 }
107165 #endif
107166 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
107167 /* Here code is inserted which will execute if the parser
107168 ** stack every overflows */
 
107169
107170 UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */
107171 sqlite3ErrorMsg(pParse, "parser stack overflow");
107172 pParse->parseError = 1;
 
107173 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
107174 }
107175
107176 /*
107177 ** Perform a shift action.
@@ -107608,66 +108087,94 @@
107608 ** { ... } // User supplied code
107609 ** #line <lineno> <thisfile>
107610 ** break;
107611 */
107612 case 5: /* explain ::= */
 
107613 { sqlite3BeginParse(pParse, 0); }
 
107614 break;
107615 case 6: /* explain ::= EXPLAIN */
 
107616 { sqlite3BeginParse(pParse, 1); }
 
107617 break;
107618 case 7: /* explain ::= EXPLAIN QUERY PLAN */
 
107619 { sqlite3BeginParse(pParse, 2); }
 
107620 break;
107621 case 8: /* cmdx ::= cmd */
 
107622 { sqlite3FinishCoding(pParse); }
 
107623 break;
107624 case 9: /* cmd ::= BEGIN transtype trans_opt */
 
107625 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
 
107626 break;
107627 case 13: /* transtype ::= */
 
107628 {yygotominor.yy4 = TK_DEFERRED;}
 
107629 break;
107630 case 14: /* transtype ::= DEFERRED */
107631 case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
107632 case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
107633 case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115);
107634 case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117);
 
107635 {yygotominor.yy4 = yymsp[0].major;}
 
107636 break;
107637 case 17: /* cmd ::= COMMIT trans_opt */
107638 case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
 
107639 {sqlite3CommitTransaction(pParse);}
 
107640 break;
107641 case 19: /* cmd ::= ROLLBACK trans_opt */
 
107642 {sqlite3RollbackTransaction(pParse);}
 
107643 break;
107644 case 22: /* cmd ::= SAVEPOINT nm */
 
107645 {
107646 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
107647 }
 
107648 break;
107649 case 23: /* cmd ::= RELEASE savepoint_opt nm */
 
107650 {
107651 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
107652 }
 
107653 break;
107654 case 24: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
 
107655 {
107656 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
107657 }
 
107658 break;
107659 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
 
107660 {
107661 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
107662 }
 
107663 break;
107664 case 27: /* createkw ::= CREATE */
 
107665 {
107666 pParse->db->lookaside.bEnabled = 0;
107667 yygotominor.yy0 = yymsp[0].minor.yy0;
107668 }
 
107669 break;
107670 case 28: /* ifnotexists ::= */
107671 case 31: /* temp ::= */ yytestcase(yyruleno==31);
107672 case 70: /* autoinc ::= */ yytestcase(yyruleno==70);
107673 case 83: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==83);
@@ -107677,44 +108184,56 @@
107677 case 109: /* ifexists ::= */ yytestcase(yyruleno==109);
107678 case 120: /* distinct ::= ALL */ yytestcase(yyruleno==120);
107679 case 121: /* distinct ::= */ yytestcase(yyruleno==121);
107680 case 222: /* between_op ::= BETWEEN */ yytestcase(yyruleno==222);
107681 case 225: /* in_op ::= IN */ yytestcase(yyruleno==225);
 
107682 {yygotominor.yy4 = 0;}
 
107683 break;
107684 case 29: /* ifnotexists ::= IF NOT EXISTS */
107685 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
107686 case 71: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==71);
107687 case 86: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==86);
107688 case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108);
107689 case 119: /* distinct ::= DISTINCT */ yytestcase(yyruleno==119);
107690 case 223: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==223);
107691 case 226: /* in_op ::= NOT IN */ yytestcase(yyruleno==226);
 
107692 {yygotominor.yy4 = 1;}
 
107693 break;
107694 case 32: /* create_table_args ::= LP columnlist conslist_opt RP */
 
107695 {
107696 sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
107697 }
 
107698 break;
107699 case 33: /* create_table_args ::= AS select */
 
107700 {
107701 sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy387);
107702 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
107703 }
 
107704 break;
107705 case 36: /* column ::= columnid type carglist */
 
107706 {
107707 yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
107708 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
107709 }
 
107710 break;
107711 case 37: /* columnid ::= nm */
 
107712 {
107713 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
107714 yygotominor.yy0 = yymsp[0].minor.yy0;
107715 }
 
107716 break;
107717 case 38: /* id ::= ID */
107718 case 39: /* id ::= INDEXED */ yytestcase(yyruleno==39);
107719 case 40: /* ids ::= ID|STRING */ yytestcase(yyruleno==40);
107720 case 41: /* nm ::= id */ yytestcase(yyruleno==41);
@@ -107734,256 +108253,373 @@
107734 case 264: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==264);
107735 case 265: /* plus_num ::= plus_opt number */ yytestcase(yyruleno==265);
107736 case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266);
107737 case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267);
107738 case 285: /* trnm ::= nm */ yytestcase(yyruleno==285);
 
107739 {yygotominor.yy0 = yymsp[0].minor.yy0;}
 
107740 break;
107741 case 45: /* type ::= typetoken */
 
107742 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
 
107743 break;
107744 case 47: /* typetoken ::= typename LP signed RP */
 
107745 {
107746 yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
107747 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
107748 }
 
107749 break;
107750 case 48: /* typetoken ::= typename LP signed COMMA signed RP */
 
107751 {
107752 yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
107753 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
107754 }
 
107755 break;
107756 case 50: /* typename ::= typename ids */
 
107757 {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
 
107758 break;
107759 case 57: /* ccons ::= DEFAULT term */
107760 case 59: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==59);
 
107761 {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy118);}
 
107762 break;
107763 case 58: /* ccons ::= DEFAULT LP expr RP */
 
107764 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy118);}
 
107765 break;
107766 case 60: /* ccons ::= DEFAULT MINUS term */
 
107767 {
107768 ExprSpan v;
107769 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy118.pExpr, 0, 0);
107770 v.zStart = yymsp[-1].minor.yy0.z;
107771 v.zEnd = yymsp[0].minor.yy118.zEnd;
107772 sqlite3AddDefaultValue(pParse,&v);
107773 }
 
107774 break;
107775 case 61: /* ccons ::= DEFAULT id */
 
107776 {
107777 ExprSpan v;
107778 spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
107779 sqlite3AddDefaultValue(pParse,&v);
107780 }
 
107781 break;
107782 case 63: /* ccons ::= NOT NULL onconf */
 
107783 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
 
107784 break;
107785 case 64: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
 
107786 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
 
107787 break;
107788 case 65: /* ccons ::= UNIQUE onconf */
 
107789 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0);}
 
107790 break;
107791 case 66: /* ccons ::= CHECK LP expr RP */
 
107792 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy118.pExpr);}
 
107793 break;
107794 case 67: /* ccons ::= REFERENCES nm idxlist_opt refargs */
 
107795 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
 
107796 break;
107797 case 68: /* ccons ::= defer_subclause */
 
107798 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
 
107799 break;
107800 case 69: /* ccons ::= COLLATE ids */
 
107801 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
 
107802 break;
107803 case 72: /* refargs ::= */
 
107804 { yygotominor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
 
107805 break;
107806 case 73: /* refargs ::= refargs refarg */
 
107807 { yygotominor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
 
107808 break;
107809 case 74: /* refarg ::= MATCH nm */
107810 case 75: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==75);
 
107811 { yygotominor.yy215.value = 0; yygotominor.yy215.mask = 0x000000; }
 
107812 break;
107813 case 76: /* refarg ::= ON DELETE refact */
 
107814 { yygotominor.yy215.value = yymsp[0].minor.yy4; yygotominor.yy215.mask = 0x0000ff; }
 
107815 break;
107816 case 77: /* refarg ::= ON UPDATE refact */
 
107817 { yygotominor.yy215.value = yymsp[0].minor.yy4<<8; yygotominor.yy215.mask = 0x00ff00; }
 
107818 break;
107819 case 78: /* refact ::= SET NULL */
 
107820 { yygotominor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
 
107821 break;
107822 case 79: /* refact ::= SET DEFAULT */
 
107823 { yygotominor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
 
107824 break;
107825 case 80: /* refact ::= CASCADE */
 
107826 { yygotominor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
 
107827 break;
107828 case 81: /* refact ::= RESTRICT */
 
107829 { yygotominor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
 
107830 break;
107831 case 82: /* refact ::= NO ACTION */
 
107832 { yygotominor.yy4 = OE_None; /* EV: R-33326-45252 */}
 
107833 break;
107834 case 84: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
107835 case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99);
107836 case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101);
107837 case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104);
 
107838 {yygotominor.yy4 = yymsp[0].minor.yy4;}
 
107839 break;
107840 case 88: /* conslist_opt ::= */
 
107841 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
 
107842 break;
107843 case 89: /* conslist_opt ::= COMMA conslist */
 
107844 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
 
107845 break;
107846 case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
 
107847 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
 
107848 break;
107849 case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */
 
107850 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0);}
 
107851 break;
107852 case 96: /* tcons ::= CHECK LP expr RP onconf */
 
107853 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy118.pExpr);}
 
107854 break;
107855 case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
 
107856 {
107857 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
107858 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
107859 }
 
107860 break;
107861 case 100: /* onconf ::= */
 
107862 {yygotominor.yy4 = OE_Default;}
 
107863 break;
107864 case 102: /* orconf ::= */
 
107865 {yygotominor.yy210 = OE_Default;}
 
107866 break;
107867 case 103: /* orconf ::= OR resolvetype */
 
107868 {yygotominor.yy210 = (u8)yymsp[0].minor.yy4;}
 
107869 break;
107870 case 105: /* resolvetype ::= IGNORE */
 
107871 {yygotominor.yy4 = OE_Ignore;}
 
107872 break;
107873 case 106: /* resolvetype ::= REPLACE */
 
107874 {yygotominor.yy4 = OE_Replace;}
 
107875 break;
107876 case 107: /* cmd ::= DROP TABLE ifexists fullname */
 
107877 {
107878 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
107879 }
 
107880 break;
107881 case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
 
107882 {
107883 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy387, yymsp[-6].minor.yy4, yymsp[-4].minor.yy4);
107884 }
 
107885 break;
107886 case 111: /* cmd ::= DROP VIEW ifexists fullname */
 
107887 {
107888 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
107889 }
 
107890 break;
107891 case 112: /* cmd ::= select */
 
107892 {
107893 SelectDest dest = {SRT_Output, 0, 0, 0, 0};
107894 sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
107895 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
107896 }
 
107897 break;
107898 case 113: /* select ::= oneselect */
 
107899 {yygotominor.yy387 = yymsp[0].minor.yy387;}
 
107900 break;
107901 case 114: /* select ::= select multiselect_op oneselect */
 
107902 {
107903 if( yymsp[0].minor.yy387 ){
107904 yymsp[0].minor.yy387->op = (u8)yymsp[-1].minor.yy4;
107905 yymsp[0].minor.yy387->pPrior = yymsp[-2].minor.yy387;
107906 }else{
107907 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
107908 }
107909 yygotominor.yy387 = yymsp[0].minor.yy387;
107910 }
 
107911 break;
107912 case 116: /* multiselect_op ::= UNION ALL */
 
107913 {yygotominor.yy4 = TK_ALL;}
 
107914 break;
107915 case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
 
107916 {
107917 yygotominor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy292.pLimit,yymsp[0].minor.yy292.pOffset);
107918 }
 
107919 break;
107920 case 122: /* sclp ::= selcollist COMMA */
107921 case 247: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==247);
 
107922 {yygotominor.yy322 = yymsp[-1].minor.yy322;}
 
107923 break;
107924 case 123: /* sclp ::= */
107925 case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151);
107926 case 159: /* groupby_opt ::= */ yytestcase(yyruleno==159);
107927 case 240: /* exprlist ::= */ yytestcase(yyruleno==240);
107928 case 246: /* idxlist_opt ::= */ yytestcase(yyruleno==246);
 
107929 {yygotominor.yy322 = 0;}
 
107930 break;
107931 case 124: /* selcollist ::= sclp expr as */
 
107932 {
107933 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, yymsp[-1].minor.yy118.pExpr);
107934 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[0].minor.yy0, 1);
107935 sqlite3ExprListSetSpan(pParse,yygotominor.yy322,&yymsp[-1].minor.yy118);
107936 }
 
107937 break;
107938 case 125: /* selcollist ::= sclp STAR */
 
107939 {
107940 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
107941 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy322, p);
107942 }
 
107943 break;
107944 case 126: /* selcollist ::= sclp nm DOT STAR */
 
107945 {
107946 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
107947 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
107948 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
107949 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, pDot);
107950 }
 
107951 break;
107952 case 129: /* as ::= */
 
107953 {yygotominor.yy0.n = 0;}
 
107954 break;
107955 case 130: /* from ::= */
 
107956 {yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
 
107957 break;
107958 case 131: /* from ::= FROM seltablist */
 
107959 {
107960 yygotominor.yy259 = yymsp[0].minor.yy259;
107961 sqlite3SrcListShiftJoinType(yygotominor.yy259);
107962 }
 
107963 break;
107964 case 132: /* stl_prefix ::= seltablist joinop */
 
107965 {
107966 yygotominor.yy259 = yymsp[-1].minor.yy259;
107967 if( ALWAYS(yygotominor.yy259 && yygotominor.yy259->nSrc>0) ) yygotominor.yy259->a[yygotominor.yy259->nSrc-1].jointype = (u8)yymsp[0].minor.yy4;
107968 }
 
107969 break;
107970 case 133: /* stl_prefix ::= */
 
107971 {yygotominor.yy259 = 0;}
 
107972 break;
107973 case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
 
107974 {
107975 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
107976 sqlite3SrcListIndexedBy(pParse, yygotominor.yy259, &yymsp[-2].minor.yy0);
107977 }
 
107978 break;
107979 case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
 
107980 {
107981 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
107982 }
 
107983 break;
107984 case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
 
107985 {
107986 if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
107987 yygotominor.yy259 = yymsp[-4].minor.yy259;
107988 }else{
107989 Select *pSubquery;
@@ -107990,180 +108626,260 @@
107990 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
107991 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,0,0,0);
107992 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
107993 }
107994 }
 
107995 break;
107996 case 137: /* dbnm ::= */
107997 case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146);
 
107998 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
 
107999 break;
108000 case 139: /* fullname ::= nm dbnm */
 
108001 {yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
 
108002 break;
108003 case 140: /* joinop ::= COMMA|JOIN */
 
108004 { yygotominor.yy4 = JT_INNER; }
 
108005 break;
108006 case 141: /* joinop ::= JOIN_KW JOIN */
 
108007 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
 
108008 break;
108009 case 142: /* joinop ::= JOIN_KW nm JOIN */
 
108010 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
 
108011 break;
108012 case 143: /* joinop ::= JOIN_KW nm nm JOIN */
 
108013 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
 
108014 break;
108015 case 144: /* on_opt ::= ON expr */
108016 case 155: /* sortitem ::= expr */ yytestcase(yyruleno==155);
108017 case 162: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==162);
108018 case 169: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==169);
108019 case 235: /* case_else ::= ELSE expr */ yytestcase(yyruleno==235);
108020 case 237: /* case_operand ::= expr */ yytestcase(yyruleno==237);
 
108021 {yygotominor.yy314 = yymsp[0].minor.yy118.pExpr;}
 
108022 break;
108023 case 145: /* on_opt ::= */
108024 case 161: /* having_opt ::= */ yytestcase(yyruleno==161);
108025 case 168: /* where_opt ::= */ yytestcase(yyruleno==168);
108026 case 236: /* case_else ::= */ yytestcase(yyruleno==236);
108027 case 238: /* case_operand ::= */ yytestcase(yyruleno==238);
 
108028 {yygotominor.yy314 = 0;}
 
108029 break;
108030 case 148: /* indexed_opt ::= NOT INDEXED */
 
108031 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
 
108032 break;
108033 case 149: /* using_opt ::= USING LP inscollist RP */
108034 case 181: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==181);
 
108035 {yygotominor.yy384 = yymsp[-1].minor.yy384;}
 
108036 break;
108037 case 150: /* using_opt ::= */
108038 case 180: /* inscollist_opt ::= */ yytestcase(yyruleno==180);
 
108039 {yygotominor.yy384 = 0;}
 
108040 break;
108041 case 152: /* orderby_opt ::= ORDER BY sortlist */
108042 case 160: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==160);
108043 case 239: /* exprlist ::= nexprlist */ yytestcase(yyruleno==239);
 
108044 {yygotominor.yy322 = yymsp[0].minor.yy322;}
 
108045 break;
108046 case 153: /* sortlist ::= sortlist COMMA sortitem sortorder */
 
108047 {
108048 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314);
108049 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108050 }
 
108051 break;
108052 case 154: /* sortlist ::= sortitem sortorder */
 
108053 {
108054 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314);
108055 if( yygotominor.yy322 && ALWAYS(yygotominor.yy322->a) ) yygotominor.yy322->a[0].sortOrder = (u8)yymsp[0].minor.yy4;
108056 }
 
108057 break;
108058 case 156: /* sortorder ::= ASC */
108059 case 158: /* sortorder ::= */ yytestcase(yyruleno==158);
 
108060 {yygotominor.yy4 = SQLITE_SO_ASC;}
 
108061 break;
108062 case 157: /* sortorder ::= DESC */
 
108063 {yygotominor.yy4 = SQLITE_SO_DESC;}
 
108064 break;
108065 case 163: /* limit_opt ::= */
 
108066 {yygotominor.yy292.pLimit = 0; yygotominor.yy292.pOffset = 0;}
 
108067 break;
108068 case 164: /* limit_opt ::= LIMIT expr */
 
108069 {yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr; yygotominor.yy292.pOffset = 0;}
 
108070 break;
108071 case 165: /* limit_opt ::= LIMIT expr OFFSET expr */
 
108072 {yygotominor.yy292.pLimit = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pOffset = yymsp[0].minor.yy118.pExpr;}
 
108073 break;
108074 case 166: /* limit_opt ::= LIMIT expr COMMA expr */
 
108075 {yygotominor.yy292.pOffset = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr;}
 
108076 break;
108077 case 167: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
 
108078 {
108079 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
108080 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314);
108081 }
 
108082 break;
108083 case 170: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
 
108084 {
108085 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
108086 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
108087 sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy210);
108088 }
 
108089 break;
108090 case 171: /* setlist ::= setlist COMMA nm EQ expr */
 
108091 {
108092 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy118.pExpr);
108093 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108094 }
 
108095 break;
108096 case 172: /* setlist ::= nm EQ expr */
 
108097 {
108098 yygotominor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy118.pExpr);
108099 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108100 }
 
108101 break;
108102 case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
 
108103 {sqlite3Insert(pParse, yymsp[-5].minor.yy259, yymsp[-1].minor.yy322, 0, yymsp[-4].minor.yy384, yymsp[-7].minor.yy210);}
 
108104 break;
108105 case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
 
108106 {sqlite3Insert(pParse, yymsp[-2].minor.yy259, 0, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
 
108107 break;
108108 case 175: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
 
108109 {sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy210);}
 
108110 break;
108111 case 176: /* insert_cmd ::= INSERT orconf */
 
108112 {yygotominor.yy210 = yymsp[0].minor.yy210;}
 
108113 break;
108114 case 177: /* insert_cmd ::= REPLACE */
 
108115 {yygotominor.yy210 = OE_Replace;}
 
108116 break;
108117 case 178: /* itemlist ::= itemlist COMMA expr */
108118 case 241: /* nexprlist ::= nexprlist COMMA expr */ yytestcase(yyruleno==241);
 
108119 {yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy118.pExpr);}
 
108120 break;
108121 case 179: /* itemlist ::= expr */
108122 case 242: /* nexprlist ::= expr */ yytestcase(yyruleno==242);
 
108123 {yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy118.pExpr);}
 
108124 break;
108125 case 182: /* inscollist ::= inscollist COMMA nm */
 
108126 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
 
108127 break;
108128 case 183: /* inscollist ::= nm */
 
108129 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
 
108130 break;
108131 case 184: /* expr ::= term */
 
108132 {yygotominor.yy118 = yymsp[0].minor.yy118;}
 
108133 break;
108134 case 185: /* expr ::= LP expr RP */
 
108135 {yygotominor.yy118.pExpr = yymsp[-1].minor.yy118.pExpr; spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
 
108136 break;
108137 case 186: /* term ::= NULL */
108138 case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
108139 case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
 
108140 {spanExpr(&yygotominor.yy118, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
 
108141 break;
108142 case 187: /* expr ::= id */
108143 case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
 
108144 {spanExpr(&yygotominor.yy118, pParse, TK_ID, &yymsp[0].minor.yy0);}
 
108145 break;
108146 case 189: /* expr ::= nm DOT nm */
 
108147 {
108148 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108149 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
108150 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
108151 spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
108152 }
 
108153 break;
108154 case 190: /* expr ::= nm DOT nm DOT nm */
 
108155 {
108156 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
108157 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108158 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
108159 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
108160 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
108161 spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
108162 }
 
108163 break;
108164 case 193: /* expr ::= REGISTER */
 
108165 {
108166 /* When doing a nested parse, one can include terms in an expression
108167 ** that look like this: #1 #2 ... These terms refer to registers
108168 ** in the virtual machine. #N is the N-th register. */
108169 if( pParse->nested==0 ){
@@ -108173,32 +108889,40 @@
108173 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
108174 if( yygotominor.yy118.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy118.pExpr->iTable);
108175 }
108176 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108177 }
 
108178 break;
108179 case 194: /* expr ::= VARIABLE */
 
108180 {
108181 spanExpr(&yygotominor.yy118, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
108182 sqlite3ExprAssignVarNumber(pParse, yygotominor.yy118.pExpr);
108183 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108184 }
 
108185 break;
108186 case 195: /* expr ::= expr COLLATE ids */
 
108187 {
108188 yygotominor.yy118.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
108189 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
108190 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108191 }
 
108192 break;
108193 case 196: /* expr ::= CAST LP expr AS typetoken RP */
 
108194 {
108195 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy118.pExpr, 0, &yymsp[-1].minor.yy0);
108196 spanSet(&yygotominor.yy118,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
108197 }
 
108198 break;
108199 case 197: /* expr ::= ID LP distinct exprlist RP */
 
108200 {
108201 if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
108202 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
108203 }
108204 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
@@ -108205,47 +108929,59 @@
108205 spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
108206 if( yymsp[-2].minor.yy4 && yygotominor.yy118.pExpr ){
108207 yygotominor.yy118.pExpr->flags |= EP_Distinct;
108208 }
108209 }
 
108210 break;
108211 case 198: /* expr ::= ID LP STAR RP */
 
108212 {
108213 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
108214 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
108215 }
 
108216 break;
108217 case 199: /* term ::= CTIME_KW */
 
108218 {
108219 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
108220 ** treated as functions that return constants */
108221 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
108222 if( yygotominor.yy118.pExpr ){
108223 yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
108224 }
108225 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108226 }
 
108227 break;
108228 case 200: /* expr ::= expr AND expr */
108229 case 201: /* expr ::= expr OR expr */ yytestcase(yyruleno==201);
108230 case 202: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==202);
108231 case 203: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==203);
108232 case 204: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==204);
108233 case 205: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==205);
108234 case 206: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==206);
108235 case 207: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==207);
 
108236 {spanBinaryExpr(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);}
 
108237 break;
108238 case 208: /* likeop ::= LIKE_KW */
108239 case 210: /* likeop ::= MATCH */ yytestcase(yyruleno==210);
 
108240 {yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 0;}
 
108241 break;
108242 case 209: /* likeop ::= NOT LIKE_KW */
108243 case 211: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==211);
 
108244 {yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 1;}
 
108245 break;
108246 case 212: /* expr ::= expr likeop expr */
 
108247 {
108248 ExprList *pList;
108249 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy118.pExpr);
108250 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy118.pExpr);
108251 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy342.eOperator);
@@ -108252,12 +108988,14 @@
108252 if( yymsp[-1].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108253 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
108254 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108255 if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
108256 }
 
108257 break;
108258 case 213: /* expr ::= expr likeop expr ESCAPE expr */
 
108259 {
108260 ExprList *pList;
108261 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
108262 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy118.pExpr);
108263 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
@@ -108265,40 +109003,56 @@
108265 if( yymsp[-3].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108266 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108267 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108268 if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
108269 }
 
108270 break;
108271 case 214: /* expr ::= expr ISNULL|NOTNULL */
 
108272 {spanUnaryPostfix(&yygotominor.yy118,pParse,yymsp[0].major,&yymsp[-1].minor.yy118,&yymsp[0].minor.yy0);}
 
108273 break;
108274 case 215: /* expr ::= expr NOT NULL */
 
108275 {spanUnaryPostfix(&yygotominor.yy118,pParse,TK_NOTNULL,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy0);}
 
108276 break;
108277 case 216: /* expr ::= expr IS expr */
 
108278 {
108279 spanBinaryExpr(&yygotominor.yy118,pParse,TK_IS,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);
108280 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_ISNULL);
108281 }
 
108282 break;
108283 case 217: /* expr ::= expr IS NOT expr */
 
108284 {
108285 spanBinaryExpr(&yygotominor.yy118,pParse,TK_ISNOT,&yymsp[-3].minor.yy118,&yymsp[0].minor.yy118);
108286 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_NOTNULL);
108287 }
 
108288 break;
108289 case 218: /* expr ::= NOT expr */
108290 case 219: /* expr ::= BITNOT expr */ yytestcase(yyruleno==219);
 
108291 {spanUnaryPrefix(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
 
108292 break;
108293 case 220: /* expr ::= MINUS expr */
 
108294 {spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UMINUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
 
108295 break;
108296 case 221: /* expr ::= PLUS expr */
 
108297 {spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UPLUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
 
108298 break;
108299 case 224: /* expr ::= expr between_op expr AND expr */
 
108300 {
108301 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
108302 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
108303 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy118.pExpr, 0, 0);
108304 if( yygotominor.yy118.pExpr ){
@@ -108308,12 +109062,14 @@
108308 }
108309 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108310 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108311 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108312 }
 
108313 break;
108314 case 227: /* expr ::= expr in_op LP exprlist RP */
 
108315 {
108316 if( yymsp[-1].minor.yy322==0 ){
108317 /* Expressions of the form
108318 **
108319 ** expr1 IN ()
@@ -108335,12 +109091,14 @@
108335 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108336 }
108337 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108338 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108339 }
 
108340 break;
108341 case 228: /* expr ::= LP select RP */
 
108342 {
108343 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
108344 if( yygotominor.yy118.pExpr ){
108345 yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
108346 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
@@ -108349,12 +109107,14 @@
108349 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
108350 }
108351 yygotominor.yy118.zStart = yymsp[-2].minor.yy0.z;
108352 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108353 }
 
108354 break;
108355 case 229: /* expr ::= expr in_op LP select RP */
 
108356 {
108357 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
108358 if( yygotominor.yy118.pExpr ){
108359 yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
108360 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
@@ -108364,12 +109124,14 @@
108364 }
108365 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108366 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
108367 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108368 }
 
108369 break;
108370 case 230: /* expr ::= expr in_op nm dbnm */
 
108371 {
108372 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
108373 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy118.pExpr, 0, 0);
108374 if( yygotominor.yy118.pExpr ){
108375 yygotominor.yy118.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
@@ -108380,12 +109142,14 @@
108380 }
108381 if( yymsp[-2].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108382 yygotominor.yy118.zStart = yymsp[-3].minor.yy118.zStart;
108383 yygotominor.yy118.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
108384 }
 
108385 break;
108386 case 231: /* expr ::= EXISTS LP select RP */
 
108387 {
108388 Expr *p = yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
108389 if( p ){
108390 p->x.pSelect = yymsp[-1].minor.yy387;
108391 ExprSetProperty(p, EP_xIsSelect);
@@ -108394,12 +109158,14 @@
108394 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
108395 }
108396 yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
108397 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108398 }
 
108399 break;
108400 case 232: /* expr ::= CASE case_operand case_exprlist case_else END */
 
108401 {
108402 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, 0);
108403 if( yygotominor.yy118.pExpr ){
108404 yygotominor.yy118.pExpr->x.pList = yymsp[-2].minor.yy322;
108405 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
@@ -108407,38 +109173,50 @@
108407 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
108408 }
108409 yygotominor.yy118.zStart = yymsp[-4].minor.yy0.z;
108410 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108411 }
 
108412 break;
108413 case 233: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
 
108414 {
108415 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy118.pExpr);
108416 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
108417 }
 
108418 break;
108419 case 234: /* case_exprlist ::= WHEN expr THEN expr */
 
108420 {
108421 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
108422 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
108423 }
 
108424 break;
108425 case 243: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
 
108426 {
108427 sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0,
108428 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy322, yymsp[-9].minor.yy4,
108429 &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy4);
108430 }
 
108431 break;
108432 case 244: /* uniqueflag ::= UNIQUE */
108433 case 298: /* raisetype ::= ABORT */ yytestcase(yyruleno==298);
 
108434 {yygotominor.yy4 = OE_Abort;}
 
108435 break;
108436 case 245: /* uniqueflag ::= */
 
108437 {yygotominor.yy4 = OE_None;}
 
108438 break;
108439 case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
 
108440 {
108441 Expr *p = 0;
108442 if( yymsp[-1].minor.yy0.n>0 ){
108443 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
108444 sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
@@ -108446,12 +109224,14 @@
108446 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
108447 sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
108448 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
108449 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108450 }
 
108451 break;
108452 case 249: /* idxlist ::= nm collate sortorder */
 
108453 {
108454 Expr *p = 0;
108455 if( yymsp[-1].minor.yy0.n>0 ){
108456 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
108457 sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
@@ -108459,214 +109239,307 @@
108459 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
108460 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108461 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
108462 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108463 }
 
108464 break;
108465 case 250: /* collate ::= */
 
108466 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
 
108467 break;
108468 case 252: /* cmd ::= DROP INDEX ifexists fullname */
 
108469 {sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
 
108470 break;
108471 case 253: /* cmd ::= VACUUM */
108472 case 254: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==254);
 
108473 {sqlite3Vacuum(pParse);}
 
108474 break;
108475 case 255: /* cmd ::= PRAGMA nm dbnm */
 
108476 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
 
108477 break;
108478 case 256: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
 
108479 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
 
108480 break;
108481 case 257: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
 
108482 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
 
108483 break;
108484 case 258: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
 
108485 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
 
108486 break;
108487 case 259: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
 
108488 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
 
108489 break;
108490 case 270: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
 
108491 {
108492 Token all;
108493 all.z = yymsp[-3].minor.yy0.z;
108494 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
108495 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
108496 }
 
108497 break;
108498 case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
 
108499 {
108500 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
108501 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
108502 }
 
108503 break;
108504 case 272: /* trigger_time ::= BEFORE */
108505 case 275: /* trigger_time ::= */ yytestcase(yyruleno==275);
 
108506 { yygotominor.yy4 = TK_BEFORE; }
 
108507 break;
108508 case 273: /* trigger_time ::= AFTER */
 
108509 { yygotominor.yy4 = TK_AFTER; }
 
108510 break;
108511 case 274: /* trigger_time ::= INSTEAD OF */
 
108512 { yygotominor.yy4 = TK_INSTEAD;}
 
108513 break;
108514 case 276: /* trigger_event ::= DELETE|INSERT */
108515 case 277: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==277);
 
108516 {yygotominor.yy90.a = yymsp[0].major; yygotominor.yy90.b = 0;}
 
108517 break;
108518 case 278: /* trigger_event ::= UPDATE OF inscollist */
 
108519 {yygotominor.yy90.a = TK_UPDATE; yygotominor.yy90.b = yymsp[0].minor.yy384;}
 
108520 break;
108521 case 281: /* when_clause ::= */
108522 case 303: /* key_opt ::= */ yytestcase(yyruleno==303);
 
108523 { yygotominor.yy314 = 0; }
 
108524 break;
108525 case 282: /* when_clause ::= WHEN expr */
108526 case 304: /* key_opt ::= KEY expr */ yytestcase(yyruleno==304);
 
108527 { yygotominor.yy314 = yymsp[0].minor.yy118.pExpr; }
 
108528 break;
108529 case 283: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
 
108530 {
108531 assert( yymsp[-2].minor.yy203!=0 );
108532 yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
108533 yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
108534 yygotominor.yy203 = yymsp[-2].minor.yy203;
108535 }
 
108536 break;
108537 case 284: /* trigger_cmd_list ::= trigger_cmd SEMI */
 
108538 {
108539 assert( yymsp[-1].minor.yy203!=0 );
108540 yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
108541 yygotominor.yy203 = yymsp[-1].minor.yy203;
108542 }
 
108543 break;
108544 case 286: /* trnm ::= nm DOT nm */
 
108545 {
108546 yygotominor.yy0 = yymsp[0].minor.yy0;
108547 sqlite3ErrorMsg(pParse,
108548 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
108549 "statements within triggers");
108550 }
 
108551 break;
108552 case 288: /* tridxby ::= INDEXED BY nm */
 
108553 {
108554 sqlite3ErrorMsg(pParse,
108555 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
108556 "within triggers");
108557 }
 
108558 break;
108559 case 289: /* tridxby ::= NOT INDEXED */
 
108560 {
108561 sqlite3ErrorMsg(pParse,
108562 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
108563 "within triggers");
108564 }
 
108565 break;
108566 case 290: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
 
108567 { yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
 
108568 break;
108569 case 291: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt VALUES LP itemlist RP */
 
108570 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy384, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy210);}
 
108571 break;
108572 case 292: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
 
108573 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
 
108574 break;
108575 case 293: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
 
108576 {yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
 
108577 break;
108578 case 294: /* trigger_cmd ::= select */
 
108579 {yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
 
108580 break;
108581 case 295: /* expr ::= RAISE LP IGNORE RP */
 
108582 {
108583 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
108584 if( yygotominor.yy118.pExpr ){
108585 yygotominor.yy118.pExpr->affinity = OE_Ignore;
108586 }
108587 yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
108588 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108589 }
 
108590 break;
108591 case 296: /* expr ::= RAISE LP raisetype COMMA nm RP */
 
108592 {
108593 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
108594 if( yygotominor.yy118.pExpr ) {
108595 yygotominor.yy118.pExpr->affinity = (char)yymsp[-3].minor.yy4;
108596 }
108597 yygotominor.yy118.zStart = yymsp[-5].minor.yy0.z;
108598 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108599 }
 
108600 break;
108601 case 297: /* raisetype ::= ROLLBACK */
 
108602 {yygotominor.yy4 = OE_Rollback;}
 
108603 break;
108604 case 299: /* raisetype ::= FAIL */
 
108605 {yygotominor.yy4 = OE_Fail;}
 
108606 break;
108607 case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
 
108608 {
108609 sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
108610 }
 
108611 break;
108612 case 301: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
 
108613 {
108614 sqlite3Attach(pParse, yymsp[-3].minor.yy118.pExpr, yymsp[-1].minor.yy118.pExpr, yymsp[0].minor.yy314);
108615 }
 
108616 break;
108617 case 302: /* cmd ::= DETACH database_kw_opt expr */
 
108618 {
108619 sqlite3Detach(pParse, yymsp[0].minor.yy118.pExpr);
108620 }
 
108621 break;
108622 case 307: /* cmd ::= REINDEX */
 
108623 {sqlite3Reindex(pParse, 0, 0);}
 
108624 break;
108625 case 308: /* cmd ::= REINDEX nm dbnm */
 
108626 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
 
108627 break;
108628 case 309: /* cmd ::= ANALYZE */
 
108629 {sqlite3Analyze(pParse, 0, 0);}
 
108630 break;
108631 case 310: /* cmd ::= ANALYZE nm dbnm */
 
108632 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
 
108633 break;
108634 case 311: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
 
108635 {
108636 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
108637 }
 
108638 break;
108639 case 312: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
 
108640 {
108641 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
108642 }
 
108643 break;
108644 case 313: /* add_column_fullname ::= fullname */
 
108645 {
108646 pParse->db->lookaside.bEnabled = 0;
108647 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
108648 }
 
108649 break;
108650 case 316: /* cmd ::= create_vtab */
 
108651 {sqlite3VtabFinishParse(pParse,0);}
 
108652 break;
108653 case 317: /* cmd ::= create_vtab LP vtabarglist RP */
 
108654 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
 
108655 break;
108656 case 318: /* create_vtab ::= createkw VIRTUAL TABLE nm dbnm USING nm */
 
108657 {
108658 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
108659 }
 
108660 break;
108661 case 321: /* vtabarg ::= */
 
108662 {sqlite3VtabArgInit(pParse);}
 
108663 break;
108664 case 323: /* vtabargtoken ::= ANY */
108665 case 324: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==324);
108666 case 325: /* lp ::= LP */ yytestcase(yyruleno==325);
 
108667 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
 
108668 break;
108669 default:
108670 /* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
108671 /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
108672 /* (2) cmdlist ::= ecmd */ yytestcase(yyruleno==2);
@@ -108764,15 +109637,17 @@
108764 int yymajor, /* The major type of the error token */
108765 YYMINORTYPE yyminor /* The minor type of the error token */
108766 ){
108767 sqlite3ParserARG_FETCH;
108768 #define TOKEN (yyminor.yy0)
 
108769
108770 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
108771 assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */
108772 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
108773 pParse->parseError = 1;
 
108774 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
108775 }
108776
108777 /*
108778 ** The following is executed when the parser accepts
@@ -108962,10 +109837,11 @@
108962 return;
108963 }
108964
108965 /************** End of parse.c ***********************************************/
108966 /************** Begin file tokenize.c ****************************************/
 
108967 /*
108968 ** 2001 September 15
108969 **
108970 ** The author disclaims copyright to this source code. In place of
108971 ** a legal notice, here is a blessing:
@@ -109027,10 +109903,11 @@
109027 ** named keywordhash.h and then included into this source file by
109028 ** the #include below.
109029 */
109030 /************** Include keywordhash.h in the middle of tokenize.c ************/
109031 /************** Begin file keywordhash.h *************************************/
 
109032 /***** This file contains automatically generated code ******
109033 **
109034 ** The code in this file has been automatically generated by
109035 **
109036 ** sqlite/tool/mkkeywordhash.c
@@ -109300,10 +110177,11 @@
109300 }
109301 #define SQLITE_N_KEYWORD 121
109302
109303 /************** End of keywordhash.h *****************************************/
109304 /************** Continuing where we left off in tokenize.c *******************/
 
109305
109306
109307 /*
109308 ** If X is a character that can be used in an identifier then
109309 ** IdChar(X) will be true. Otherwise it is false.
@@ -109764,10 +110642,11 @@
109764 return nErr;
109765 }
109766
109767 /************** End of tokenize.c ********************************************/
109768 /************** Begin file complete.c ****************************************/
 
109769 /*
109770 ** 2001 September 15
109771 **
109772 ** The author disclaims copyright to this source code. In place of
109773 ** a legal notice, here is a blessing:
@@ -110049,10 +110928,11 @@
110049 #endif /* SQLITE_OMIT_UTF16 */
110050 #endif /* SQLITE_OMIT_COMPLETE */
110051
110052 /************** End of complete.c ********************************************/
110053 /************** Begin file main.c ********************************************/
 
110054 /*
110055 ** 2001 September 15
110056 **
110057 ** The author disclaims copyright to this source code. In place of
110058 ** a legal notice, here is a blessing:
@@ -110069,10 +110949,11 @@
110069 */
110070
110071 #ifdef SQLITE_ENABLE_FTS3
110072 /************** Include fts3.h in the middle of main.c ***********************/
110073 /************** Begin file fts3.h ********************************************/
 
110074 /*
110075 ** 2006 Oct 10
110076 **
110077 ** The author disclaims copyright to this source code. In place of
110078 ** a legal notice, here is a blessing:
@@ -110097,14 +110978,16 @@
110097 } /* extern "C" */
110098 #endif /* __cplusplus */
110099
110100 /************** End of fts3.h ************************************************/
110101 /************** Continuing where we left off in main.c ***********************/
 
110102 #endif
110103 #ifdef SQLITE_ENABLE_RTREE
110104 /************** Include rtree.h in the middle of main.c **********************/
110105 /************** Begin file rtree.h *******************************************/
 
110106 /*
110107 ** 2008 May 26
110108 **
110109 ** The author disclaims copyright to this source code. In place of
110110 ** a legal notice, here is a blessing:
@@ -110129,14 +111012,16 @@
110129 } /* extern "C" */
110130 #endif /* __cplusplus */
110131
110132 /************** End of rtree.h ***********************************************/
110133 /************** Continuing where we left off in main.c ***********************/
 
110134 #endif
110135 #ifdef SQLITE_ENABLE_ICU
110136 /************** Include sqliteicu.h in the middle of main.c ******************/
110137 /************** Begin file sqliteicu.h ***************************************/
 
110138 /*
110139 ** 2008 May 26
110140 **
110141 ** The author disclaims copyright to this source code. In place of
110142 ** a legal notice, here is a blessing:
@@ -110162,10 +111047,11 @@
110162 #endif /* __cplusplus */
110163
110164
110165 /************** End of sqliteicu.h *******************************************/
110166 /************** Continuing where we left off in main.c ***********************/
 
110167 #endif
110168
110169 #ifndef SQLITE_AMALGAMATION
110170 /* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
110171 ** contains the text of SQLITE_VERSION macro.
@@ -113092,10 +113978,11 @@
113092 return 0;
113093 }
113094
113095 /************** End of main.c ************************************************/
113096 /************** Begin file notify.c ******************************************/
 
113097 /*
113098 ** 2009 March 3
113099 **
113100 ** The author disclaims copyright to this source code. In place of
113101 ** a legal notice, here is a blessing:
@@ -113425,10 +114312,11 @@
113425 }
113426 #endif
113427
113428 /************** End of notify.c **********************************************/
113429 /************** Begin file fts3.c ********************************************/
 
113430 /*
113431 ** 2006 Oct 10
113432 **
113433 ** The author disclaims copyright to this source code. In place of
113434 ** a legal notice, here is a blessing:
@@ -113721,10 +114609,11 @@
113721 ** into a single segment.
113722 */
113723
113724 /************** Include fts3Int.h in the middle of fts3.c ********************/
113725 /************** Begin file fts3Int.h *****************************************/
 
113726 /*
113727 ** 2009 Nov 12
113728 **
113729 ** The author disclaims copyright to this source code. In place of
113730 ** a legal notice, here is a blessing:
@@ -113759,10 +114648,11 @@
113759 SQLITE_API extern const sqlite3_api_routines *sqlite3_api;
113760 #endif
113761
113762 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
113763 /************** Begin file fts3_tokenizer.h **********************************/
 
113764 /*
113765 ** 2006 July 10
113766 **
113767 ** The author disclaims copyright to this source code.
113768 **
@@ -113913,12 +114803,14 @@
113913
113914 #endif /* _FTS3_TOKENIZER_H_ */
113915
113916 /************** End of fts3_tokenizer.h **************************************/
113917 /************** Continuing where we left off in fts3Int.h ********************/
 
113918 /************** Include fts3_hash.h in the middle of fts3Int.h ***************/
113919 /************** Begin file fts3_hash.h ***************************************/
 
113920 /*
113921 ** 2001 September 22
113922 **
113923 ** The author disclaims copyright to this source code. In place of
113924 ** a legal notice, here is a blessing:
@@ -114030,10 +114922,11 @@
114030
114031 #endif /* _FTS3_HASH_H_ */
114032
114033 /************** End of fts3_hash.h *******************************************/
114034 /************** Continuing where we left off in fts3Int.h ********************/
 
114035
114036 /*
114037 ** This constant controls how often segments are merged. Once there are
114038 ** FTS3_MERGE_COUNT segments of level N, they are merged into a single
114039 ** segment of level N+1.
@@ -114506,10 +115399,11 @@
114506 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
114507 #endif /* _FTSINT_H */
114508
114509 /************** End of fts3Int.h *********************************************/
114510 /************** Continuing where we left off in fts3.c ***********************/
 
114511 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
114512
114513 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
114514 # define SQLITE_CORE 1
114515 #endif
@@ -119055,10 +119949,11 @@
119055
119056 #endif
119057
119058 /************** End of fts3.c ************************************************/
119059 /************** Begin file fts3_aux.c ****************************************/
 
119060 /*
119061 ** 2011 Jan 27
119062 **
119063 ** The author disclaims copyright to this source code. In place of
119064 ** a legal notice, here is a blessing:
@@ -119531,10 +120426,11 @@
119531
119532 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
119533
119534 /************** End of fts3_aux.c ********************************************/
119535 /************** Begin file fts3_expr.c ***************************************/
 
119536 /*
119537 ** 2008 Nov 28
119538 **
119539 ** The author disclaims copyright to this source code. In place of
119540 ** a legal notice, here is a blessing:
@@ -120497,10 +121393,11 @@
120497 #endif
120498 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
120499
120500 /************** End of fts3_expr.c *******************************************/
120501 /************** Begin file fts3_hash.c ***************************************/
 
120502 /*
120503 ** 2001 September 22
120504 **
120505 ** The author disclaims copyright to this source code. In place of
120506 ** a legal notice, here is a blessing:
@@ -120881,10 +121778,11 @@
120881
120882 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
120883
120884 /************** End of fts3_hash.c *******************************************/
120885 /************** Begin file fts3_porter.c *************************************/
 
120886 /*
120887 ** 2006 September 30
120888 **
120889 ** The author disclaims copyright to this source code. In place of
120890 ** a legal notice, here is a blessing:
@@ -121527,10 +122425,11 @@
121527
121528 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
121529
121530 /************** End of fts3_porter.c *****************************************/
121531 /************** Begin file fts3_tokenizer.c **********************************/
 
121532 /*
121533 ** 2007 June 22
121534 **
121535 ** The author disclaims copyright to this source code. In place of
121536 ** a legal notice, here is a blessing:
@@ -122018,10 +122917,11 @@
122018
122019 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
122020
122021 /************** End of fts3_tokenizer.c **************************************/
122022 /************** Begin file fts3_tokenizer1.c *********************************/
 
122023 /*
122024 ** 2006 Oct 10
122025 **
122026 ** The author disclaims copyright to this source code. In place of
122027 ** a legal notice, here is a blessing:
@@ -122252,10 +123152,11 @@
122252
122253 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
122254
122255 /************** End of fts3_tokenizer1.c *************************************/
122256 /************** Begin file fts3_write.c **************************************/
 
122257 /*
122258 ** 2009 Oct 23
122259 **
122260 ** The author disclaims copyright to this source code. In place of
122261 ** a legal notice, here is a blessing:
@@ -125522,10 +126423,11 @@
125522
125523 #endif
125524
125525 /************** End of fts3_write.c ******************************************/
125526 /************** Begin file fts3_snippet.c ************************************/
 
125527 /*
125528 ** 2009 Oct 23
125529 **
125530 ** The author disclaims copyright to this source code. In place of
125531 ** a legal notice, here is a blessing:
@@ -127023,10 +127925,11 @@
127023
127024 #endif
127025
127026 /************** End of fts3_snippet.c ****************************************/
127027 /************** Begin file rtree.c *******************************************/
 
127028 /*
127029 ** 2001 September 15
127030 **
127031 ** The author disclaims copyright to this source code. In place of
127032 ** a legal notice, here is a blessing:
@@ -130304,10 +131207,11 @@
130304
130305 #endif
130306
130307 /************** End of rtree.c ***********************************************/
130308 /************** Begin file icu.c *********************************************/
 
130309 /*
130310 ** 2007 May 6
130311 **
130312 ** The author disclaims copyright to this source code. In place of
130313 ** a legal notice, here is a blessing:
@@ -130806,10 +131710,11 @@
130806
130807 #endif
130808
130809 /************** End of icu.c *************************************************/
130810 /************** Begin file fts3_icu.c ****************************************/
 
130811 /*
130812 ** 2007 June 22
130813 **
130814 ** The author disclaims copyright to this source code. In place of
130815 ** a legal notice, here is a blessing:
130816
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.9. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -24,10 +24,11 @@
24 #endif
25 #ifndef SQLITE_API
26 # define SQLITE_API
27 #endif
28 /************** Begin file sqliteInt.h ***************************************/
29 #line 1 "tsrc/sqliteInt.h"
30 /*
31 ** 2001 September 15
32 **
33 ** The author disclaims copyright to this source code. In place of
34 ** a legal notice, here is a blessing:
@@ -78,10 +79,11 @@
79 #include "config.h"
80 #endif
81
82 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
83 /************** Begin file sqliteLimit.h *************************************/
84 #line 1 "tsrc/sqliteLimit.h"
85 /*
86 ** 2007 May 7
87 **
88 ** The author disclaims copyright to this source code. In place of
89 ** a legal notice, here is a blessing:
@@ -289,10 +291,11 @@
291 # define SQLITE_MAX_TRIGGER_DEPTH 1000
292 #endif
293
294 /************** End of sqliteLimit.h *****************************************/
295 /************** Continuing where we left off in sqliteInt.h ******************/
296 #line 54 "tsrc/sqliteInt.h"
297
298 /* Disable nuisance warnings on Borland compilers */
299 #if defined(__BORLANDC__)
300 #pragma warn -rch /* unreachable code */
301 #pragma warn -ccc /* Condition is always true or false */
@@ -394,11 +397,11 @@
397 ** assert() macro is enabled, each call into the Win32 native heap subsystem
398 ** will cause HeapValidate to be called. If heap validation should fail, an
399 ** assertion will be triggered.
400 **
401 ** (Historical note: There used to be several other options, but we've
402 ** pared it down to just these three.)
403 **
404 ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
405 ** the default.
406 */
407 #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1
@@ -545,10 +548,11 @@
548 # define unlikely(X) !!(X)
549 #endif
550
551 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
552 /************** Begin file sqlite3.h *****************************************/
553 #line 1 "tsrc/sqlite3.h"
554 /*
555 ** 2001 September 15
556 **
557 ** The author disclaims copyright to this source code. In place of
558 ** a legal notice, here is a blessing:
@@ -654,13 +658,13 @@
658 **
659 ** See also: [sqlite3_libversion()],
660 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
661 ** [sqlite_version()] and [sqlite_source_id()].
662 */
663 #define SQLITE_VERSION "3.7.9"
664 #define SQLITE_VERSION_NUMBER 3007009
665 #define SQLITE_SOURCE_ID "2011-10-07 18:24:25 d4f95b3b6e9f4a4072606af5daa17ea7c645382e"
666
667 /*
668 ** CAPI3REF: Run-Time Library Version Numbers
669 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
670 **
@@ -1318,11 +1322,15 @@
1322 ** in order for the database to be readable. The fourth parameter to
1323 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
1324 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
1325 ** WAL mode. If the integer is -1, then it is overwritten with the current
1326 ** WAL persistence setting.
1327 **
1328 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
1329 ** a write transaction to indicate that, unless it is rolled back for some
1330 ** reason, the entire database file will be overwritten by the current
1331 ** transaction. This is used by VACUUM operations.
1332 */
1333 #define SQLITE_FCNTL_LOCKSTATE 1
1334 #define SQLITE_GET_LOCKPROXYFILE 2
1335 #define SQLITE_SET_LOCKPROXYFILE 3
1336 #define SQLITE_LAST_ERRNO 4
@@ -1330,10 +1338,11 @@
1338 #define SQLITE_FCNTL_CHUNK_SIZE 6
1339 #define SQLITE_FCNTL_FILE_POINTER 7
1340 #define SQLITE_FCNTL_SYNC_OMITTED 8
1341 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
1342 #define SQLITE_FCNTL_PERSIST_WAL 10
1343 #define SQLITE_FCNTL_OVERWRITE 11
1344
1345 /*
1346 ** CAPI3REF: Mutex Handle
1347 **
1348 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3397,11 +3406,11 @@
3406 ** a schema change, on the first [sqlite3_step()] call following any change
3407 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3408 ** ^The specific value of WHERE-clause [parameter] might influence the
3409 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3410 ** or [GLOB] operator or if the parameter is compared to an indexed column
3411 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3412 ** the
3413 ** </li>
3414 ** </ol>
3415 */
3416 SQLITE_API int sqlite3_prepare(
@@ -3900,10 +3909,16 @@
3909 ** current row of the result set of [prepared statement] P.
3910 ** ^If prepared statement P does not have results ready to return
3911 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3912 ** interfaces) then sqlite3_data_count(P) returns 0.
3913 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3914 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
3915 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
3916 ** will return non-zero if previous call to [sqlite3_step](P) returned
3917 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
3918 ** where it always returns zero since each step of that multi-step
3919 ** pragma returns 0 columns of data.
3920 **
3921 ** See also: [sqlite3_column_count()]
3922 */
3923 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3924
@@ -6362,20 +6377,34 @@
6377 ** <dd>This parameter returns the approximate number of of bytes of heap
6378 ** and lookaside memory used by all prepared statements associated with
6379 ** the database connection.)^
6380 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6381 ** </dd>
6382 **
6383 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
6384 ** <dd>This parameter returns the number of pager cache hits that have
6385 ** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
6386 ** is always 0.
6387 ** </dd>
6388 **
6389 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
6390 ** <dd>This parameter returns the number of pager cache misses that have
6391 ** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
6392 ** is always 0.
6393 ** </dd>
6394 ** </dl>
6395 */
6396 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
6397 #define SQLITE_DBSTATUS_CACHE_USED 1
6398 #define SQLITE_DBSTATUS_SCHEMA_USED 2
6399 #define SQLITE_DBSTATUS_STMT_USED 3
6400 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
6401 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
6402 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
6403 #define SQLITE_DBSTATUS_CACHE_HIT 7
6404 #define SQLITE_DBSTATUS_CACHE_MISS 8
6405 #define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
6406
6407
6408 /*
6409 ** CAPI3REF: Prepared Statement Status
6410 **
@@ -6425,11 +6454,10 @@
6454 ** <dd>^This is the number of rows inserted into transient indices that
6455 ** were created automatically in order to help joins run faster.
6456 ** A non-zero value in this counter may indicate an opportunity to
6457 ** improvement performance by adding permanent indices that do not
6458 ** need to be reinitialized each time the statement is run.</dd>
 
6459 ** </dl>
6460 */
6461 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6462 #define SQLITE_STMTSTATUS_SORT 2
6463 #define SQLITE_STMTSTATUS_AUTOINDEX 3
@@ -7305,12 +7333,14 @@
7333 #endif /* ifndef _SQLITE3RTREE_H_ */
7334
7335
7336 /************** End of sqlite3.h *********************************************/
7337 /************** Continuing where we left off in sqliteInt.h ******************/
7338 #line 309 "tsrc/sqliteInt.h"
7339 /************** Include hash.h in the middle of sqliteInt.h ******************/
7340 /************** Begin file hash.h ********************************************/
7341 #line 1 "tsrc/hash.h"
7342 /*
7343 ** 2001 September 22
7344 **
7345 ** The author disclaims copyright to this source code. In place of
7346 ** a legal notice, here is a blessing:
@@ -7406,12 +7436,14 @@
7436
7437 #endif /* _SQLITE_HASH_H_ */
7438
7439 /************** End of hash.h ************************************************/
7440 /************** Continuing where we left off in sqliteInt.h ******************/
7441 #line 310 "tsrc/sqliteInt.h"
7442 /************** Include parse.h in the middle of sqliteInt.h *****************/
7443 /************** Begin file parse.h *******************************************/
7444 #line 1 "tsrc/parse.h"
7445 #define TK_SEMI 1
7446 #define TK_EXPLAIN 2
7447 #define TK_QUERY 3
7448 #define TK_PLAN 4
7449 #define TK_BEGIN 5
@@ -7568,10 +7600,11 @@
7600 #define TK_UMINUS 156
7601 #define TK_UPLUS 157
7602
7603 /************** End of parse.h ***********************************************/
7604 /************** Continuing where we left off in sqliteInt.h ******************/
7605 #line 311 "tsrc/sqliteInt.h"
7606 #include <stdio.h>
7607 #include <stdlib.h>
7608 #include <string.h>
7609 #include <assert.h>
7610 #include <stddef.h>
@@ -7711,10 +7744,22 @@
7744 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
7745 ** have to specify the value in the less intuitive manner shown:
7746 */
7747 #define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
7748
7749 /*
7750 ** The datatype used to store estimates of the number of rows in a
7751 ** table or index. This is an unsigned integer type. For 99.9% of
7752 ** the world, a 32-bit integer is sufficient. But a 64-bit integer
7753 ** can be used at compile-time if desired.
7754 */
7755 #ifdef SQLITE_64BIT_STATS
7756 typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */
7757 #else
7758 typedef u32 tRowcnt; /* 32-bit is the default */
7759 #endif
7760
7761 /*
7762 ** Macros to determine whether the machine is big or little endian,
7763 ** evaluated at runtime.
7764 */
7765 #ifdef SQLITE_AMALGAMATION
@@ -7911,10 +7956,11 @@
7956 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
7957 ** pointer types (i.e. FuncDef) defined above.
7958 */
7959 /************** Include btree.h in the middle of sqliteInt.h *****************/
7960 /************** Begin file btree.h *******************************************/
7961 #line 1 "tsrc/btree.h"
7962 /*
7963 ** 2001 September 15
7964 **
7965 ** The author disclaims copyright to this source code. In place of
7966 ** a legal notice, here is a blessing:
@@ -8155,12 +8201,14 @@
8201
8202 #endif /* _BTREE_H_ */
8203
8204 /************** End of btree.h ***********************************************/
8205 /************** Continuing where we left off in sqliteInt.h ******************/
8206 #line 665 "tsrc/sqliteInt.h"
8207 /************** Include vdbe.h in the middle of sqliteInt.h ******************/
8208 /************** Begin file vdbe.h ********************************************/
8209 #line 1 "tsrc/vdbe.h"
8210 /*
8211 ** 2001 September 15
8212 **
8213 ** The author disclaims copyright to this source code. In place of
8214 ** a legal notice, here is a blessing:
@@ -8321,10 +8369,11 @@
8369 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
8370 ** header file that defines a number for each opcode used by the VDBE.
8371 */
8372 /************** Include opcodes.h in the middle of vdbe.h ********************/
8373 /************** Begin file opcodes.h *****************************************/
8374 #line 1 "tsrc/opcodes.h"
8375 /* Automatically generated. Do not edit */
8376 /* See the mkopcodeh.awk script for details */
8377 #define OP_Goto 1
8378 #define OP_Gosub 2
8379 #define OP_Return 3
@@ -8509,10 +8558,11 @@
8558 /* 136 */ 0x01, 0x00, 0x01, 0x00, 0x00, 0x04, 0x04, 0x04,\
8559 /* 144 */ 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00,}
8560
8561 /************** End of opcodes.h *********************************************/
8562 /************** Continuing where we left off in vdbe.h ***********************/
8563 #line 164 "tsrc/vdbe.h"
8564
8565 /*
8566 ** Prototypes for the VDBE interface. See comments on the implementation
8567 ** for a description of what each of these routines does.
8568 */
@@ -8583,12 +8633,14 @@
8633
8634 #endif
8635
8636 /************** End of vdbe.h ************************************************/
8637 /************** Continuing where we left off in sqliteInt.h ******************/
8638 #line 666 "tsrc/sqliteInt.h"
8639 /************** Include pager.h in the middle of sqliteInt.h *****************/
8640 /************** Begin file pager.h *******************************************/
8641 #line 1 "tsrc/pager.h"
8642 /*
8643 ** 2001 September 15
8644 **
8645 ** The author disclaims copyright to this source code. In place of
8646 ** a legal notice, here is a blessing:
@@ -8742,10 +8794,11 @@
8794 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
8795 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
8796 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
8797 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
8798 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
8799 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
8800
8801 /* Functions used to truncate the database file. */
8802 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
8803
8804 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
@@ -8769,12 +8822,14 @@
8822
8823 #endif /* _PAGER_H_ */
8824
8825 /************** End of pager.h ***********************************************/
8826 /************** Continuing where we left off in sqliteInt.h ******************/
8827 #line 667 "tsrc/sqliteInt.h"
8828 /************** Include pcache.h in the middle of sqliteInt.h ****************/
8829 /************** Begin file pcache.h ******************************************/
8830 #line 1 "tsrc/pcache.h"
8831 /*
8832 ** 2008 August 05
8833 **
8834 ** The author disclaims copyright to this source code. In place of
8835 ** a legal notice, here is a blessing:
@@ -8929,13 +8984,15 @@
8984
8985 #endif /* _PCACHE_H_ */
8986
8987 /************** End of pcache.h **********************************************/
8988 /************** Continuing where we left off in sqliteInt.h ******************/
8989 #line 668 "tsrc/sqliteInt.h"
8990
8991 /************** Include os.h in the middle of sqliteInt.h ********************/
8992 /************** Begin file os.h **********************************************/
8993 #line 1 "tsrc/os.h"
8994 /*
8995 ** 2001 September 16
8996 **
8997 ** The author disclaims copyright to this source code. In place of
8998 ** a legal notice, here is a blessing:
@@ -9214,12 +9271,14 @@
9271
9272 #endif /* _SQLITE_OS_H_ */
9273
9274 /************** End of os.h **************************************************/
9275 /************** Continuing where we left off in sqliteInt.h ******************/
9276 #line 670 "tsrc/sqliteInt.h"
9277 /************** Include mutex.h in the middle of sqliteInt.h *****************/
9278 /************** Begin file mutex.h *******************************************/
9279 #line 1 "tsrc/mutex.h"
9280 /*
9281 ** 2007 August 28
9282 **
9283 ** The author disclaims copyright to this source code. In place of
9284 ** a legal notice, here is a blessing:
@@ -9290,10 +9349,11 @@
9349 #define sqlite3MutexEnd()
9350 #endif /* defined(SQLITE_MUTEX_OMIT) */
9351
9352 /************** End of mutex.h ***********************************************/
9353 /************** Continuing where we left off in sqliteInt.h ******************/
9354 #line 671 "tsrc/sqliteInt.h"
9355
9356
9357 /*
9358 ** Each database file to be accessed by the system is an instance
9359 ** of the following structure. There are normally two of these structures
@@ -9918,11 +9978,11 @@
9978 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
9979 int nCol; /* Number of columns in this table */
9980 Column *aCol; /* Information about each column */
9981 Index *pIndex; /* List of SQL indexes on this table. */
9982 int tnum; /* Root BTree node for this table (see note above) */
9983 tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
9984 Select *pSelect; /* NULL for tables. Points to definition if a view. */
9985 u16 nRef; /* Number of pointers to this Table */
9986 u8 tabFlags; /* Mask of TF_* values */
9987 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
9988 FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10117,11 +10177,11 @@
10177 */
10178 struct Index {
10179 char *zName; /* Name of this index */
10180 int nColumn; /* Number of columns in the table used by this index */
10181 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10182 tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
10183 Table *pTable; /* The SQL table being indexed */
10184 int tnum; /* Page containing root of this index in database file */
10185 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10186 u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
10187 u8 bUnordered; /* Use this index for == or IN queries only */
@@ -10128,24 +10188,32 @@
10188 char *zColAff; /* String defining the affinity of each column */
10189 Index *pNext; /* The next index associated with the same table */
10190 Schema *pSchema; /* Schema containing this index */
10191 u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
10192 char **azColl; /* Array of collation sequence names for index */
10193 #ifdef SQLITE_ENABLE_STAT3
10194 int nSample; /* Number of elements in aSample[] */
10195 tRowcnt avgEq; /* Average nEq value for key values not in aSample */
10196 IndexSample *aSample; /* Samples of the left-most key */
10197 #endif
10198 };
10199
10200 /*
10201 ** Each sample stored in the sqlite_stat2 table is represented in memory
10202 ** using a structure of this type.
10203 */
10204 struct IndexSample {
10205 union {
10206 char *z; /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */
10207 double r; /* Value if eType is SQLITE_FLOAT */
10208 i64 i; /* Value if eType is SQLITE_INTEGER */
10209 } u;
10210 u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
10211 int nByte; /* Size in byte of text or blob. */
10212 tRowcnt nEq; /* Est. number of rows where the key equals this sample */
10213 tRowcnt nLt; /* Est. number of rows where key is less than this sample */
10214 tRowcnt nDLt; /* Est. number of distinct keys less than this sample */
10215 };
10216
10217 /*
10218 ** Each token coming out of the lexer is an instance of
10219 ** this structure. Tokens are also used as part of an expression.
@@ -10593,14 +10661,14 @@
10661 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
10662 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
10663 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
10664 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
10665 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
10666 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
10667 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
10668 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
10669 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
10670
10671 /*
10672 ** The WHERE clause processing routine has two halves. The
10673 ** first part does the start of the WHERE loop and the second
10674 ** half does the tail of the WHERE loop. An instance of
@@ -11350,10 +11418,11 @@
11418 #else
11419 # define sqlite3ViewGetColumnNames(A,B) 0
11420 #endif
11421
11422 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
11423 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
11424 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
11425 #ifndef SQLITE_OMIT_AUTOINCREMENT
11426 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
11427 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
11428 #else
@@ -11606,11 +11675,11 @@
11675 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11676 void(*)(void*));
11677 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
11678 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
11679 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
11680 #ifdef SQLITE_ENABLE_STAT3
11681 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *);
11682 #endif
11683 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
11684 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
11685 #ifndef SQLITE_AMALGAMATION
@@ -11893,10 +11962,11 @@
11962
11963 #endif /* _SQLITEINT_H_ */
11964
11965 /************** End of sqliteInt.h *******************************************/
11966 /************** Begin file global.c ******************************************/
11967 #line 1 "tsrc/global.c"
11968 /*
11969 ** 2008 June 13
11970 **
11971 ** The author disclaims copyright to this source code. In place of
11972 ** a legal notice, here is a blessing:
@@ -12115,10 +12185,11 @@
12185 */
12186 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
12187
12188 /************** End of global.c **********************************************/
12189 /************** Begin file ctime.c *******************************************/
12190 #line 1 "tsrc/ctime.c"
12191 /*
12192 ** 2010 February 23
12193 **
12194 ** The author disclaims copyright to this source code. In place of
12195 ** a legal notice, here is a blessing:
@@ -12232,10 +12303,13 @@
12303 #ifdef SQLITE_ENABLE_RTREE
12304 "ENABLE_RTREE",
12305 #endif
12306 #ifdef SQLITE_ENABLE_STAT2
12307 "ENABLE_STAT2",
12308 #endif
12309 #ifdef SQLITE_ENABLE_STAT3
12310 "ENABLE_STAT3",
12311 #endif
12312 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
12313 "ENABLE_UNLOCK_NOTIFY",
12314 #endif
12315 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
@@ -12445,13 +12519,10 @@
12519 "OMIT_WSD",
12520 #endif
12521 #ifdef SQLITE_OMIT_XFER_OPT
12522 "OMIT_XFER_OPT",
12523 #endif
 
 
 
12524 #ifdef SQLITE_PERFORMANCE_TRACE
12525 "PERFORMANCE_TRACE",
12526 #endif
12527 #ifdef SQLITE_PROXY_DEBUG
12528 "PROXY_DEBUG",
@@ -12519,10 +12590,11 @@
12590
12591 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
12592
12593 /************** End of ctime.c ***********************************************/
12594 /************** Begin file status.c ******************************************/
12595 #line 1 "tsrc/status.c"
12596 /*
12597 ** 2008 June 18
12598 **
12599 ** The author disclaims copyright to this source code. In place of
12600 ** a legal notice, here is a blessing:
@@ -12536,10 +12608,11 @@
12608 ** This module implements the sqlite3_status() interface and related
12609 ** functionality.
12610 */
12611 /************** Include vdbeInt.h in the middle of status.c ******************/
12612 /************** Begin file vdbeInt.h *****************************************/
12613 #line 1 "tsrc/vdbeInt.h"
12614 /*
12615 ** 2003 September 6
12616 **
12617 ** The author disclaims copyright to this source code. In place of
12618 ** a legal notice, here is a blessing:
@@ -12987,10 +13060,11 @@
13060
13061 #endif /* !defined(_VDBEINT_H_) */
13062
13063 /************** End of vdbeInt.h *********************************************/
13064 /************** Continuing where we left off in status.c *********************/
13065 #line 18 "tsrc/status.c"
13066
13067 /*
13068 ** Variables in which to record status information.
13069 */
13070 typedef struct sqlite3StatType sqlite3StatType;
@@ -13189,10 +13263,32 @@
13263 *pHighwater = 0;
13264 *pCurrent = nByte;
13265
13266 break;
13267 }
13268
13269 /*
13270 ** Set *pCurrent to the total cache hits or misses encountered by all
13271 ** pagers the database handle is connected to. *pHighwater is always set
13272 ** to zero.
13273 */
13274 case SQLITE_DBSTATUS_CACHE_HIT:
13275 case SQLITE_DBSTATUS_CACHE_MISS: {
13276 int i;
13277 int nRet = 0;
13278 assert( SQLITE_DBSTATUS_CACHE_MISS==SQLITE_DBSTATUS_CACHE_HIT+1 );
13279
13280 for(i=0; i<db->nDb; i++){
13281 if( db->aDb[i].pBt ){
13282 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
13283 sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
13284 }
13285 }
13286 *pHighwater = 0;
13287 *pCurrent = nRet;
13288 break;
13289 }
13290
13291 default: {
13292 rc = SQLITE_ERROR;
13293 }
13294 }
@@ -13200,10 +13296,11 @@
13296 return rc;
13297 }
13298
13299 /************** End of status.c **********************************************/
13300 /************** Begin file date.c ********************************************/
13301 #line 1 "tsrc/date.c"
13302 /*
13303 ** 2003 October 31
13304 **
13305 ** The author disclaims copyright to this source code. In place of
13306 ** a legal notice, here is a blessing:
@@ -14327,10 +14424,11 @@
14424 }
14425 }
14426
14427 /************** End of date.c ************************************************/
14428 /************** Begin file os.c **********************************************/
14429 #line 1 "tsrc/os.c"
14430 /*
14431 ** 2005 November 29
14432 **
14433 ** The author disclaims copyright to this source code. In place of
14434 ** a legal notice, here is a blessing:
@@ -14660,10 +14758,11 @@
14758 return SQLITE_OK;
14759 }
14760
14761 /************** End of os.c **************************************************/
14762 /************** Begin file fault.c *******************************************/
14763 #line 1 "tsrc/fault.c"
14764 /*
14765 ** 2008 Jan 22
14766 **
14767 ** The author disclaims copyright to this source code. In place of
14768 ** a legal notice, here is a blessing:
@@ -14749,10 +14848,11 @@
14848
14849 #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
14850
14851 /************** End of fault.c ***********************************************/
14852 /************** Begin file mem0.c ********************************************/
14853 #line 1 "tsrc/mem0.c"
14854 /*
14855 ** 2008 October 28
14856 **
14857 ** The author disclaims copyright to this source code. In place of
14858 ** a legal notice, here is a blessing:
@@ -14810,10 +14910,11 @@
14910
14911 #endif /* SQLITE_ZERO_MALLOC */
14912
14913 /************** End of mem0.c ************************************************/
14914 /************** Begin file mem1.c ********************************************/
14915 #line 1 "tsrc/mem1.c"
14916 /*
14917 ** 2007 August 14
14918 **
14919 ** The author disclaims copyright to this source code. In place of
14920 ** a legal notice, here is a blessing:
@@ -14962,10 +15063,11 @@
15063
15064 #endif /* SQLITE_SYSTEM_MALLOC */
15065
15066 /************** End of mem1.c ************************************************/
15067 /************** Begin file mem2.c ********************************************/
15068 #line 1 "tsrc/mem2.c"
15069 /*
15070 ** 2007 August 15
15071 **
15072 ** The author disclaims copyright to this source code. In place of
15073 ** a legal notice, here is a blessing:
@@ -15492,10 +15594,11 @@
15594
15595 #endif /* SQLITE_MEMDEBUG */
15596
15597 /************** End of mem2.c ************************************************/
15598 /************** Begin file mem3.c ********************************************/
15599 #line 1 "tsrc/mem3.c"
15600 /*
15601 ** 2007 October 14
15602 **
15603 ** The author disclaims copyright to this source code. In place of
15604 ** a legal notice, here is a blessing:
@@ -16181,10 +16284,11 @@
16284
16285 #endif /* SQLITE_ENABLE_MEMSYS3 */
16286
16287 /************** End of mem3.c ************************************************/
16288 /************** Begin file mem5.c ********************************************/
16289 #line 1 "tsrc/mem5.c"
16290 /*
16291 ** 2007 October 14
16292 **
16293 ** The author disclaims copyright to this source code. In place of
16294 ** a legal notice, here is a blessing:
@@ -16764,10 +16868,11 @@
16868
16869 #endif /* SQLITE_ENABLE_MEMSYS5 */
16870
16871 /************** End of mem5.c ************************************************/
16872 /************** Begin file mutex.c *******************************************/
16873 #line 1 "tsrc/mutex.c"
16874 /*
16875 ** 2007 August 14
16876 **
16877 ** The author disclaims copyright to this source code. In place of
16878 ** a legal notice, here is a blessing:
@@ -16919,10 +17024,11 @@
17024
17025 #endif /* SQLITE_MUTEX_OMIT */
17026
17027 /************** End of mutex.c ***********************************************/
17028 /************** Begin file mutex_noop.c **************************************/
17029 #line 1 "tsrc/mutex_noop.c"
17030 /*
17031 ** 2008 October 07
17032 **
17033 ** The author disclaims copyright to this source code. In place of
17034 ** a legal notice, here is a blessing:
@@ -17127,10 +17233,11 @@
17233 #endif /* SQLITE_MUTEX_NOOP */
17234 #endif /* SQLITE_MUTEX_OMIT */
17235
17236 /************** End of mutex_noop.c ******************************************/
17237 /************** Begin file mutex_os2.c ***************************************/
17238 #line 1 "tsrc/mutex_os2.c"
17239 /*
17240 ** 2007 August 28
17241 **
17242 ** The author disclaims copyright to this source code. In place of
17243 ** a legal notice, here is a blessing:
@@ -17403,10 +17510,11 @@
17510 }
17511 #endif /* SQLITE_MUTEX_OS2 */
17512
17513 /************** End of mutex_os2.c *******************************************/
17514 /************** Begin file mutex_unix.c **************************************/
17515 #line 1 "tsrc/mutex_unix.c"
17516 /*
17517 ** 2007 August 28
17518 **
17519 ** The author disclaims copyright to this source code. In place of
17520 ** a legal notice, here is a blessing:
@@ -17756,10 +17864,11 @@
17864
17865 #endif /* SQLITE_MUTEX_PTHREAD */
17866
17867 /************** End of mutex_unix.c ******************************************/
17868 /************** Begin file mutex_w32.c ***************************************/
17869 #line 1 "tsrc/mutex_w32.c"
17870 /*
17871 ** 2007 August 14
17872 **
17873 ** The author disclaims copyright to this source code. In place of
17874 ** a legal notice, here is a blessing:
@@ -18090,10 +18199,11 @@
18199 }
18200 #endif /* SQLITE_MUTEX_W32 */
18201
18202 /************** End of mutex_w32.c *******************************************/
18203 /************** Begin file malloc.c ******************************************/
18204 #line 1 "tsrc/malloc.c"
18205 /*
18206 ** 2001 September 15
18207 **
18208 ** The author disclaims copyright to this source code. In place of
18209 ** a legal notice, here is a blessing:
@@ -18869,10 +18979,11 @@
18979 return rc & (db ? db->errMask : 0xff);
18980 }
18981
18982 /************** End of malloc.c **********************************************/
18983 /************** Begin file printf.c ******************************************/
18984 #line 1 "tsrc/printf.c"
18985 /*
18986 ** The "printf" code that follows dates from the 1980's. It is in
18987 ** the public domain. The original comments are included here for
18988 ** completeness. They are very out-of-date but might be useful as
18989 ** an historical reference. Most of the "enhancements" have been backed
@@ -19900,10 +20011,11 @@
20011 }
20012 #endif
20013
20014 /************** End of printf.c **********************************************/
20015 /************** Begin file random.c ******************************************/
20016 #line 1 "tsrc/random.c"
20017 /*
20018 ** 2001 September 15
20019 **
20020 ** The author disclaims copyright to this source code. In place of
20021 ** a legal notice, here is a blessing:
@@ -20047,10 +20159,11 @@
20159 }
20160 #endif /* SQLITE_OMIT_BUILTIN_TEST */
20161
20162 /************** End of random.c **********************************************/
20163 /************** Begin file utf.c *********************************************/
20164 #line 1 "tsrc/utf.c"
20165 /*
20166 ** 2004 April 13
20167 **
20168 ** The author disclaims copyright to this source code. In place of
20169 ** a legal notice, here is a blessing:
@@ -20511,11 +20624,11 @@
20624 ** no longer required.
20625 **
20626 ** If a malloc failure occurs, NULL is returned and the db.mallocFailed
20627 ** flag set.
20628 */
20629 #ifdef SQLITE_ENABLE_STAT3
20630 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
20631 Mem m;
20632 memset(&m, 0, sizeof(m));
20633 m.db = db;
20634 sqlite3VdbeMemSetStr(&m, z, n, SQLITE_UTF8, SQLITE_STATIC);
@@ -20608,10 +20721,11 @@
20721 #endif /* SQLITE_TEST */
20722 #endif /* SQLITE_OMIT_UTF16 */
20723
20724 /************** End of utf.c *************************************************/
20725 /************** Begin file util.c ********************************************/
20726 #line 1 "tsrc/util.c"
20727 /*
20728 ** 2001 September 15
20729 **
20730 ** The author disclaims copyright to this source code. In place of
20731 ** a legal notice, here is a blessing:
@@ -21790,10 +21904,11 @@
21904 }
21905 #endif
21906
21907 /************** End of util.c ************************************************/
21908 /************** Begin file hash.c ********************************************/
21909 #line 1 "tsrc/hash.c"
21910 /*
21911 ** 2001 September 22
21912 **
21913 ** The author disclaims copyright to this source code. In place of
21914 ** a legal notice, here is a blessing:
@@ -22069,10 +22184,11 @@
22184 return 0;
22185 }
22186
22187 /************** End of hash.c ************************************************/
22188 /************** Begin file opcodes.c *****************************************/
22189 #line 1 "tsrc/opcodes.c"
22190 /* Automatically generated. Do not edit */
22191 /* See the mkopcodec.awk script for details. */
22192 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
22193 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
22194 static const char *const azName[] = { "?",
@@ -22231,10 +22347,11 @@
22347 }
22348 #endif
22349
22350 /************** End of opcodes.c *********************************************/
22351 /************** Begin file os_os2.c ******************************************/
22352 #line 1 "tsrc/os_os2.c"
22353 /*
22354 ** 2006 Feb 14
22355 **
22356 ** The author disclaims copyright to this source code. In place of
22357 ** a legal notice, here is a blessing:
@@ -22287,10 +22404,11 @@
22404 /*
22405 ** Include code that is common to all os_*.c files
22406 */
22407 /************** Include os_common.h in the middle of os_os2.c ****************/
22408 /************** Begin file os_common.h ***************************************/
22409 #line 1 "tsrc/os_common.h"
22410 /*
22411 ** 2004 May 22
22412 **
22413 ** The author disclaims copyright to this source code. In place of
22414 ** a legal notice, here is a blessing:
@@ -22340,10 +22458,11 @@
22458 ** hwtime.h contains inline assembler code for implementing
22459 ** high-performance timing routines.
22460 */
22461 /************** Include hwtime.h in the middle of os_common.h ****************/
22462 /************** Begin file hwtime.h ******************************************/
22463 #line 1 "tsrc/hwtime.h"
22464 /*
22465 ** 2008 May 27
22466 **
22467 ** The author disclaims copyright to this source code. In place of
22468 ** a legal notice, here is a blessing:
@@ -22428,10 +22547,11 @@
22547
22548 #endif /* !defined(_HWTIME_H_) */
22549
22550 /************** End of hwtime.h **********************************************/
22551 /************** Continuing where we left off in os_common.h ******************/
22552 #line 53 "tsrc/os_common.h"
22553
22554 static sqlite_uint64 g_start;
22555 static sqlite_uint64 g_elapsed;
22556 #define TIMER_START g_start=sqlite3Hwtime()
22557 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -22494,10 +22614,11 @@
22614
22615 #endif /* !defined(_OS_COMMON_H_) */
22616
22617 /************** End of os_common.h *******************************************/
22618 /************** Continuing where we left off in os_os2.c *********************/
22619 #line 57 "tsrc/os_os2.c"
22620
22621 /* Forward references */
22622 typedef struct os2File os2File; /* The file structure */
22623 typedef struct os2ShmNode os2ShmNode; /* A shared descritive memory node */
22624 typedef struct os2ShmLink os2ShmLink; /* A connection to shared-memory */
@@ -24365,10 +24486,11 @@
24486
24487 #endif /* SQLITE_OS_OS2 */
24488
24489 /************** End of os_os2.c **********************************************/
24490 /************** Begin file os_unix.c *****************************************/
24491 #line 1 "tsrc/os_unix.c"
24492 /*
24493 ** 2004 May 22
24494 **
24495 ** The author disclaims copyright to this source code. In place of
24496 ** a legal notice, here is a blessing:
@@ -24629,10 +24751,11 @@
24751 /*
24752 ** Include code that is common to all os_*.c files
24753 */
24754 /************** Include os_common.h in the middle of os_unix.c ***************/
24755 /************** Begin file os_common.h ***************************************/
24756 #line 1 "tsrc/os_common.h"
24757 /*
24758 ** 2004 May 22
24759 **
24760 ** The author disclaims copyright to this source code. In place of
24761 ** a legal notice, here is a blessing:
@@ -24682,10 +24805,11 @@
24805 ** hwtime.h contains inline assembler code for implementing
24806 ** high-performance timing routines.
24807 */
24808 /************** Include hwtime.h in the middle of os_common.h ****************/
24809 /************** Begin file hwtime.h ******************************************/
24810 #line 1 "tsrc/hwtime.h"
24811 /*
24812 ** 2008 May 27
24813 **
24814 ** The author disclaims copyright to this source code. In place of
24815 ** a legal notice, here is a blessing:
@@ -24770,10 +24894,11 @@
24894
24895 #endif /* !defined(_HWTIME_H_) */
24896
24897 /************** End of hwtime.h **********************************************/
24898 /************** Continuing where we left off in os_common.h ******************/
24899 #line 53 "tsrc/os_common.h"
24900
24901 static sqlite_uint64 g_start;
24902 static sqlite_uint64 g_elapsed;
24903 #define TIMER_START g_start=sqlite3Hwtime()
24904 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -24836,10 +24961,11 @@
24961
24962 #endif /* !defined(_OS_COMMON_H_) */
24963
24964 /************** End of os_common.h *******************************************/
24965 /************** Continuing where we left off in os_unix.c ********************/
24966 #line 265 "tsrc/os_unix.c"
24967
24968 /*
24969 ** Define various macros that are missing from some systems.
24970 */
24971 #ifndef O_LARGEFILE
@@ -29462,12 +29588,20 @@
29588 **
29589 ** where NN is a 4 digit decimal number. The NN naming schemes are
29590 ** used by the test_multiplex.c module.
29591 */
29592 nDb = sqlite3Strlen30(zPath) - 1;
29593 #ifdef SQLITE_ENABLE_8_3_NAMES
29594 while( nDb>0 && zPath[nDb]!='-' && zPath[nDb]!='/' ) nDb--;
29595 if( nDb==0 || zPath[nDb]=='/' ) return SQLITE_OK;
29596 #else
29597 while( zPath[nDb]!='-' ){
29598 assert( nDb>0 );
29599 assert( zPath[nDb]!='\n' );
29600 nDb--;
29601 }
29602 #endif
29603 memcpy(zDb, zPath, nDb);
29604 zDb[nDb] = '\0';
29605
29606 if( 0==osStat(zDb, &sStat) ){
29607 *pMode = sStat.st_mode & 0777;
@@ -31345,10 +31479,11 @@
31479
31480 #endif /* SQLITE_OS_UNIX */
31481
31482 /************** End of os_unix.c *********************************************/
31483 /************** Begin file os_win.c ******************************************/
31484 #line 1 "tsrc/os_win.c"
31485 /*
31486 ** 2004 May 22
31487 **
31488 ** The author disclaims copyright to this source code. In place of
31489 ** a legal notice, here is a blessing:
@@ -31406,10 +31541,11 @@
31541 /*
31542 ** Include code that is common to all os_*.c files
31543 */
31544 /************** Include os_common.h in the middle of os_win.c ****************/
31545 /************** Begin file os_common.h ***************************************/
31546 #line 1 "tsrc/os_common.h"
31547 /*
31548 ** 2004 May 22
31549 **
31550 ** The author disclaims copyright to this source code. In place of
31551 ** a legal notice, here is a blessing:
@@ -31459,10 +31595,11 @@
31595 ** hwtime.h contains inline assembler code for implementing
31596 ** high-performance timing routines.
31597 */
31598 /************** Include hwtime.h in the middle of os_common.h ****************/
31599 /************** Begin file hwtime.h ******************************************/
31600 #line 1 "tsrc/hwtime.h"
31601 /*
31602 ** 2008 May 27
31603 **
31604 ** The author disclaims copyright to this source code. In place of
31605 ** a legal notice, here is a blessing:
@@ -31547,10 +31684,11 @@
31684
31685 #endif /* !defined(_HWTIME_H_) */
31686
31687 /************** End of hwtime.h **********************************************/
31688 /************** Continuing where we left off in os_common.h ******************/
31689 #line 53 "tsrc/os_common.h"
31690
31691 static sqlite_uint64 g_start;
31692 static sqlite_uint64 g_elapsed;
31693 #define TIMER_START g_start=sqlite3Hwtime()
31694 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
@@ -31613,10 +31751,11 @@
31751
31752 #endif /* !defined(_OS_COMMON_H_) */
31753
31754 /************** End of os_common.h *******************************************/
31755 /************** Continuing where we left off in os_win.c *********************/
31756 #line 62 "tsrc/os_win.c"
31757
31758 /*
31759 ** Some microsoft compilers lack this definition.
31760 */
31761 #ifndef INVALID_FILE_ATTRIBUTES
@@ -34169,11 +34308,11 @@
34308
34309 if( h==INVALID_HANDLE_VALUE ){
34310 pFile->lastErrno = GetLastError();
34311 winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name);
34312 free(zConverted);
34313 if( isReadWrite && !isExclusive ){
34314 return winOpen(pVfs, zName, id,
34315 ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
34316 }else{
34317 return SQLITE_CANTOPEN_BKPT;
34318 }
@@ -34758,10 +34897,11 @@
34897
34898 #endif /* SQLITE_OS_WIN */
34899
34900 /************** End of os_win.c **********************************************/
34901 /************** Begin file bitvec.c ******************************************/
34902 #line 1 "tsrc/bitvec.c"
34903 /*
34904 ** 2008 February 16
34905 **
34906 ** The author disclaims copyright to this source code. In place of
34907 ** a legal notice, here is a blessing:
@@ -35168,10 +35308,11 @@
35308 }
35309 #endif /* SQLITE_OMIT_BUILTIN_TEST */
35310
35311 /************** End of bitvec.c **********************************************/
35312 /************** Begin file pcache.c ******************************************/
35313 #line 1 "tsrc/pcache.c"
35314 /*
35315 ** 2008 August 05
35316 **
35317 ** The author disclaims copyright to this source code. In place of
35318 ** a legal notice, here is a blessing:
@@ -35764,10 +35905,11 @@
35905 }
35906 #endif
35907
35908 /************** End of pcache.c **********************************************/
35909 /************** Begin file pcache1.c *****************************************/
35910 #line 1 "tsrc/pcache1.c"
35911 /*
35912 ** 2008 November 05
35913 **
35914 ** The author disclaims copyright to this source code. In place of
35915 ** a legal notice, here is a blessing:
@@ -35789,12 +35931,10 @@
35931 typedef struct PCache1 PCache1;
35932 typedef struct PgHdr1 PgHdr1;
35933 typedef struct PgFreeslot PgFreeslot;
35934 typedef struct PGroup PGroup;
35935
 
 
35936
35937 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
35938 ** of one or more PCaches that are able to recycle each others unpinned
35939 ** pages when they are under memory pressure. A PGroup is an instance of
35940 ** the following object.
@@ -35821,69 +35961,11 @@
35961 int nMaxPage; /* Sum of nMax for purgeable caches */
35962 int nMinPage; /* Sum of nMin for purgeable caches */
35963 int mxPinned; /* nMaxpage + 10 - nMinPage */
35964 int nCurrentPage; /* Number of purgeable pages allocated */
35965 PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
35966 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35967
35968 /* Each page cache is an instance of the following object. Every
35969 ** open database file (including each in-memory database and each
35970 ** temporary or transient database) has a single page cache which
35971 ** is an instance of this object.
@@ -35983,21 +36065,10 @@
36065 **
36066 ** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
36067 */
36068 #define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
36069 #define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage)
 
 
 
 
 
 
 
 
 
 
 
36070
36071 /*
36072 ** Macros to enter and leave the PCache LRU mutex.
36073 */
36074 #define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
@@ -36120,159 +36191,32 @@
36191 return iSize;
36192 }
36193 }
36194 #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
36195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36196 /*
36197 ** Allocate a new page object initially associated with cache pCache.
36198 */
36199 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
36200 int nByte = sizeof(PgHdr1) + pCache->szPage;
36201 PgHdr1 *p = 0;
36202 void *pPg;
36203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36204 /* The group mutex must be released before pcache1Alloc() is called. This
36205 ** is because it may call sqlite3_release_memory(), which assumes that
36206 ** this mutex is not held. */
36207 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
36208 pcache1LeaveMutex(pCache->pGroup);
36209 pPg = pcache1Alloc(nByte);
36210 pcache1EnterMutex(pCache->pGroup);
36211
36212 if( pPg ){
36213 p = PAGE_TO_PGHDR1(pCache, pPg);
36214 if( pCache->bPurgeable ){
36215 pCache->pGroup->nCurrentPage++;
36216 }
 
 
36217 }
 
36218 return p;
36219 }
36220
36221 /*
36222 ** Free a page object allocated by pcache1AllocPage().
@@ -36282,53 +36226,12 @@
36226 ** with a NULL pointer, so we mark the NULL test with ALWAYS().
36227 */
36228 static void pcache1FreePage(PgHdr1 *p){
36229 if( ALWAYS(p) ){
36230 PCache1 *pCache = p->pCache;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36231 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
36232 pcache1Free(PGHDR1_TO_PAGE(p));
 
36233 if( pCache->bPurgeable ){
36234 pCache->pGroup->nCurrentPage--;
36235 }
36236 }
36237 }
@@ -36935,13 +36838,10 @@
36838 ** been released, the function returns. The return value is the total number
36839 ** of bytes of memory released.
36840 */
36841 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
36842 int nFree = 0;
 
 
 
36843 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
36844 assert( sqlite3_mutex_notheld(pcache1.mutex) );
36845 if( pcache1.pStart==0 ){
36846 PgHdr1 *p;
36847 pcache1EnterMutex(&pcache1.grp);
@@ -36980,10 +36880,11 @@
36880 }
36881 #endif
36882
36883 /************** End of pcache1.c *********************************************/
36884 /************** Begin file rowset.c ******************************************/
36885 #line 1 "tsrc/rowset.c"
36886 /*
36887 ** 2008 December 3
36888 **
36889 ** The author disclaims copyright to this source code. In place of
36890 ** a legal notice, here is a blessing:
@@ -37404,10 +37305,11 @@
37305 return 0;
37306 }
37307
37308 /************** End of rowset.c **********************************************/
37309 /************** Begin file pager.c *******************************************/
37310 #line 1 "tsrc/pager.c"
37311 /*
37312 ** 2001 September 15
37313 **
37314 ** The author disclaims copyright to this source code. In place of
37315 ** a legal notice, here is a blessing:
@@ -37427,10 +37329,11 @@
37329 ** another is writing.
37330 */
37331 #ifndef SQLITE_OMIT_DISKIO
37332 /************** Include wal.h in the middle of pager.c ***********************/
37333 /************** Begin file wal.h *********************************************/
37334 #line 1 "tsrc/wal.h"
37335 /*
37336 ** 2010 February 1
37337 **
37338 ** The author disclaims copyright to this source code. In place of
37339 ** a legal notice, here is a blessing:
@@ -37551,10 +37454,11 @@
37454 #endif /* ifndef SQLITE_OMIT_WAL */
37455 #endif /* _WAL_H_ */
37456
37457 /************** End of wal.h *************************************************/
37458 /************** Continuing where we left off in pager.c **********************/
37459 #line 24 "tsrc/pager.c"
37460
37461
37462 /******************* NOTES ON THE DESIGN OF THE PAGER ************************
37463 **
37464 ** This comment block describes invariants that hold when using a rollback
@@ -38200,12 +38104,12 @@
38104 i64 journalSizeLimit; /* Size limit for persistent journal files */
38105 char *zFilename; /* Name of the database file */
38106 char *zJournal; /* Name of the journal file */
38107 int (*xBusyHandler)(void*); /* Function to call when busy */
38108 void *pBusyHandlerArg; /* Context argument for xBusyHandler */
38109 int nHit, nMiss; /* Total cache hits and misses */
38110 #ifdef SQLITE_TEST
 
38111 int nRead, nWrite; /* Database pages read/written */
38112 #endif
38113 void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */
38114 #ifdef SQLITE_HAS_CODEC
38115 void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
@@ -41699,11 +41603,11 @@
41603 ** The doNotSpill flag inhibits all cache spilling regardless of whether
41604 ** or not a sync is required. This is set during a rollback.
41605 **
41606 ** Spilling is also prohibited when in an error state since that could
41607 ** lead to database corruption. In the current implementaton it
41608 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==1
41609 ** while in the error state, hence it is impossible for this routine to
41610 ** be called in the error state. Nevertheless, we include a NEVER()
41611 ** test for the error state as a safeguard against future changes.
41612 */
41613 if( NEVER(pPager->errCode) ) return SQLITE_OK;
@@ -42535,18 +42439,17 @@
42439
42440 if( (*ppPage)->pPager && !noContent ){
42441 /* In this case the pcache already contains an initialized copy of
42442 ** the page. Return without further ado. */
42443 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
42444 pPager->nHit++;
42445 return SQLITE_OK;
42446
42447 }else{
42448 /* The pager cache has created a new page. Its content needs to
42449 ** be initialized. */
42450
 
42451 pPg = *ppPage;
42452 pPg->pPager = pPager;
42453
42454 /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
42455 ** number greater than this, or the unused locking-page, is requested. */
@@ -42578,10 +42481,11 @@
42481 }
42482 memset(pPg->pData, 0, pPager->pageSize);
42483 IOTRACE(("ZERO %p %d\n", pPager, pgno));
42484 }else{
42485 assert( pPg->pPager==pPager );
42486 pPager->nMiss++;
42487 rc = readDbPage(pPg);
42488 if( rc!=SQLITE_OK ){
42489 goto pager_acquire_err;
42490 }
42491 }
@@ -43611,10 +43515,35 @@
43515 a[9] = pPager->nRead;
43516 a[10] = pPager->nWrite;
43517 return a;
43518 }
43519 #endif
43520
43521 /*
43522 ** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or
43523 ** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the
43524 ** current cache hit or miss count, according to the value of eStat. If the
43525 ** reset parameter is non-zero, the cache hit or miss count is zeroed before
43526 ** returning.
43527 */
43528 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){
43529 int *piStat;
43530
43531 assert( eStat==SQLITE_DBSTATUS_CACHE_HIT
43532 || eStat==SQLITE_DBSTATUS_CACHE_MISS
43533 );
43534 if( eStat==SQLITE_DBSTATUS_CACHE_HIT ){
43535 piStat = &pPager->nHit;
43536 }else{
43537 piStat = &pPager->nMiss;
43538 }
43539
43540 *pnVal += *piStat;
43541 if( reset ){
43542 *piStat = 0;
43543 }
43544 }
43545
43546 /*
43547 ** Return true if this is an in-memory pager.
43548 */
43549 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
@@ -44362,10 +44291,11 @@
44291
44292 #endif /* SQLITE_OMIT_DISKIO */
44293
44294 /************** End of pager.c ***********************************************/
44295 /************** Begin file wal.c *********************************************/
44296 #line 1 "tsrc/wal.c"
44297 /*
44298 ** 2010 February 1
44299 **
44300 ** The author disclaims copyright to this source code. In place of
44301 ** a legal notice, here is a blessing:
@@ -47316,10 +47246,11 @@
47246
47247 #endif /* #ifndef SQLITE_OMIT_WAL */
47248
47249 /************** End of wal.c *************************************************/
47250 /************** Begin file btmutex.c *****************************************/
47251 #line 1 "tsrc/btmutex.c"
47252 /*
47253 ** 2007 August 27
47254 **
47255 ** The author disclaims copyright to this source code. In place of
47256 ** a legal notice, here is a blessing:
@@ -47335,10 +47266,11 @@
47266 ** big and we want to break it down some. This packaged seemed like
47267 ** a good breakout.
47268 */
47269 /************** Include btreeInt.h in the middle of btmutex.c ****************/
47270 /************** Begin file btreeInt.h ****************************************/
47271 #line 1 "tsrc/btreeInt.h"
47272 /*
47273 ** 2004 April 6
47274 **
47275 ** The author disclaims copyright to this source code. In place of
47276 ** a legal notice, here is a blessing:
@@ -47980,10 +47912,11 @@
47912 #define get4byte sqlite3Get4byte
47913 #define put4byte sqlite3Put4byte
47914
47915 /************** End of btreeInt.h ********************************************/
47916 /************** Continuing where we left off in btmutex.c ********************/
47917 #line 19 "tsrc/btmutex.c"
47918 #ifndef SQLITE_OMIT_SHARED_CACHE
47919 #if SQLITE_THREADSAFE
47920
47921 /*
47922 ** Obtain the BtShared mutex associated with B-Tree handle p. Also,
@@ -48252,10 +48185,11 @@
48185 #endif /* if SQLITE_THREADSAFE */
48186 #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */
48187
48188 /************** End of btmutex.c *********************************************/
48189 /************** Begin file btree.c *******************************************/
48190 #line 1 "tsrc/btree.c"
48191 /*
48192 ** 2004 April 6
48193 **
48194 ** The author disclaims copyright to this source code. In place of
48195 ** a legal notice, here is a blessing:
@@ -56439,10 +56373,11 @@
56373 return rc;
56374 }
56375
56376 /************** End of btree.c ***********************************************/
56377 /************** Begin file backup.c ******************************************/
56378 #line 1 "tsrc/backup.c"
56379 /*
56380 ** 2009 January 28
56381 **
56382 ** The author disclaims copyright to this source code. In place of
56383 ** a legal notice, here is a blessing:
@@ -57108,13 +57043,21 @@
57043 ** goes wrong, the transaction on pTo is rolled back. If successful, the
57044 ** transaction is committed before returning.
57045 */
57046 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
57047 int rc;
57048 sqlite3_file *pFd; /* File descriptor for database pTo */
57049 sqlite3_backup b;
57050 sqlite3BtreeEnter(pTo);
57051 sqlite3BtreeEnter(pFrom);
57052
57053 assert( sqlite3BtreeIsInTrans(pTo) );
57054 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
57055 if( pFd->pMethods ){
57056 i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
57057 sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
57058 }
57059
57060 /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
57061 ** to 0. This is used by the implementations of sqlite3_backup_step()
57062 ** and sqlite3_backup_finish() to detect that they are being called
57063 ** from this function, not directly by the user.
@@ -57137,18 +57080,20 @@
57080 rc = sqlite3_backup_finish(&b);
57081 if( rc==SQLITE_OK ){
57082 pTo->pBt->pageSizeFixed = 0;
57083 }
57084
57085 assert( sqlite3BtreeIsInTrans(pTo)==0 );
57086 sqlite3BtreeLeave(pFrom);
57087 sqlite3BtreeLeave(pTo);
57088 return rc;
57089 }
57090 #endif /* SQLITE_OMIT_VACUUM */
57091
57092 /************** End of backup.c **********************************************/
57093 /************** Begin file vdbemem.c *****************************************/
57094 #line 1 "tsrc/vdbemem.c"
57095 /*
57096 ** 2004 May 26
57097 **
57098 ** The author disclaims copyright to this source code. In place of
57099 ** a legal notice, here is a blessing:
@@ -58171,15 +58116,15 @@
58116 *ppVal = 0;
58117 return SQLITE_OK;
58118 }
58119 op = pExpr->op;
58120
58121 /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT3.
58122 ** The ifdef here is to enable us to achieve 100% branch test coverage even
58123 ** when SQLITE_ENABLE_STAT3 is omitted.
58124 */
58125 #ifdef SQLITE_ENABLE_STAT3
58126 if( op==TK_REGISTER ) op = pExpr->op2;
58127 #else
58128 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
58129 #endif
58130
@@ -58299,10 +58244,11 @@
58244 return 0;
58245 }
58246
58247 /************** End of vdbemem.c *********************************************/
58248 /************** Begin file vdbeaux.c *****************************************/
58249 #line 1 "tsrc/vdbeaux.c"
58250 /*
58251 ** 2003 September 6
58252 **
58253 ** The author disclaims copyright to this source code. In place of
58254 ** a legal notice, here is a blessing:
@@ -58874,12 +58820,12 @@
58820 /*
58821 ** Change the P2 operand of instruction addr so that it points to
58822 ** the address of the next instruction to be coded.
58823 */
58824 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
58825 assert( addr>=0 || p->db->mallocFailed );
58826 if( addr>=0 ) sqlite3VdbeChangeP2(p, addr, p->nOp);
58827 }
58828
58829
58830 /*
58831 ** If the input FuncDef structure is ephemeral, then free it. If
@@ -59441,11 +59387,11 @@
59387 SubProgram **apSub = 0; /* Array of sub-vdbes */
59388 Mem *pSub = 0; /* Memory cell hold array of subprogs */
59389 sqlite3 *db = p->db; /* The database connection */
59390 int i; /* Loop counter */
59391 int rc = SQLITE_OK; /* Return code */
59392 Mem *pMem = &p->aMem[1]; /* First Mem of result set */
59393
59394 assert( p->explain );
59395 assert( p->magic==VDBE_MAGIC_RUN );
59396 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
59397
@@ -59452,10 +59398,11 @@
59398 /* Even though this opcode does not use dynamic strings for
59399 ** the result, result columns may become dynamic if the user calls
59400 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
59401 */
59402 releaseMemArray(pMem, 8);
59403 p->pResultSet = 0;
59404
59405 if( p->rc==SQLITE_NOMEM ){
59406 /* This happens if a malloc() inside a call to sqlite3_column_text() or
59407 ** sqlite3_column_text16() failed. */
59408 db->mallocFailed = 1;
@@ -59606,10 +59553,11 @@
59553 pMem->type = SQLITE_NULL;
59554 }
59555 }
59556
59557 p->nResColumn = 8 - 4*(p->explain-1);
59558 p->pResultSet = &p->aMem[1];
59559 p->rc = SQLITE_OK;
59560 rc = SQLITE_ROW;
59561 }
59562 return rc;
59563 }
@@ -61538,10 +61486,11 @@
61486 }
61487 }
61488
61489 /************** End of vdbeaux.c *********************************************/
61490 /************** Begin file vdbeapi.c *****************************************/
61491 #line 1 "tsrc/vdbeapi.c"
61492 /*
61493 ** 2004 May 26
61494 **
61495 ** The author disclaims copyright to this source code. In place of
61496 ** a legal notice, here is a blessing:
@@ -62845,10 +62794,11 @@
62794 return v;
62795 }
62796
62797 /************** End of vdbeapi.c *********************************************/
62798 /************** Begin file vdbetrace.c ***************************************/
62799 #line 1 "tsrc/vdbetrace.c"
62800 /*
62801 ** 2009 November 25
62802 **
62803 ** The author disclaims copyright to this source code. In place of
62804 ** a legal notice, here is a blessing:
@@ -63000,10 +62950,11 @@
62950
62951 #endif /* #ifndef SQLITE_OMIT_TRACE */
62952
62953 /************** End of vdbetrace.c *******************************************/
62954 /************** Begin file vdbe.c ********************************************/
62955 #line 1 "tsrc/vdbe.c"
62956 /*
62957 ** 2001 September 15
62958 **
62959 ** The author disclaims copyright to this source code. In place of
62960 ** a legal notice, here is a blessing:
@@ -63469,10 +63420,11 @@
63420 ** hwtime.h contains inline assembler code for implementing
63421 ** high-performance timing routines.
63422 */
63423 /************** Include hwtime.h in the middle of vdbe.c *********************/
63424 /************** Begin file hwtime.h ******************************************/
63425 #line 1 "tsrc/hwtime.h"
63426 /*
63427 ** 2008 May 27
63428 **
63429 ** The author disclaims copyright to this source code. In place of
63430 ** a legal notice, here is a blessing:
@@ -63557,10 +63509,11 @@
63509
63510 #endif /* !defined(_HWTIME_H_) */
63511
63512 /************** End of hwtime.h **********************************************/
63513 /************** Continuing where we left off in vdbe.c ***********************/
63514 #line 471 "tsrc/vdbe.c"
63515
63516 #endif
63517
63518 /*
63519 ** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
@@ -69801,10 +69754,11 @@
69754 goto vdbe_error_halt;
69755 }
69756
69757 /************** End of vdbe.c ************************************************/
69758 /************** Begin file vdbeblob.c ****************************************/
69759 #line 1 "tsrc/vdbeblob.c"
69760 /*
69761 ** 2007 May 1
69762 **
69763 ** The author disclaims copyright to this source code. In place of
69764 ** a legal notice, here is a blessing:
@@ -70271,10 +70225,11 @@
70225
70226 #endif /* #ifndef SQLITE_OMIT_INCRBLOB */
70227
70228 /************** End of vdbeblob.c ********************************************/
70229 /************** Begin file vdbesort.c ****************************************/
70230 #line 1 "tsrc/vdbesort.c"
70231 /*
70232 ** 2011 July 9
70233 **
70234 ** The author disclaims copyright to this source code. In place of
70235 ** a legal notice, here is a blessing:
@@ -71154,10 +71109,11 @@
71109
71110 #endif /* #ifndef SQLITE_OMIT_MERGE_SORT */
71111
71112 /************** End of vdbesort.c ********************************************/
71113 /************** Begin file journal.c *****************************************/
71114 #line 1 "tsrc/journal.c"
71115 /*
71116 ** 2007 August 22
71117 **
71118 ** The author disclaims copyright to this source code. In place of
71119 ** a legal notice, here is a blessing:
@@ -71394,10 +71350,11 @@
71350 }
71351 #endif
71352
71353 /************** End of journal.c *********************************************/
71354 /************** Begin file memjournal.c **************************************/
71355 #line 1 "tsrc/memjournal.c"
71356 /*
71357 ** 2008 October 7
71358 **
71359 ** The author disclaims copyright to this source code. In place of
71360 ** a legal notice, here is a blessing:
@@ -71655,10 +71612,11 @@
71612 return sizeof(MemJournal);
71613 }
71614
71615 /************** End of memjournal.c ******************************************/
71616 /************** Begin file walker.c ******************************************/
71617 #line 1 "tsrc/walker.c"
71618 /*
71619 ** 2008 August 16
71620 **
71621 ** The author disclaims copyright to this source code. In place of
71622 ** a legal notice, here is a blessing:
@@ -71793,10 +71751,11 @@
71751 return rc & WRC_Abort;
71752 }
71753
71754 /************** End of walker.c **********************************************/
71755 /************** Begin file resolve.c *****************************************/
71756 #line 1 "tsrc/resolve.c"
71757 /*
71758 ** 2008 August 18
71759 **
71760 ** The author disclaims copyright to this source code. In place of
71761 ** a legal notice, here is a blessing:
@@ -73013,10 +72972,11 @@
72972 sqlite3WalkSelect(&w, p);
72973 }
72974
72975 /************** End of resolve.c *********************************************/
72976 /************** Begin file expr.c ********************************************/
72977 #line 1 "tsrc/expr.c"
72978 /*
72979 ** 2001 September 15
72980 **
72981 ** The author disclaims copyright to this source code. In place of
72982 ** a legal notice, here is a blessing:
@@ -76770,10 +76730,11 @@
76730 }
76731 }
76732
76733 /************** End of expr.c ************************************************/
76734 /************** Begin file alter.c *******************************************/
76735 #line 1 "tsrc/alter.c"
76736 /*
76737 ** 2005 February 15
76738 **
76739 ** The author disclaims copyright to this source code. In place of
76740 ** a legal notice, here is a blessing:
@@ -77598,10 +77559,11 @@
77559 }
77560 #endif /* SQLITE_ALTER_TABLE */
77561
77562 /************** End of alter.c ***********************************************/
77563 /************** Begin file analyze.c *****************************************/
77564 #line 1 "tsrc/analyze.c"
77565 /*
77566 ** 2005 July 8
77567 **
77568 ** The author disclaims copyright to this source code. In place of
77569 ** a legal notice, here is a blessing:
@@ -77610,10 +77572,112 @@
77572 ** May you find forgiveness for yourself and forgive others.
77573 ** May you share freely, never taking more than you give.
77574 **
77575 *************************************************************************
77576 ** This file contains code associated with the ANALYZE command.
77577 **
77578 ** The ANALYZE command gather statistics about the content of tables
77579 ** and indices. These statistics are made available to the query planner
77580 ** to help it make better decisions about how to perform queries.
77581 **
77582 ** The following system tables are or have been supported:
77583 **
77584 ** CREATE TABLE sqlite_stat1(tbl, idx, stat);
77585 ** CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
77586 ** CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
77587 **
77588 ** Additional tables might be added in future releases of SQLite.
77589 ** The sqlite_stat2 table is not created or used unless the SQLite version
77590 ** is between 3.6.18 and 3.7.8, inclusive, and unless SQLite is compiled
77591 ** with SQLITE_ENABLE_STAT2. The sqlite_stat2 table is deprecated.
77592 ** The sqlite_stat2 table is superceded by sqlite_stat3, which is only
77593 ** created and used by SQLite versions 3.7.9 and later and with
77594 ** SQLITE_ENABLE_STAT3 defined. The fucntionality of sqlite_stat3
77595 ** is a superset of sqlite_stat2.
77596 **
77597 ** Format of sqlite_stat1:
77598 **
77599 ** There is normally one row per index, with the index identified by the
77600 ** name in the idx column. The tbl column is the name of the table to
77601 ** which the index belongs. In each such row, the stat column will be
77602 ** a string consisting of a list of integers. The first integer in this
77603 ** list is the number of rows in the index and in the table. The second
77604 ** integer is the average number of rows in the index that have the same
77605 ** value in the first column of the index. The third integer is the average
77606 ** number of rows in the index that have the same value for the first two
77607 ** columns. The N-th integer (for N>1) is the average number of rows in
77608 ** the index which have the same value for the first N-1 columns. For
77609 ** a K-column index, there will be K+1 integers in the stat column. If
77610 ** the index is unique, then the last integer will be 1.
77611 **
77612 ** The list of integers in the stat column can optionally be followed
77613 ** by the keyword "unordered". The "unordered" keyword, if it is present,
77614 ** must be separated from the last integer by a single space. If the
77615 ** "unordered" keyword is present, then the query planner assumes that
77616 ** the index is unordered and will not use the index for a range query.
77617 **
77618 ** If the sqlite_stat1.idx column is NULL, then the sqlite_stat1.stat
77619 ** column contains a single integer which is the (estimated) number of
77620 ** rows in the table identified by sqlite_stat1.tbl.
77621 **
77622 ** Format of sqlite_stat2:
77623 **
77624 ** The sqlite_stat2 is only created and is only used if SQLite is compiled
77625 ** with SQLITE_ENABLE_STAT2 and if the SQLite version number is between
77626 ** 3.6.18 and 3.7.8. The "stat2" table contains additional information
77627 ** about the distribution of keys within an index. The index is identified by
77628 ** the "idx" column and the "tbl" column is the name of the table to which
77629 ** the index belongs. There are usually 10 rows in the sqlite_stat2
77630 ** table for each index.
77631 **
77632 ** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
77633 ** inclusive are samples of the left-most key value in the index taken at
77634 ** evenly spaced points along the index. Let the number of samples be S
77635 ** (10 in the standard build) and let C be the number of rows in the index.
77636 ** Then the sampled rows are given by:
77637 **
77638 ** rownumber = (i*C*2 + C)/(S*2)
77639 **
77640 ** For i between 0 and S-1. Conceptually, the index space is divided into
77641 ** S uniform buckets and the samples are the middle row from each bucket.
77642 **
77643 ** The format for sqlite_stat2 is recorded here for legacy reference. This
77644 ** version of SQLite does not support sqlite_stat2. It neither reads nor
77645 ** writes the sqlite_stat2 table. This version of SQLite only supports
77646 ** sqlite_stat3.
77647 **
77648 ** Format for sqlite_stat3:
77649 **
77650 ** The sqlite_stat3 is an enhancement to sqlite_stat2. A new name is
77651 ** used to avoid compatibility problems.
77652 **
77653 ** The format of the sqlite_stat3 table is similar to the format of
77654 ** the sqlite_stat2 table. There are multiple entries for each index.
77655 ** The idx column names the index and the tbl column is the table of the
77656 ** index. If the idx and tbl columns are the same, then the sample is
77657 ** of the INTEGER PRIMARY KEY. The sample column is a value taken from
77658 ** the left-most column of the index. The nEq column is the approximate
77659 ** number of entires in the index whose left-most column exactly matches
77660 ** the sample. nLt is the approximate number of entires whose left-most
77661 ** column is less than the sample. The nDLt column is the approximate
77662 ** number of distinct left-most entries in the index that are less than
77663 ** the sample.
77664 **
77665 ** Future versions of SQLite might change to store a string containing
77666 ** multiple integers values in the nDLt column of sqlite_stat3. The first
77667 ** integer will be the number of prior index entires that are distinct in
77668 ** the left-most column. The second integer will be the number of prior index
77669 ** entries that are distinct in the first two columns. The third integer
77670 ** will be the number of prior index entries that are distinct in the first
77671 ** three columns. And so forth. With that extension, the nDLt field is
77672 ** similar in function to the sqlite_stat1.stat field.
77673 **
77674 ** There can be an arbitrary number of sqlite_stat3 entries per index.
77675 ** The ANALYZE command will typically generate sqlite_stat3 tables
77676 ** that contain between 10 and 40 samples which are distributed across
77677 ** the key space, though not uniformly, and which include samples with
77678 ** largest possible nEq values.
77679 */
77680 #ifndef SQLITE_OMIT_ANALYZE
77681
77682 /*
77683 ** This routine generates code that opens the sqlite_stat1 table for
@@ -77641,12 +77705,18 @@
77705 static const struct {
77706 const char *zName;
77707 const char *zCols;
77708 } aTable[] = {
77709 { "sqlite_stat1", "tbl,idx,stat" },
77710 #ifdef SQLITE_ENABLE_STAT3
77711 { "sqlite_stat3", "tbl,idx,neq,nlt,ndlt,sample" },
77712 #endif
77713 };
77714 static const char *azToDrop[] = {
77715 "sqlite_stat2",
77716 #ifndef SQLITE_ENABLE_STAT3
77717 "sqlite_stat3",
77718 #endif
77719 };
77720
77721 int aRoot[] = {0, 0};
77722 u8 aCreateTbl[] = {0, 0};
@@ -77658,10 +77728,24 @@
77728 if( v==0 ) return;
77729 assert( sqlite3BtreeHoldsAllMutexes(db) );
77730 assert( sqlite3VdbeDb(v)==db );
77731 pDb = &db->aDb[iDb];
77732
77733 /* Drop all statistics tables that this version of SQLite does not
77734 ** understand.
77735 */
77736 for(i=0; i<ArraySize(azToDrop); i++){
77737 Table *pTab = sqlite3FindTable(db, azToDrop[i], pDb->zName);
77738 if( pTab ){
77739 sqlite3CodeDropTable(pParse, pTab, iDb, 0);
77740 break;
77741 }
77742 }
77743
77744 /* Create new statistic tables if they do not exist, or clear them
77745 ** if they do already exist.
77746 */
77747 for(i=0; i<ArraySize(aTable); i++){
77748 const char *zTab = aTable[i].zName;
77749 Table *pStat;
77750 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
77751 /* The sqlite_stat[12] table does not exist. Create it. Note that a
@@ -77688,17 +77772,237 @@
77772 sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
77773 }
77774 }
77775 }
77776
77777 /* Open the sqlite_stat[13] tables for writing. */
77778 for(i=0; i<ArraySize(aTable); i++){
77779 sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);
77780 sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);
77781 sqlite3VdbeChangeP5(v, aCreateTbl[i]);
77782 }
77783 }
77784
77785 /*
77786 ** Recommended number of samples for sqlite_stat3
77787 */
77788 #ifndef SQLITE_STAT3_SAMPLES
77789 # define SQLITE_STAT3_SAMPLES 24
77790 #endif
77791
77792 /*
77793 ** Three SQL functions - stat3_init(), stat3_push(), and stat3_pop() -
77794 ** share an instance of the following structure to hold their state
77795 ** information.
77796 */
77797 typedef struct Stat3Accum Stat3Accum;
77798 struct Stat3Accum {
77799 tRowcnt nRow; /* Number of rows in the entire table */
77800 tRowcnt nPSample; /* How often to do a periodic sample */
77801 int iMin; /* Index of entry with minimum nEq and hash */
77802 int mxSample; /* Maximum number of samples to accumulate */
77803 int nSample; /* Current number of samples */
77804 u32 iPrn; /* Pseudo-random number used for sampling */
77805 struct Stat3Sample {
77806 i64 iRowid; /* Rowid in main table of the key */
77807 tRowcnt nEq; /* sqlite_stat3.nEq */
77808 tRowcnt nLt; /* sqlite_stat3.nLt */
77809 tRowcnt nDLt; /* sqlite_stat3.nDLt */
77810 u8 isPSample; /* True if a periodic sample */
77811 u32 iHash; /* Tiebreaker hash */
77812 } *a; /* An array of samples */
77813 };
77814
77815 #ifdef SQLITE_ENABLE_STAT3
77816 /*
77817 ** Implementation of the stat3_init(C,S) SQL function. The two parameters
77818 ** are the number of rows in the table or index (C) and the number of samples
77819 ** to accumulate (S).
77820 **
77821 ** This routine allocates the Stat3Accum object.
77822 **
77823 ** The return value is the Stat3Accum object (P).
77824 */
77825 static void stat3Init(
77826 sqlite3_context *context,
77827 int argc,
77828 sqlite3_value **argv
77829 ){
77830 Stat3Accum *p;
77831 tRowcnt nRow;
77832 int mxSample;
77833 int n;
77834
77835 UNUSED_PARAMETER(argc);
77836 nRow = (tRowcnt)sqlite3_value_int64(argv[0]);
77837 mxSample = sqlite3_value_int(argv[1]);
77838 n = sizeof(*p) + sizeof(p->a[0])*mxSample;
77839 p = sqlite3_malloc( n );
77840 if( p==0 ){
77841 sqlite3_result_error_nomem(context);
77842 return;
77843 }
77844 memset(p, 0, n);
77845 p->a = (struct Stat3Sample*)&p[1];
77846 p->nRow = nRow;
77847 p->mxSample = mxSample;
77848 p->nPSample = p->nRow/(mxSample/3+1) + 1;
77849 sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
77850 sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
77851 }
77852 static const FuncDef stat3InitFuncdef = {
77853 2, /* nArg */
77854 SQLITE_UTF8, /* iPrefEnc */
77855 0, /* flags */
77856 0, /* pUserData */
77857 0, /* pNext */
77858 stat3Init, /* xFunc */
77859 0, /* xStep */
77860 0, /* xFinalize */
77861 "stat3_init", /* zName */
77862 0, /* pHash */
77863 0 /* pDestructor */
77864 };
77865
77866
77867 /*
77868 ** Implementation of the stat3_push(nEq,nLt,nDLt,rowid,P) SQL function. The
77869 ** arguments describe a single key instance. This routine makes the
77870 ** decision about whether or not to retain this key for the sqlite_stat3
77871 ** table.
77872 **
77873 ** The return value is NULL.
77874 */
77875 static void stat3Push(
77876 sqlite3_context *context,
77877 int argc,
77878 sqlite3_value **argv
77879 ){
77880 Stat3Accum *p = (Stat3Accum*)sqlite3_value_blob(argv[4]);
77881 tRowcnt nEq = sqlite3_value_int64(argv[0]);
77882 tRowcnt nLt = sqlite3_value_int64(argv[1]);
77883 tRowcnt nDLt = sqlite3_value_int64(argv[2]);
77884 i64 rowid = sqlite3_value_int64(argv[3]);
77885 u8 isPSample = 0;
77886 u8 doInsert = 0;
77887 int iMin = p->iMin;
77888 struct Stat3Sample *pSample;
77889 int i;
77890 u32 h;
77891
77892 UNUSED_PARAMETER(context);
77893 UNUSED_PARAMETER(argc);
77894 if( nEq==0 ) return;
77895 h = p->iPrn = p->iPrn*1103515245 + 12345;
77896 if( (nLt/p->nPSample)!=((nEq+nLt)/p->nPSample) ){
77897 doInsert = isPSample = 1;
77898 }else if( p->nSample<p->mxSample ){
77899 doInsert = 1;
77900 }else{
77901 if( nEq>p->a[iMin].nEq || (nEq==p->a[iMin].nEq && h>p->a[iMin].iHash) ){
77902 doInsert = 1;
77903 }
77904 }
77905 if( !doInsert ) return;
77906 if( p->nSample==p->mxSample ){
77907 assert( p->nSample - iMin - 1 >= 0 );
77908 memmove(&p->a[iMin], &p->a[iMin+1], sizeof(p->a[0])*(p->nSample-iMin-1));
77909 pSample = &p->a[p->nSample-1];
77910 }else{
77911 pSample = &p->a[p->nSample++];
77912 }
77913 pSample->iRowid = rowid;
77914 pSample->nEq = nEq;
77915 pSample->nLt = nLt;
77916 pSample->nDLt = nDLt;
77917 pSample->iHash = h;
77918 pSample->isPSample = isPSample;
77919
77920 /* Find the new minimum */
77921 if( p->nSample==p->mxSample ){
77922 pSample = p->a;
77923 i = 0;
77924 while( pSample->isPSample ){
77925 i++;
77926 pSample++;
77927 assert( i<p->nSample );
77928 }
77929 nEq = pSample->nEq;
77930 h = pSample->iHash;
77931 iMin = i;
77932 for(i++, pSample++; i<p->nSample; i++, pSample++){
77933 if( pSample->isPSample ) continue;
77934 if( pSample->nEq<nEq
77935 || (pSample->nEq==nEq && pSample->iHash<h)
77936 ){
77937 iMin = i;
77938 nEq = pSample->nEq;
77939 h = pSample->iHash;
77940 }
77941 }
77942 p->iMin = iMin;
77943 }
77944 }
77945 static const FuncDef stat3PushFuncdef = {
77946 5, /* nArg */
77947 SQLITE_UTF8, /* iPrefEnc */
77948 0, /* flags */
77949 0, /* pUserData */
77950 0, /* pNext */
77951 stat3Push, /* xFunc */
77952 0, /* xStep */
77953 0, /* xFinalize */
77954 "stat3_push", /* zName */
77955 0, /* pHash */
77956 0 /* pDestructor */
77957 };
77958
77959 /*
77960 ** Implementation of the stat3_get(P,N,...) SQL function. This routine is
77961 ** used to query the results. Content is returned for the Nth sqlite_stat3
77962 ** row where N is between 0 and S-1 and S is the number of samples. The
77963 ** value returned depends on the number of arguments.
77964 **
77965 ** argc==2 result: rowid
77966 ** argc==3 result: nEq
77967 ** argc==4 result: nLt
77968 ** argc==5 result: nDLt
77969 */
77970 static void stat3Get(
77971 sqlite3_context *context,
77972 int argc,
77973 sqlite3_value **argv
77974 ){
77975 int n = sqlite3_value_int(argv[1]);
77976 Stat3Accum *p = (Stat3Accum*)sqlite3_value_blob(argv[0]);
77977
77978 assert( p!=0 );
77979 if( p->nSample<=n ) return;
77980 switch( argc ){
77981 case 2: sqlite3_result_int64(context, p->a[n].iRowid); break;
77982 case 3: sqlite3_result_int64(context, p->a[n].nEq); break;
77983 case 4: sqlite3_result_int64(context, p->a[n].nLt); break;
77984 default: sqlite3_result_int64(context, p->a[n].nDLt); break;
77985 }
77986 }
77987 static const FuncDef stat3GetFuncdef = {
77988 -1, /* nArg */
77989 SQLITE_UTF8, /* iPrefEnc */
77990 0, /* flags */
77991 0, /* pUserData */
77992 0, /* pNext */
77993 stat3Get, /* xFunc */
77994 0, /* xStep */
77995 0, /* xFinalize */
77996 "stat3_get", /* zName */
77997 0, /* pHash */
77998 0 /* pDestructor */
77999 };
78000 #endif /* SQLITE_ENABLE_STAT3 */
78001
78002
78003
78004
78005 /*
78006 ** Generate code to do an analysis of all indices associated with
78007 ** a single table.
78008 */
@@ -77718,24 +78022,31 @@
78022 int endOfLoop; /* The end of the loop */
78023 int jZeroRows = -1; /* Jump from here if number of rows is zero */
78024 int iDb; /* Index of database containing pTab */
78025 int regTabname = iMem++; /* Register containing table name */
78026 int regIdxname = iMem++; /* Register containing index name */
78027 int regStat1 = iMem++; /* The stat column of sqlite_stat1 */
78028 #ifdef SQLITE_ENABLE_STAT3
78029 int regNumEq = regStat1; /* Number of instances. Same as regStat1 */
78030 int regNumLt = iMem++; /* Number of keys less than regSample */
78031 int regNumDLt = iMem++; /* Number of distinct keys less than regSample */
78032 int regSample = iMem++; /* The next sample value */
78033 int regRowid = regSample; /* Rowid of a sample */
78034 int regAccum = iMem++; /* Register to hold Stat3Accum object */
78035 int regLoop = iMem++; /* Loop counter */
78036 int regCount = iMem++; /* Number of rows in the table or index */
78037 int regTemp1 = iMem++; /* Intermediate register */
78038 int regTemp2 = iMem++; /* Intermediate register */
78039 int once = 1; /* One-time initialization */
78040 int shortJump = 0; /* Instruction address */
78041 int iTabCur = pParse->nTab++; /* Table cursor */
78042 #endif
78043 int regCol = iMem++; /* Content of a column in analyzed table */
78044 int regRec = iMem++; /* Register holding completed record */
78045 int regTemp = iMem++; /* Temporary use register */
78046 int regNewRowid = iMem++; /* Rowid for the inserted record */
78047
 
 
 
 
 
 
 
 
78048
78049 v = sqlite3GetVdbe(pParse);
78050 if( v==0 || NEVER(pTab==0) ){
78051 return;
78052 }
@@ -77764,13 +78075,18 @@
78075 iIdxCur = pParse->nTab++;
78076 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
78077 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
78078 int nCol;
78079 KeyInfo *pKey;
78080 int addrIfNot = 0; /* address of OP_IfNot */
78081 int *aChngAddr; /* Array of jump instruction addresses */
78082
78083 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
78084 VdbeNoopComment((v, "Begin analysis of %s", pIdx->zName));
78085 nCol = pIdx->nColumn;
78086 aChngAddr = sqlite3DbMallocRaw(db, sizeof(int)*nCol);
78087 if( aChngAddr==0 ) continue;
78088 pKey = sqlite3IndexKeyinfo(pParse, pIdx);
78089 if( iMem+1+(nCol*2)>pParse->nMem ){
78090 pParse->nMem = iMem+1+(nCol*2);
78091 }
78092
@@ -77781,35 +78097,24 @@
78097 VdbeComment((v, "%s", pIdx->zName));
78098
78099 /* Populate the register containing the index name. */
78100 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
78101
78102 #ifdef SQLITE_ENABLE_STAT3
78103 if( once ){
78104 once = 0;
78105 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
78106 }
78107 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regCount);
78108 sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_STAT3_SAMPLES, regTemp1);
78109 sqlite3VdbeAddOp2(v, OP_Integer, 0, regNumEq);
78110 sqlite3VdbeAddOp2(v, OP_Integer, 0, regNumLt);
78111 sqlite3VdbeAddOp2(v, OP_Integer, -1, regNumDLt);
78112 sqlite3VdbeAddOp4(v, OP_Function, 1, regCount, regAccum,
78113 (char*)&stat3InitFuncdef, P4_FUNCDEF);
78114 sqlite3VdbeChangeP5(v, 2);
78115 #endif /* SQLITE_ENABLE_STAT3 */
 
 
 
 
 
 
 
 
 
 
 
78116
78117 /* The block of memory cells initialized here is used as follows.
78118 **
78119 ** iMem:
78120 ** The total number of rows in the table.
@@ -77835,79 +78140,87 @@
78140 /* Start the analysis loop. This loop runs through all the entries in
78141 ** the index b-tree. */
78142 endOfLoop = sqlite3VdbeMakeLabel(v);
78143 sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
78144 topOfLoop = sqlite3VdbeCurrentAddr(v);
78145 sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1); /* Increment row counter */
78146
78147 for(i=0; i<nCol; i++){
78148 CollSeq *pColl;
78149 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
78150 if( i==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78151 /* Always record the very first row */
78152 addrIfNot = sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
78153 }
78154 assert( pIdx->azColl!=0 );
78155 assert( pIdx->azColl[i]!=0 );
78156 pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
78157 aChngAddr[i] = sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
78158 (char*)pColl, P4_COLLSEQ);
78159 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
78160 VdbeComment((v, "jump if column %d changed", i));
78161 #ifdef SQLITE_ENABLE_STAT3
78162 if( i==0 ){
78163 sqlite3VdbeAddOp2(v, OP_AddImm, regNumEq, 1);
78164 VdbeComment((v, "incr repeat count"));
78165 }
78166 #endif
78167 }
78168 sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
78169 for(i=0; i<nCol; i++){
78170 sqlite3VdbeJumpHere(v, aChngAddr[i]); /* Set jump dest for the OP_Ne */
78171 if( i==0 ){
78172 sqlite3VdbeJumpHere(v, addrIfNot); /* Jump dest for OP_IfNot */
78173 #ifdef SQLITE_ENABLE_STAT3
78174 sqlite3VdbeAddOp4(v, OP_Function, 1, regNumEq, regTemp2,
78175 (char*)&stat3PushFuncdef, P4_FUNCDEF);
78176 sqlite3VdbeChangeP5(v, 5);
78177 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, pIdx->nColumn, regRowid);
78178 sqlite3VdbeAddOp3(v, OP_Add, regNumEq, regNumLt, regNumLt);
78179 sqlite3VdbeAddOp2(v, OP_AddImm, regNumDLt, 1);
78180 sqlite3VdbeAddOp2(v, OP_Integer, 1, regNumEq);
78181 #endif
78182 }
 
78183 sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
78184 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
78185 }
78186 sqlite3DbFree(db, aChngAddr);
78187
78188 /* Always jump here after updating the iMem+1...iMem+1+nCol counters */
78189 sqlite3VdbeResolveLabel(v, endOfLoop);
78190
78191 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
78192 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
78193 #ifdef SQLITE_ENABLE_STAT3
78194 sqlite3VdbeAddOp4(v, OP_Function, 1, regNumEq, regTemp2,
78195 (char*)&stat3PushFuncdef, P4_FUNCDEF);
78196 sqlite3VdbeChangeP5(v, 5);
78197 sqlite3VdbeAddOp2(v, OP_Integer, -1, regLoop);
78198 shortJump =
78199 sqlite3VdbeAddOp2(v, OP_AddImm, regLoop, 1);
78200 sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regTemp1,
78201 (char*)&stat3GetFuncdef, P4_FUNCDEF);
78202 sqlite3VdbeChangeP5(v, 2);
78203 sqlite3VdbeAddOp1(v, OP_IsNull, regTemp1);
78204 sqlite3VdbeAddOp3(v, OP_NotExists, iTabCur, shortJump, regTemp1);
78205 sqlite3VdbeAddOp3(v, OP_Column, iTabCur, pIdx->aiColumn[0], regSample);
78206 sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[0], regSample);
78207 sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumEq,
78208 (char*)&stat3GetFuncdef, P4_FUNCDEF);
78209 sqlite3VdbeChangeP5(v, 3);
78210 sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumLt,
78211 (char*)&stat3GetFuncdef, P4_FUNCDEF);
78212 sqlite3VdbeChangeP5(v, 4);
78213 sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumDLt,
78214 (char*)&stat3GetFuncdef, P4_FUNCDEF);
78215 sqlite3VdbeChangeP5(v, 5);
78216 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regRec, "bbbbbb", 0);
78217 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
78218 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regNewRowid);
78219 sqlite3VdbeAddOp2(v, OP_Goto, 0, shortJump);
78220 sqlite3VdbeJumpHere(v, shortJump+2);
78221 #endif
78222
78223 /* Store the results in sqlite_stat1.
78224 **
78225 ** The result is a single row of the sqlite_stat1 table. The first
78226 ** two columns are the names of the table and index. The third column
@@ -77923,50 +78236,51 @@
78236 **
78237 ** If K==0 then no entry is made into the sqlite_stat1 table.
78238 ** If K>0 then it is always the case the D>0 so division by zero
78239 ** is never possible.
78240 */
78241 sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regStat1);
78242 if( jZeroRows<0 ){
78243 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
78244 }
78245 for(i=0; i<nCol; i++){
78246 sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0);
78247 sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regStat1, regStat1);
78248 sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
78249 sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
78250 sqlite3VdbeAddOp3(v, OP_Divide, iMem+i+1, regTemp, regTemp);
78251 sqlite3VdbeAddOp1(v, OP_ToInt, regTemp);
78252 sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regStat1, regStat1);
78253 }
78254 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
78255 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
78256 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
78257 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
78258 }
78259
78260 /* If the table has no indices, create a single sqlite_stat1 entry
78261 ** containing NULL as the index name and the row count as the content.
78262 */
78263 if( pTab->pIndex==0 ){
78264 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb);
78265 VdbeComment((v, "%s", pTab->zName));
78266 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat1);
78267 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
78268 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
78269 }else{
78270 sqlite3VdbeJumpHere(v, jZeroRows);
78271 jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto);
78272 }
78273 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
78274 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
78275 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
78276 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
78277 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
78278 if( pParse->nMem<regRec ) pParse->nMem = regRec;
78279 sqlite3VdbeJumpHere(v, jZeroRows);
78280 }
78281
78282
78283 /*
78284 ** Generate code that will cause the most recent index analysis to
78285 ** be loaded into internal hash tables where is can be used.
78286 */
@@ -77987,11 +78301,11 @@
78301 int iStatCur;
78302 int iMem;
78303
78304 sqlite3BeginWriteOperation(pParse, 0, iDb);
78305 iStatCur = pParse->nTab;
78306 pParse->nTab += 3;
78307 openStatTable(pParse, iDb, iStatCur, 0, 0);
78308 iMem = pParse->nMem+1;
78309 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
78310 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
78311 Table *pTab = (Table*)sqliteHashData(k);
@@ -78012,11 +78326,11 @@
78326 assert( pTab!=0 );
78327 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
78328 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78329 sqlite3BeginWriteOperation(pParse, 0, iDb);
78330 iStatCur = pParse->nTab;
78331 pParse->nTab += 3;
78332 if( pOnlyIdx ){
78333 openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");
78334 }else{
78335 openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
78336 }
@@ -78117,11 +78431,11 @@
78431 static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
78432 analysisInfo *pInfo = (analysisInfo*)pData;
78433 Index *pIndex;
78434 Table *pTable;
78435 int i, c, n;
78436 tRowcnt v;
78437 const char *z;
78438
78439 assert( argc==3 );
78440 UNUSED_PARAMETER2(NotUsed, argc);
78441
@@ -78160,40 +78474,172 @@
78474 /*
78475 ** If the Index.aSample variable is not NULL, delete the aSample[] array
78476 ** and its contents.
78477 */
78478 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
78479 #ifdef SQLITE_ENABLE_STAT3
78480 if( pIdx->aSample ){
78481 int j;
78482 for(j=0; j<pIdx->nSample; j++){
78483 IndexSample *p = &pIdx->aSample[j];
78484 if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
78485 sqlite3DbFree(db, p->u.z);
78486 }
78487 }
78488 sqlite3DbFree(db, pIdx->aSample);
78489 }
78490 if( db && db->pnBytesFreed==0 ){
78491 pIdx->nSample = 0;
78492 pIdx->aSample = 0;
78493 }
78494 #else
78495 UNUSED_PARAMETER(db);
78496 UNUSED_PARAMETER(pIdx);
78497 #endif
78498 }
78499
78500 #ifdef SQLITE_ENABLE_STAT3
78501 /*
78502 ** Load content from the sqlite_stat3 table into the Index.aSample[]
78503 ** arrays of all indices.
78504 */
78505 static int loadStat3(sqlite3 *db, const char *zDb){
78506 int rc; /* Result codes from subroutines */
78507 sqlite3_stmt *pStmt = 0; /* An SQL statement being run */
78508 char *zSql; /* Text of the SQL statement */
78509 Index *pPrevIdx = 0; /* Previous index in the loop */
78510 int idx = 0; /* slot in pIdx->aSample[] for next sample */
78511 int eType; /* Datatype of a sample */
78512 IndexSample *pSample; /* A slot in pIdx->aSample[] */
78513
78514 if( !sqlite3FindTable(db, "sqlite_stat3", zDb) ){
78515 return SQLITE_OK;
78516 }
78517
78518 zSql = sqlite3MPrintf(db,
78519 "SELECT idx,count(*) FROM %Q.sqlite_stat3"
78520 " GROUP BY idx", zDb);
78521 if( !zSql ){
78522 return SQLITE_NOMEM;
78523 }
78524 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
78525 sqlite3DbFree(db, zSql);
78526 if( rc ) return rc;
78527
78528 while( sqlite3_step(pStmt)==SQLITE_ROW ){
78529 char *zIndex; /* Index name */
78530 Index *pIdx; /* Pointer to the index object */
78531 int nSample; /* Number of samples */
78532
78533 zIndex = (char *)sqlite3_column_text(pStmt, 0);
78534 if( zIndex==0 ) continue;
78535 nSample = sqlite3_column_int(pStmt, 1);
78536 pIdx = sqlite3FindIndex(db, zIndex, zDb);
78537 if( pIdx==0 ) continue;
78538 assert( pIdx->nSample==0 );
78539 pIdx->nSample = nSample;
78540 pIdx->aSample = sqlite3MallocZero( nSample*sizeof(IndexSample) );
78541 pIdx->avgEq = pIdx->aiRowEst[1];
78542 if( pIdx->aSample==0 ){
78543 db->mallocFailed = 1;
78544 sqlite3_finalize(pStmt);
78545 return SQLITE_NOMEM;
78546 }
78547 }
78548 rc = sqlite3_finalize(pStmt);
78549 if( rc ) return rc;
78550
78551 zSql = sqlite3MPrintf(db,
78552 "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat3", zDb);
78553 if( !zSql ){
78554 return SQLITE_NOMEM;
78555 }
78556 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
78557 sqlite3DbFree(db, zSql);
78558 if( rc ) return rc;
78559
78560 while( sqlite3_step(pStmt)==SQLITE_ROW ){
78561 char *zIndex; /* Index name */
78562 Index *pIdx; /* Pointer to the index object */
78563 int i; /* Loop counter */
78564 tRowcnt sumEq; /* Sum of the nEq values */
78565
78566 zIndex = (char *)sqlite3_column_text(pStmt, 0);
78567 if( zIndex==0 ) continue;
78568 pIdx = sqlite3FindIndex(db, zIndex, zDb);
78569 if( pIdx==0 ) continue;
78570 if( pIdx==pPrevIdx ){
78571 idx++;
78572 }else{
78573 pPrevIdx = pIdx;
78574 idx = 0;
78575 }
78576 assert( idx<pIdx->nSample );
78577 pSample = &pIdx->aSample[idx];
78578 pSample->nEq = (tRowcnt)sqlite3_column_int64(pStmt, 1);
78579 pSample->nLt = (tRowcnt)sqlite3_column_int64(pStmt, 2);
78580 pSample->nDLt = (tRowcnt)sqlite3_column_int64(pStmt, 3);
78581 if( idx==pIdx->nSample-1 ){
78582 if( pSample->nDLt>0 ){
78583 for(i=0, sumEq=0; i<=idx-1; i++) sumEq += pIdx->aSample[i].nEq;
78584 pIdx->avgEq = (pSample->nLt - sumEq)/pSample->nDLt;
78585 }
78586 if( pIdx->avgEq<=0 ) pIdx->avgEq = 1;
78587 }
78588 eType = sqlite3_column_type(pStmt, 4);
78589 pSample->eType = (u8)eType;
78590 switch( eType ){
78591 case SQLITE_INTEGER: {
78592 pSample->u.i = sqlite3_column_int64(pStmt, 4);
78593 break;
78594 }
78595 case SQLITE_FLOAT: {
78596 pSample->u.r = sqlite3_column_double(pStmt, 4);
78597 break;
78598 }
78599 case SQLITE_NULL: {
78600 break;
78601 }
78602 default: assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB ); {
78603 const char *z = (const char *)(
78604 (eType==SQLITE_BLOB) ?
78605 sqlite3_column_blob(pStmt, 4):
78606 sqlite3_column_text(pStmt, 4)
78607 );
78608 int n = z ? sqlite3_column_bytes(pStmt, 4) : 0;
78609 pSample->nByte = n;
78610 if( n < 1){
78611 pSample->u.z = 0;
78612 }else{
78613 pSample->u.z = sqlite3Malloc(n);
78614 if( pSample->u.z==0 ){
78615 db->mallocFailed = 1;
78616 sqlite3_finalize(pStmt);
78617 return SQLITE_NOMEM;
78618 }
78619 memcpy(pSample->u.z, z, n);
78620 }
78621 }
78622 }
78623 }
78624 return sqlite3_finalize(pStmt);
78625 }
78626 #endif /* SQLITE_ENABLE_STAT3 */
78627
78628 /*
78629 ** Load the content of the sqlite_stat1 and sqlite_stat3 tables. The
78630 ** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
78631 ** arrays. The contents of sqlite_stat3 are used to populate the
78632 ** Index.aSample[] arrays.
78633 **
78634 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
78635 ** is returned. In this case, even if SQLITE_ENABLE_STAT3 was defined
78636 ** during compilation and the sqlite_stat3 table is present, no data is
78637 ** read from it.
78638 **
78639 ** If SQLITE_ENABLE_STAT3 was defined during compilation and the
78640 ** sqlite_stat3 table is not present in the database, SQLITE_ERROR is
78641 ** returned. However, in this case, data is read from the sqlite_stat1
78642 ** table (if it is present) before returning.
78643 **
78644 ** If an OOM error occurs, this function always sets db->mallocFailed.
78645 ** This means if the caller does not care about other errors, the return
@@ -78211,12 +78657,14 @@
78657 /* Clear any prior statistics */
78658 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
78659 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
78660 Index *pIdx = sqliteHashData(i);
78661 sqlite3DefaultRowEst(pIdx);
78662 #ifdef SQLITE_ENABLE_STAT3
78663 sqlite3DeleteIndexSamples(db, pIdx);
78664 pIdx->aSample = 0;
78665 #endif
78666 }
78667
78668 /* Check to make sure the sqlite_stat1 table exists */
78669 sInfo.db = db;
78670 sInfo.zDatabase = db->aDb[iDb].zName;
@@ -78224,91 +78672,23 @@
78672 return SQLITE_ERROR;
78673 }
78674
78675 /* Load new statistics out of the sqlite_stat1 table */
78676 zSql = sqlite3MPrintf(db,
78677 "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
78678 if( zSql==0 ){
78679 rc = SQLITE_NOMEM;
78680 }else{
78681 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
78682 sqlite3DbFree(db, zSql);
78683 }
78684
78685
78686 /* Load the statistics from the sqlite_stat3 table. */
78687 #ifdef SQLITE_ENABLE_STAT3
78688 if( rc==SQLITE_OK ){
78689 rc = loadStat3(db, sInfo.zDatabase);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78690 }
78691 #endif
78692
78693 if( rc==SQLITE_NOMEM ){
78694 db->mallocFailed = 1;
@@ -78319,10 +78699,11 @@
78699
78700 #endif /* SQLITE_OMIT_ANALYZE */
78701
78702 /************** End of analyze.c *********************************************/
78703 /************** Begin file attach.c ******************************************/
78704 #line 1 "tsrc/attach.c"
78705 /*
78706 ** 2003 April 6
78707 **
78708 ** The author disclaims copyright to this source code. In place of
78709 ** a legal notice, here is a blessing:
@@ -78878,10 +79259,11 @@
79259 }
79260 #endif
79261
79262 /************** End of attach.c **********************************************/
79263 /************** Begin file auth.c ********************************************/
79264 #line 1 "tsrc/auth.c"
79265 /*
79266 ** 2003 January 11
79267 **
79268 ** The author disclaims copyright to this source code. In place of
79269 ** a legal notice, here is a blessing:
@@ -79129,10 +79511,11 @@
79511
79512 #endif /* SQLITE_OMIT_AUTHORIZATION */
79513
79514 /************** End of auth.c ************************************************/
79515 /************** Begin file build.c *******************************************/
79516 #line 1 "tsrc/build.c"
79517 /*
79518 ** 2001 September 15
79519 **
79520 ** The author disclaims copyright to this source code. In place of
79521 ** a legal notice, here is a blessing:
@@ -81120,11 +81503,15 @@
81503 Parse *pParse, /* The parsing context */
81504 int iDb, /* The database number */
81505 const char *zType, /* "idx" or "tbl" */
81506 const char *zName /* Name of index or table */
81507 ){
81508 static const char *azStatTab[] = {
81509 "sqlite_stat1",
81510 "sqlite_stat2",
81511 "sqlite_stat3",
81512 };
81513 int i;
81514 const char *zDbName = pParse->db->aDb[iDb].zName;
81515 for(i=0; i<ArraySize(azStatTab); i++){
81516 if( sqlite3FindTable(pParse->db, azStatTab[i], zDbName) ){
81517 sqlite3NestedParse(pParse,
@@ -81132,10 +81519,80 @@
81519 zDbName, azStatTab[i], zType, zName
81520 );
81521 }
81522 }
81523 }
81524
81525 /*
81526 ** Generate code to drop a table.
81527 */
81528 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
81529 Vdbe *v;
81530 sqlite3 *db = pParse->db;
81531 Trigger *pTrigger;
81532 Db *pDb = &db->aDb[iDb];
81533
81534 v = sqlite3GetVdbe(pParse);
81535 assert( v!=0 );
81536 sqlite3BeginWriteOperation(pParse, 1, iDb);
81537
81538 #ifndef SQLITE_OMIT_VIRTUALTABLE
81539 if( IsVirtual(pTab) ){
81540 sqlite3VdbeAddOp0(v, OP_VBegin);
81541 }
81542 #endif
81543
81544 /* Drop all triggers associated with the table being dropped. Code
81545 ** is generated to remove entries from sqlite_master and/or
81546 ** sqlite_temp_master if required.
81547 */
81548 pTrigger = sqlite3TriggerList(pParse, pTab);
81549 while( pTrigger ){
81550 assert( pTrigger->pSchema==pTab->pSchema ||
81551 pTrigger->pSchema==db->aDb[1].pSchema );
81552 sqlite3DropTriggerPtr(pParse, pTrigger);
81553 pTrigger = pTrigger->pNext;
81554 }
81555
81556 #ifndef SQLITE_OMIT_AUTOINCREMENT
81557 /* Remove any entries of the sqlite_sequence table associated with
81558 ** the table being dropped. This is done before the table is dropped
81559 ** at the btree level, in case the sqlite_sequence table needs to
81560 ** move as a result of the drop (can happen in auto-vacuum mode).
81561 */
81562 if( pTab->tabFlags & TF_Autoincrement ){
81563 sqlite3NestedParse(pParse,
81564 "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
81565 pDb->zName, pTab->zName
81566 );
81567 }
81568 #endif
81569
81570 /* Drop all SQLITE_MASTER table and index entries that refer to the
81571 ** table. The program name loops through the master table and deletes
81572 ** every row that refers to a table of the same name as the one being
81573 ** dropped. Triggers are handled seperately because a trigger can be
81574 ** created in the temp database that refers to a table in another
81575 ** database.
81576 */
81577 sqlite3NestedParse(pParse,
81578 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
81579 pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
81580 if( !isView && !IsVirtual(pTab) ){
81581 destroyTable(pParse, pTab);
81582 }
81583
81584 /* Remove the table entry from SQLite's internal schema and modify
81585 ** the schema cookie.
81586 */
81587 if( IsVirtual(pTab) ){
81588 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
81589 }
81590 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
81591 sqlite3ChangeCookie(pParse, iDb);
81592 sqliteViewResetAll(db, iDb);
81593 }
81594
81595 /*
81596 ** This routine is called to do the work of a DROP TABLE statement.
81597 ** pName is the name of the table to be dropped.
81598 */
@@ -81225,72 +81682,15 @@
81682 /* Generate code to remove the table from the master table
81683 ** on disk.
81684 */
81685 v = sqlite3GetVdbe(pParse);
81686 if( v ){
 
 
81687 sqlite3BeginWriteOperation(pParse, 1, iDb);
81688 sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName);
 
 
 
 
 
81689 sqlite3FkDropTable(pParse, pName, pTab);
81690 sqlite3CodeDropTable(pParse, pTab, iDb, isView);
81691 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81692
81693 exit_drop_table:
81694 sqlite3SrcListDelete(db, pName);
81695 }
81696
@@ -81769,24 +82169,24 @@
82169 */
82170 nName = sqlite3Strlen30(zName);
82171 nCol = pList->nExpr;
82172 pIndex = sqlite3DbMallocZero(db,
82173 sizeof(Index) + /* Index structure */
82174 sizeof(tRowcnt)*(nCol+1) + /* Index.aiRowEst */
82175 sizeof(int)*nCol + /* Index.aiColumn */
 
82176 sizeof(char *)*nCol + /* Index.azColl */
82177 sizeof(u8)*nCol + /* Index.aSortOrder */
82178 nName + 1 + /* Index.zName */
82179 nExtra /* Collation sequence names */
82180 );
82181 if( db->mallocFailed ){
82182 goto exit_create_index;
82183 }
82184 pIndex->aiRowEst = (tRowcnt*)(&pIndex[1]);
82185 pIndex->azColl = (char**)(&pIndex->aiRowEst[nCol+1]);
82186 pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
82187 pIndex->aSortOrder = (u8 *)(&pIndex->aiColumn[nCol]);
 
82188 pIndex->zName = (char *)(&pIndex->aSortOrder[nCol]);
82189 zExtra = (char *)(&pIndex->zName[nName+1]);
82190 memcpy(pIndex->zName, zName, nName+1);
82191 pIndex->pTable = pTab;
82192 pIndex->nColumn = pList->nExpr;
@@ -82059,13 +82459,13 @@
82459 ** Apart from that, we have little to go on besides intuition as to
82460 ** how aiRowEst[] should be initialized. The numbers generated here
82461 ** are based on typical values found in actual indices.
82462 */
82463 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
82464 tRowcnt *a = pIdx->aiRowEst;
82465 int i;
82466 tRowcnt n;
82467 assert( a!=0 );
82468 a[0] = pIdx->pTable->nRowEst;
82469 if( a[0]<10 ) a[0] = 10;
82470 n = 10;
82471 for(i=1; i<=pIdx->nColumn; i++){
@@ -82932,10 +83332,11 @@
83332 return pKey;
83333 }
83334
83335 /************** End of build.c ***********************************************/
83336 /************** Begin file callback.c ****************************************/
83337 #line 1 "tsrc/callback.c"
83338 /*
83339 ** 2005 May 23
83340 **
83341 ** The author disclaims copyright to this source code. In place of
83342 ** a legal notice, here is a blessing:
@@ -83391,10 +83792,11 @@
83792 return p;
83793 }
83794
83795 /************** End of callback.c ********************************************/
83796 /************** Begin file delete.c ******************************************/
83797 #line 1 "tsrc/delete.c"
83798 /*
83799 ** 2001 September 15
83800 **
83801 ** The author disclaims copyright to this source code. In place of
83802 ** a legal notice, here is a blessing:
@@ -84045,10 +84447,11 @@
84447 return regBase;
84448 }
84449
84450 /************** End of delete.c **********************************************/
84451 /************** Begin file func.c ********************************************/
84452 #line 1 "tsrc/func.c"
84453 /*
84454 ** 2002 February 23
84455 **
84456 ** The author disclaims copyright to this source code. In place of
84457 ** a legal notice, here is a blessing:
@@ -85653,10 +86056,11 @@
86056 #endif
86057 }
86058
86059 /************** End of func.c ************************************************/
86060 /************** Begin file fkey.c ********************************************/
86061 #line 1 "tsrc/fkey.c"
86062 /*
86063 **
86064 ** The author disclaims copyright to this source code. In place of
86065 ** a legal notice, here is a blessing:
86066 **
@@ -86873,10 +87277,11 @@
87277 }
87278 #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */
87279
87280 /************** End of fkey.c ************************************************/
87281 /************** Begin file insert.c ******************************************/
87282 #line 1 "tsrc/insert.c"
87283 /*
87284 ** 2001 September 15
87285 **
87286 ** The author disclaims copyright to this source code. In place of
87287 ** a legal notice, here is a blessing:
@@ -88621,10 +89026,13 @@
89026 */
89027 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
89028 return 0;
89029 }
89030 #endif
89031 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
89032 return 0;
89033 }
89034
89035 /* If we get this far, it means either:
89036 **
89037 ** * We can always do the transfer if the table contains an
89038 ** an integer primary key
@@ -88718,10 +89126,11 @@
89126 }
89127 #endif /* SQLITE_OMIT_XFER_OPT */
89128
89129 /************** End of insert.c **********************************************/
89130 /************** Begin file legacy.c ******************************************/
89131 #line 1 "tsrc/legacy.c"
89132 /*
89133 ** 2001 September 15
89134 **
89135 ** The author disclaims copyright to this source code. In place of
89136 ** a legal notice, here is a blessing:
@@ -88865,10 +89274,11 @@
89274 return rc;
89275 }
89276
89277 /************** End of legacy.c **********************************************/
89278 /************** Begin file loadext.c *****************************************/
89279 #line 1 "tsrc/loadext.c"
89280 /*
89281 ** 2006 June 7
89282 **
89283 ** The author disclaims copyright to this source code. In place of
89284 ** a legal notice, here is a blessing:
@@ -88885,10 +89295,11 @@
89295 #ifndef SQLITE_CORE
89296 #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
89297 #endif
89298 /************** Include sqlite3ext.h in the middle of loadext.c **************/
89299 /************** Begin file sqlite3ext.h **************************************/
89300 #line 1 "tsrc/sqlite3ext.h"
89301 /*
89302 ** 2006 June 7
89303 **
89304 ** The author disclaims copyright to this source code. In place of
89305 ** a legal notice, here is a blessing:
@@ -89313,10 +89724,11 @@
89724
89725 #endif /* _SQLITE3EXT_H_ */
89726
89727 /************** End of sqlite3ext.h ******************************************/
89728 /************** Continuing where we left off in loadext.c ********************/
89729 #line 20 "tsrc/loadext.c"
89730 /* #include <string.h> */
89731
89732 #ifndef SQLITE_OMIT_LOAD_EXTENSION
89733
89734 /*
@@ -89952,10 +90364,11 @@
90364 }
90365 }
90366
90367 /************** End of loadext.c *********************************************/
90368 /************** Begin file pragma.c ******************************************/
90369 #line 1 "tsrc/pragma.c"
90370 /*
90371 ** 2003 April 6
90372 **
90373 ** The author disclaims copyright to this source code. In place of
90374 ** a legal notice, here is a blessing:
@@ -91480,10 +91893,11 @@
91893
91894 #endif /* SQLITE_OMIT_PRAGMA */
91895
91896 /************** End of pragma.c **********************************************/
91897 /************** Begin file prepare.c *****************************************/
91898 #line 1 "tsrc/prepare.c"
91899 /*
91900 ** 2005 May 25
91901 **
91902 ** The author disclaims copyright to this source code. In place of
91903 ** a legal notice, here is a blessing:
@@ -92340,10 +92754,11 @@
92754
92755 #endif /* SQLITE_OMIT_UTF16 */
92756
92757 /************** End of prepare.c *********************************************/
92758 /************** Begin file select.c ******************************************/
92759 #line 1 "tsrc/select.c"
92760 /*
92761 ** 2001 September 15
92762 **
92763 ** The author disclaims copyright to this source code. In place of
92764 ** a legal notice, here is a blessing:
@@ -96928,10 +97343,11 @@
97343 *****************************************************************************/
97344 #endif /* defined(SQLITE_TEST) || defined(SQLITE_DEBUG) */
97345
97346 /************** End of select.c **********************************************/
97347 /************** Begin file table.c *******************************************/
97348 #line 1 "tsrc/table.c"
97349 /*
97350 ** 2001 September 15
97351 **
97352 ** The author disclaims copyright to this source code. In place of
97353 ** a legal notice, here is a blessing:
@@ -97127,10 +97543,11 @@
97543
97544 #endif /* SQLITE_OMIT_GET_TABLE */
97545
97546 /************** End of table.c ***********************************************/
97547 /************** Begin file trigger.c *****************************************/
97548 #line 1 "tsrc/trigger.c"
97549 /*
97550 **
97551 ** The author disclaims copyright to this source code. In place of
97552 ** a legal notice, here is a blessing:
97553 **
@@ -98252,10 +98669,11 @@
98669
98670 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
98671
98672 /************** End of trigger.c *********************************************/
98673 /************** Begin file update.c ******************************************/
98674 #line 1 "tsrc/update.c"
98675 /*
98676 ** 2001 September 15
98677 **
98678 ** The author disclaims copyright to this source code. In place of
98679 ** a legal notice, here is a blessing:
@@ -98924,10 +99342,11 @@
99342 }
99343 #endif /* SQLITE_OMIT_VIRTUALTABLE */
99344
99345 /************** End of update.c **********************************************/
99346 /************** Begin file vacuum.c ******************************************/
99347 #line 1 "tsrc/vacuum.c"
99348 /*
99349 ** 2003 April 6
99350 **
99351 ** The author disclaims copyright to this source code. In place of
99352 ** a legal notice, here is a blessing:
@@ -98969,11 +99388,11 @@
99388 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
99389 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
99390 return sqlite3_errcode(db);
99391 }
99392 VVA_ONLY( rc = ) sqlite3_step(pStmt);
99393 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
99394 return vacuumFinalize(db, pStmt, pzErrMsg);
99395 }
99396
99397 /*
99398 ** Execute zSql on database db. The statement returns exactly
@@ -99187,17 +99606,15 @@
99606 " WHERE type='view' OR type='trigger'"
99607 " OR (type='table' AND rootpage=0)"
99608 );
99609 if( rc ) goto end_of_vacuum;
99610
99611 /* At this point, there is a write transaction open on both the
99612 ** vacuum database and the main database. Assuming no error occurs,
99613 ** both transactions are closed by this block - the main database
99614 ** transaction by sqlite3BtreeCopyFile() and the other by an explicit
99615 ** call to sqlite3BtreeCommit().
 
 
99616 */
99617 {
99618 u32 meta;
99619 int i;
99620
@@ -99270,10 +99687,11 @@
99687
99688 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
99689
99690 /************** End of vacuum.c **********************************************/
99691 /************** Begin file vtab.c ********************************************/
99692 #line 1 "tsrc/vtab.c"
99693 /*
99694 ** 2006 June 10
99695 **
99696 ** The author disclaims copyright to this source code. In place of
99697 ** a legal notice, here is a blessing:
@@ -100338,10 +100756,11 @@
100756
100757 #endif /* SQLITE_OMIT_VIRTUALTABLE */
100758
100759 /************** End of vtab.c ************************************************/
100760 /************** Begin file where.c *******************************************/
100761 #line 1 "tsrc/where.c"
100762 /*
100763 ** 2001 September 15
100764 **
100765 ** The author disclaims copyright to this source code. In place of
100766 ** a legal notice, here is a blessing:
@@ -100457,25 +100876,35 @@
100876 #define TERM_CODED 0x04 /* This term is already coded */
100877 #define TERM_COPIED 0x08 /* Has a child */
100878 #define TERM_ORINFO 0x10 /* Need to free the WhereTerm.u.pOrInfo object */
100879 #define TERM_ANDINFO 0x20 /* Need to free the WhereTerm.u.pAndInfo obj */
100880 #define TERM_OR_OK 0x40 /* Used during OR-clause processing */
100881 #ifdef SQLITE_ENABLE_STAT3
100882 # define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
100883 #else
100884 # define TERM_VNULL 0x00 /* Disabled if not using stat3 */
100885 #endif
100886
100887 /*
100888 ** An instance of the following structure holds all information about a
100889 ** WHERE clause. Mostly this is a container for one or more WhereTerms.
100890 **
100891 ** Explanation of pOuter: For a WHERE clause of the form
100892 **
100893 ** a AND ((b AND c) OR (d AND e)) AND f
100894 **
100895 ** There are separate WhereClause objects for the whole clause and for
100896 ** the subclauses "(b AND c)" and "(d AND e)". The pOuter field of the
100897 ** subclauses points to the WhereClause object for the whole clause.
100898 */
100899 struct WhereClause {
100900 Parse *pParse; /* The parser context */
100901 WhereMaskSet *pMaskSet; /* Mapping of table cursor numbers to bitmasks */
100902 Bitmask vmask; /* Bitmask identifying virtual table cursors */
100903 WhereClause *pOuter; /* Outer conjunction */
100904 u8 op; /* Split operator. TK_AND or TK_OR */
100905 u16 wctrlFlags; /* Might include WHERE_AND_ONLY */
100906 int nTerm; /* Number of terms */
100907 int nSlot; /* Number of entries in a[] */
100908 WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
100909 #if defined(SQLITE_SMALL_STACK)
100910 WhereTerm aStatic[1]; /* Initial static space for a[] */
@@ -100600,18 +101029,21 @@
101029 ** Initialize a preallocated WhereClause structure.
101030 */
101031 static void whereClauseInit(
101032 WhereClause *pWC, /* The WhereClause to be initialized */
101033 Parse *pParse, /* The parsing context */
101034 WhereMaskSet *pMaskSet, /* Mapping from table cursor numbers to bitmasks */
101035 u16 wctrlFlags /* Might include WHERE_AND_ONLY */
101036 ){
101037 pWC->pParse = pParse;
101038 pWC->pMaskSet = pMaskSet;
101039 pWC->pOuter = 0;
101040 pWC->nTerm = 0;
101041 pWC->nSlot = ArraySize(pWC->aStatic);
101042 pWC->a = pWC->aStatic;
101043 pWC->vmask = 0;
101044 pWC->wctrlFlags = wctrlFlags;
101045 }
101046
101047 /* Forward reference */
101048 static void whereClauseClear(WhereClause*);
101049
@@ -100923,40 +101355,42 @@
101355 ){
101356 WhereTerm *pTerm;
101357 int k;
101358 assert( iCur>=0 );
101359 op &= WO_ALL;
101360 for(; pWC; pWC=pWC->pOuter){
101361 for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
101362 if( pTerm->leftCursor==iCur
101363 && (pTerm->prereqRight & notReady)==0
101364 && pTerm->u.leftColumn==iColumn
101365 && (pTerm->eOperator & op)!=0
101366 ){
101367 if( pIdx && pTerm->eOperator!=WO_ISNULL ){
101368 Expr *pX = pTerm->pExpr;
101369 CollSeq *pColl;
101370 char idxaff;
101371 int j;
101372 Parse *pParse = pWC->pParse;
101373
101374 idxaff = pIdx->pTable->aCol[iColumn].affinity;
101375 if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue;
101376
101377 /* Figure out the collation sequence required from an index for
101378 ** it to be useful for optimising expression pX. Store this
101379 ** value in variable pColl.
101380 */
101381 assert(pX->pLeft);
101382 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
101383 assert(pColl || pParse->nErr);
101384
101385 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
101386 if( NEVER(j>=pIdx->nColumn) ) return 0;
101387 }
101388 if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
101389 }
101390 return pTerm;
101391 }
101392 }
101393 }
101394 return 0;
101395 }
101396
@@ -101216,11 +101650,11 @@
101650 assert( pExpr->op==TK_OR );
101651 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
101652 if( pOrInfo==0 ) return;
101653 pTerm->wtFlags |= TERM_ORINFO;
101654 pOrWc = &pOrInfo->wc;
101655 whereClauseInit(pOrWc, pWC->pParse, pMaskSet, pWC->wctrlFlags);
101656 whereSplit(pOrWc, pExpr, TK_OR);
101657 exprAnalyzeAll(pSrc, pOrWc);
101658 if( db->mallocFailed ) return;
101659 assert( pOrWc->nTerm>=2 );
101660
@@ -101243,13 +101677,14 @@
101677 Bitmask b = 0;
101678 pOrTerm->u.pAndInfo = pAndInfo;
101679 pOrTerm->wtFlags |= TERM_ANDINFO;
101680 pOrTerm->eOperator = WO_AND;
101681 pAndWC = &pAndInfo->wc;
101682 whereClauseInit(pAndWC, pWC->pParse, pMaskSet, pWC->wctrlFlags);
101683 whereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
101684 exprAnalyzeAll(pSrc, pAndWC);
101685 pAndWC->pOuter = pWC;
101686 testcase( db->mallocFailed );
101687 if( !db->mallocFailed ){
101688 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
101689 assert( pAndTerm->pExpr );
101690 if( allowedOp(pAndTerm->pExpr->op) ){
@@ -101679,12 +102114,12 @@
102114 pNewTerm->prereqAll = pTerm->prereqAll;
102115 }
102116 }
102117 #endif /* SQLITE_OMIT_VIRTUALTABLE */
102118
102119 #ifdef SQLITE_ENABLE_STAT3
102120 /* When sqlite_stat3 histogram data is available an operator of the
102121 ** form "x IS NOT NULL" can sometimes be evaluated more efficiently
102122 ** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
102123 ** virtual term of that form.
102124 **
102125 ** Note that the virtual term must be tagged with TERM_VNULL. This
@@ -101718,11 +102153,11 @@
102153 pTerm->nChild = 1;
102154 pTerm->wtFlags |= TERM_COPIED;
102155 pNewTerm->prereqAll = pTerm->prereqAll;
102156 }
102157 }
102158 #endif /* SQLITE_ENABLE_STAT */
102159
102160 /* Prevent ON clause terms of a LEFT JOIN from being used to drive
102161 ** an index for tables to the left of the join.
102162 */
102163 pTerm->prereqRight |= extraRight;
@@ -102140,14 +102575,17 @@
102575 const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
102576 const Bitmask maskSrc = getMask(pWC->pMaskSet, iCur); /* Bitmask for pSrc */
102577 WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */
102578 WhereTerm *pTerm; /* A single term of the WHERE clause */
102579
102580 /* The OR-clause optimization is disallowed if the INDEXED BY or
102581 ** NOT INDEXED clauses are used or if the WHERE_AND_ONLY bit is set. */
102582 if( pSrc->notIndexed || pSrc->pIndex!=0 ){
102583 return;
102584 }
102585 if( pWC->wctrlFlags & WHERE_AND_ONLY ){
102586 return;
102587 }
102588
102589 /* Search the WHERE clause terms for a usable WO_OR term. */
102590 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
102591 if( pTerm->eOperator==WO_OR
@@ -102172,10 +102610,11 @@
102610 bestIndex(pParse, pAndWC, pSrc, notReady, notValid, 0, &sTermCost);
102611 }else if( pOrTerm->leftCursor==iCur ){
102612 WhereClause tempWC;
102613 tempWC.pParse = pWC->pParse;
102614 tempWC.pMaskSet = pWC->pMaskSet;
102615 tempWC.pOuter = pWC;
102616 tempWC.op = TK_AND;
102617 tempWC.a = pOrTerm;
102618 tempWC.nTerm = 1;
102619 bestIndex(pParse, &tempWC, pSrc, notReady, notValid, 0, &sTermCost);
102620 }else{
@@ -102766,71 +103205,90 @@
103205 */
103206 bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
103207 }
103208 #endif /* SQLITE_OMIT_VIRTUALTABLE */
103209
103210 #ifdef SQLITE_ENABLE_STAT3
103211 /*
103212 ** Estimate the location of a particular key among all keys in an
103213 ** index. Store the results in aStat as follows:
103214 **
103215 ** aStat[0] Est. number of rows less than pVal
103216 ** aStat[1] Est. number of rows equal to pVal
103217 **
103218 ** Return SQLITE_OK on success.
103219 */
103220 static int whereKeyStats(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103221 Parse *pParse, /* Database connection */
103222 Index *pIdx, /* Index to consider domain of */
103223 sqlite3_value *pVal, /* Value to consider */
103224 int roundUp, /* Round up if true. Round down if false */
103225 tRowcnt *aStat /* OUT: stats written here */
103226 ){
103227 tRowcnt n;
103228 IndexSample *aSample;
103229 int i, eType;
103230 int isEq = 0;
103231 i64 v;
103232 double r, rS;
103233
103234 assert( roundUp==0 || roundUp==1 );
103235 assert( pIdx->nSample>0 );
103236 if( pVal==0 ) return SQLITE_ERROR;
103237 n = pIdx->aiRowEst[0];
103238 aSample = pIdx->aSample;
103239 i = 0;
103240 eType = sqlite3_value_type(pVal);
103241
103242 if( eType==SQLITE_INTEGER ){
103243 v = sqlite3_value_int64(pVal);
103244 r = (i64)v;
103245 for(i=0; i<pIdx->nSample; i++){
103246 if( aSample[i].eType==SQLITE_NULL ) continue;
103247 if( aSample[i].eType>=SQLITE_TEXT ) break;
103248 if( aSample[i].eType==SQLITE_INTEGER ){
103249 if( aSample[i].u.i>=v ){
103250 isEq = aSample[i].u.i==v;
103251 break;
103252 }
103253 }else{
103254 assert( aSample[i].eType==SQLITE_FLOAT );
103255 if( aSample[i].u.r>=r ){
103256 isEq = aSample[i].u.r==r;
103257 break;
103258 }
103259 }
103260 }
103261 }else if( eType==SQLITE_FLOAT ){
103262 r = sqlite3_value_double(pVal);
103263 for(i=0; i<pIdx->nSample; i++){
103264 if( aSample[i].eType==SQLITE_NULL ) continue;
103265 if( aSample[i].eType>=SQLITE_TEXT ) break;
103266 if( aSample[i].eType==SQLITE_FLOAT ){
103267 rS = aSample[i].u.r;
103268 }else{
103269 rS = aSample[i].u.i;
103270 }
103271 if( rS>=r ){
103272 isEq = rS==r;
103273 break;
103274 }
103275 }
103276 }else if( eType==SQLITE_NULL ){
103277 i = 0;
103278 if( aSample[0].eType==SQLITE_NULL ) isEq = 1;
103279 }else{
103280 assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
103281 for(i=0; i<pIdx->nSample; i++){
103282 if( aSample[i].eType==SQLITE_TEXT || aSample[i].eType==SQLITE_BLOB ){
103283 break;
103284 }
103285 }
103286 if( i<pIdx->nSample ){
103287 sqlite3 *db = pParse->db;
103288 CollSeq *pColl;
103289 const u8 *z;
 
 
 
 
 
103290 if( eType==SQLITE_BLOB ){
103291 z = (const u8 *)sqlite3_value_blob(pVal);
103292 pColl = db->pDfltColl;
103293 assert( pColl->enc==SQLITE_UTF8 );
103294 }else{
@@ -102845,16 +103303,16 @@
103303 return SQLITE_NOMEM;
103304 }
103305 assert( z && pColl && pColl->xCmp );
103306 }
103307 n = sqlite3ValueBytes(pVal, pColl->enc);
103308
103309 for(; i<pIdx->nSample; i++){
103310 int c;
103311 int eSampletype = aSample[i].eType;
103312 if( eSampletype<eType ) continue;
103313 if( eSampletype!=eType ) break;
103314 #ifndef SQLITE_OMIT_UTF16
103315 if( pColl->enc!=SQLITE_UTF8 ){
103316 int nSample;
103317 char *zSample = sqlite3Utf8to16(
103318 db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
@@ -102868,20 +103326,51 @@
103326 }else
103327 #endif
103328 {
103329 c = pColl->xCmp(pColl->pUser, aSample[i].nByte, aSample[i].u.z, n, z);
103330 }
103331 if( c>=0 ){
103332 if( c==0 ) isEq = 1;
103333 break;
103334 }
103335 }
103336 }
103337 }
103338
103339 /* At this point, aSample[i] is the first sample that is greater than
103340 ** or equal to pVal. Or if i==pIdx->nSample, then all samples are less
103341 ** than pVal. If aSample[i]==pVal, then isEq==1.
103342 */
103343 if( isEq ){
103344 assert( i<pIdx->nSample );
103345 aStat[0] = aSample[i].nLt;
103346 aStat[1] = aSample[i].nEq;
103347 }else{
103348 tRowcnt iLower, iUpper, iGap;
103349 if( i==0 ){
103350 iLower = 0;
103351 iUpper = aSample[0].nLt;
103352 }else{
103353 iUpper = i>=pIdx->nSample ? n : aSample[i].nLt;
103354 iLower = aSample[i-1].nEq + aSample[i-1].nLt;
103355 }
103356 aStat[1] = pIdx->avgEq;
103357 if( iLower>=iUpper ){
103358 iGap = 0;
103359 }else{
103360 iGap = iUpper - iLower;
103361 }
103362 if( roundUp ){
103363 iGap = (iGap*2)/3;
103364 }else{
103365 iGap = iGap/3;
103366 }
103367 aStat[0] = iLower + iGap;
103368 }
103369 return SQLITE_OK;
103370 }
103371 #endif /* SQLITE_ENABLE_STAT3 */
103372
103373 /*
103374 ** If expression pExpr represents a literal value, set *pp to point to
103375 ** an sqlite3_value structure containing the same value, with affinity
103376 ** aff applied to it, before returning. It is the responsibility of the
@@ -102895,11 +103384,11 @@
103384 **
103385 ** If neither of the above apply, set *pp to NULL.
103386 **
103387 ** If an error occurs, return an error code. Otherwise, SQLITE_OK.
103388 */
103389 #ifdef SQLITE_ENABLE_STAT3
103390 static int valueFromExpr(
103391 Parse *pParse,
103392 Expr *pExpr,
103393 u8 aff,
103394 sqlite3_value **pp
@@ -102943,106 +103432,92 @@
103432 **
103433 ** ... FROM t1 WHERE a > ? AND a < ? ...
103434 **
103435 ** then nEq should be passed 0.
103436 **
103437 ** The returned value is an integer divisor to reduce the estimated
103438 ** search space. A return value of 1 means that range constraints are
103439 ** no help at all. A return value of 2 means range constraints are
103440 ** expected to reduce the search space by half. And so forth...
 
 
103441 **
103442 ** In the absence of sqlite_stat3 ANALYZE data, each range inequality
103443 ** reduces the search space by a factor of 4. Hence a single constraint (x>?)
103444 ** results in a return of 4 and a range constraint (x>? AND x<?) results
103445 ** in a return of 16.
103446 */
103447 static int whereRangeScanEst(
103448 Parse *pParse, /* Parsing & code generating context */
103449 Index *p, /* The index containing the range-compared column; "x" */
103450 int nEq, /* index into p->aCol[] of the range-compared column */
103451 WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */
103452 WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
103453 double *pRangeDiv /* OUT: Reduce search space by this divisor */
103454 ){
103455 int rc = SQLITE_OK;
103456
103457 #ifdef SQLITE_ENABLE_STAT3
103458
103459 if( nEq==0 && p->nSample ){
103460 sqlite3_value *pRangeVal;
103461 tRowcnt iLower = 0;
103462 tRowcnt iUpper = p->aiRowEst[0];
103463 tRowcnt a[2];
 
 
 
103464 u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
103465
103466 if( pLower ){
103467 Expr *pExpr = pLower->pExpr->pRight;
103468 rc = valueFromExpr(pParse, pExpr, aff, &pRangeVal);
103469 assert( pLower->eOperator==WO_GT || pLower->eOperator==WO_GE );
103470 if( rc==SQLITE_OK
103471 && whereKeyStats(pParse, p, pRangeVal, 0, a)==SQLITE_OK
103472 ){
103473 iLower = a[0];
103474 if( pLower->eOperator==WO_GT ) iLower += a[1];
103475 }
103476 sqlite3ValueFree(pRangeVal);
103477 }
103478 if( rc==SQLITE_OK && pUpper ){
103479 Expr *pExpr = pUpper->pExpr->pRight;
103480 rc = valueFromExpr(pParse, pExpr, aff, &pRangeVal);
103481 assert( pUpper->eOperator==WO_LT || pUpper->eOperator==WO_LE );
103482 if( rc==SQLITE_OK
103483 && whereKeyStats(pParse, p, pRangeVal, 1, a)==SQLITE_OK
103484 ){
103485 iUpper = a[0];
103486 if( pUpper->eOperator==WO_LE ) iUpper += a[1];
103487 }
103488 sqlite3ValueFree(pRangeVal);
103489 }
103490 if( rc==SQLITE_OK ){
103491 if( iUpper<=iLower ){
103492 *pRangeDiv = (double)p->aiRowEst[0];
103493 }else{
103494 *pRangeDiv = (double)p->aiRowEst[0]/(double)(iUpper - iLower);
103495 }
103496 WHERETRACE(("range scan regions: %u..%u div=%g\n",
103497 (u32)iLower, (u32)iUpper, *pRangeDiv));
103498 return SQLITE_OK;
103499 }
103500 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103501 #else
103502 UNUSED_PARAMETER(pParse);
103503 UNUSED_PARAMETER(p);
103504 UNUSED_PARAMETER(nEq);
103505 #endif
103506 assert( pLower || pUpper );
103507 *pRangeDiv = (double)1;
103508 if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ) *pRangeDiv *= (double)4;
103509 if( pUpper ) *pRangeDiv *= (double)4;
103510 return rc;
103511 }
103512
103513 #ifdef SQLITE_ENABLE_STAT3
103514 /*
103515 ** Estimate the number of rows that will be returned based on
103516 ** an equality constraint x=VALUE and where that VALUE occurs in
103517 ** the histogram data. This only works when x is the left-most
103518 ** column of an index and sqlite_stat3 histogram data is available
103519 ** for that index. When pExpr==NULL that means the constraint is
103520 ** "x IS NULL" instead of "x=VALUE".
103521 **
103522 ** Write the estimated row count into *pnRow and return SQLITE_OK.
103523 ** If unable to make an estimate, leave *pnRow unchanged and return
@@ -103058,44 +103533,36 @@
103533 Index *p, /* The index whose left-most column is pTerm */
103534 Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
103535 double *pnRow /* Write the revised row estimate here */
103536 ){
103537 sqlite3_value *pRhs = 0; /* VALUE on right-hand side of pTerm */
 
103538 u8 aff; /* Column affinity */
103539 int rc; /* Subfunction return code */
103540 tRowcnt a[2]; /* Statistics */
103541
103542 assert( p->aSample!=0 );
103543 assert( p->nSample>0 );
103544 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
103545 if( pExpr ){
103546 rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
103547 if( rc ) goto whereEqualScanEst_cancel;
103548 }else{
103549 pRhs = sqlite3ValueNew(pParse->db);
103550 }
103551 if( pRhs==0 ) return SQLITE_NOTFOUND;
103552 rc = whereKeyStats(pParse, p, pRhs, 0, a);
103553 if( rc==SQLITE_OK ){
103554 WHERETRACE(("equality scan regions: %d\n", (int)a[1]));
103555 *pnRow = a[1];
103556 }
 
 
 
 
 
 
 
 
103557 whereEqualScanEst_cancel:
103558 sqlite3ValueFree(pRhs);
103559 return rc;
103560 }
103561 #endif /* defined(SQLITE_ENABLE_STAT3) */
103562
103563 #ifdef SQLITE_ENABLE_STAT3
103564 /*
103565 ** Estimate the number of rows that will be returned based on
103566 ** an IN constraint where the right-hand side of the IN operator
103567 ** is a list of values. Example:
103568 **
@@ -103114,64 +103581,29 @@
103581 Parse *pParse, /* Parsing & code generating context */
103582 Index *p, /* The index whose left-most column is pTerm */
103583 ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
103584 double *pnRow /* Write the revised row estimate here */
103585 ){
103586 int rc = SQLITE_OK; /* Subfunction return code */
103587 double nEst; /* Number of rows for a single term */
103588 double nRowEst = (double)0; /* New estimate of the number of rows */
103589 int i; /* Loop counter */
 
 
 
 
 
 
 
103590
103591 assert( p->aSample!=0 );
103592 for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){
103593 nEst = p->aiRowEst[0];
103594 rc = whereEqualScanEst(pParse, p, pList->a[i].pExpr, &nEst);
103595 nRowEst += nEst;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103596 }
103597 if( rc==SQLITE_OK ){
 
 
 
 
 
 
 
 
 
103598 if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
103599 *pnRow = nRowEst;
103600 WHERETRACE(("IN row estimate: est=%g\n", nRowEst));
 
103601 }
 
103602 return rc;
103603 }
103604 #endif /* defined(SQLITE_ENABLE_STAT3) */
103605
103606
103607 /*
103608 ** Find the best query plan for accessing a particular table. Write the
103609 ** best query plan and its cost into the WhereCost object supplied as the
@@ -103214,11 +103646,11 @@
103646 Index *pProbe; /* An index we are evaluating */
103647 Index *pIdx; /* Copy of pProbe, or zero for IPK index */
103648 int eqTermMask; /* Current mask of valid equality operators */
103649 int idxEqTermMask; /* Index mask of valid equality operators */
103650 Index sPk; /* A fake index object for the primary key */
103651 tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
103652 int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
103653 int wsFlagMask; /* Allowed flags in pCost->plan.wsFlag */
103654
103655 /* Initialize the cost to a worst-case value */
103656 memset(pCost, 0, sizeof(*pCost));
@@ -103269,14 +103701,14 @@
103701 }
103702
103703 /* Loop over all indices looking for the best one to use
103704 */
103705 for(; pProbe; pIdx=pProbe=pProbe->pNext){
103706 const tRowcnt * const aiRowEst = pProbe->aiRowEst;
103707 double cost; /* Cost of using pProbe */
103708 double nRow; /* Estimated number of rows in result set */
103709 double log10N = (double)1; /* base-10 logarithm of nRow (inexact) */
103710 int rev; /* True to scan in reverse order */
103711 int wsFlags = 0;
103712 Bitmask used = 0;
103713
103714 /* The following variables are populated based on the properties of
@@ -103312,18 +103744,16 @@
103744 ** Set to true if there was at least one "x IN (SELECT ...)" term used
103745 ** in determining the value of nInMul. Note that the RHS of the
103746 ** IN operator must be a SELECT, not a value list, for this variable
103747 ** to be true.
103748 **
103749 ** rangeDiv:
103750 ** An estimate of a divisor by which to reduce the search space due
103751 ** to inequality constraints. In the absence of sqlite_stat3 ANALYZE
103752 ** data, a single inequality reduces the search space to 1/4rd its
103753 ** original size (rangeDiv==4). Two inequalities reduce the search
103754 ** space to 1/16th of its original size (rangeDiv==16).
 
 
103755 **
103756 ** bSort:
103757 ** Boolean. True if there is an ORDER BY clause that will require an
103758 ** external sort (i.e. scanning the index being evaluated will not
103759 ** correctly order records).
@@ -103344,26 +103774,27 @@
103774 ** SELECT a, b, c FROM tbl WHERE a = 1;
103775 */
103776 int nEq; /* Number of == or IN terms matching index */
103777 int bInEst = 0; /* True if "x IN (SELECT...)" seen */
103778 int nInMul = 1; /* Number of distinct equalities to lookup */
103779 double rangeDiv = (double)1; /* Estimated reduction in search space */
103780 int nBound = 0; /* Number of range constraints seen */
103781 int bSort = !!pOrderBy; /* True if external sort required */
103782 int bDist = !!pDistinct; /* True if index cannot help with DISTINCT */
103783 int bLookup = 0; /* True if not a covering index */
103784 WhereTerm *pTerm; /* A single term of the WHERE clause */
103785 #ifdef SQLITE_ENABLE_STAT3
103786 WhereTerm *pFirstTerm = 0; /* First term matching the index */
103787 #endif
103788
103789 /* Determine the values of nEq and nInMul */
103790 for(nEq=0; nEq<pProbe->nColumn; nEq++){
103791 int j = pProbe->aiColumn[nEq];
103792 pTerm = findTerm(pWC, iCur, j, notReady, eqTermMask, pIdx);
103793 if( pTerm==0 ) break;
103794 wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
103795 testcase( pTerm->pWC!=pWC );
103796 if( pTerm->eOperator & WO_IN ){
103797 Expr *pExpr = pTerm->pExpr;
103798 wsFlags |= WHERE_COLUMN_IN;
103799 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
103800 /* "x IN (SELECT ...)": Assume the SELECT returns 25 rows */
@@ -103374,32 +103805,34 @@
103805 nInMul *= pExpr->x.pList->nExpr;
103806 }
103807 }else if( pTerm->eOperator & WO_ISNULL ){
103808 wsFlags |= WHERE_COLUMN_NULL;
103809 }
103810 #ifdef SQLITE_ENABLE_STAT3
103811 if( nEq==0 && pProbe->aSample ) pFirstTerm = pTerm;
103812 #endif
103813 used |= pTerm->prereqRight;
103814 }
103815
103816 /* Determine the value of rangeDiv */
103817 if( nEq<pProbe->nColumn && pProbe->bUnordered==0 ){
103818 int j = pProbe->aiColumn[nEq];
103819 if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
103820 WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
103821 WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
103822 whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &rangeDiv);
103823 if( pTop ){
103824 nBound = 1;
103825 wsFlags |= WHERE_TOP_LIMIT;
103826 used |= pTop->prereqRight;
103827 testcase( pTop->pWC!=pWC );
103828 }
103829 if( pBtm ){
103830 nBound++;
103831 wsFlags |= WHERE_BTM_LIMIT;
103832 used |= pBtm->prereqRight;
103833 testcase( pBtm->pWC!=pWC );
103834 }
103835 wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
103836 }
103837 }else if( pProbe->onError!=OE_None ){
103838 testcase( wsFlags & WHERE_COLUMN_IN );
@@ -103458,32 +103891,34 @@
103891 if( bInEst && nRow*2>aiRowEst[0] ){
103892 nRow = aiRowEst[0]/2;
103893 nInMul = (int)(nRow / aiRowEst[nEq]);
103894 }
103895
103896 #ifdef SQLITE_ENABLE_STAT3
103897 /* If the constraint is of the form x=VALUE or x IN (E1,E2,...)
103898 ** and we do not think that values of x are unique and if histogram
103899 ** data is available for column x, then it might be possible
103900 ** to get a better estimate on the number of rows based on
103901 ** VALUE and how common that value is according to the histogram.
103902 */
103903 if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 && aiRowEst[1]>1 ){
103904 assert( (pFirstTerm->eOperator & (WO_EQ|WO_ISNULL|WO_IN))!=0 );
103905 if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){
103906 testcase( pFirstTerm->eOperator==WO_EQ );
103907 testcase( pFirstTerm->eOperator==WO_ISNULL );
103908 whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow);
103909 }else if( bInEst==0 ){
103910 assert( pFirstTerm->eOperator==WO_IN );
103911 whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow);
103912 }
103913 }
103914 #endif /* SQLITE_ENABLE_STAT3 */
103915
103916 /* Adjust the number of output rows and downward to reflect rows
103917 ** that are excluded by range constraints.
103918 */
103919 nRow = nRow/rangeDiv;
103920 if( nRow<1 ) nRow = 1;
103921
103922 /* Experiments run on real SQLite databases show that the time needed
103923 ** to do a binary search to locate a row in a table or index is roughly
103924 ** log10(N) times the time to move from one row to the next row within
@@ -103608,14 +104043,14 @@
104043 if( nRow<2 ) nRow = 2;
104044 }
104045
104046
104047 WHERETRACE((
104048 "%s(%s): nEq=%d nInMul=%d rangeDiv=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
104049 " notReady=0x%llx log10N=%.1f nRow=%.1f cost=%.1f used=0x%llx\n",
104050 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
104051 nEq, nInMul, (int)rangeDiv, bSort, bLookup, wsFlags,
104052 notReady, log10N, nRow, cost, used
104053 ));
104054
104055 /* If this index is the best we have seen so far, then record this
104056 ** index and its cost in the pCost structure.
@@ -104115,11 +104550,12 @@
104550 */
104551 static Bitmask codeOneLoopStart(
104552 WhereInfo *pWInfo, /* Complete information about the WHERE clause */
104553 int iLevel, /* Which level of pWInfo->a[] should be coded */
104554 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
104555 Bitmask notReady, /* Which tables are currently available */
104556 Expr *pWhere /* Complete WHERE clause */
104557 ){
104558 int j, k; /* Loop counters */
104559 int iCur; /* The VDBE cursor for the table */
104560 int addrNxt; /* Where to jump to continue with the next IN case */
104561 int omitTable; /* True if we use the index only */
@@ -104597,11 +105033,12 @@
105033 int regRowset = 0; /* Register for RowSet object */
105034 int regRowid = 0; /* Register holding rowid */
105035 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
105036 int iRetInit; /* Address of regReturn init */
105037 int untestedTerms = 0; /* Some terms not completely tested */
105038 int ii; /* Loop counter */
105039 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
105040
105041 pTerm = pLevel->plan.u.pTerm;
105042 assert( pTerm!=0 );
105043 assert( pTerm->eOperator==WO_OR );
105044 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
@@ -104646,18 +105083,33 @@
105083 regRowset = ++pParse->nMem;
105084 regRowid = ++pParse->nMem;
105085 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
105086 }
105087 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
105088
105089 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
105090 ** Then for every term xN, evaluate as the subexpression: xN AND z
105091 ** That way, terms in y that are factored into the disjunction will
105092 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
105093 */
105094 if( pWC->nTerm>1 ){
105095 pAndExpr = sqlite3ExprAlloc(pParse->db, TK_AND, 0, 0);
105096 pAndExpr->pRight = pWhere;
105097 }
105098
105099 for(ii=0; ii<pOrWc->nTerm; ii++){
105100 WhereTerm *pOrTerm = &pOrWc->a[ii];
105101 if( pOrTerm->leftCursor==iCur || pOrTerm->eOperator==WO_AND ){
105102 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
105103 Expr *pOrExpr = pOrTerm->pExpr;
105104 if( pAndExpr ){
105105 pAndExpr->pLeft = pOrExpr;
105106 pOrExpr = pAndExpr;
105107 }
105108 /* Loop through table entries that match term pOrTerm. */
105109 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
105110 WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
105111 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY);
105112 if( pSubWInfo ){
105113 explainOneScan(
105114 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
105115 );
@@ -104681,10 +105133,11 @@
105133 /* Finish the loop through table entries that match term pOrTerm. */
105134 sqlite3WhereEnd(pSubWInfo);
105135 }
105136 }
105137 }
105138 sqlite3DbFree(pParse->db, pAndExpr);
105139 sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
105140 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
105141 sqlite3VdbeResolveLabel(v, iLoopBody);
105142
105143 if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
@@ -104962,11 +105415,11 @@
105415
105416 /* Split the WHERE clause into separate subexpressions where each
105417 ** subexpression is separated by an AND operator.
105418 */
105419 initMaskSet(pMaskSet);
105420 whereClauseInit(pWC, pParse, pMaskSet, wctrlFlags);
105421 sqlite3ExprCodeConstants(pParse, pWhere);
105422 whereSplit(pWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
105423
105424 /* Special case: a WHERE clause that is constant. Evaluate the
105425 ** expression and either jump over all of the code or fall thru.
@@ -105290,11 +105743,11 @@
105743 int iCur = pTabItem->iCursor;
105744 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
105745 }else
105746 #endif
105747 if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
105748 && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){
105749 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
105750 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
105751 testcase( pTab->nCol==BMS-1 );
105752 testcase( pTab->nCol==BMS );
105753 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
@@ -105335,11 +105788,11 @@
105788 */
105789 notReady = ~(Bitmask)0;
105790 for(i=0; i<nTabList; i++){
105791 pLevel = &pWInfo->a[i];
105792 explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
105793 notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady, pWhere);
105794 pWInfo->iContinue = pLevel->addrCont;
105795 }
105796
105797 #ifdef SQLITE_TEST /* For testing and debugging use only */
105798 /* Record in the query plan information about the current table
@@ -105470,11 +105923,11 @@
105923 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
105924 Table *pTab = pTabItem->pTab;
105925 assert( pTab!=0 );
105926 if( (pTab->tabFlags & TF_Ephemeral)==0
105927 && pTab->pSelect==0
105928 && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
105929 ){
105930 int ws = pLevel->plan.wsFlags;
105931 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
105932 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
105933 }
@@ -105531,10 +105984,11 @@
105984 return;
105985 }
105986
105987 /************** End of where.c ***********************************************/
105988 /************** Begin file parse.c *******************************************/
105989 #line 1 "tsrc/parse.c"
105990 /* Driver template for the LEMON parser generator.
105991 ** The author disclaims copyright to this source code.
105992 **
105993 ** This version of "lempar.c" is modified, slightly, for use by SQLite.
105994 ** The only modifications are the addition of a couple of NEVER()
@@ -105543,10 +105997,11 @@
105997 ** specific grammar used by SQLite.
105998 */
105999 /* First off, code is included that follows the "include" declaration
106000 ** in the input grammar file. */
106001 /* #include <stdio.h> */
106002 #line 51 "parse.y"
106003
106004
106005 /*
106006 ** Disable all error recovery processing in the parser push-down
106007 ** automaton.
@@ -105590,10 +106045,11 @@
106045 /*
106046 ** An instance of this structure holds the ATTACH key and the key type.
106047 */
106048 struct AttachKey { int type; Token key; };
106049
106050 #line 722 "parse.y"
106051
106052 /* This is a utility routine used to set the ExprSpan.zStart and
106053 ** ExprSpan.zEnd values of pOut so that the span covers the complete
106054 ** range of text beginning with pStart and going to the end of pEnd.
106055 */
@@ -105609,10 +106065,11 @@
106065 static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token *pValue){
106066 pOut->pExpr = sqlite3PExpr(pParse, op, 0, 0, pValue);
106067 pOut->zStart = pValue->z;
106068 pOut->zEnd = &pValue->z[pValue->n];
106069 }
106070 #line 817 "parse.y"
106071
106072 /* This routine constructs a binary expression node out of two ExprSpan
106073 ** objects and uses the result to populate a new ExprSpan object.
106074 */
106075 static void spanBinaryExpr(
@@ -105624,10 +106081,11 @@
106081 ){
106082 pOut->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0);
106083 pOut->zStart = pLeft->zStart;
106084 pOut->zEnd = pRight->zEnd;
106085 }
106086 #line 873 "parse.y"
106087
106088 /* Construct an expression node for a unary postfix operator
106089 */
106090 static void spanUnaryPostfix(
106091 ExprSpan *pOut, /* Write the new expression node here */
@@ -105638,10 +106096,11 @@
106096 ){
106097 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
106098 pOut->zStart = pOperand->zStart;
106099 pOut->zEnd = &pPostOp->z[pPostOp->n];
106100 }
106101 #line 892 "parse.y"
106102
106103 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
106104 ** unary TK_ISNULL or TK_NOTNULL expression. */
106105 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
106106 sqlite3 *db = pParse->db;
@@ -105649,10 +106108,11 @@
106108 pA->op = (u8)op;
106109 sqlite3ExprDelete(db, pA->pRight);
106110 pA->pRight = 0;
106111 }
106112 }
106113 #line 920 "parse.y"
106114
106115 /* Construct an expression node for a unary prefix operator
106116 */
106117 static void spanUnaryPrefix(
106118 ExprSpan *pOut, /* Write the new expression node here */
@@ -105663,10 +106123,11 @@
106123 ){
106124 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
106125 pOut->zStart = pPreOp->z;
106126 pOut->zEnd = pOperand->zEnd;
106127 }
106128 #line 141 "parse.c"
106129 /* Next is all token values, in a form suitable for use by makeheaders.
106130 ** This section will be null unless lemon is run with the -m switch.
106131 */
106132 /*
106133 ** These constants (all generated automatically by the parser generator)
@@ -106918,17 +107379,21 @@
107379 ** inside the C code.
107380 */
107381 case 160: /* select */
107382 case 194: /* oneselect */
107383 {
107384 #line 403 "parse.y"
107385 sqlite3SelectDelete(pParse->db, (yypminor->yy387));
107386 #line 1399 "parse.c"
107387 }
107388 break;
107389 case 174: /* term */
107390 case 175: /* expr */
107391 {
107392 #line 720 "parse.y"
107393 sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
107394 #line 1407 "parse.c"
107395 }
107396 break;
107397 case 179: /* idxlist_opt */
107398 case 187: /* idxlist */
107399 case 197: /* selcollist */
@@ -106940,19 +107405,23 @@
107405 case 217: /* setlist */
107406 case 220: /* itemlist */
107407 case 221: /* exprlist */
107408 case 226: /* case_exprlist */
107409 {
107410 #line 1103 "parse.y"
107411 sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
107412 #line 1425 "parse.c"
107413 }
107414 break;
107415 case 193: /* fullname */
107416 case 198: /* from */
107417 case 206: /* seltablist */
107418 case 207: /* stl_prefix */
107419 {
107420 #line 534 "parse.y"
107421 sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
107422 #line 1435 "parse.c"
107423 }
107424 break;
107425 case 199: /* where_opt */
107426 case 201: /* having_opt */
107427 case 210: /* on_opt */
@@ -106960,29 +107429,37 @@
107429 case 225: /* case_operand */
107430 case 227: /* case_else */
107431 case 238: /* when_clause */
107432 case 243: /* key_opt */
107433 {
107434 #line 644 "parse.y"
107435 sqlite3ExprDelete(pParse->db, (yypminor->yy314));
107436 #line 1449 "parse.c"
107437 }
107438 break;
107439 case 211: /* using_opt */
107440 case 213: /* inscollist */
107441 case 219: /* inscollist_opt */
107442 {
107443 #line 566 "parse.y"
107444 sqlite3IdListDelete(pParse->db, (yypminor->yy384));
107445 #line 1458 "parse.c"
107446 }
107447 break;
107448 case 234: /* trigger_cmd_list */
107449 case 239: /* trigger_cmd */
107450 {
107451 #line 1210 "parse.y"
107452 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
107453 #line 1466 "parse.c"
107454 }
107455 break;
107456 case 236: /* trigger_event */
107457 {
107458 #line 1196 "parse.y"
107459 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
107460 #line 1473 "parse.c"
107461 }
107462 break;
107463 default: break; /* If no destructor action specified: do nothing */
107464 }
107465 }
@@ -107164,14 +107641,16 @@
107641 }
107642 #endif
107643 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
107644 /* Here code is inserted which will execute if the parser
107645 ** stack every overflows */
107646 #line 38 "parse.y"
107647
107648 UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */
107649 sqlite3ErrorMsg(pParse, "parser stack overflow");
107650 pParse->parseError = 1;
107651 #line 1664 "parse.c"
107652 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
107653 }
107654
107655 /*
107656 ** Perform a shift action.
@@ -107608,66 +108087,94 @@
108087 ** { ... } // User supplied code
108088 ** #line <lineno> <thisfile>
108089 ** break;
108090 */
108091 case 5: /* explain ::= */
108092 #line 107 "parse.y"
108093 { sqlite3BeginParse(pParse, 0); }
108094 #line 2107 "parse.c"
108095 break;
108096 case 6: /* explain ::= EXPLAIN */
108097 #line 109 "parse.y"
108098 { sqlite3BeginParse(pParse, 1); }
108099 #line 2112 "parse.c"
108100 break;
108101 case 7: /* explain ::= EXPLAIN QUERY PLAN */
108102 #line 110 "parse.y"
108103 { sqlite3BeginParse(pParse, 2); }
108104 #line 2117 "parse.c"
108105 break;
108106 case 8: /* cmdx ::= cmd */
108107 #line 112 "parse.y"
108108 { sqlite3FinishCoding(pParse); }
108109 #line 2122 "parse.c"
108110 break;
108111 case 9: /* cmd ::= BEGIN transtype trans_opt */
108112 #line 117 "parse.y"
108113 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
108114 #line 2127 "parse.c"
108115 break;
108116 case 13: /* transtype ::= */
108117 #line 122 "parse.y"
108118 {yygotominor.yy4 = TK_DEFERRED;}
108119 #line 2132 "parse.c"
108120 break;
108121 case 14: /* transtype ::= DEFERRED */
108122 case 15: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==15);
108123 case 16: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==16);
108124 case 115: /* multiselect_op ::= UNION */ yytestcase(yyruleno==115);
108125 case 117: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==117);
108126 #line 123 "parse.y"
108127 {yygotominor.yy4 = yymsp[0].major;}
108128 #line 2141 "parse.c"
108129 break;
108130 case 17: /* cmd ::= COMMIT trans_opt */
108131 case 18: /* cmd ::= END trans_opt */ yytestcase(yyruleno==18);
108132 #line 126 "parse.y"
108133 {sqlite3CommitTransaction(pParse);}
108134 #line 2147 "parse.c"
108135 break;
108136 case 19: /* cmd ::= ROLLBACK trans_opt */
108137 #line 128 "parse.y"
108138 {sqlite3RollbackTransaction(pParse);}
108139 #line 2152 "parse.c"
108140 break;
108141 case 22: /* cmd ::= SAVEPOINT nm */
108142 #line 132 "parse.y"
108143 {
108144 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
108145 }
108146 #line 2159 "parse.c"
108147 break;
108148 case 23: /* cmd ::= RELEASE savepoint_opt nm */
108149 #line 135 "parse.y"
108150 {
108151 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
108152 }
108153 #line 2166 "parse.c"
108154 break;
108155 case 24: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
108156 #line 138 "parse.y"
108157 {
108158 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
108159 }
108160 #line 2173 "parse.c"
108161 break;
108162 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
108163 #line 145 "parse.y"
108164 {
108165 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
108166 }
108167 #line 2180 "parse.c"
108168 break;
108169 case 27: /* createkw ::= CREATE */
108170 #line 148 "parse.y"
108171 {
108172 pParse->db->lookaside.bEnabled = 0;
108173 yygotominor.yy0 = yymsp[0].minor.yy0;
108174 }
108175 #line 2188 "parse.c"
108176 break;
108177 case 28: /* ifnotexists ::= */
108178 case 31: /* temp ::= */ yytestcase(yyruleno==31);
108179 case 70: /* autoinc ::= */ yytestcase(yyruleno==70);
108180 case 83: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==83);
@@ -107677,44 +108184,56 @@
108184 case 109: /* ifexists ::= */ yytestcase(yyruleno==109);
108185 case 120: /* distinct ::= ALL */ yytestcase(yyruleno==120);
108186 case 121: /* distinct ::= */ yytestcase(yyruleno==121);
108187 case 222: /* between_op ::= BETWEEN */ yytestcase(yyruleno==222);
108188 case 225: /* in_op ::= IN */ yytestcase(yyruleno==225);
108189 #line 153 "parse.y"
108190 {yygotominor.yy4 = 0;}
108191 #line 2204 "parse.c"
108192 break;
108193 case 29: /* ifnotexists ::= IF NOT EXISTS */
108194 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
108195 case 71: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==71);
108196 case 86: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==86);
108197 case 108: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==108);
108198 case 119: /* distinct ::= DISTINCT */ yytestcase(yyruleno==119);
108199 case 223: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==223);
108200 case 226: /* in_op ::= NOT IN */ yytestcase(yyruleno==226);
108201 #line 154 "parse.y"
108202 {yygotominor.yy4 = 1;}
108203 #line 2216 "parse.c"
108204 break;
108205 case 32: /* create_table_args ::= LP columnlist conslist_opt RP */
108206 #line 160 "parse.y"
108207 {
108208 sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
108209 }
108210 #line 2223 "parse.c"
108211 break;
108212 case 33: /* create_table_args ::= AS select */
108213 #line 163 "parse.y"
108214 {
108215 sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy387);
108216 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
108217 }
108218 #line 2231 "parse.c"
108219 break;
108220 case 36: /* column ::= columnid type carglist */
108221 #line 175 "parse.y"
108222 {
108223 yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
108224 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
108225 }
108226 #line 2239 "parse.c"
108227 break;
108228 case 37: /* columnid ::= nm */
108229 #line 179 "parse.y"
108230 {
108231 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
108232 yygotominor.yy0 = yymsp[0].minor.yy0;
108233 }
108234 #line 2247 "parse.c"
108235 break;
108236 case 38: /* id ::= ID */
108237 case 39: /* id ::= INDEXED */ yytestcase(yyruleno==39);
108238 case 40: /* ids ::= ID|STRING */ yytestcase(yyruleno==40);
108239 case 41: /* nm ::= id */ yytestcase(yyruleno==41);
@@ -107734,256 +108253,373 @@
108253 case 264: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==264);
108254 case 265: /* plus_num ::= plus_opt number */ yytestcase(yyruleno==265);
108255 case 266: /* minus_num ::= MINUS number */ yytestcase(yyruleno==266);
108256 case 267: /* number ::= INTEGER|FLOAT */ yytestcase(yyruleno==267);
108257 case 285: /* trnm ::= nm */ yytestcase(yyruleno==285);
108258 #line 189 "parse.y"
108259 {yygotominor.yy0 = yymsp[0].minor.yy0;}
108260 #line 2273 "parse.c"
108261 break;
108262 case 45: /* type ::= typetoken */
108263 #line 251 "parse.y"
108264 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
108265 #line 2278 "parse.c"
108266 break;
108267 case 47: /* typetoken ::= typename LP signed RP */
108268 #line 253 "parse.y"
108269 {
108270 yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
108271 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
108272 }
108273 #line 2286 "parse.c"
108274 break;
108275 case 48: /* typetoken ::= typename LP signed COMMA signed RP */
108276 #line 257 "parse.y"
108277 {
108278 yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
108279 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
108280 }
108281 #line 2294 "parse.c"
108282 break;
108283 case 50: /* typename ::= typename ids */
108284 #line 263 "parse.y"
108285 {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
108286 #line 2299 "parse.c"
108287 break;
108288 case 57: /* ccons ::= DEFAULT term */
108289 case 59: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==59);
108290 #line 274 "parse.y"
108291 {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy118);}
108292 #line 2305 "parse.c"
108293 break;
108294 case 58: /* ccons ::= DEFAULT LP expr RP */
108295 #line 275 "parse.y"
108296 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy118);}
108297 #line 2310 "parse.c"
108298 break;
108299 case 60: /* ccons ::= DEFAULT MINUS term */
108300 #line 277 "parse.y"
108301 {
108302 ExprSpan v;
108303 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy118.pExpr, 0, 0);
108304 v.zStart = yymsp[-1].minor.yy0.z;
108305 v.zEnd = yymsp[0].minor.yy118.zEnd;
108306 sqlite3AddDefaultValue(pParse,&v);
108307 }
108308 #line 2321 "parse.c"
108309 break;
108310 case 61: /* ccons ::= DEFAULT id */
108311 #line 284 "parse.y"
108312 {
108313 ExprSpan v;
108314 spanExpr(&v, pParse, TK_STRING, &yymsp[0].minor.yy0);
108315 sqlite3AddDefaultValue(pParse,&v);
108316 }
108317 #line 2330 "parse.c"
108318 break;
108319 case 63: /* ccons ::= NOT NULL onconf */
108320 #line 294 "parse.y"
108321 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
108322 #line 2335 "parse.c"
108323 break;
108324 case 64: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
108325 #line 296 "parse.y"
108326 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
108327 #line 2340 "parse.c"
108328 break;
108329 case 65: /* ccons ::= UNIQUE onconf */
108330 #line 297 "parse.y"
108331 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0);}
108332 #line 2345 "parse.c"
108333 break;
108334 case 66: /* ccons ::= CHECK LP expr RP */
108335 #line 298 "parse.y"
108336 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy118.pExpr);}
108337 #line 2350 "parse.c"
108338 break;
108339 case 67: /* ccons ::= REFERENCES nm idxlist_opt refargs */
108340 #line 300 "parse.y"
108341 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
108342 #line 2355 "parse.c"
108343 break;
108344 case 68: /* ccons ::= defer_subclause */
108345 #line 301 "parse.y"
108346 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
108347 #line 2360 "parse.c"
108348 break;
108349 case 69: /* ccons ::= COLLATE ids */
108350 #line 302 "parse.y"
108351 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
108352 #line 2365 "parse.c"
108353 break;
108354 case 72: /* refargs ::= */
108355 #line 315 "parse.y"
108356 { yygotominor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
108357 #line 2370 "parse.c"
108358 break;
108359 case 73: /* refargs ::= refargs refarg */
108360 #line 316 "parse.y"
108361 { yygotominor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
108362 #line 2375 "parse.c"
108363 break;
108364 case 74: /* refarg ::= MATCH nm */
108365 case 75: /* refarg ::= ON INSERT refact */ yytestcase(yyruleno==75);
108366 #line 318 "parse.y"
108367 { yygotominor.yy215.value = 0; yygotominor.yy215.mask = 0x000000; }
108368 #line 2381 "parse.c"
108369 break;
108370 case 76: /* refarg ::= ON DELETE refact */
108371 #line 320 "parse.y"
108372 { yygotominor.yy215.value = yymsp[0].minor.yy4; yygotominor.yy215.mask = 0x0000ff; }
108373 #line 2386 "parse.c"
108374 break;
108375 case 77: /* refarg ::= ON UPDATE refact */
108376 #line 321 "parse.y"
108377 { yygotominor.yy215.value = yymsp[0].minor.yy4<<8; yygotominor.yy215.mask = 0x00ff00; }
108378 #line 2391 "parse.c"
108379 break;
108380 case 78: /* refact ::= SET NULL */
108381 #line 323 "parse.y"
108382 { yygotominor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
108383 #line 2396 "parse.c"
108384 break;
108385 case 79: /* refact ::= SET DEFAULT */
108386 #line 324 "parse.y"
108387 { yygotominor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
108388 #line 2401 "parse.c"
108389 break;
108390 case 80: /* refact ::= CASCADE */
108391 #line 325 "parse.y"
108392 { yygotominor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
108393 #line 2406 "parse.c"
108394 break;
108395 case 81: /* refact ::= RESTRICT */
108396 #line 326 "parse.y"
108397 { yygotominor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
108398 #line 2411 "parse.c"
108399 break;
108400 case 82: /* refact ::= NO ACTION */
108401 #line 327 "parse.y"
108402 { yygotominor.yy4 = OE_None; /* EV: R-33326-45252 */}
108403 #line 2416 "parse.c"
108404 break;
108405 case 84: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
108406 case 99: /* defer_subclause_opt ::= defer_subclause */ yytestcase(yyruleno==99);
108407 case 101: /* onconf ::= ON CONFLICT resolvetype */ yytestcase(yyruleno==101);
108408 case 104: /* resolvetype ::= raisetype */ yytestcase(yyruleno==104);
108409 #line 330 "parse.y"
108410 {yygotominor.yy4 = yymsp[0].minor.yy4;}
108411 #line 2424 "parse.c"
108412 break;
108413 case 88: /* conslist_opt ::= */
108414 #line 339 "parse.y"
108415 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
108416 #line 2429 "parse.c"
108417 break;
108418 case 89: /* conslist_opt ::= COMMA conslist */
108419 #line 340 "parse.y"
108420 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
108421 #line 2434 "parse.c"
108422 break;
108423 case 94: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
108424 #line 346 "parse.y"
108425 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
108426 #line 2439 "parse.c"
108427 break;
108428 case 95: /* tcons ::= UNIQUE LP idxlist RP onconf */
108429 #line 348 "parse.y"
108430 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0);}
108431 #line 2444 "parse.c"
108432 break;
108433 case 96: /* tcons ::= CHECK LP expr RP onconf */
108434 #line 350 "parse.y"
108435 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy118.pExpr);}
108436 #line 2449 "parse.c"
108437 break;
108438 case 97: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
108439 #line 352 "parse.y"
108440 {
108441 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
108442 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
108443 }
108444 #line 2457 "parse.c"
108445 break;
108446 case 100: /* onconf ::= */
108447 #line 366 "parse.y"
108448 {yygotominor.yy4 = OE_Default;}
108449 #line 2462 "parse.c"
108450 break;
108451 case 102: /* orconf ::= */
108452 #line 368 "parse.y"
108453 {yygotominor.yy210 = OE_Default;}
108454 #line 2467 "parse.c"
108455 break;
108456 case 103: /* orconf ::= OR resolvetype */
108457 #line 369 "parse.y"
108458 {yygotominor.yy210 = (u8)yymsp[0].minor.yy4;}
108459 #line 2472 "parse.c"
108460 break;
108461 case 105: /* resolvetype ::= IGNORE */
108462 #line 371 "parse.y"
108463 {yygotominor.yy4 = OE_Ignore;}
108464 #line 2477 "parse.c"
108465 break;
108466 case 106: /* resolvetype ::= REPLACE */
108467 #line 372 "parse.y"
108468 {yygotominor.yy4 = OE_Replace;}
108469 #line 2482 "parse.c"
108470 break;
108471 case 107: /* cmd ::= DROP TABLE ifexists fullname */
108472 #line 376 "parse.y"
108473 {
108474 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
108475 }
108476 #line 2489 "parse.c"
108477 break;
108478 case 110: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
108479 #line 386 "parse.y"
108480 {
108481 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy387, yymsp[-6].minor.yy4, yymsp[-4].minor.yy4);
108482 }
108483 #line 2496 "parse.c"
108484 break;
108485 case 111: /* cmd ::= DROP VIEW ifexists fullname */
108486 #line 389 "parse.y"
108487 {
108488 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
108489 }
108490 #line 2503 "parse.c"
108491 break;
108492 case 112: /* cmd ::= select */
108493 #line 396 "parse.y"
108494 {
108495 SelectDest dest = {SRT_Output, 0, 0, 0, 0};
108496 sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
108497 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
108498 }
108499 #line 2512 "parse.c"
108500 break;
108501 case 113: /* select ::= oneselect */
108502 #line 407 "parse.y"
108503 {yygotominor.yy387 = yymsp[0].minor.yy387;}
108504 #line 2517 "parse.c"
108505 break;
108506 case 114: /* select ::= select multiselect_op oneselect */
108507 #line 409 "parse.y"
108508 {
108509 if( yymsp[0].minor.yy387 ){
108510 yymsp[0].minor.yy387->op = (u8)yymsp[-1].minor.yy4;
108511 yymsp[0].minor.yy387->pPrior = yymsp[-2].minor.yy387;
108512 }else{
108513 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
108514 }
108515 yygotominor.yy387 = yymsp[0].minor.yy387;
108516 }
108517 #line 2530 "parse.c"
108518 break;
108519 case 116: /* multiselect_op ::= UNION ALL */
108520 #line 420 "parse.y"
108521 {yygotominor.yy4 = TK_ALL;}
108522 #line 2535 "parse.c"
108523 break;
108524 case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
108525 #line 424 "parse.y"
108526 {
108527 yygotominor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy292.pLimit,yymsp[0].minor.yy292.pOffset);
108528 }
108529 #line 2542 "parse.c"
108530 break;
108531 case 122: /* sclp ::= selcollist COMMA */
108532 case 247: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==247);
108533 #line 445 "parse.y"
108534 {yygotominor.yy322 = yymsp[-1].minor.yy322;}
108535 #line 2548 "parse.c"
108536 break;
108537 case 123: /* sclp ::= */
108538 case 151: /* orderby_opt ::= */ yytestcase(yyruleno==151);
108539 case 159: /* groupby_opt ::= */ yytestcase(yyruleno==159);
108540 case 240: /* exprlist ::= */ yytestcase(yyruleno==240);
108541 case 246: /* idxlist_opt ::= */ yytestcase(yyruleno==246);
108542 #line 446 "parse.y"
108543 {yygotominor.yy322 = 0;}
108544 #line 2557 "parse.c"
108545 break;
108546 case 124: /* selcollist ::= sclp expr as */
108547 #line 447 "parse.y"
108548 {
108549 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, yymsp[-1].minor.yy118.pExpr);
108550 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[0].minor.yy0, 1);
108551 sqlite3ExprListSetSpan(pParse,yygotominor.yy322,&yymsp[-1].minor.yy118);
108552 }
108553 #line 2566 "parse.c"
108554 break;
108555 case 125: /* selcollist ::= sclp STAR */
108556 #line 452 "parse.y"
108557 {
108558 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
108559 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy322, p);
108560 }
108561 #line 2574 "parse.c"
108562 break;
108563 case 126: /* selcollist ::= sclp nm DOT STAR */
108564 #line 456 "parse.y"
108565 {
108566 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
108567 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108568 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
108569 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, pDot);
108570 }
108571 #line 2584 "parse.c"
108572 break;
108573 case 129: /* as ::= */
108574 #line 469 "parse.y"
108575 {yygotominor.yy0.n = 0;}
108576 #line 2589 "parse.c"
108577 break;
108578 case 130: /* from ::= */
108579 #line 481 "parse.y"
108580 {yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
108581 #line 2594 "parse.c"
108582 break;
108583 case 131: /* from ::= FROM seltablist */
108584 #line 482 "parse.y"
108585 {
108586 yygotominor.yy259 = yymsp[0].minor.yy259;
108587 sqlite3SrcListShiftJoinType(yygotominor.yy259);
108588 }
108589 #line 2602 "parse.c"
108590 break;
108591 case 132: /* stl_prefix ::= seltablist joinop */
108592 #line 490 "parse.y"
108593 {
108594 yygotominor.yy259 = yymsp[-1].minor.yy259;
108595 if( ALWAYS(yygotominor.yy259 && yygotominor.yy259->nSrc>0) ) yygotominor.yy259->a[yygotominor.yy259->nSrc-1].jointype = (u8)yymsp[0].minor.yy4;
108596 }
108597 #line 2610 "parse.c"
108598 break;
108599 case 133: /* stl_prefix ::= */
108600 #line 494 "parse.y"
108601 {yygotominor.yy259 = 0;}
108602 #line 2615 "parse.c"
108603 break;
108604 case 134: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
108605 #line 495 "parse.y"
108606 {
108607 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
108608 sqlite3SrcListIndexedBy(pParse, yygotominor.yy259, &yymsp[-2].minor.yy0);
108609 }
108610 #line 2623 "parse.c"
108611 break;
108612 case 135: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
108613 #line 501 "parse.y"
108614 {
108615 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
108616 }
108617 #line 2630 "parse.c"
108618 break;
108619 case 136: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
108620 #line 505 "parse.y"
108621 {
108622 if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
108623 yygotominor.yy259 = yymsp[-4].minor.yy259;
108624 }else{
108625 Select *pSubquery;
@@ -107990,180 +108626,260 @@
108626 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
108627 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,0,0,0);
108628 yygotominor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
108629 }
108630 }
108631 #line 2644 "parse.c"
108632 break;
108633 case 137: /* dbnm ::= */
108634 case 146: /* indexed_opt ::= */ yytestcase(yyruleno==146);
108635 #line 530 "parse.y"
108636 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
108637 #line 2650 "parse.c"
108638 break;
108639 case 139: /* fullname ::= nm dbnm */
108640 #line 535 "parse.y"
108641 {yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
108642 #line 2655 "parse.c"
108643 break;
108644 case 140: /* joinop ::= COMMA|JOIN */
108645 #line 539 "parse.y"
108646 { yygotominor.yy4 = JT_INNER; }
108647 #line 2660 "parse.c"
108648 break;
108649 case 141: /* joinop ::= JOIN_KW JOIN */
108650 #line 540 "parse.y"
108651 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
108652 #line 2665 "parse.c"
108653 break;
108654 case 142: /* joinop ::= JOIN_KW nm JOIN */
108655 #line 541 "parse.y"
108656 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
108657 #line 2670 "parse.c"
108658 break;
108659 case 143: /* joinop ::= JOIN_KW nm nm JOIN */
108660 #line 543 "parse.y"
108661 { yygotominor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
108662 #line 2675 "parse.c"
108663 break;
108664 case 144: /* on_opt ::= ON expr */
108665 case 155: /* sortitem ::= expr */ yytestcase(yyruleno==155);
108666 case 162: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==162);
108667 case 169: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==169);
108668 case 235: /* case_else ::= ELSE expr */ yytestcase(yyruleno==235);
108669 case 237: /* case_operand ::= expr */ yytestcase(yyruleno==237);
108670 #line 547 "parse.y"
108671 {yygotominor.yy314 = yymsp[0].minor.yy118.pExpr;}
108672 #line 2685 "parse.c"
108673 break;
108674 case 145: /* on_opt ::= */
108675 case 161: /* having_opt ::= */ yytestcase(yyruleno==161);
108676 case 168: /* where_opt ::= */ yytestcase(yyruleno==168);
108677 case 236: /* case_else ::= */ yytestcase(yyruleno==236);
108678 case 238: /* case_operand ::= */ yytestcase(yyruleno==238);
108679 #line 548 "parse.y"
108680 {yygotominor.yy314 = 0;}
108681 #line 2694 "parse.c"
108682 break;
108683 case 148: /* indexed_opt ::= NOT INDEXED */
108684 #line 563 "parse.y"
108685 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
108686 #line 2699 "parse.c"
108687 break;
108688 case 149: /* using_opt ::= USING LP inscollist RP */
108689 case 181: /* inscollist_opt ::= LP inscollist RP */ yytestcase(yyruleno==181);
108690 #line 567 "parse.y"
108691 {yygotominor.yy384 = yymsp[-1].minor.yy384;}
108692 #line 2705 "parse.c"
108693 break;
108694 case 150: /* using_opt ::= */
108695 case 180: /* inscollist_opt ::= */ yytestcase(yyruleno==180);
108696 #line 568 "parse.y"
108697 {yygotominor.yy384 = 0;}
108698 #line 2711 "parse.c"
108699 break;
108700 case 152: /* orderby_opt ::= ORDER BY sortlist */
108701 case 160: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==160);
108702 case 239: /* exprlist ::= nexprlist */ yytestcase(yyruleno==239);
108703 #line 579 "parse.y"
108704 {yygotominor.yy322 = yymsp[0].minor.yy322;}
108705 #line 2718 "parse.c"
108706 break;
108707 case 153: /* sortlist ::= sortlist COMMA sortitem sortorder */
108708 #line 580 "parse.y"
108709 {
108710 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314);
108711 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
108712 }
108713 #line 2726 "parse.c"
108714 break;
108715 case 154: /* sortlist ::= sortitem sortorder */
108716 #line 584 "parse.y"
108717 {
108718 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314);
108719 if( yygotominor.yy322 && ALWAYS(yygotominor.yy322->a) ) yygotominor.yy322->a[0].sortOrder = (u8)yymsp[0].minor.yy4;
108720 }
108721 #line 2734 "parse.c"
108722 break;
108723 case 156: /* sortorder ::= ASC */
108724 case 158: /* sortorder ::= */ yytestcase(yyruleno==158);
108725 #line 592 "parse.y"
108726 {yygotominor.yy4 = SQLITE_SO_ASC;}
108727 #line 2740 "parse.c"
108728 break;
108729 case 157: /* sortorder ::= DESC */
108730 #line 593 "parse.y"
108731 {yygotominor.yy4 = SQLITE_SO_DESC;}
108732 #line 2745 "parse.c"
108733 break;
108734 case 163: /* limit_opt ::= */
108735 #line 619 "parse.y"
108736 {yygotominor.yy292.pLimit = 0; yygotominor.yy292.pOffset = 0;}
108737 #line 2750 "parse.c"
108738 break;
108739 case 164: /* limit_opt ::= LIMIT expr */
108740 #line 620 "parse.y"
108741 {yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr; yygotominor.yy292.pOffset = 0;}
108742 #line 2755 "parse.c"
108743 break;
108744 case 165: /* limit_opt ::= LIMIT expr OFFSET expr */
108745 #line 622 "parse.y"
108746 {yygotominor.yy292.pLimit = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pOffset = yymsp[0].minor.yy118.pExpr;}
108747 #line 2760 "parse.c"
108748 break;
108749 case 166: /* limit_opt ::= LIMIT expr COMMA expr */
108750 #line 624 "parse.y"
108751 {yygotominor.yy292.pOffset = yymsp[-2].minor.yy118.pExpr; yygotominor.yy292.pLimit = yymsp[0].minor.yy118.pExpr;}
108752 #line 2765 "parse.c"
108753 break;
108754 case 167: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
108755 #line 637 "parse.y"
108756 {
108757 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
108758 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314);
108759 }
108760 #line 2773 "parse.c"
108761 break;
108762 case 170: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
108763 #line 660 "parse.y"
108764 {
108765 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
108766 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
108767 sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy210);
108768 }
108769 #line 2782 "parse.c"
108770 break;
108771 case 171: /* setlist ::= setlist COMMA nm EQ expr */
108772 #line 670 "parse.y"
108773 {
108774 yygotominor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy118.pExpr);
108775 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108776 }
108777 #line 2790 "parse.c"
108778 break;
108779 case 172: /* setlist ::= nm EQ expr */
108780 #line 674 "parse.y"
108781 {
108782 yygotominor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy118.pExpr);
108783 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
108784 }
108785 #line 2798 "parse.c"
108786 break;
108787 case 173: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
108788 #line 683 "parse.y"
108789 {sqlite3Insert(pParse, yymsp[-5].minor.yy259, yymsp[-1].minor.yy322, 0, yymsp[-4].minor.yy384, yymsp[-7].minor.yy210);}
108790 #line 2803 "parse.c"
108791 break;
108792 case 174: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
108793 #line 685 "parse.y"
108794 {sqlite3Insert(pParse, yymsp[-2].minor.yy259, 0, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy210);}
108795 #line 2808 "parse.c"
108796 break;
108797 case 175: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
108798 #line 687 "parse.y"
108799 {sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy210);}
108800 #line 2813 "parse.c"
108801 break;
108802 case 176: /* insert_cmd ::= INSERT orconf */
108803 #line 690 "parse.y"
108804 {yygotominor.yy210 = yymsp[0].minor.yy210;}
108805 #line 2818 "parse.c"
108806 break;
108807 case 177: /* insert_cmd ::= REPLACE */
108808 #line 691 "parse.y"
108809 {yygotominor.yy210 = OE_Replace;}
108810 #line 2823 "parse.c"
108811 break;
108812 case 178: /* itemlist ::= itemlist COMMA expr */
108813 case 241: /* nexprlist ::= nexprlist COMMA expr */ yytestcase(yyruleno==241);
108814 #line 698 "parse.y"
108815 {yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy118.pExpr);}
108816 #line 2829 "parse.c"
108817 break;
108818 case 179: /* itemlist ::= expr */
108819 case 242: /* nexprlist ::= expr */ yytestcase(yyruleno==242);
108820 #line 700 "parse.y"
108821 {yygotominor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy118.pExpr);}
108822 #line 2835 "parse.c"
108823 break;
108824 case 182: /* inscollist ::= inscollist COMMA nm */
108825 #line 710 "parse.y"
108826 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
108827 #line 2840 "parse.c"
108828 break;
108829 case 183: /* inscollist ::= nm */
108830 #line 712 "parse.y"
108831 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
108832 #line 2845 "parse.c"
108833 break;
108834 case 184: /* expr ::= term */
108835 #line 743 "parse.y"
108836 {yygotominor.yy118 = yymsp[0].minor.yy118;}
108837 #line 2850 "parse.c"
108838 break;
108839 case 185: /* expr ::= LP expr RP */
108840 #line 744 "parse.y"
108841 {yygotominor.yy118.pExpr = yymsp[-1].minor.yy118.pExpr; spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
108842 #line 2855 "parse.c"
108843 break;
108844 case 186: /* term ::= NULL */
108845 case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
108846 case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
108847 #line 745 "parse.y"
108848 {spanExpr(&yygotominor.yy118, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
108849 #line 2862 "parse.c"
108850 break;
108851 case 187: /* expr ::= id */
108852 case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
108853 #line 746 "parse.y"
108854 {spanExpr(&yygotominor.yy118, pParse, TK_ID, &yymsp[0].minor.yy0);}
108855 #line 2868 "parse.c"
108856 break;
108857 case 189: /* expr ::= nm DOT nm */
108858 #line 748 "parse.y"
108859 {
108860 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108861 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
108862 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
108863 spanSet(&yygotominor.yy118,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
108864 }
108865 #line 2878 "parse.c"
108866 break;
108867 case 190: /* expr ::= nm DOT nm DOT nm */
108868 #line 754 "parse.y"
108869 {
108870 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
108871 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
108872 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
108873 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
108874 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
108875 spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
108876 }
108877 #line 2890 "parse.c"
108878 break;
108879 case 193: /* expr ::= REGISTER */
108880 #line 764 "parse.y"
108881 {
108882 /* When doing a nested parse, one can include terms in an expression
108883 ** that look like this: #1 #2 ... These terms refer to registers
108884 ** in the virtual machine. #N is the N-th register. */
108885 if( pParse->nested==0 ){
@@ -108173,32 +108889,40 @@
108889 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
108890 if( yygotominor.yy118.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy118.pExpr->iTable);
108891 }
108892 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108893 }
108894 #line 2907 "parse.c"
108895 break;
108896 case 194: /* expr ::= VARIABLE */
108897 #line 777 "parse.y"
108898 {
108899 spanExpr(&yygotominor.yy118, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
108900 sqlite3ExprAssignVarNumber(pParse, yygotominor.yy118.pExpr);
108901 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108902 }
108903 #line 2916 "parse.c"
108904 break;
108905 case 195: /* expr ::= expr COLLATE ids */
108906 #line 782 "parse.y"
108907 {
108908 yygotominor.yy118.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
108909 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
108910 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
108911 }
108912 #line 2925 "parse.c"
108913 break;
108914 case 196: /* expr ::= CAST LP expr AS typetoken RP */
108915 #line 788 "parse.y"
108916 {
108917 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy118.pExpr, 0, &yymsp[-1].minor.yy0);
108918 spanSet(&yygotominor.yy118,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
108919 }
108920 #line 2933 "parse.c"
108921 break;
108922 case 197: /* expr ::= ID LP distinct exprlist RP */
108923 #line 793 "parse.y"
108924 {
108925 if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
108926 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
108927 }
108928 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
@@ -108205,47 +108929,59 @@
108929 spanSet(&yygotominor.yy118,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
108930 if( yymsp[-2].minor.yy4 && yygotominor.yy118.pExpr ){
108931 yygotominor.yy118.pExpr->flags |= EP_Distinct;
108932 }
108933 }
108934 #line 2947 "parse.c"
108935 break;
108936 case 198: /* expr ::= ID LP STAR RP */
108937 #line 803 "parse.y"
108938 {
108939 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
108940 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
108941 }
108942 #line 2955 "parse.c"
108943 break;
108944 case 199: /* term ::= CTIME_KW */
108945 #line 807 "parse.y"
108946 {
108947 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
108948 ** treated as functions that return constants */
108949 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
108950 if( yygotominor.yy118.pExpr ){
108951 yygotominor.yy118.pExpr->op = TK_CONST_FUNC;
108952 }
108953 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
108954 }
108955 #line 2968 "parse.c"
108956 break;
108957 case 200: /* expr ::= expr AND expr */
108958 case 201: /* expr ::= expr OR expr */ yytestcase(yyruleno==201);
108959 case 202: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==202);
108960 case 203: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==203);
108961 case 204: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==204);
108962 case 205: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==205);
108963 case 206: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==206);
108964 case 207: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==207);
108965 #line 834 "parse.y"
108966 {spanBinaryExpr(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);}
108967 #line 2980 "parse.c"
108968 break;
108969 case 208: /* likeop ::= LIKE_KW */
108970 case 210: /* likeop ::= MATCH */ yytestcase(yyruleno==210);
108971 #line 847 "parse.y"
108972 {yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 0;}
108973 #line 2986 "parse.c"
108974 break;
108975 case 209: /* likeop ::= NOT LIKE_KW */
108976 case 211: /* likeop ::= NOT MATCH */ yytestcase(yyruleno==211);
108977 #line 848 "parse.y"
108978 {yygotominor.yy342.eOperator = yymsp[0].minor.yy0; yygotominor.yy342.not = 1;}
108979 #line 2992 "parse.c"
108980 break;
108981 case 212: /* expr ::= expr likeop expr */
108982 #line 851 "parse.y"
108983 {
108984 ExprList *pList;
108985 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy118.pExpr);
108986 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy118.pExpr);
108987 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy342.eOperator);
@@ -108252,12 +108988,14 @@
108988 if( yymsp[-1].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
108989 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
108990 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
108991 if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
108992 }
108993 #line 3006 "parse.c"
108994 break;
108995 case 213: /* expr ::= expr likeop expr ESCAPE expr */
108996 #line 861 "parse.y"
108997 {
108998 ExprList *pList;
108999 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
109000 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy118.pExpr);
109001 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
@@ -108265,40 +109003,56 @@
109003 if( yymsp[-3].minor.yy342.not ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
109004 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
109005 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
109006 if( yygotominor.yy118.pExpr ) yygotominor.yy118.pExpr->flags |= EP_InfixFunc;
109007 }
109008 #line 3021 "parse.c"
109009 break;
109010 case 214: /* expr ::= expr ISNULL|NOTNULL */
109011 #line 889 "parse.y"
109012 {spanUnaryPostfix(&yygotominor.yy118,pParse,yymsp[0].major,&yymsp[-1].minor.yy118,&yymsp[0].minor.yy0);}
109013 #line 3026 "parse.c"
109014 break;
109015 case 215: /* expr ::= expr NOT NULL */
109016 #line 890 "parse.y"
109017 {spanUnaryPostfix(&yygotominor.yy118,pParse,TK_NOTNULL,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy0);}
109018 #line 3031 "parse.c"
109019 break;
109020 case 216: /* expr ::= expr IS expr */
109021 #line 911 "parse.y"
109022 {
109023 spanBinaryExpr(&yygotominor.yy118,pParse,TK_IS,&yymsp[-2].minor.yy118,&yymsp[0].minor.yy118);
109024 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_ISNULL);
109025 }
109026 #line 3039 "parse.c"
109027 break;
109028 case 217: /* expr ::= expr IS NOT expr */
109029 #line 915 "parse.y"
109030 {
109031 spanBinaryExpr(&yygotominor.yy118,pParse,TK_ISNOT,&yymsp[-3].minor.yy118,&yymsp[0].minor.yy118);
109032 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy118.pExpr, yygotominor.yy118.pExpr, TK_NOTNULL);
109033 }
109034 #line 3047 "parse.c"
109035 break;
109036 case 218: /* expr ::= NOT expr */
109037 case 219: /* expr ::= BITNOT expr */ yytestcase(yyruleno==219);
109038 #line 938 "parse.y"
109039 {spanUnaryPrefix(&yygotominor.yy118,pParse,yymsp[-1].major,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
109040 #line 3053 "parse.c"
109041 break;
109042 case 220: /* expr ::= MINUS expr */
109043 #line 941 "parse.y"
109044 {spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UMINUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
109045 #line 3058 "parse.c"
109046 break;
109047 case 221: /* expr ::= PLUS expr */
109048 #line 943 "parse.y"
109049 {spanUnaryPrefix(&yygotominor.yy118,pParse,TK_UPLUS,&yymsp[0].minor.yy118,&yymsp[-1].minor.yy0);}
109050 #line 3063 "parse.c"
109051 break;
109052 case 224: /* expr ::= expr between_op expr AND expr */
109053 #line 948 "parse.y"
109054 {
109055 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
109056 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy118.pExpr);
109057 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy118.pExpr, 0, 0);
109058 if( yygotominor.yy118.pExpr ){
@@ -108308,12 +109062,14 @@
109062 }
109063 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
109064 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
109065 yygotominor.yy118.zEnd = yymsp[0].minor.yy118.zEnd;
109066 }
109067 #line 3080 "parse.c"
109068 break;
109069 case 227: /* expr ::= expr in_op LP exprlist RP */
109070 #line 965 "parse.y"
109071 {
109072 if( yymsp[-1].minor.yy322==0 ){
109073 /* Expressions of the form
109074 **
109075 ** expr1 IN ()
@@ -108335,12 +109091,14 @@
109091 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
109092 }
109093 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
109094 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109095 }
109096 #line 3109 "parse.c"
109097 break;
109098 case 228: /* expr ::= LP select RP */
109099 #line 990 "parse.y"
109100 {
109101 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
109102 if( yygotominor.yy118.pExpr ){
109103 yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
109104 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
@@ -108349,12 +109107,14 @@
109107 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
109108 }
109109 yygotominor.yy118.zStart = yymsp[-2].minor.yy0.z;
109110 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109111 }
109112 #line 3125 "parse.c"
109113 break;
109114 case 229: /* expr ::= expr in_op LP select RP */
109115 #line 1002 "parse.y"
109116 {
109117 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy118.pExpr, 0, 0);
109118 if( yygotominor.yy118.pExpr ){
109119 yygotominor.yy118.pExpr->x.pSelect = yymsp[-1].minor.yy387;
109120 ExprSetProperty(yygotominor.yy118.pExpr, EP_xIsSelect);
@@ -108364,12 +109124,14 @@
109124 }
109125 if( yymsp[-3].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
109126 yygotominor.yy118.zStart = yymsp[-4].minor.yy118.zStart;
109127 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109128 }
109129 #line 3142 "parse.c"
109130 break;
109131 case 230: /* expr ::= expr in_op nm dbnm */
109132 #line 1015 "parse.y"
109133 {
109134 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
109135 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy118.pExpr, 0, 0);
109136 if( yygotominor.yy118.pExpr ){
109137 yygotominor.yy118.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
@@ -108380,12 +109142,14 @@
109142 }
109143 if( yymsp[-2].minor.yy4 ) yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy118.pExpr, 0, 0);
109144 yygotominor.yy118.zStart = yymsp[-3].minor.yy118.zStart;
109145 yygotominor.yy118.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
109146 }
109147 #line 3160 "parse.c"
109148 break;
109149 case 231: /* expr ::= EXISTS LP select RP */
109150 #line 1029 "parse.y"
109151 {
109152 Expr *p = yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
109153 if( p ){
109154 p->x.pSelect = yymsp[-1].minor.yy387;
109155 ExprSetProperty(p, EP_xIsSelect);
@@ -108394,12 +109158,14 @@
109158 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
109159 }
109160 yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
109161 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109162 }
109163 #line 3176 "parse.c"
109164 break;
109165 case 232: /* expr ::= CASE case_operand case_exprlist case_else END */
109166 #line 1044 "parse.y"
109167 {
109168 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, 0);
109169 if( yygotominor.yy118.pExpr ){
109170 yygotominor.yy118.pExpr->x.pList = yymsp[-2].minor.yy322;
109171 sqlite3ExprSetHeight(pParse, yygotominor.yy118.pExpr);
@@ -108407,38 +109173,50 @@
109173 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
109174 }
109175 yygotominor.yy118.zStart = yymsp[-4].minor.yy0.z;
109176 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109177 }
109178 #line 3191 "parse.c"
109179 break;
109180 case 233: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
109181 #line 1057 "parse.y"
109182 {
109183 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy118.pExpr);
109184 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
109185 }
109186 #line 3199 "parse.c"
109187 break;
109188 case 234: /* case_exprlist ::= WHEN expr THEN expr */
109189 #line 1061 "parse.y"
109190 {
109191 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy118.pExpr);
109192 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yygotominor.yy322, yymsp[0].minor.yy118.pExpr);
109193 }
109194 #line 3207 "parse.c"
109195 break;
109196 case 243: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
109197 #line 1090 "parse.y"
109198 {
109199 sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0,
109200 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy322, yymsp[-9].minor.yy4,
109201 &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy4);
109202 }
109203 #line 3216 "parse.c"
109204 break;
109205 case 244: /* uniqueflag ::= UNIQUE */
109206 case 298: /* raisetype ::= ABORT */ yytestcase(yyruleno==298);
109207 #line 1097 "parse.y"
109208 {yygotominor.yy4 = OE_Abort;}
109209 #line 3222 "parse.c"
109210 break;
109211 case 245: /* uniqueflag ::= */
109212 #line 1098 "parse.y"
109213 {yygotominor.yy4 = OE_None;}
109214 #line 3227 "parse.c"
109215 break;
109216 case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
109217 #line 1107 "parse.y"
109218 {
109219 Expr *p = 0;
109220 if( yymsp[-1].minor.yy0.n>0 ){
109221 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
109222 sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
@@ -108446,12 +109224,14 @@
109224 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
109225 sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
109226 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
109227 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
109228 }
109229 #line 3242 "parse.c"
109230 break;
109231 case 249: /* idxlist ::= nm collate sortorder */
109232 #line 1118 "parse.y"
109233 {
109234 Expr *p = 0;
109235 if( yymsp[-1].minor.yy0.n>0 ){
109236 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
109237 sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
@@ -108459,214 +109239,307 @@
109239 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
109240 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
109241 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
109242 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
109243 }
109244 #line 3257 "parse.c"
109245 break;
109246 case 250: /* collate ::= */
109247 #line 1131 "parse.y"
109248 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
109249 #line 3262 "parse.c"
109250 break;
109251 case 252: /* cmd ::= DROP INDEX ifexists fullname */
109252 #line 1137 "parse.y"
109253 {sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
109254 #line 3267 "parse.c"
109255 break;
109256 case 253: /* cmd ::= VACUUM */
109257 case 254: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==254);
109258 #line 1143 "parse.y"
109259 {sqlite3Vacuum(pParse);}
109260 #line 3273 "parse.c"
109261 break;
109262 case 255: /* cmd ::= PRAGMA nm dbnm */
109263 #line 1151 "parse.y"
109264 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
109265 #line 3278 "parse.c"
109266 break;
109267 case 256: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
109268 #line 1152 "parse.y"
109269 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
109270 #line 3283 "parse.c"
109271 break;
109272 case 257: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
109273 #line 1153 "parse.y"
109274 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
109275 #line 3288 "parse.c"
109276 break;
109277 case 258: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
109278 #line 1155 "parse.y"
109279 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
109280 #line 3293 "parse.c"
109281 break;
109282 case 259: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
109283 #line 1157 "parse.y"
109284 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
109285 #line 3298 "parse.c"
109286 break;
109287 case 270: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
109288 #line 1175 "parse.y"
109289 {
109290 Token all;
109291 all.z = yymsp[-3].minor.yy0.z;
109292 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
109293 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
109294 }
109295 #line 3308 "parse.c"
109296 break;
109297 case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
109298 #line 1184 "parse.y"
109299 {
109300 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
109301 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
109302 }
109303 #line 3316 "parse.c"
109304 break;
109305 case 272: /* trigger_time ::= BEFORE */
109306 case 275: /* trigger_time ::= */ yytestcase(yyruleno==275);
109307 #line 1190 "parse.y"
109308 { yygotominor.yy4 = TK_BEFORE; }
109309 #line 3322 "parse.c"
109310 break;
109311 case 273: /* trigger_time ::= AFTER */
109312 #line 1191 "parse.y"
109313 { yygotominor.yy4 = TK_AFTER; }
109314 #line 3327 "parse.c"
109315 break;
109316 case 274: /* trigger_time ::= INSTEAD OF */
109317 #line 1192 "parse.y"
109318 { yygotominor.yy4 = TK_INSTEAD;}
109319 #line 3332 "parse.c"
109320 break;
109321 case 276: /* trigger_event ::= DELETE|INSERT */
109322 case 277: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==277);
109323 #line 1197 "parse.y"
109324 {yygotominor.yy90.a = yymsp[0].major; yygotominor.yy90.b = 0;}
109325 #line 3338 "parse.c"
109326 break;
109327 case 278: /* trigger_event ::= UPDATE OF inscollist */
109328 #line 1199 "parse.y"
109329 {yygotominor.yy90.a = TK_UPDATE; yygotominor.yy90.b = yymsp[0].minor.yy384;}
109330 #line 3343 "parse.c"
109331 break;
109332 case 281: /* when_clause ::= */
109333 case 303: /* key_opt ::= */ yytestcase(yyruleno==303);
109334 #line 1206 "parse.y"
109335 { yygotominor.yy314 = 0; }
109336 #line 3349 "parse.c"
109337 break;
109338 case 282: /* when_clause ::= WHEN expr */
109339 case 304: /* key_opt ::= KEY expr */ yytestcase(yyruleno==304);
109340 #line 1207 "parse.y"
109341 { yygotominor.yy314 = yymsp[0].minor.yy118.pExpr; }
109342 #line 3355 "parse.c"
109343 break;
109344 case 283: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
109345 #line 1211 "parse.y"
109346 {
109347 assert( yymsp[-2].minor.yy203!=0 );
109348 yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
109349 yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
109350 yygotominor.yy203 = yymsp[-2].minor.yy203;
109351 }
109352 #line 3365 "parse.c"
109353 break;
109354 case 284: /* trigger_cmd_list ::= trigger_cmd SEMI */
109355 #line 1217 "parse.y"
109356 {
109357 assert( yymsp[-1].minor.yy203!=0 );
109358 yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
109359 yygotominor.yy203 = yymsp[-1].minor.yy203;
109360 }
109361 #line 3374 "parse.c"
109362 break;
109363 case 286: /* trnm ::= nm DOT nm */
109364 #line 1229 "parse.y"
109365 {
109366 yygotominor.yy0 = yymsp[0].minor.yy0;
109367 sqlite3ErrorMsg(pParse,
109368 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
109369 "statements within triggers");
109370 }
109371 #line 3384 "parse.c"
109372 break;
109373 case 288: /* tridxby ::= INDEXED BY nm */
109374 #line 1241 "parse.y"
109375 {
109376 sqlite3ErrorMsg(pParse,
109377 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
109378 "within triggers");
109379 }
109380 #line 3393 "parse.c"
109381 break;
109382 case 289: /* tridxby ::= NOT INDEXED */
109383 #line 1246 "parse.y"
109384 {
109385 sqlite3ErrorMsg(pParse,
109386 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
109387 "within triggers");
109388 }
109389 #line 3402 "parse.c"
109390 break;
109391 case 290: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
109392 #line 1259 "parse.y"
109393 { yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
109394 #line 3407 "parse.c"
109395 break;
109396 case 291: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt VALUES LP itemlist RP */
109397 #line 1264 "parse.y"
109398 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy384, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy210);}
109399 #line 3412 "parse.c"
109400 break;
109401 case 292: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
109402 #line 1267 "parse.y"
109403 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
109404 #line 3417 "parse.c"
109405 break;
109406 case 293: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
109407 #line 1271 "parse.y"
109408 {yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
109409 #line 3422 "parse.c"
109410 break;
109411 case 294: /* trigger_cmd ::= select */
109412 #line 1274 "parse.y"
109413 {yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
109414 #line 3427 "parse.c"
109415 break;
109416 case 295: /* expr ::= RAISE LP IGNORE RP */
109417 #line 1277 "parse.y"
109418 {
109419 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
109420 if( yygotominor.yy118.pExpr ){
109421 yygotominor.yy118.pExpr->affinity = OE_Ignore;
109422 }
109423 yygotominor.yy118.zStart = yymsp[-3].minor.yy0.z;
109424 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109425 }
109426 #line 3439 "parse.c"
109427 break;
109428 case 296: /* expr ::= RAISE LP raisetype COMMA nm RP */
109429 #line 1285 "parse.y"
109430 {
109431 yygotominor.yy118.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
109432 if( yygotominor.yy118.pExpr ) {
109433 yygotominor.yy118.pExpr->affinity = (char)yymsp[-3].minor.yy4;
109434 }
109435 yygotominor.yy118.zStart = yymsp[-5].minor.yy0.z;
109436 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
109437 }
109438 #line 3451 "parse.c"
109439 break;
109440 case 297: /* raisetype ::= ROLLBACK */
109441 #line 1296 "parse.y"
109442 {yygotominor.yy4 = OE_Rollback;}
109443 #line 3456 "parse.c"
109444 break;
109445 case 299: /* raisetype ::= FAIL */
109446 #line 1298 "parse.y"
109447 {yygotominor.yy4 = OE_Fail;}
109448 #line 3461 "parse.c"
109449 break;
109450 case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
109451 #line 1303 "parse.y"
109452 {
109453 sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
109454 }
109455 #line 3468 "parse.c"
109456 break;
109457 case 301: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
109458 #line 1310 "parse.y"
109459 {
109460 sqlite3Attach(pParse, yymsp[-3].minor.yy118.pExpr, yymsp[-1].minor.yy118.pExpr, yymsp[0].minor.yy314);
109461 }
109462 #line 3475 "parse.c"
109463 break;
109464 case 302: /* cmd ::= DETACH database_kw_opt expr */
109465 #line 1313 "parse.y"
109466 {
109467 sqlite3Detach(pParse, yymsp[0].minor.yy118.pExpr);
109468 }
109469 #line 3482 "parse.c"
109470 break;
109471 case 307: /* cmd ::= REINDEX */
109472 #line 1328 "parse.y"
109473 {sqlite3Reindex(pParse, 0, 0);}
109474 #line 3487 "parse.c"
109475 break;
109476 case 308: /* cmd ::= REINDEX nm dbnm */
109477 #line 1329 "parse.y"
109478 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
109479 #line 3492 "parse.c"
109480 break;
109481 case 309: /* cmd ::= ANALYZE */
109482 #line 1334 "parse.y"
109483 {sqlite3Analyze(pParse, 0, 0);}
109484 #line 3497 "parse.c"
109485 break;
109486 case 310: /* cmd ::= ANALYZE nm dbnm */
109487 #line 1335 "parse.y"
109488 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
109489 #line 3502 "parse.c"
109490 break;
109491 case 311: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
109492 #line 1340 "parse.y"
109493 {
109494 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
109495 }
109496 #line 3509 "parse.c"
109497 break;
109498 case 312: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
109499 #line 1343 "parse.y"
109500 {
109501 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
109502 }
109503 #line 3516 "parse.c"
109504 break;
109505 case 313: /* add_column_fullname ::= fullname */
109506 #line 1346 "parse.y"
109507 {
109508 pParse->db->lookaside.bEnabled = 0;
109509 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
109510 }
109511 #line 3524 "parse.c"
109512 break;
109513 case 316: /* cmd ::= create_vtab */
109514 #line 1356 "parse.y"
109515 {sqlite3VtabFinishParse(pParse,0);}
109516 #line 3529 "parse.c"
109517 break;
109518 case 317: /* cmd ::= create_vtab LP vtabarglist RP */
109519 #line 1357 "parse.y"
109520 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
109521 #line 3534 "parse.c"
109522 break;
109523 case 318: /* create_vtab ::= createkw VIRTUAL TABLE nm dbnm USING nm */
109524 #line 1358 "parse.y"
109525 {
109526 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
109527 }
109528 #line 3541 "parse.c"
109529 break;
109530 case 321: /* vtabarg ::= */
109531 #line 1363 "parse.y"
109532 {sqlite3VtabArgInit(pParse);}
109533 #line 3546 "parse.c"
109534 break;
109535 case 323: /* vtabargtoken ::= ANY */
109536 case 324: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==324);
109537 case 325: /* lp ::= LP */ yytestcase(yyruleno==325);
109538 #line 1365 "parse.y"
109539 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
109540 #line 3553 "parse.c"
109541 break;
109542 default:
109543 /* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
109544 /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
109545 /* (2) cmdlist ::= ecmd */ yytestcase(yyruleno==2);
@@ -108764,15 +109637,17 @@
109637 int yymajor, /* The major type of the error token */
109638 YYMINORTYPE yyminor /* The minor type of the error token */
109639 ){
109640 sqlite3ParserARG_FETCH;
109641 #define TOKEN (yyminor.yy0)
109642 #line 32 "parse.y"
109643
109644 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
109645 assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */
109646 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
109647 pParse->parseError = 1;
109648 #line 3661 "parse.c"
109649 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
109650 }
109651
109652 /*
109653 ** The following is executed when the parser accepts
@@ -108962,10 +109837,11 @@
109837 return;
109838 }
109839
109840 /************** End of parse.c ***********************************************/
109841 /************** Begin file tokenize.c ****************************************/
109842 #line 1 "tsrc/tokenize.c"
109843 /*
109844 ** 2001 September 15
109845 **
109846 ** The author disclaims copyright to this source code. In place of
109847 ** a legal notice, here is a blessing:
@@ -109027,10 +109903,11 @@
109903 ** named keywordhash.h and then included into this source file by
109904 ** the #include below.
109905 */
109906 /************** Include keywordhash.h in the middle of tokenize.c ************/
109907 /************** Begin file keywordhash.h *************************************/
109908 #line 1 "tsrc/keywordhash.h"
109909 /***** This file contains automatically generated code ******
109910 **
109911 ** The code in this file has been automatically generated by
109912 **
109913 ** sqlite/tool/mkkeywordhash.c
@@ -109300,10 +110177,11 @@
110177 }
110178 #define SQLITE_N_KEYWORD 121
110179
110180 /************** End of keywordhash.h *****************************************/
110181 /************** Continuing where we left off in tokenize.c *******************/
110182 #line 66 "tsrc/tokenize.c"
110183
110184
110185 /*
110186 ** If X is a character that can be used in an identifier then
110187 ** IdChar(X) will be true. Otherwise it is false.
@@ -109764,10 +110642,11 @@
110642 return nErr;
110643 }
110644
110645 /************** End of tokenize.c ********************************************/
110646 /************** Begin file complete.c ****************************************/
110647 #line 1 "tsrc/complete.c"
110648 /*
110649 ** 2001 September 15
110650 **
110651 ** The author disclaims copyright to this source code. In place of
110652 ** a legal notice, here is a blessing:
@@ -110049,10 +110928,11 @@
110928 #endif /* SQLITE_OMIT_UTF16 */
110929 #endif /* SQLITE_OMIT_COMPLETE */
110930
110931 /************** End of complete.c ********************************************/
110932 /************** Begin file main.c ********************************************/
110933 #line 1 "tsrc/main.c"
110934 /*
110935 ** 2001 September 15
110936 **
110937 ** The author disclaims copyright to this source code. In place of
110938 ** a legal notice, here is a blessing:
@@ -110069,10 +110949,11 @@
110949 */
110950
110951 #ifdef SQLITE_ENABLE_FTS3
110952 /************** Include fts3.h in the middle of main.c ***********************/
110953 /************** Begin file fts3.h ********************************************/
110954 #line 1 "tsrc/fts3.h"
110955 /*
110956 ** 2006 Oct 10
110957 **
110958 ** The author disclaims copyright to this source code. In place of
110959 ** a legal notice, here is a blessing:
@@ -110097,14 +110978,16 @@
110978 } /* extern "C" */
110979 #endif /* __cplusplus */
110980
110981 /************** End of fts3.h ************************************************/
110982 /************** Continuing where we left off in main.c ***********************/
110983 #line 21 "tsrc/main.c"
110984 #endif
110985 #ifdef SQLITE_ENABLE_RTREE
110986 /************** Include rtree.h in the middle of main.c **********************/
110987 /************** Begin file rtree.h *******************************************/
110988 #line 1 "tsrc/rtree.h"
110989 /*
110990 ** 2008 May 26
110991 **
110992 ** The author disclaims copyright to this source code. In place of
110993 ** a legal notice, here is a blessing:
@@ -110129,14 +111012,16 @@
111012 } /* extern "C" */
111013 #endif /* __cplusplus */
111014
111015 /************** End of rtree.h ***********************************************/
111016 /************** Continuing where we left off in main.c ***********************/
111017 #line 24 "tsrc/main.c"
111018 #endif
111019 #ifdef SQLITE_ENABLE_ICU
111020 /************** Include sqliteicu.h in the middle of main.c ******************/
111021 /************** Begin file sqliteicu.h ***************************************/
111022 #line 1 "tsrc/sqliteicu.h"
111023 /*
111024 ** 2008 May 26
111025 **
111026 ** The author disclaims copyright to this source code. In place of
111027 ** a legal notice, here is a blessing:
@@ -110162,10 +111047,11 @@
111047 #endif /* __cplusplus */
111048
111049
111050 /************** End of sqliteicu.h *******************************************/
111051 /************** Continuing where we left off in main.c ***********************/
111052 #line 27 "tsrc/main.c"
111053 #endif
111054
111055 #ifndef SQLITE_AMALGAMATION
111056 /* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
111057 ** contains the text of SQLITE_VERSION macro.
@@ -113092,10 +113978,11 @@
113978 return 0;
113979 }
113980
113981 /************** End of main.c ************************************************/
113982 /************** Begin file notify.c ******************************************/
113983 #line 1 "tsrc/notify.c"
113984 /*
113985 ** 2009 March 3
113986 **
113987 ** The author disclaims copyright to this source code. In place of
113988 ** a legal notice, here is a blessing:
@@ -113425,10 +114312,11 @@
114312 }
114313 #endif
114314
114315 /************** End of notify.c **********************************************/
114316 /************** Begin file fts3.c ********************************************/
114317 #line 1 "tsrc/fts3.c"
114318 /*
114319 ** 2006 Oct 10
114320 **
114321 ** The author disclaims copyright to this source code. In place of
114322 ** a legal notice, here is a blessing:
@@ -113721,10 +114609,11 @@
114609 ** into a single segment.
114610 */
114611
114612 /************** Include fts3Int.h in the middle of fts3.c ********************/
114613 /************** Begin file fts3Int.h *****************************************/
114614 #line 1 "tsrc/fts3Int.h"
114615 /*
114616 ** 2009 Nov 12
114617 **
114618 ** The author disclaims copyright to this source code. In place of
114619 ** a legal notice, here is a blessing:
@@ -113759,10 +114648,11 @@
114648 SQLITE_API extern const sqlite3_api_routines *sqlite3_api;
114649 #endif
114650
114651 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
114652 /************** Begin file fts3_tokenizer.h **********************************/
114653 #line 1 "tsrc/fts3_tokenizer.h"
114654 /*
114655 ** 2006 July 10
114656 **
114657 ** The author disclaims copyright to this source code.
114658 **
@@ -113913,12 +114803,14 @@
114803
114804 #endif /* _FTS3_TOKENIZER_H_ */
114805
114806 /************** End of fts3_tokenizer.h **************************************/
114807 /************** Continuing where we left off in fts3Int.h ********************/
114808 #line 40 "tsrc/fts3Int.h"
114809 /************** Include fts3_hash.h in the middle of fts3Int.h ***************/
114810 /************** Begin file fts3_hash.h ***************************************/
114811 #line 1 "tsrc/fts3_hash.h"
114812 /*
114813 ** 2001 September 22
114814 **
114815 ** The author disclaims copyright to this source code. In place of
114816 ** a legal notice, here is a blessing:
@@ -114030,10 +114922,11 @@
114922
114923 #endif /* _FTS3_HASH_H_ */
114924
114925 /************** End of fts3_hash.h *******************************************/
114926 /************** Continuing where we left off in fts3Int.h ********************/
114927 #line 41 "tsrc/fts3Int.h"
114928
114929 /*
114930 ** This constant controls how often segments are merged. Once there are
114931 ** FTS3_MERGE_COUNT segments of level N, they are merged into a single
114932 ** segment of level N+1.
@@ -114506,10 +115399,11 @@
115399 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
115400 #endif /* _FTSINT_H */
115401
115402 /************** End of fts3Int.h *********************************************/
115403 /************** Continuing where we left off in fts3.c ***********************/
115404 #line 296 "tsrc/fts3.c"
115405 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
115406
115407 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
115408 # define SQLITE_CORE 1
115409 #endif
@@ -119055,10 +119949,11 @@
119949
119950 #endif
119951
119952 /************** End of fts3.c ************************************************/
119953 /************** Begin file fts3_aux.c ****************************************/
119954 #line 1 "tsrc/fts3_aux.c"
119955 /*
119956 ** 2011 Jan 27
119957 **
119958 ** The author disclaims copyright to this source code. In place of
119959 ** a legal notice, here is a blessing:
@@ -119531,10 +120426,11 @@
120426
120427 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
120428
120429 /************** End of fts3_aux.c ********************************************/
120430 /************** Begin file fts3_expr.c ***************************************/
120431 #line 1 "tsrc/fts3_expr.c"
120432 /*
120433 ** 2008 Nov 28
120434 **
120435 ** The author disclaims copyright to this source code. In place of
120436 ** a legal notice, here is a blessing:
@@ -120497,10 +121393,11 @@
121393 #endif
121394 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
121395
121396 /************** End of fts3_expr.c *******************************************/
121397 /************** Begin file fts3_hash.c ***************************************/
121398 #line 1 "tsrc/fts3_hash.c"
121399 /*
121400 ** 2001 September 22
121401 **
121402 ** The author disclaims copyright to this source code. In place of
121403 ** a legal notice, here is a blessing:
@@ -120881,10 +121778,11 @@
121778
121779 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
121780
121781 /************** End of fts3_hash.c *******************************************/
121782 /************** Begin file fts3_porter.c *************************************/
121783 #line 1 "tsrc/fts3_porter.c"
121784 /*
121785 ** 2006 September 30
121786 **
121787 ** The author disclaims copyright to this source code. In place of
121788 ** a legal notice, here is a blessing:
@@ -121527,10 +122425,11 @@
122425
122426 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
122427
122428 /************** End of fts3_porter.c *****************************************/
122429 /************** Begin file fts3_tokenizer.c **********************************/
122430 #line 1 "tsrc/fts3_tokenizer.c"
122431 /*
122432 ** 2007 June 22
122433 **
122434 ** The author disclaims copyright to this source code. In place of
122435 ** a legal notice, here is a blessing:
@@ -122018,10 +122917,11 @@
122917
122918 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
122919
122920 /************** End of fts3_tokenizer.c **************************************/
122921 /************** Begin file fts3_tokenizer1.c *********************************/
122922 #line 1 "tsrc/fts3_tokenizer1.c"
122923 /*
122924 ** 2006 Oct 10
122925 **
122926 ** The author disclaims copyright to this source code. In place of
122927 ** a legal notice, here is a blessing:
@@ -122252,10 +123152,11 @@
123152
123153 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
123154
123155 /************** End of fts3_tokenizer1.c *************************************/
123156 /************** Begin file fts3_write.c **************************************/
123157 #line 1 "tsrc/fts3_write.c"
123158 /*
123159 ** 2009 Oct 23
123160 **
123161 ** The author disclaims copyright to this source code. In place of
123162 ** a legal notice, here is a blessing:
@@ -125522,10 +126423,11 @@
126423
126424 #endif
126425
126426 /************** End of fts3_write.c ******************************************/
126427 /************** Begin file fts3_snippet.c ************************************/
126428 #line 1 "tsrc/fts3_snippet.c"
126429 /*
126430 ** 2009 Oct 23
126431 **
126432 ** The author disclaims copyright to this source code. In place of
126433 ** a legal notice, here is a blessing:
@@ -127023,10 +127925,11 @@
127925
127926 #endif
127927
127928 /************** End of fts3_snippet.c ****************************************/
127929 /************** Begin file rtree.c *******************************************/
127930 #line 1 "tsrc/rtree.c"
127931 /*
127932 ** 2001 September 15
127933 **
127934 ** The author disclaims copyright to this source code. In place of
127935 ** a legal notice, here is a blessing:
@@ -130304,10 +131207,11 @@
131207
131208 #endif
131209
131210 /************** End of rtree.c ***********************************************/
131211 /************** Begin file icu.c *********************************************/
131212 #line 1 "tsrc/icu.c"
131213 /*
131214 ** 2007 May 6
131215 **
131216 ** The author disclaims copyright to this source code. In place of
131217 ** a legal notice, here is a blessing:
@@ -130806,10 +131710,11 @@
131710
131711 #endif
131712
131713 /************** End of icu.c *************************************************/
131714 /************** Begin file fts3_icu.c ****************************************/
131715 #line 1 "tsrc/fts3_icu.c"
131716 /*
131717 ** 2007 June 22
131718 **
131719 ** The author disclaims copyright to this source code. In place of
131720 ** a legal notice, here is a blessing:
131721
+31 -7
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.8"
111
-#define SQLITE_VERSION_NUMBER 3007008
112
-#define SQLITE_SOURCE_ID "2011-09-19 14:49:19 3e0da808d2f5b4d12046e05980ca04578f581177"
110
+#define SQLITE_VERSION "3.7.9"
111
+#define SQLITE_VERSION_NUMBER 3007009
112
+#define SQLITE_SOURCE_ID "2011-10-07 18:24:25 d4f95b3b6e9f4a4072606af5daa17ea7c645382e"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -769,11 +769,15 @@
769769
** in order for the database to be readable. The fourth parameter to
770770
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
771771
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
772772
** WAL mode. If the integer is -1, then it is overwritten with the current
773773
** WAL persistence setting.
774
-**
774
+**
775
+** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
776
+** a write transaction to indicate that, unless it is rolled back for some
777
+** reason, the entire database file will be overwritten by the current
778
+** transaction. This is used by VACUUM operations.
775779
*/
776780
#define SQLITE_FCNTL_LOCKSTATE 1
777781
#define SQLITE_GET_LOCKPROXYFILE 2
778782
#define SQLITE_SET_LOCKPROXYFILE 3
779783
#define SQLITE_LAST_ERRNO 4
@@ -781,10 +785,11 @@
781785
#define SQLITE_FCNTL_CHUNK_SIZE 6
782786
#define SQLITE_FCNTL_FILE_POINTER 7
783787
#define SQLITE_FCNTL_SYNC_OMITTED 8
784788
#define SQLITE_FCNTL_WIN32_AV_RETRY 9
785789
#define SQLITE_FCNTL_PERSIST_WAL 10
790
+#define SQLITE_FCNTL_OVERWRITE 11
786791
787792
/*
788793
** CAPI3REF: Mutex Handle
789794
**
790795
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2848,11 +2853,11 @@
28482853
** a schema change, on the first [sqlite3_step()] call following any change
28492854
** to the [sqlite3_bind_text | bindings] of that [parameter].
28502855
** ^The specific value of WHERE-clause [parameter] might influence the
28512856
** choice of query plan if the parameter is the left-hand side of a [LIKE]
28522857
** or [GLOB] operator or if the parameter is compared to an indexed column
2853
-** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
2858
+** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
28542859
** the
28552860
** </li>
28562861
** </ol>
28572862
*/
28582863
SQLITE_API int sqlite3_prepare(
@@ -3351,10 +3356,16 @@
33513356
** current row of the result set of [prepared statement] P.
33523357
** ^If prepared statement P does not have results ready to return
33533358
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
33543359
** interfaces) then sqlite3_data_count(P) returns 0.
33553360
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3361
+** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
3362
+** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
3363
+** will return non-zero if previous call to [sqlite3_step](P) returned
3364
+** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
3365
+** where it always returns zero since each step of that multi-step
3366
+** pragma returns 0 columns of data.
33563367
**
33573368
** See also: [sqlite3_column_count()]
33583369
*/
33593370
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
33603371
@@ -5813,20 +5824,34 @@
58135824
** <dd>This parameter returns the approximate number of of bytes of heap
58145825
** and lookaside memory used by all prepared statements associated with
58155826
** the database connection.)^
58165827
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
58175828
** </dd>
5829
+**
5830
+** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
5831
+** <dd>This parameter returns the number of pager cache hits that have
5832
+** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
5833
+** is always 0.
5834
+** </dd>
5835
+**
5836
+** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
5837
+** <dd>This parameter returns the number of pager cache misses that have
5838
+** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
5839
+** is always 0.
5840
+** </dd>
58185841
** </dl>
58195842
*/
58205843
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
58215844
#define SQLITE_DBSTATUS_CACHE_USED 1
58225845
#define SQLITE_DBSTATUS_SCHEMA_USED 2
58235846
#define SQLITE_DBSTATUS_STMT_USED 3
58245847
#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
58255848
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
58265849
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5827
-#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
5850
+#define SQLITE_DBSTATUS_CACHE_HIT 7
5851
+#define SQLITE_DBSTATUS_CACHE_MISS 8
5852
+#define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
58285853
58295854
58305855
/*
58315856
** CAPI3REF: Prepared Statement Status
58325857
**
@@ -5876,11 +5901,10 @@
58765901
** <dd>^This is the number of rows inserted into transient indices that
58775902
** were created automatically in order to help joins run faster.
58785903
** A non-zero value in this counter may indicate an opportunity to
58795904
** improvement performance by adding permanent indices that do not
58805905
** need to be reinitialized each time the statement is run.</dd>
5881
-**
58825906
** </dl>
58835907
*/
58845908
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
58855909
#define SQLITE_STMTSTATUS_SORT 2
58865910
#define SQLITE_STMTSTATUS_AUTOINDEX 3
58875911
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.8"
111 #define SQLITE_VERSION_NUMBER 3007008
112 #define SQLITE_SOURCE_ID "2011-09-19 14:49:19 3e0da808d2f5b4d12046e05980ca04578f581177"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -769,11 +769,15 @@
769 ** in order for the database to be readable. The fourth parameter to
770 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
771 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
772 ** WAL mode. If the integer is -1, then it is overwritten with the current
773 ** WAL persistence setting.
774 **
 
 
 
 
775 */
776 #define SQLITE_FCNTL_LOCKSTATE 1
777 #define SQLITE_GET_LOCKPROXYFILE 2
778 #define SQLITE_SET_LOCKPROXYFILE 3
779 #define SQLITE_LAST_ERRNO 4
@@ -781,10 +785,11 @@
781 #define SQLITE_FCNTL_CHUNK_SIZE 6
782 #define SQLITE_FCNTL_FILE_POINTER 7
783 #define SQLITE_FCNTL_SYNC_OMITTED 8
784 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
785 #define SQLITE_FCNTL_PERSIST_WAL 10
 
786
787 /*
788 ** CAPI3REF: Mutex Handle
789 **
790 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2848,11 +2853,11 @@
2848 ** a schema change, on the first [sqlite3_step()] call following any change
2849 ** to the [sqlite3_bind_text | bindings] of that [parameter].
2850 ** ^The specific value of WHERE-clause [parameter] might influence the
2851 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
2852 ** or [GLOB] operator or if the parameter is compared to an indexed column
2853 ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
2854 ** the
2855 ** </li>
2856 ** </ol>
2857 */
2858 SQLITE_API int sqlite3_prepare(
@@ -3351,10 +3356,16 @@
3351 ** current row of the result set of [prepared statement] P.
3352 ** ^If prepared statement P does not have results ready to return
3353 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3354 ** interfaces) then sqlite3_data_count(P) returns 0.
3355 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
 
 
 
 
 
 
3356 **
3357 ** See also: [sqlite3_column_count()]
3358 */
3359 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3360
@@ -5813,20 +5824,34 @@
5813 ** <dd>This parameter returns the approximate number of of bytes of heap
5814 ** and lookaside memory used by all prepared statements associated with
5815 ** the database connection.)^
5816 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5817 ** </dd>
 
 
 
 
 
 
 
 
 
 
 
 
5818 ** </dl>
5819 */
5820 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5821 #define SQLITE_DBSTATUS_CACHE_USED 1
5822 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5823 #define SQLITE_DBSTATUS_STMT_USED 3
5824 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5825 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5826 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5827 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
 
 
5828
5829
5830 /*
5831 ** CAPI3REF: Prepared Statement Status
5832 **
@@ -5876,11 +5901,10 @@
5876 ** <dd>^This is the number of rows inserted into transient indices that
5877 ** were created automatically in order to help joins run faster.
5878 ** A non-zero value in this counter may indicate an opportunity to
5879 ** improvement performance by adding permanent indices that do not
5880 ** need to be reinitialized each time the statement is run.</dd>
5881 **
5882 ** </dl>
5883 */
5884 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5885 #define SQLITE_STMTSTATUS_SORT 2
5886 #define SQLITE_STMTSTATUS_AUTOINDEX 3
5887
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.9"
111 #define SQLITE_VERSION_NUMBER 3007009
112 #define SQLITE_SOURCE_ID "2011-10-07 18:24:25 d4f95b3b6e9f4a4072606af5daa17ea7c645382e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -769,11 +769,15 @@
769 ** in order for the database to be readable. The fourth parameter to
770 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
771 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
772 ** WAL mode. If the integer is -1, then it is overwritten with the current
773 ** WAL persistence setting.
774 **
775 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
776 ** a write transaction to indicate that, unless it is rolled back for some
777 ** reason, the entire database file will be overwritten by the current
778 ** transaction. This is used by VACUUM operations.
779 */
780 #define SQLITE_FCNTL_LOCKSTATE 1
781 #define SQLITE_GET_LOCKPROXYFILE 2
782 #define SQLITE_SET_LOCKPROXYFILE 3
783 #define SQLITE_LAST_ERRNO 4
@@ -781,10 +785,11 @@
785 #define SQLITE_FCNTL_CHUNK_SIZE 6
786 #define SQLITE_FCNTL_FILE_POINTER 7
787 #define SQLITE_FCNTL_SYNC_OMITTED 8
788 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
789 #define SQLITE_FCNTL_PERSIST_WAL 10
790 #define SQLITE_FCNTL_OVERWRITE 11
791
792 /*
793 ** CAPI3REF: Mutex Handle
794 **
795 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2848,11 +2853,11 @@
2853 ** a schema change, on the first [sqlite3_step()] call following any change
2854 ** to the [sqlite3_bind_text | bindings] of that [parameter].
2855 ** ^The specific value of WHERE-clause [parameter] might influence the
2856 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
2857 ** or [GLOB] operator or if the parameter is compared to an indexed column
2858 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
2859 ** the
2860 ** </li>
2861 ** </ol>
2862 */
2863 SQLITE_API int sqlite3_prepare(
@@ -3351,10 +3356,16 @@
3356 ** current row of the result set of [prepared statement] P.
3357 ** ^If prepared statement P does not have results ready to return
3358 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3359 ** interfaces) then sqlite3_data_count(P) returns 0.
3360 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3361 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
3362 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
3363 ** will return non-zero if previous call to [sqlite3_step](P) returned
3364 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
3365 ** where it always returns zero since each step of that multi-step
3366 ** pragma returns 0 columns of data.
3367 **
3368 ** See also: [sqlite3_column_count()]
3369 */
3370 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3371
@@ -5813,20 +5824,34 @@
5824 ** <dd>This parameter returns the approximate number of of bytes of heap
5825 ** and lookaside memory used by all prepared statements associated with
5826 ** the database connection.)^
5827 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5828 ** </dd>
5829 **
5830 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
5831 ** <dd>This parameter returns the number of pager cache hits that have
5832 ** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
5833 ** is always 0.
5834 ** </dd>
5835 **
5836 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
5837 ** <dd>This parameter returns the number of pager cache misses that have
5838 ** occurred. ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
5839 ** is always 0.
5840 ** </dd>
5841 ** </dl>
5842 */
5843 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5844 #define SQLITE_DBSTATUS_CACHE_USED 1
5845 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5846 #define SQLITE_DBSTATUS_STMT_USED 3
5847 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5848 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5849 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5850 #define SQLITE_DBSTATUS_CACHE_HIT 7
5851 #define SQLITE_DBSTATUS_CACHE_MISS 8
5852 #define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
5853
5854
5855 /*
5856 ** CAPI3REF: Prepared Statement Status
5857 **
@@ -5876,11 +5901,10 @@
5901 ** <dd>^This is the number of rows inserted into transient indices that
5902 ** were created automatically in order to help joins run faster.
5903 ** A non-zero value in this counter may indicate an opportunity to
5904 ** improvement performance by adding permanent indices that do not
5905 ** need to be reinitialized each time the statement is run.</dd>
 
5906 ** </dl>
5907 */
5908 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5909 #define SQLITE_STMTSTATUS_SORT 2
5910 #define SQLITE_STMTSTATUS_AUTOINDEX 3
5911
+2 -2
--- src/th.c
+++ src/th.c
@@ -1817,12 +1817,12 @@
18171817
rc = thSubstWord(interp, pExpr->zValue, pExpr->nValue);
18181818
}else{
18191819
int eArgType = 0; /* Actual type of arguments */
18201820
18211821
/* Argument values */
1822
- int iLeft;
1823
- int iRight;
1822
+ int iLeft = 0;
1823
+ int iRight = 0;
18241824
double fLeft;
18251825
double fRight;
18261826
18271827
/* Left and right arguments as strings */
18281828
char *zLeft = 0; int nLeft = 0;
18291829
--- src/th.c
+++ src/th.c
@@ -1817,12 +1817,12 @@
1817 rc = thSubstWord(interp, pExpr->zValue, pExpr->nValue);
1818 }else{
1819 int eArgType = 0; /* Actual type of arguments */
1820
1821 /* Argument values */
1822 int iLeft;
1823 int iRight;
1824 double fLeft;
1825 double fRight;
1826
1827 /* Left and right arguments as strings */
1828 char *zLeft = 0; int nLeft = 0;
1829
--- src/th.c
+++ src/th.c
@@ -1817,12 +1817,12 @@
1817 rc = thSubstWord(interp, pExpr->zValue, pExpr->nValue);
1818 }else{
1819 int eArgType = 0; /* Actual type of arguments */
1820
1821 /* Argument values */
1822 int iLeft = 0;
1823 int iRight = 0;
1824 double fLeft;
1825 double fRight;
1826
1827 /* Left and right arguments as strings */
1828 char *zLeft = 0; int nLeft = 0;
1829
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -85,6 +85,19 @@
8585
been a smoother ride than Git was.
8686
8787
<blockquote>
8888
<i>viablepanic at [http://www.reddit.com/r/programming/comments/bxcto/why_not_fossil_scm/]</i>
8989
</blockquote>
90
+
91
+<li>In the fossil community - and hence in fossil itself - development history
92
+is pretty much sacrosanct. The very name "fossil" was to chosen to
93
+reflect the unchanging nature of things in that history.
94
+
95
+<p>In git (or rather, the git community), the development history is part of
96
+the published aspect of the project, so it provides tools for rearranging
97
+that history so you can present what you "should" have done rather
98
+than what you actually did.
99
+
100
+<blockquote>
101
+<i>Mike Meyer on the Fossil mailing list, 2011-10-04</i>
102
+</blockquote>
90103
</ol>
91104
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -85,6 +85,19 @@
85 been a smoother ride than Git was.
86
87 <blockquote>
88 <i>viablepanic at [http://www.reddit.com/r/programming/comments/bxcto/why_not_fossil_scm/]</i>
89 </blockquote>
 
 
 
 
 
 
 
 
 
 
 
 
 
90 </ol>
91
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -85,6 +85,19 @@
85 been a smoother ride than Git was.
86
87 <blockquote>
88 <i>viablepanic at [http://www.reddit.com/r/programming/comments/bxcto/why_not_fossil_scm/]</i>
89 </blockquote>
90
91 <li>In the fossil community - and hence in fossil itself - development history
92 is pretty much sacrosanct. The very name "fossil" was to chosen to
93 reflect the unchanging nature of things in that history.
94
95 <p>In git (or rather, the git community), the development history is part of
96 the published aspect of the project, so it provides tools for rearranging
97 that history so you can present what you "should" have done rather
98 than what you actually did.
99
100 <blockquote>
101 <i>Mike Meyer on the Fossil mailing list, 2011-10-04</i>
102 </blockquote>
103 </ol>
104

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button