Fossil SCM

Update the built-in SQLite to the latest 3.22 alpha version.

drh 2017-12-06 20:53 trunk
Commit 63fb653a7e943ae192e46cb8dbbbe2c792407960b86381cf4b1290f6e4afeaf2
3 files changed +86 -71 +760 -437 +1 -1
+86 -71
--- src/shell.c
+++ src/shell.c
@@ -2548,16 +2548,13 @@
25482548
i = 0;
25492549
break;
25502550
}
25512551
}
25522552
if( i==0 ){
2553
- putc('"', out);
2554
- for(i=0; z[i]; i++){
2555
- if( z[i]=='"' ) putc('"', out);
2556
- putc(z[i], out);
2557
- }
2558
- putc('"', out);
2553
+ char *zQuoted = sqlite3_mprintf("\"%w\"", z);
2554
+ utf8_printf(out, "%s", zQuoted);
2555
+ sqlite3_free(zQuoted);
25592556
}else{
25602557
utf8_printf(out, "%s", z);
25612558
}
25622559
}
25632560
if( bSep ){
@@ -5256,14 +5253,14 @@
52565253
** This SELECT statement returns one row for each foreign key constraint
52575254
** in the schema of the main database. The column values are:
52585255
**
52595256
** 0. The text of an SQL statement similar to:
52605257
**
5261
- ** "EXPLAIN QUERY PLAN SELECT rowid FROM child_table WHERE child_key=?"
5258
+ ** "EXPLAIN QUERY PLAN SELECT 1 FROM child_table WHERE child_key=?"
52625259
**
5263
- ** This is the same SELECT that the foreign keys implementation needs
5264
- ** to run internally on child tables. If there is an index that can
5260
+ ** This SELECT is similar to the one that the foreign keys implementation
5261
+ ** needs to run internally on child tables. If there is an index that can
52655262
** be used to optimize this query, then it can also be used by the FK
52665263
** implementation to optimize DELETE or UPDATE statements on the parent
52675264
** table.
52685265
**
52695266
** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
@@ -5287,11 +5284,11 @@
52875284
**
52885285
** These six values are used by the C logic below to generate the report.
52895286
*/
52905287
const char *zSql =
52915288
"SELECT "
5292
- " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
5289
+ " 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
52935290
" || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
52945291
" || fkey_collate_clause("
52955292
" f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
52965293
", "
52975294
" 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
@@ -7280,66 +7277,91 @@
72807277
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
72817278
}
72827279
}else
72837280
72847281
#ifndef SQLITE_UNTESTABLE
7285
- if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
7282
+ if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
72867283
static const struct {
72877284
const char *zCtrlName; /* Name of a test-control option */
72887285
int ctrlCode; /* Integer code for that option */
7286
+ const char *zUsage; /* Usage notes */
72897287
} aCtrl[] = {
7290
- { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE },
7291
- { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE },
7292
- { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET },
7293
- { "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST },
7294
- { "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL },
7295
- { "benign_malloc_hooks", SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS },
7296
- { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE },
7297
- { "assert", SQLITE_TESTCTRL_ASSERT },
7298
- { "always", SQLITE_TESTCTRL_ALWAYS },
7299
- { "reserve", SQLITE_TESTCTRL_RESERVE },
7300
- { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
7301
- { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
7302
- { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
7303
- { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
7304
- { "imposter", SQLITE_TESTCTRL_IMPOSTER },
7288
+ { "always", SQLITE_TESTCTRL_ALWAYS, "BOOLEAN" },
7289
+ { "assert", SQLITE_TESTCTRL_ASSERT, "BOOLEAN" },
7290
+ /*{ "benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, "" },*/
7291
+ /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
7292
+ { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
7293
+ /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" }, */
7294
+ { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
7295
+#ifdef SQLITE_N_KEYWORD
7296
+ { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD, "IDENTIFIER" },
7297
+#endif
7298
+ { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
7299
+ { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
7300
+ { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
7301
+ { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
7302
+ { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET, "" },
7303
+ { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
7304
+ { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
7305
+ { "reserve", SQLITE_TESTCTRL_RESERVE, "BYTES-OF-RESERVE" },
73057306
};
73067307
int testctrl = -1;
7307
- int rc2 = 0;
7308
+ int iCtrl = -1;
7309
+ int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
7310
+ int isOk = 0;
73087311
int i, n2;
7312
+ const char *zCmd = 0;
7313
+
73097314
open_db(p, 0);
7315
+ zCmd = nArg>=2 ? azArg[1] : "help";
7316
+
7317
+ /* The argument can optionally begin with "-" or "--" */
7318
+ if( zCmd[0]=='-' && zCmd[1] ){
7319
+ zCmd++;
7320
+ if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
7321
+ }
7322
+
7323
+ /* --help lists all test-controls */
7324
+ if( strcmp(zCmd,"help")==0 ){
7325
+ utf8_printf(p->out, "Available test-controls:\n");
7326
+ for(i=0; i<ArraySize(aCtrl); i++){
7327
+ utf8_printf(p->out, " .testctrl %s %s\n",
7328
+ aCtrl[i].zCtrlName, aCtrl[i].zUsage);
7329
+ }
7330
+ rc = 1;
7331
+ goto meta_command_exit;
7332
+ }
73107333
73117334
/* convert testctrl text option to value. allow any unique prefix
73127335
** of the option name, or a numerical value. */
7313
- n2 = strlen30(azArg[1]);
7336
+ n2 = strlen30(zCmd);
73147337
for(i=0; i<ArraySize(aCtrl); i++){
7315
- if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
7338
+ if( strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){
73167339
if( testctrl<0 ){
73177340
testctrl = aCtrl[i].ctrlCode;
7341
+ iCtrl = i;
73187342
}else{
7319
- utf8_printf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
7320
- testctrl = -1;
7321
- break;
7343
+ utf8_printf(stderr, "Error: ambiguous test-control: \"%s\"\n"
7344
+ "Use \".testctrl --help\" for help\n", zCmd);
7345
+ rc = 1;
7346
+ goto meta_command_exit;
73227347
}
73237348
}
73247349
}
7325
- if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
7326
- if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
7327
- utf8_printf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
7350
+ if( testctrl<0 ){
7351
+ utf8_printf(stderr,"Error: unknown test-control: %s\n"
7352
+ "Use \".testctrl --help\" for help\n", zCmd);
73287353
}else{
73297354
switch(testctrl){
73307355
73317356
/* sqlite3_test_control(int, db, int) */
73327357
case SQLITE_TESTCTRL_OPTIMIZATIONS:
73337358
case SQLITE_TESTCTRL_RESERVE:
73347359
if( nArg==3 ){
73357360
int opt = (int)strtol(azArg[2], 0, 0);
73367361
rc2 = sqlite3_test_control(testctrl, p->db, opt);
7337
- raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7338
- } else {
7339
- utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
7340
- azArg[1]);
7362
+ isOk = 3;
73417363
}
73427364
break;
73437365
73447366
/* sqlite3_test_control(int) */
73457367
case SQLITE_TESTCTRL_PRNG_SAVE:
@@ -7346,54 +7368,50 @@
73467368
case SQLITE_TESTCTRL_PRNG_RESTORE:
73477369
case SQLITE_TESTCTRL_PRNG_RESET:
73487370
case SQLITE_TESTCTRL_BYTEORDER:
73497371
if( nArg==2 ){
73507372
rc2 = sqlite3_test_control(testctrl);
7351
- raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7352
- } else {
7353
- utf8_printf(stderr,"Error: testctrl %s takes no options\n",
7354
- azArg[1]);
7373
+ isOk = testctrl==SQLITE_TESTCTRL_BYTEORDER ? 1 : 3;
73557374
}
73567375
break;
73577376
73587377
/* sqlite3_test_control(int, uint) */
73597378
case SQLITE_TESTCTRL_PENDING_BYTE:
73607379
if( nArg==3 ){
73617380
unsigned int opt = (unsigned int)integerValue(azArg[2]);
73627381
rc2 = sqlite3_test_control(testctrl, opt);
7363
- raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7364
- } else {
7365
- utf8_printf(stderr,"Error: testctrl %s takes a single unsigned"
7366
- " int option\n", azArg[1]);
7382
+ isOk = 3;
73677383
}
73687384
break;
73697385
73707386
/* sqlite3_test_control(int, int) */
73717387
case SQLITE_TESTCTRL_ASSERT:
73727388
case SQLITE_TESTCTRL_ALWAYS:
7389
+ if( nArg==3 ){
7390
+ int opt = booleanValue(azArg[2]);
7391
+ rc2 = sqlite3_test_control(testctrl, opt);
7392
+ isOk = 1;
7393
+ }
7394
+ break;
7395
+
7396
+ /* sqlite3_test_control(int, int) */
7397
+ case SQLITE_TESTCTRL_LOCALTIME_FAULT:
73737398
case SQLITE_TESTCTRL_NEVER_CORRUPT:
73747399
if( nArg==3 ){
73757400
int opt = booleanValue(azArg[2]);
73767401
rc2 = sqlite3_test_control(testctrl, opt);
7377
- raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7378
- } else {
7379
- utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
7380
- azArg[1]);
7402
+ isOk = 3;
73817403
}
73827404
break;
73837405
73847406
/* sqlite3_test_control(int, char *) */
73857407
#ifdef SQLITE_N_KEYWORD
73867408
case SQLITE_TESTCTRL_ISKEYWORD:
73877409
if( nArg==3 ){
73887410
const char *opt = azArg[2];
73897411
rc2 = sqlite3_test_control(testctrl, opt);
7390
- raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7391
- } else {
7392
- utf8_printf(stderr,
7393
- "Error: testctrl %s takes a single char * option\n",
7394
- azArg[1]);
7412
+ isOk = 1;
73957413
}
73967414
break;
73977415
#endif
73987416
73997417
case SQLITE_TESTCTRL_IMPOSTER:
@@ -7400,25 +7418,22 @@
74007418
if( nArg==5 ){
74017419
rc2 = sqlite3_test_control(testctrl, p->db,
74027420
azArg[2],
74037421
integerValue(azArg[3]),
74047422
integerValue(azArg[4]));
7405
- raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7406
- }else{
7407
- raw_printf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
7408
- }
7409
- break;
7410
-
7411
- case SQLITE_TESTCTRL_BITVEC_TEST:
7412
- case SQLITE_TESTCTRL_FAULT_INSTALL:
7413
- case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
7414
- default:
7415
- utf8_printf(stderr,
7416
- "Error: CLI support for testctrl %s not implemented\n",
7417
- azArg[1]);
7418
- break;
7419
- }
7423
+ isOk = 3;
7424
+ }
7425
+ break;
7426
+ }
7427
+ }
7428
+ if( isOk==0 && iCtrl>=0 ){
7429
+ utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd, aCtrl[iCtrl].zUsage);
7430
+ rc = 1;
7431
+ }else if( isOk==1 ){
7432
+ raw_printf(p->out, "%d\n", rc2);
7433
+ }else if( isOk==2 ){
7434
+ raw_printf(p->out, "0x%08x\n", rc2);
74207435
}
74217436
}else
74227437
#endif /* !defined(SQLITE_UNTESTABLE) */
74237438
74247439
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 ){
74257440
--- src/shell.c
+++ src/shell.c
@@ -2548,16 +2548,13 @@
2548 i = 0;
2549 break;
2550 }
2551 }
2552 if( i==0 ){
2553 putc('"', out);
2554 for(i=0; z[i]; i++){
2555 if( z[i]=='"' ) putc('"', out);
2556 putc(z[i], out);
2557 }
2558 putc('"', out);
2559 }else{
2560 utf8_printf(out, "%s", z);
2561 }
2562 }
2563 if( bSep ){
@@ -5256,14 +5253,14 @@
5256 ** This SELECT statement returns one row for each foreign key constraint
5257 ** in the schema of the main database. The column values are:
5258 **
5259 ** 0. The text of an SQL statement similar to:
5260 **
5261 ** "EXPLAIN QUERY PLAN SELECT rowid FROM child_table WHERE child_key=?"
5262 **
5263 ** This is the same SELECT that the foreign keys implementation needs
5264 ** to run internally on child tables. If there is an index that can
5265 ** be used to optimize this query, then it can also be used by the FK
5266 ** implementation to optimize DELETE or UPDATE statements on the parent
5267 ** table.
5268 **
5269 ** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
@@ -5287,11 +5284,11 @@
5287 **
5288 ** These six values are used by the C logic below to generate the report.
5289 */
5290 const char *zSql =
5291 "SELECT "
5292 " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
5293 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
5294 " || fkey_collate_clause("
5295 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
5296 ", "
5297 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
@@ -7280,66 +7277,91 @@
7280 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
7281 }
7282 }else
7283
7284 #ifndef SQLITE_UNTESTABLE
7285 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
7286 static const struct {
7287 const char *zCtrlName; /* Name of a test-control option */
7288 int ctrlCode; /* Integer code for that option */
 
7289 } aCtrl[] = {
7290 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE },
7291 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE },
7292 { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET },
7293 { "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST },
7294 { "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL },
7295 { "benign_malloc_hooks", SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS },
7296 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE },
7297 { "assert", SQLITE_TESTCTRL_ASSERT },
7298 { "always", SQLITE_TESTCTRL_ALWAYS },
7299 { "reserve", SQLITE_TESTCTRL_RESERVE },
7300 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
7301 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
7302 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
7303 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
7304 { "imposter", SQLITE_TESTCTRL_IMPOSTER },
 
 
 
7305 };
7306 int testctrl = -1;
7307 int rc2 = 0;
 
 
7308 int i, n2;
 
 
7309 open_db(p, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7310
7311 /* convert testctrl text option to value. allow any unique prefix
7312 ** of the option name, or a numerical value. */
7313 n2 = strlen30(azArg[1]);
7314 for(i=0; i<ArraySize(aCtrl); i++){
7315 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
7316 if( testctrl<0 ){
7317 testctrl = aCtrl[i].ctrlCode;
 
7318 }else{
7319 utf8_printf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
7320 testctrl = -1;
7321 break;
 
7322 }
7323 }
7324 }
7325 if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
7326 if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
7327 utf8_printf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
7328 }else{
7329 switch(testctrl){
7330
7331 /* sqlite3_test_control(int, db, int) */
7332 case SQLITE_TESTCTRL_OPTIMIZATIONS:
7333 case SQLITE_TESTCTRL_RESERVE:
7334 if( nArg==3 ){
7335 int opt = (int)strtol(azArg[2], 0, 0);
7336 rc2 = sqlite3_test_control(testctrl, p->db, opt);
7337 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7338 } else {
7339 utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
7340 azArg[1]);
7341 }
7342 break;
7343
7344 /* sqlite3_test_control(int) */
7345 case SQLITE_TESTCTRL_PRNG_SAVE:
@@ -7346,54 +7368,50 @@
7346 case SQLITE_TESTCTRL_PRNG_RESTORE:
7347 case SQLITE_TESTCTRL_PRNG_RESET:
7348 case SQLITE_TESTCTRL_BYTEORDER:
7349 if( nArg==2 ){
7350 rc2 = sqlite3_test_control(testctrl);
7351 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7352 } else {
7353 utf8_printf(stderr,"Error: testctrl %s takes no options\n",
7354 azArg[1]);
7355 }
7356 break;
7357
7358 /* sqlite3_test_control(int, uint) */
7359 case SQLITE_TESTCTRL_PENDING_BYTE:
7360 if( nArg==3 ){
7361 unsigned int opt = (unsigned int)integerValue(azArg[2]);
7362 rc2 = sqlite3_test_control(testctrl, opt);
7363 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7364 } else {
7365 utf8_printf(stderr,"Error: testctrl %s takes a single unsigned"
7366 " int option\n", azArg[1]);
7367 }
7368 break;
7369
7370 /* sqlite3_test_control(int, int) */
7371 case SQLITE_TESTCTRL_ASSERT:
7372 case SQLITE_TESTCTRL_ALWAYS:
 
 
 
 
 
 
 
 
 
7373 case SQLITE_TESTCTRL_NEVER_CORRUPT:
7374 if( nArg==3 ){
7375 int opt = booleanValue(azArg[2]);
7376 rc2 = sqlite3_test_control(testctrl, opt);
7377 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7378 } else {
7379 utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
7380 azArg[1]);
7381 }
7382 break;
7383
7384 /* sqlite3_test_control(int, char *) */
7385 #ifdef SQLITE_N_KEYWORD
7386 case SQLITE_TESTCTRL_ISKEYWORD:
7387 if( nArg==3 ){
7388 const char *opt = azArg[2];
7389 rc2 = sqlite3_test_control(testctrl, opt);
7390 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7391 } else {
7392 utf8_printf(stderr,
7393 "Error: testctrl %s takes a single char * option\n",
7394 azArg[1]);
7395 }
7396 break;
7397 #endif
7398
7399 case SQLITE_TESTCTRL_IMPOSTER:
@@ -7400,25 +7418,22 @@
7400 if( nArg==5 ){
7401 rc2 = sqlite3_test_control(testctrl, p->db,
7402 azArg[2],
7403 integerValue(azArg[3]),
7404 integerValue(azArg[4]));
7405 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
7406 }else{
7407 raw_printf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
7408 }
7409 break;
7410
7411 case SQLITE_TESTCTRL_BITVEC_TEST:
7412 case SQLITE_TESTCTRL_FAULT_INSTALL:
7413 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
7414 default:
7415 utf8_printf(stderr,
7416 "Error: CLI support for testctrl %s not implemented\n",
7417 azArg[1]);
7418 break;
7419 }
7420 }
7421 }else
7422 #endif /* !defined(SQLITE_UNTESTABLE) */
7423
7424 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 ){
7425
--- src/shell.c
+++ src/shell.c
@@ -2548,16 +2548,13 @@
2548 i = 0;
2549 break;
2550 }
2551 }
2552 if( i==0 ){
2553 char *zQuoted = sqlite3_mprintf("\"%w\"", z);
2554 utf8_printf(out, "%s", zQuoted);
2555 sqlite3_free(zQuoted);
 
 
 
2556 }else{
2557 utf8_printf(out, "%s", z);
2558 }
2559 }
2560 if( bSep ){
@@ -5256,14 +5253,14 @@
5253 ** This SELECT statement returns one row for each foreign key constraint
5254 ** in the schema of the main database. The column values are:
5255 **
5256 ** 0. The text of an SQL statement similar to:
5257 **
5258 ** "EXPLAIN QUERY PLAN SELECT 1 FROM child_table WHERE child_key=?"
5259 **
5260 ** This SELECT is similar to the one that the foreign keys implementation
5261 ** needs to run internally on child tables. If there is an index that can
5262 ** be used to optimize this query, then it can also be used by the FK
5263 ** implementation to optimize DELETE or UPDATE statements on the parent
5264 ** table.
5265 **
5266 ** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
@@ -5287,11 +5284,11 @@
5284 **
5285 ** These six values are used by the C logic below to generate the report.
5286 */
5287 const char *zSql =
5288 "SELECT "
5289 " 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
5290 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
5291 " || fkey_collate_clause("
5292 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
5293 ", "
5294 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
@@ -7280,66 +7277,91 @@
7277 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
7278 }
7279 }else
7280
7281 #ifndef SQLITE_UNTESTABLE
7282 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
7283 static const struct {
7284 const char *zCtrlName; /* Name of a test-control option */
7285 int ctrlCode; /* Integer code for that option */
7286 const char *zUsage; /* Usage notes */
7287 } aCtrl[] = {
7288 { "always", SQLITE_TESTCTRL_ALWAYS, "BOOLEAN" },
7289 { "assert", SQLITE_TESTCTRL_ASSERT, "BOOLEAN" },
7290 /*{ "benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, "" },*/
7291 /*{ "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, "" },*/
7292 { "byteorder", SQLITE_TESTCTRL_BYTEORDER, "" },
7293 /*{ "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, "" }, */
7294 { "imposter", SQLITE_TESTCTRL_IMPOSTER, "SCHEMA ON/OFF ROOTPAGE"},
7295 #ifdef SQLITE_N_KEYWORD
7296 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD, "IDENTIFIER" },
7297 #endif
7298 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
7299 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
7300 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
7301 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
7302 { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET, "" },
7303 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
7304 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
7305 { "reserve", SQLITE_TESTCTRL_RESERVE, "BYTES-OF-RESERVE" },
7306 };
7307 int testctrl = -1;
7308 int iCtrl = -1;
7309 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
7310 int isOk = 0;
7311 int i, n2;
7312 const char *zCmd = 0;
7313
7314 open_db(p, 0);
7315 zCmd = nArg>=2 ? azArg[1] : "help";
7316
7317 /* The argument can optionally begin with "-" or "--" */
7318 if( zCmd[0]=='-' && zCmd[1] ){
7319 zCmd++;
7320 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
7321 }
7322
7323 /* --help lists all test-controls */
7324 if( strcmp(zCmd,"help")==0 ){
7325 utf8_printf(p->out, "Available test-controls:\n");
7326 for(i=0; i<ArraySize(aCtrl); i++){
7327 utf8_printf(p->out, " .testctrl %s %s\n",
7328 aCtrl[i].zCtrlName, aCtrl[i].zUsage);
7329 }
7330 rc = 1;
7331 goto meta_command_exit;
7332 }
7333
7334 /* convert testctrl text option to value. allow any unique prefix
7335 ** of the option name, or a numerical value. */
7336 n2 = strlen30(zCmd);
7337 for(i=0; i<ArraySize(aCtrl); i++){
7338 if( strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){
7339 if( testctrl<0 ){
7340 testctrl = aCtrl[i].ctrlCode;
7341 iCtrl = i;
7342 }else{
7343 utf8_printf(stderr, "Error: ambiguous test-control: \"%s\"\n"
7344 "Use \".testctrl --help\" for help\n", zCmd);
7345 rc = 1;
7346 goto meta_command_exit;
7347 }
7348 }
7349 }
7350 if( testctrl<0 ){
7351 utf8_printf(stderr,"Error: unknown test-control: %s\n"
7352 "Use \".testctrl --help\" for help\n", zCmd);
7353 }else{
7354 switch(testctrl){
7355
7356 /* sqlite3_test_control(int, db, int) */
7357 case SQLITE_TESTCTRL_OPTIMIZATIONS:
7358 case SQLITE_TESTCTRL_RESERVE:
7359 if( nArg==3 ){
7360 int opt = (int)strtol(azArg[2], 0, 0);
7361 rc2 = sqlite3_test_control(testctrl, p->db, opt);
7362 isOk = 3;
 
 
 
7363 }
7364 break;
7365
7366 /* sqlite3_test_control(int) */
7367 case SQLITE_TESTCTRL_PRNG_SAVE:
@@ -7346,54 +7368,50 @@
7368 case SQLITE_TESTCTRL_PRNG_RESTORE:
7369 case SQLITE_TESTCTRL_PRNG_RESET:
7370 case SQLITE_TESTCTRL_BYTEORDER:
7371 if( nArg==2 ){
7372 rc2 = sqlite3_test_control(testctrl);
7373 isOk = testctrl==SQLITE_TESTCTRL_BYTEORDER ? 1 : 3;
 
 
 
7374 }
7375 break;
7376
7377 /* sqlite3_test_control(int, uint) */
7378 case SQLITE_TESTCTRL_PENDING_BYTE:
7379 if( nArg==3 ){
7380 unsigned int opt = (unsigned int)integerValue(azArg[2]);
7381 rc2 = sqlite3_test_control(testctrl, opt);
7382 isOk = 3;
 
 
 
7383 }
7384 break;
7385
7386 /* sqlite3_test_control(int, int) */
7387 case SQLITE_TESTCTRL_ASSERT:
7388 case SQLITE_TESTCTRL_ALWAYS:
7389 if( nArg==3 ){
7390 int opt = booleanValue(azArg[2]);
7391 rc2 = sqlite3_test_control(testctrl, opt);
7392 isOk = 1;
7393 }
7394 break;
7395
7396 /* sqlite3_test_control(int, int) */
7397 case SQLITE_TESTCTRL_LOCALTIME_FAULT:
7398 case SQLITE_TESTCTRL_NEVER_CORRUPT:
7399 if( nArg==3 ){
7400 int opt = booleanValue(azArg[2]);
7401 rc2 = sqlite3_test_control(testctrl, opt);
7402 isOk = 3;
 
 
 
7403 }
7404 break;
7405
7406 /* sqlite3_test_control(int, char *) */
7407 #ifdef SQLITE_N_KEYWORD
7408 case SQLITE_TESTCTRL_ISKEYWORD:
7409 if( nArg==3 ){
7410 const char *opt = azArg[2];
7411 rc2 = sqlite3_test_control(testctrl, opt);
7412 isOk = 1;
 
 
 
 
7413 }
7414 break;
7415 #endif
7416
7417 case SQLITE_TESTCTRL_IMPOSTER:
@@ -7400,25 +7418,22 @@
7418 if( nArg==5 ){
7419 rc2 = sqlite3_test_control(testctrl, p->db,
7420 azArg[2],
7421 integerValue(azArg[3]),
7422 integerValue(azArg[4]));
7423 isOk = 3;
7424 }
7425 break;
7426 }
7427 }
7428 if( isOk==0 && iCtrl>=0 ){
7429 utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd, aCtrl[iCtrl].zUsage);
7430 rc = 1;
7431 }else if( isOk==1 ){
7432 raw_printf(p->out, "%d\n", rc2);
7433 }else if( isOk==2 ){
7434 raw_printf(p->out, "0x%08x\n", rc2);
 
 
 
7435 }
7436 }else
7437 #endif /* !defined(SQLITE_UNTESTABLE) */
7438
7439 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 ){
7440
+760 -437
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
11471147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11481148
** [sqlite_version()] and [sqlite_source_id()].
11491149
*/
11501150
#define SQLITE_VERSION "3.22.0"
11511151
#define SQLITE_VERSION_NUMBER 3022000
1152
-#define SQLITE_SOURCE_ID "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3"
1152
+#define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbcc71"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -16532,11 +16532,10 @@
1653216532
Expr *pHaving; /* The HAVING clause */
1653316533
ExprList *pOrderBy; /* The ORDER BY clause */
1653416534
Select *pPrior; /* Prior select in a compound select statement */
1653516535
Select *pNext; /* Next select to the left in a compound */
1653616536
Expr *pLimit; /* LIMIT expression. NULL means not used. */
16537
- Expr *pOffset; /* OFFSET expression. NULL means not used. */
1653816537
With *pWith; /* WITH clause attached to this select. Or NULL. */
1653916538
};
1654016539
1654116540
/*
1654216541
** Allowed values for Select.selFlags. The "SF" prefix stands for
@@ -17215,10 +17214,11 @@
1721517214
** the same name but without the _BKPT suffix. These macros invoke
1721617215
** routines that report the line-number on which the error originated
1721717216
** using sqlite3_log(). The routines also provide a convenient place
1721817217
** to set a debugger breakpoint.
1721917218
*/
17219
+SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType);
1722017220
SQLITE_PRIVATE int sqlite3CorruptError(int);
1722117221
SQLITE_PRIVATE int sqlite3MisuseError(int);
1722217222
SQLITE_PRIVATE int sqlite3CantopenError(int);
1722317223
#define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
1722417224
#define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
@@ -17372,10 +17372,16 @@
1737217372
SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*);
1737317373
1737417374
/* Access to mutexes used by sqlite3_status() */
1737517375
SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
1737617376
SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
17377
+
17378
+#if defined(SQLITE_ENABLE_MULTITHREADED_CHECKS) && !defined(SQLITE_MUTEX_OMIT)
17379
+SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex*);
17380
+#else
17381
+# define sqlite3MutexWarnOnContention(x)
17382
+#endif
1737717383
1737817384
#ifndef SQLITE_OMIT_FLOATING_POINT
1737917385
SQLITE_PRIVATE int sqlite3IsNaN(double);
1738017386
#else
1738117387
# define sqlite3IsNaN(X) 0
@@ -17539,20 +17545,20 @@
1753917545
SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
1754017546
Expr*, int, int, u8);
1754117547
SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
1754217548
SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
1754317549
SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
17544
- Expr*,ExprList*,u32,Expr*,Expr*);
17550
+ Expr*,ExprList*,u32,Expr*);
1754517551
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
1754617552
SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
1754717553
SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
1754817554
SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
1754917555
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
17550
-SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*);
17556
+SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
1755117557
#endif
17552
-SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*, Expr*);
17553
-SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,Expr*);
17558
+SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
17559
+SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*);
1755417560
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
1755517561
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
1755617562
SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
1755717563
SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
1755817564
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
@@ -17672,11 +17678,11 @@
1767217678
SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*);
1767317679
SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*);
1767417680
SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
1767517681
1767617682
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
17677
-SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,Expr*,int);
17683
+SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int);
1767817684
#endif
1767917685
1768017686
#ifndef SQLITE_OMIT_TRIGGER
1768117687
SQLITE_PRIVATE void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
1768217688
Expr*,int, int);
@@ -23393,10 +23399,197 @@
2339323399
static SQLITE_WSD int mutexIsInit = 0;
2339423400
#endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */
2339523401
2339623402
2339723403
#ifndef SQLITE_MUTEX_OMIT
23404
+
23405
+#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
23406
+/*
23407
+** This block (enclosed by SQLITE_ENABLE_MULTITHREADED_CHECKS) contains
23408
+** the implementation of a wrapper around the system default mutex
23409
+** implementation (sqlite3DefaultMutex()).
23410
+**
23411
+** Most calls are passed directly through to the underlying default
23412
+** mutex implementation. Except, if a mutex is configured by calling
23413
+** sqlite3MutexWarnOnContention() on it, then if contention is ever
23414
+** encountered within xMutexEnter() a warning is emitted via sqlite3_log().
23415
+**
23416
+** This type of mutex is used as the database handle mutex when testing
23417
+** apps that usually use SQLITE_CONFIG_MULTITHREAD mode.
23418
+*/
23419
+
23420
+/*
23421
+** Type for all mutexes used when SQLITE_ENABLE_MULTITHREADED_CHECKS
23422
+** is defined. Variable CheckMutex.mutex is a pointer to the real mutex
23423
+** allocated by the system mutex implementation. Variable iType is usually set
23424
+** to the type of mutex requested - SQLITE_MUTEX_RECURSIVE, SQLITE_MUTEX_FAST
23425
+** or one of the static mutex identifiers. Or, if this is a recursive mutex
23426
+** that has been configured using sqlite3MutexWarnOnContention(), it is
23427
+** set to SQLITE_MUTEX_WARNONCONTENTION.
23428
+*/
23429
+typedef struct CheckMutex CheckMutex;
23430
+struct CheckMutex {
23431
+ int iType;
23432
+ sqlite3_mutex *mutex;
23433
+};
23434
+
23435
+#define SQLITE_MUTEX_WARNONCONTENTION (-1)
23436
+
23437
+/*
23438
+** Pointer to real mutex methods object used by the CheckMutex
23439
+** implementation. Set by checkMutexInit().
23440
+*/
23441
+static SQLITE_WSD const sqlite3_mutex_methods *pGlobalMutexMethods;
23442
+
23443
+#ifdef SQLITE_DEBUG
23444
+static int checkMutexHeld(sqlite3_mutex *p){
23445
+ return pGlobalMutexMethods->xMutexHeld(((CheckMutex*)p)->mutex);
23446
+}
23447
+static int checkMutexNotheld(sqlite3_mutex *p){
23448
+ return pGlobalMutexMethods->xMutexNotheld(((CheckMutex*)p)->mutex);
23449
+}
23450
+#endif
23451
+
23452
+/*
23453
+** Initialize and deinitialize the mutex subsystem.
23454
+*/
23455
+static int checkMutexInit(void){
23456
+ pGlobalMutexMethods = sqlite3DefaultMutex();
23457
+ return SQLITE_OK;
23458
+}
23459
+static int checkMutexEnd(void){
23460
+ pGlobalMutexMethods = 0;
23461
+ return SQLITE_OK;
23462
+}
23463
+
23464
+/*
23465
+** Allocate a mutex.
23466
+*/
23467
+static sqlite3_mutex *checkMutexAlloc(int iType){
23468
+ static CheckMutex staticMutexes[] = {
23469
+ {2, 0}, {3, 0}, {4, 0}, {5, 0},
23470
+ {6, 0}, {7, 0}, {8, 0}, {9, 0},
23471
+ {10, 0}, {11, 0}, {12, 0}, {13, 0}
23472
+ };
23473
+ CheckMutex *p = 0;
23474
+
23475
+ assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 );
23476
+ if( iType<2 ){
23477
+ p = sqlite3MallocZero(sizeof(CheckMutex));
23478
+ if( p==0 ) return 0;
23479
+ p->iType = iType;
23480
+ }else{
23481
+#ifdef SQLITE_ENABLE_API_ARMOR
23482
+ if( iType-2>=ArraySize(staticMutexes) ){
23483
+ (void)SQLITE_MISUSE_BKPT;
23484
+ return 0;
23485
+ }
23486
+#endif
23487
+ p = &staticMutexes[iType-2];
23488
+ }
23489
+
23490
+ if( p->mutex==0 ){
23491
+ p->mutex = pGlobalMutexMethods->xMutexAlloc(iType);
23492
+ if( p->mutex==0 ){
23493
+ if( iType<2 ){
23494
+ sqlite3_free(p);
23495
+ }
23496
+ p = 0;
23497
+ }
23498
+ }
23499
+
23500
+ return (sqlite3_mutex*)p;
23501
+}
23502
+
23503
+/*
23504
+** Free a mutex.
23505
+*/
23506
+static void checkMutexFree(sqlite3_mutex *p){
23507
+ assert( SQLITE_MUTEX_RECURSIVE<2 );
23508
+ assert( SQLITE_MUTEX_FAST<2 );
23509
+ assert( SQLITE_MUTEX_WARNONCONTENTION<2 );
23510
+
23511
+#if SQLITE_ENABLE_API_ARMOR
23512
+ if( ((CheckMutex*)p)->iType<2 )
23513
+#endif
23514
+ {
23515
+ CheckMutex *pCheck = (CheckMutex*)p;
23516
+ pGlobalMutexMethods->xMutexFree(pCheck->mutex);
23517
+ sqlite3_free(pCheck);
23518
+ }
23519
+#ifdef SQLITE_ENABLE_API_ARMOR
23520
+ else{
23521
+ (void)SQLITE_MISUSE_BKPT;
23522
+ }
23523
+#endif
23524
+}
23525
+
23526
+/*
23527
+** Enter the mutex.
23528
+*/
23529
+static void checkMutexEnter(sqlite3_mutex *p){
23530
+ CheckMutex *pCheck = (CheckMutex*)p;
23531
+ if( pCheck->iType==SQLITE_MUTEX_WARNONCONTENTION ){
23532
+ if( SQLITE_OK==pGlobalMutexMethods->xMutexTry(pCheck->mutex) ){
23533
+ return;
23534
+ }
23535
+ sqlite3_log(SQLITE_MISUSE,
23536
+ "illegal multi-threaded access to database connection"
23537
+ );
23538
+ }
23539
+ pGlobalMutexMethods->xMutexEnter(pCheck->mutex);
23540
+}
23541
+
23542
+/*
23543
+** Enter the mutex (do not block).
23544
+*/
23545
+static int checkMutexTry(sqlite3_mutex *p){
23546
+ CheckMutex *pCheck = (CheckMutex*)p;
23547
+ return pGlobalMutexMethods->xMutexTry(pCheck->mutex);
23548
+}
23549
+
23550
+/*
23551
+** Leave the mutex.
23552
+*/
23553
+static void checkMutexLeave(sqlite3_mutex *p){
23554
+ CheckMutex *pCheck = (CheckMutex*)p;
23555
+ pGlobalMutexMethods->xMutexLeave(pCheck->mutex);
23556
+}
23557
+
23558
+sqlite3_mutex_methods const *multiThreadedCheckMutex(void){
23559
+ static const sqlite3_mutex_methods sMutex = {
23560
+ checkMutexInit,
23561
+ checkMutexEnd,
23562
+ checkMutexAlloc,
23563
+ checkMutexFree,
23564
+ checkMutexEnter,
23565
+ checkMutexTry,
23566
+ checkMutexLeave,
23567
+#ifdef SQLITE_DEBUG
23568
+ checkMutexHeld,
23569
+ checkMutexNotheld
23570
+#else
23571
+ 0,
23572
+ 0
23573
+#endif
23574
+ };
23575
+ return &sMutex;
23576
+}
23577
+
23578
+/*
23579
+** Mark the SQLITE_MUTEX_RECURSIVE mutex passed as the only argument as
23580
+** one on which there should be no contention.
23581
+*/
23582
+SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex *p){
23583
+ if( sqlite3GlobalConfig.mutex.xMutexAlloc==checkMutexAlloc ){
23584
+ CheckMutex *pCheck = (CheckMutex*)p;
23585
+ assert( pCheck->iType==SQLITE_MUTEX_RECURSIVE );
23586
+ pCheck->iType = SQLITE_MUTEX_WARNONCONTENTION;
23587
+ }
23588
+}
23589
+#endif /* ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS */
23590
+
2339823591
/*
2339923592
** Initialize the mutex system.
2340023593
*/
2340123594
SQLITE_PRIVATE int sqlite3MutexInit(void){
2340223595
int rc = SQLITE_OK;
@@ -23408,11 +23601,15 @@
2340823601
*/
2340923602
sqlite3_mutex_methods const *pFrom;
2341023603
sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
2341123604
2341223605
if( sqlite3GlobalConfig.bCoreMutex ){
23606
+#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
23607
+ pFrom = multiThreadedCheckMutex();
23608
+#else
2341323609
pFrom = sqlite3DefaultMutex();
23610
+#endif
2341423611
}else{
2341523612
pFrom = sqlite3NoopMutex();
2341623613
}
2341723614
pTo->xMutexInit = pFrom->xMutexInit;
2341823615
pTo->xMutexEnd = pFrom->xMutexEnd;
@@ -23534,10 +23731,11 @@
2353423731
return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
2353523732
}
2353623733
#endif
2353723734
2353823735
#endif /* !defined(SQLITE_MUTEX_OMIT) */
23736
+
2353923737
2354023738
/************** End of mutex.c ***********************************************/
2354123739
/************** Begin file mutex_noop.c **************************************/
2354223740
/*
2354323741
** 2008 October 07
@@ -26817,11 +27015,10 @@
2681727015
if( p->pWhere ) n++;
2681827016
if( p->pGroupBy ) n++;
2681927017
if( p->pHaving ) n++;
2682027018
if( p->pOrderBy ) n++;
2682127019
if( p->pLimit ) n++;
26822
- if( p->pOffset ) n++;
2682327020
}
2682427021
sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
2682527022
if( p->pSrc && p->pSrc->nSrc ){
2682627023
int i;
2682727024
pView = sqlite3TreeViewPush(pView, (n--)>0);
@@ -26874,16 +27071,16 @@
2687427071
if( p->pOrderBy ){
2687527072
sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
2687627073
}
2687727074
if( p->pLimit ){
2687827075
sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
26879
- sqlite3TreeViewExpr(pView, p->pLimit, 0);
26880
- sqlite3TreeViewPop(pView);
26881
- }
26882
- if( p->pOffset ){
26883
- sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
26884
- sqlite3TreeViewExpr(pView, p->pOffset, 0);
27076
+ sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0);
27077
+ if( p->pLimit->pRight ){
27078
+ sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
27079
+ sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
27080
+ sqlite3TreeViewPop(pView);
27081
+ }
2688527082
sqlite3TreeViewPop(pView);
2688627083
}
2688727084
if( p->pPrior ){
2688827085
const char *zOp = "UNION";
2688927086
switch( p->op ){
@@ -57728,12 +57925,11 @@
5772857925
assert( pWal->nWiData>0 );
5772957926
assert( pWal->apWiData[0]!=0 );
5773057927
pInfo = walCkptInfo(pWal);
5773157928
if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
5773257929
#ifdef SQLITE_ENABLE_SNAPSHOT
57733
- && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0
57734
- || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr)))
57930
+ && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
5773557931
#endif
5773657932
){
5773757933
/* The WAL has been completely backfilled (or it is empty).
5773857934
** and can be safely ignored.
5773957935
*/
@@ -60149,10 +60345,35 @@
6014960345
#define downgradeAllSharedCacheTableLocks(a)
6015060346
#define hasSharedCacheTableLock(a,b,c,d) 1
6015160347
#define hasReadConflicts(a, b) 0
6015260348
#endif
6015360349
60350
+/*
60351
+** Implementation of the SQLITE_CORRUPT_PAGE() macro. Takes a single
60352
+** (MemPage*) as an argument. The (MemPage*) must not be NULL.
60353
+**
60354
+** If SQLITE_DEBUG is not defined, then this macro is equivalent to
60355
+** SQLITE_CORRUPT_BKPT. Or, if SQLITE_DEBUG is set, then the log message
60356
+** normally produced as a side-effect of SQLITE_CORRUPT_BKPT is augmented
60357
+** with the page number and filename associated with the (MemPage*).
60358
+*/
60359
+#ifdef SQLITE_DEBUG
60360
+int corruptPageError(int lineno, MemPage *p){
60361
+ char *zMsg = sqlite3_mprintf("database corruption page %d of %s",
60362
+ (int)p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0)
60363
+ );
60364
+ if( zMsg ){
60365
+ sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg);
60366
+ }
60367
+ sqlite3_free(zMsg);
60368
+ return SQLITE_CORRUPT_BKPT;
60369
+}
60370
+# define SQLITE_CORRUPT_PAGE(pMemPage) corruptPageError(__LINE__, pMemPage)
60371
+#else
60372
+# define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno)
60373
+#endif
60374
+
6015460375
#ifndef SQLITE_OMIT_SHARED_CACHE
6015560376
6015660377
#ifdef SQLITE_DEBUG
6015760378
/*
6015860379
**** This function is only used as part of an assert() statement. ***
@@ -61437,11 +61658,11 @@
6143761658
u8 *pAddr;
6143861659
int sz2 = 0;
6143961660
int sz = get2byte(&data[iFree+2]);
6144061661
int top = get2byte(&data[hdr+5]);
6144161662
if( top>=iFree ){
61442
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61663
+ return SQLITE_CORRUPT_PAGE(pPage);
6144361664
}
6144461665
if( iFree2 ){
6144561666
assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */
6144661667
sz2 = get2byte(&data[iFree2+2]);
6144761668
assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
@@ -61471,17 +61692,17 @@
6147161692
testcase( pc==iCellLast );
6147261693
/* These conditions have already been verified in btreeInitPage()
6147361694
** if PRAGMA cell_size_check=ON.
6147461695
*/
6147561696
if( pc<iCellFirst || pc>iCellLast ){
61476
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61697
+ return SQLITE_CORRUPT_PAGE(pPage);
6147761698
}
6147861699
assert( pc>=iCellFirst && pc<=iCellLast );
6147961700
size = pPage->xCellSize(pPage, &src[pc]);
6148061701
cbrk -= size;
6148161702
if( cbrk<iCellFirst || pc+size>usableSize ){
61482
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61703
+ return SQLITE_CORRUPT_PAGE(pPage);
6148361704
}
6148461705
assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
6148561706
testcase( cbrk+size==usableSize );
6148661707
testcase( pc+size==usableSize );
6148761708
put2byte(pAddr, cbrk);
@@ -61497,11 +61718,11 @@
6149761718
}
6149861719
data[hdr+7] = 0;
6149961720
6150061721
defragment_out:
6150161722
if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
61502
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61723
+ return SQLITE_CORRUPT_PAGE(pPage);
6150361724
}
6150461725
assert( cbrk>=iCellFirst );
6150561726
put2byte(&data[hdr+5], cbrk);
6150661727
data[hdr+1] = 0;
6150761728
data[hdr+2] = 0;
@@ -61541,11 +61762,11 @@
6154161762
size = get2byte(&aData[pc+2]);
6154261763
if( (x = size - nByte)>=0 ){
6154361764
testcase( x==4 );
6154461765
testcase( x==3 );
6154561766
if( size+pc > usableSize ){
61546
- *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61767
+ *pRc = SQLITE_CORRUPT_PAGE(pPg);
6154761768
return 0;
6154861769
}else if( x<4 ){
6154961770
/* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
6155061771
** number of bytes in fragments may not exceed 60. */
6155161772
if( aData[hdr+7]>57 ) return 0;
@@ -61564,11 +61785,11 @@
6156461785
iAddr = pc;
6156561786
pc = get2byte(&aData[pc]);
6156661787
if( pc<iAddr+size ) break;
6156761788
}
6156861789
if( pc ){
61569
- *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61790
+ *pRc = SQLITE_CORRUPT_PAGE(pPg);
6157061791
}
6157161792
6157261793
return 0;
6157361794
}
6157461795
@@ -61612,11 +61833,11 @@
6161261833
assert( top<=(int)pPage->pBt->usableSize ); /* Prevent by getAndInitPage() */
6161361834
if( gap>top ){
6161461835
if( top==0 && pPage->pBt->usableSize==65536 ){
6161561836
top = 65536;
6161661837
}else{
61617
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61838
+ return SQLITE_CORRUPT_PAGE(pPage);
6161861839
}
6161961840
}
6162061841
6162161842
/* If there is enough space between gap and top for one more cell pointer
6162261843
** array entry offset, and if the freelist is not empty, then search the
@@ -61702,16 +61923,16 @@
6170261923
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
6170361924
}else{
6170461925
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
6170561926
if( iFreeBlk<iPtr+4 ){
6170661927
if( iFreeBlk==0 ) break;
61707
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61928
+ return SQLITE_CORRUPT_PAGE(pPage);
6170861929
}
6170961930
iPtr = iFreeBlk;
6171061931
}
6171161932
if( iFreeBlk>pPage->pBt->usableSize-4 ){
61712
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61933
+ return SQLITE_CORRUPT_PAGE(pPage);
6171361934
}
6171461935
assert( iFreeBlk>iPtr || iFreeBlk==0 );
6171561936
6171661937
/* At this point:
6171761938
** iFreeBlk: First freeblock after iStart, or zero if none
@@ -61719,14 +61940,14 @@
6171961940
**
6172061941
** Check to see if iFreeBlk should be coalesced onto the end of iStart.
6172161942
*/
6172261943
if( iFreeBlk && iEnd+3>=iFreeBlk ){
6172361944
nFrag = iFreeBlk - iEnd;
61724
- if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61945
+ if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
6172561946
iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
6172661947
if( iEnd > pPage->pBt->usableSize ){
61727
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
61948
+ return SQLITE_CORRUPT_PAGE(pPage);
6172861949
}
6172961950
iSize = iEnd - iStart;
6173061951
iFreeBlk = get2byte(&data[iFreeBlk]);
6173161952
}
6173261953
@@ -61735,25 +61956,25 @@
6173561956
** coalesced onto the end of iPtr.
6173661957
*/
6173761958
if( iPtr>hdr+1 ){
6173861959
int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
6173961960
if( iPtrEnd+3>=iStart ){
61740
- if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61961
+ if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage);
6174161962
nFrag += iStart - iPtrEnd;
6174261963
iSize = iEnd - iPtr;
6174361964
iStart = iPtr;
6174461965
}
6174561966
}
61746
- if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61967
+ if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
6174761968
data[hdr+7] -= nFrag;
6174861969
}
6174961970
x = get2byte(&data[hdr+5]);
6175061971
if( iStart<=x ){
6175161972
/* The new freeblock is at the beginning of the cell content area,
6175261973
** so just extend the cell content area rather than create another
6175361974
** freelist entry */
61754
- if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61975
+ if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
6175561976
put2byte(&data[hdr+1], iFreeBlk);
6175661977
put2byte(&data[hdr+5], iEnd);
6175761978
}else{
6175861979
/* Insert the new freeblock into the freelist */
6175961980
put2byte(&data[iPtr], iStart);
@@ -61822,11 +62043,11 @@
6182262043
pPage->maxLocal = pBt->maxLocal;
6182362044
pPage->minLocal = pBt->minLocal;
6182462045
}else{
6182562046
/* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
6182662047
** an error. */
61827
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62048
+ return SQLITE_CORRUPT_PAGE(pPage);
6182862049
}
6182962050
pPage->max1bytePayload = pBt->max1bytePayload;
6183062051
return SQLITE_OK;
6183162052
}
6183262053
@@ -61863,11 +62084,11 @@
6186362084
hdr = pPage->hdrOffset;
6186462085
data = pPage->aData;
6186562086
/* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
6186662087
** the b-tree page type. */
6186762088
if( decodeFlags(pPage, data[hdr]) ){
61868
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62089
+ return SQLITE_CORRUPT_PAGE(pPage);
6186962090
}
6187062091
assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
6187162092
pPage->maskPage = (u16)(pBt->pageSize - 1);
6187262093
pPage->nOverflow = 0;
6187362094
usableSize = pBt->usableSize;
@@ -61882,11 +62103,11 @@
6188262103
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
6188362104
** number of cells on the page. */
6188462105
pPage->nCell = get2byte(&data[hdr+3]);
6188562106
if( pPage->nCell>MX_CELL(pBt) ){
6188662107
/* To many cells for a single page. The page must be corrupt */
61887
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62108
+ return SQLITE_CORRUPT_PAGE(pPage);
6188862109
}
6188962110
testcase( pPage->nCell==MX_CELL(pBt) );
6189062111
/* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
6189162112
** possible for a root page of a table that contains no rows) then the
6189262113
** offset to the cell content area will equal the page size minus the
@@ -61910,16 +62131,16 @@
6191062131
for(i=0; i<pPage->nCell; i++){
6191162132
pc = get2byteAligned(&data[cellOffset+i*2]);
6191262133
testcase( pc==iCellFirst );
6191362134
testcase( pc==iCellLast );
6191462135
if( pc<iCellFirst || pc>iCellLast ){
61915
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62136
+ return SQLITE_CORRUPT_PAGE(pPage);
6191662137
}
6191762138
sz = pPage->xCellSize(pPage, &data[pc]);
6191862139
testcase( pc+sz==usableSize );
6191962140
if( pc+sz>usableSize ){
61920
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62141
+ return SQLITE_CORRUPT_PAGE(pPage);
6192162142
}
6192262143
}
6192362144
if( !pPage->leaf ) iCellLast++;
6192462145
}
6192562146
@@ -61933,30 +62154,30 @@
6193362154
u32 next, size;
6193462155
if( pc<iCellFirst ){
6193562156
/* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
6193662157
** always be at least one cell before the first freeblock.
6193762158
*/
61938
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62159
+ return SQLITE_CORRUPT_PAGE(pPage);
6193962160
}
6194062161
while( 1 ){
6194162162
if( pc>iCellLast ){
6194262163
/* Freeblock off the end of the page */
61943
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62164
+ return SQLITE_CORRUPT_PAGE(pPage);
6194462165
}
6194562166
next = get2byte(&data[pc]);
6194662167
size = get2byte(&data[pc+2]);
6194762168
nFree = nFree + size;
6194862169
if( next<=pc+size+3 ) break;
6194962170
pc = next;
6195062171
}
6195162172
if( next>0 ){
6195262173
/* Freeblock not in ascending order */
61953
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62174
+ return SQLITE_CORRUPT_PAGE(pPage);
6195462175
}
6195562176
if( pc+size>(unsigned int)usableSize ){
6195662177
/* Last freeblock extends past page end */
61957
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62178
+ return SQLITE_CORRUPT_PAGE(pPage);
6195862179
}
6195962180
}
6196062181
6196162182
/* At this point, nFree contains the sum of the offset to the start
6196262183
** of the cell-content area plus the number of free bytes within
@@ -61964,11 +62185,11 @@
6196462185
** of the page, then the page must be corrupted. This check also
6196562186
** serves to verify that the offset to the start of the cell-content
6196662187
** area, according to the page header, lies within the page.
6196762188
*/
6196862189
if( nFree>usableSize ){
61969
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
62190
+ return SQLITE_CORRUPT_PAGE(pPage);
6197062191
}
6197162192
pPage->nFree = (u16)(nFree - iCellFirst);
6197262193
pPage->isInit = 1;
6197362194
return SQLITE_OK;
6197462195
}
@@ -63495,11 +63716,11 @@
6349563716
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6349663717
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6349763718
if( eType==PTRMAP_OVERFLOW2 ){
6349863719
/* The pointer is always the first 4 bytes of the page in this case. */
6349963720
if( get4byte(pPage->aData)!=iFrom ){
63500
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
63721
+ return SQLITE_CORRUPT_PAGE(pPage);
6350163722
}
6350263723
put4byte(pPage->aData, iTo);
6350363724
}else{
6350463725
int i;
6350563726
int nCell;
@@ -63514,11 +63735,11 @@
6351463735
if( eType==PTRMAP_OVERFLOW1 ){
6351563736
CellInfo info;
6351663737
pPage->xParseCell(pPage, pCell, &info);
6351763738
if( info.nLocal<info.nPayload ){
6351863739
if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
63519
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
63740
+ return SQLITE_CORRUPT_PAGE(pPage);
6352063741
}
6352163742
if( iFrom==get4byte(pCell+info.nSize-4) ){
6352263743
put4byte(pCell+info.nSize-4, iTo);
6352363744
break;
6352463745
}
@@ -63532,11 +63753,11 @@
6353263753
}
6353363754
6353463755
if( i==nCell ){
6353563756
if( eType!=PTRMAP_BTREE ||
6353663757
get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
63537
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
63758
+ return SQLITE_CORRUPT_PAGE(pPage);
6353863759
}
6353963760
put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
6354063761
}
6354163762
}
6354263763
return SQLITE_OK;
@@ -64630,11 +64851,11 @@
6463064851
/* Trying to read or write past the end of the data is an error. The
6463164852
** conditional above is really:
6463264853
** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
6463364854
** but is recast into its current form to avoid integer overflow problems
6463464855
*/
64635
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
64856
+ return SQLITE_CORRUPT_PAGE(pPage);
6463664857
}
6463764858
6463864859
/* Check if data must be read/written to/from the btree page itself. */
6463964860
if( offset<pCur->info.nLocal ){
6464064861
int a = amt;
@@ -64778,11 +64999,11 @@
6477864999
}
6477965000
}
6478065001
6478165002
if( rc==SQLITE_OK && amt>0 ){
6478265003
/* Overflow chain ends prematurely */
64783
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
65004
+ return SQLITE_CORRUPT_PAGE(pPage);
6478465005
}
6478565006
return rc;
6478665007
}
6478765008
6478865009
/*
@@ -65056,11 +65277,11 @@
6505665277
** if pCur->iPage>=0). But this is not so if the database is corrupted
6505765278
** in such a way that page pRoot is linked into a second b-tree table
6505865279
** (or the freelist). */
6505965280
assert( pRoot->intKey==1 || pRoot->intKey==0 );
6506065281
if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
65061
- return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno);
65282
+ return SQLITE_CORRUPT_PAGE(pCur->pPage);
6506265283
}
6506365284
6506465285
skip_init:
6506565286
pCur->ix = 0;
6506665287
pCur->info.nSize = 0;
@@ -65329,11 +65550,11 @@
6532965550
i64 nCellKey;
6533065551
pCell = findCellPastPtr(pPage, idx);
6533165552
if( pPage->intKeyLeaf ){
6533265553
while( 0x80 <= *(pCell++) ){
6533365554
if( pCell>=pPage->aDataEnd ){
65334
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
65555
+ return SQLITE_CORRUPT_PAGE(pPage);
6533565556
}
6533665557
}
6533765558
}
6533865559
getVarint(pCell, (u64*)&nCellKey);
6533965560
if( nCellKey<intKey ){
@@ -65403,11 +65624,11 @@
6540365624
testcase( nCell<0 ); /* True if key size is 2^32 or more */
6540465625
testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
6540565626
testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
6540665627
testcase( nCell==2 ); /* Minimum legal index key size */
6540765628
if( nCell<2 ){
65408
- rc = SQLITE_CORRUPT_PGNO(pPage->pgno);
65629
+ rc = SQLITE_CORRUPT_PAGE(pPage);
6540965630
goto moveto_finish;
6541065631
}
6541165632
pCellKey = sqlite3Malloc( nCell+18 );
6541265633
if( pCellKey==0 ){
6541365634
rc = SQLITE_NOMEM_BKPT;
@@ -66206,11 +66427,11 @@
6620666427
if( pInfo->nLocal==pInfo->nPayload ){
6620766428
return SQLITE_OK; /* No overflow pages. Return without doing anything */
6620866429
}
6620966430
if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
6621066431
/* Cell extends past end of page */
66211
- return SQLITE_CORRUPT_PGNO(pPage->pgno);
66432
+ return SQLITE_CORRUPT_PAGE(pPage);
6621266433
}
6621366434
ovflPgno = get4byte(pCell + pInfo->nSize - 4);
6621466435
pBt = pPage->pBt;
6621566436
assert( pBt->usableSize > 4 );
6621666437
ovflPageSize = pBt->usableSize - 4;
@@ -72103,11 +72324,15 @@
7210372324
const char *zNeg = "";
7210472325
int rc = SQLITE_OK;
7210572326
7210672327
assert( pExpr!=0 );
7210772328
while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
72329
+#if defined(SQLITE_ENABLE_STAT3_OR_STAT4)
72330
+ if( op==TK_REGISTER ) op = pExpr->op2;
72331
+#else
7210872332
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
72333
+#endif
7210972334
7211072335
/* Compressed expressions only appear when parsing the DEFAULT clause
7211172336
** on a table column definition, and hence only when pCtx==0. This
7211272337
** check ensures that an EP_TokenOnly expression is never passed down
7211372338
** into valueFromFunction(). */
@@ -74813,10 +75038,11 @@
7481375038
needXcommit = 1;
7481475039
sqlite3BtreeEnter(pBt);
7481575040
pPager = sqlite3BtreePager(pBt);
7481675041
if( db->aDb[i].safety_level!=PAGER_SYNCHRONOUS_OFF
7481775042
&& aMJNeeded[sqlite3PagerGetJournalMode(pPager)]
75043
+ && sqlite3PagerIsMemdb(pPager)==0
7481875044
){
7481975045
assert( i!=1 );
7482075046
nTrans++;
7482175047
}
7482275048
rc = sqlite3PagerExclusiveLock(pPager);
@@ -90556,11 +90782,10 @@
9055690782
if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
9055790783
if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
9055890784
if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
9055990785
if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
9056090786
if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
90561
- if( sqlite3WalkExpr(pWalker, p->pOffset) ) return WRC_Abort;
9056290787
return WRC_Continue;
9056390788
}
9056490789
9056590790
/*
9056690791
** Walk the parse trees associated with all subqueries in the
@@ -91824,12 +92049,11 @@
9182492049
/* Resolve the expressions in the LIMIT and OFFSET clauses. These
9182592050
** are not allowed to refer to any names, so pass an empty NameContext.
9182692051
*/
9182792052
memset(&sNC, 0, sizeof(sNC));
9182892053
sNC.pParse = pParse;
91829
- if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
91830
- sqlite3ResolveExprNames(&sNC, p->pOffset) ){
92054
+ if( sqlite3ResolveExprNames(&sNC, p->pLimit) ){
9183192055
return WRC_Abort;
9183292056
}
9183392057
9183492058
/* If the SF_Converted flags is set, then this Select object was
9183592059
** was created by the convertCompoundSelectToSubquery() function.
@@ -92826,11 +93050,10 @@
9282693050
static void heightOfSelect(Select *p, int *pnHeight){
9282793051
if( p ){
9282893052
heightOfExpr(p->pWhere, pnHeight);
9282993053
heightOfExpr(p->pHaving, pnHeight);
9283093054
heightOfExpr(p->pLimit, pnHeight);
92831
- heightOfExpr(p->pOffset, pnHeight);
9283293055
heightOfExprList(p->pEList, pnHeight);
9283393056
heightOfExprList(p->pGroupBy, pnHeight);
9283493057
heightOfExprList(p->pOrderBy, pnHeight);
9283593058
heightOfSelect(p->pPrior, pnHeight);
9283693059
}
@@ -93625,11 +93848,10 @@
9362593848
pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
9362693849
pNew->op = p->op;
9362793850
pNew->pNext = pNext;
9362893851
pNew->pPrior = 0;
9362993852
pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
93630
- pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
9363193853
pNew->iLimit = 0;
9363293854
pNew->iOffset = 0;
9363393855
pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
9363493856
pNew->addrOpenEphm[0] = -1;
9363593857
pNew->addrOpenEphm[1] = -1;
@@ -94262,11 +94484,10 @@
9426294484
testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate );
9426394485
return 0; /* No DISTINCT keyword and no aggregate functions */
9426494486
}
9426594487
assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
9426694488
if( p->pLimit ) return 0; /* Has no LIMIT clause */
94267
- assert( p->pOffset==0 ); /* No LIMIT means no OFFSET */
9426894489
if( p->pWhere ) return 0; /* Has no WHERE clause */
9426994490
pSrc = p->pSrc;
9427094491
assert( pSrc!=0 );
9427194492
if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
9427294493
if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
@@ -94352,20 +94573,19 @@
9435294573
** If the RHS of the IN operator is a list or a more complex subquery, then
9435394574
** an ephemeral table might need to be generated from the RHS and then
9435494575
** pX->iTable made to point to the ephemeral table instead of an
9435594576
** existing table.
9435694577
**
94357
-** The inFlags parameter must contain exactly one of the bits
94358
-** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains
94359
-** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
94360
-** fast membership test. When the IN_INDEX_LOOP bit is set, the
94361
-** IN index will be used to loop over all values of the RHS of the
94362
-** IN operator.
94578
+** The inFlags parameter must contain, at a minimum, one of the bits
94579
+** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
94580
+** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
94581
+** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
94582
+** be used to loop over all values of the RHS of the IN operator.
9436394583
**
9436494584
** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
9436594585
** through the set members) then the b-tree must not contain duplicates.
94366
-** An epheremal table must be used unless the selected columns are guaranteed
94586
+** An epheremal table will be created unless the selected columns are guaranteed
9436794587
** to be unique - either because it is an INTEGER PRIMARY KEY or due to
9436894588
** a UNIQUE constraint or index.
9436994589
**
9437094590
** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
9437194591
** for fast set membership tests) then an epheremal table must
@@ -94902,10 +95122,11 @@
9490295122
** preexisting limit is discarded in place of the new LIMIT 1.
9490395123
*/
9490495124
Select *pSel; /* SELECT statement to encode */
9490595125
SelectDest dest; /* How to deal with SELECT result */
9490695126
int nReg; /* Registers to allocate */
95127
+ Expr *pLimit; /* New limit expression */
9490795128
9490895129
testcase( pExpr->op==TK_EXISTS );
9490995130
testcase( pExpr->op==TK_SELECT );
9491095131
assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
9491195132
assert( ExprHasProperty(pExpr, EP_xIsSelect) );
@@ -94923,13 +95144,17 @@
9492395144
}else{
9492495145
dest.eDest = SRT_Exists;
9492595146
sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
9492695147
VdbeComment((v, "Init EXISTS result"));
9492795148
}
94928
- sqlite3ExprDelete(pParse->db, pSel->pLimit);
94929
- pSel->pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,
94930
- &sqlite3IntTokens[1], 0);
95149
+ pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
95150
+ if( pSel->pLimit ){
95151
+ sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
95152
+ pSel->pLimit->pLeft = pLimit;
95153
+ }else{
95154
+ pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
95155
+ }
9493195156
pSel->iLimit = 0;
9493295157
pSel->selFlags &= ~SF_MultiValue;
9493395158
if( sqlite3Select(pParse, pSel, &dest) ){
9493495159
return 0;
9493595160
}
@@ -100713,13 +100938,10 @@
100713100938
return 1;
100714100939
}
100715100940
if( sqlite3FixExpr(pFix, pSelect->pLimit) ){
100716100941
return 1;
100717100942
}
100718
- if( sqlite3FixExpr(pFix, pSelect->pOffset) ){
100719
- return 1;
100720
- }
100721100943
pSelect = pSelect->pPrior;
100722100944
}
100723100945
return 0;
100724100946
}
100725100947
SQLITE_PRIVATE int sqlite3FixExpr(
@@ -106085,11 +106307,10 @@
106085106307
Parse *pParse, /* Parsing context */
106086106308
Table *pView, /* View definition */
106087106309
Expr *pWhere, /* Optional WHERE clause to be added */
106088106310
ExprList *pOrderBy, /* Optional ORDER BY clause */
106089106311
Expr *pLimit, /* Optional LIMIT clause */
106090
- Expr *pOffset, /* Optional OFFSET clause */
106091106312
int iCur /* Cursor number for ephemeral table */
106092106313
){
106093106314
SelectDest dest;
106094106315
Select *pSel;
106095106316
SrcList *pFrom;
@@ -106103,11 +106324,11 @@
106103106324
pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
106104106325
assert( pFrom->a[0].pOn==0 );
106105106326
assert( pFrom->a[0].pUsing==0 );
106106106327
}
106107106328
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
106108
- SF_IncludeHidden, pLimit, pOffset);
106329
+ SF_IncludeHidden, pLimit);
106109106330
sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
106110106331
sqlite3Select(pParse, pSel, &dest);
106111106332
sqlite3SelectDelete(db, pSel);
106112106333
}
106113106334
#endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -106125,11 +106346,10 @@
106125106346
Parse *pParse, /* The parser context */
106126106347
SrcList *pSrc, /* the FROM clause -- which tables to scan */
106127106348
Expr *pWhere, /* The WHERE clause. May be null */
106128106349
ExprList *pOrderBy, /* The ORDER BY clause. May be null */
106129106350
Expr *pLimit, /* The LIMIT clause. May be null */
106130
- Expr *pOffset, /* The OFFSET clause. May be null */
106131106351
char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
106132106352
){
106133106353
sqlite3 *db = pParse->db;
106134106354
Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */
106135106355
Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
@@ -106142,21 +106362,17 @@
106142106362
*/
106143106363
if( pOrderBy && pLimit==0 ) {
106144106364
sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
106145106365
sqlite3ExprDelete(pParse->db, pWhere);
106146106366
sqlite3ExprListDelete(pParse->db, pOrderBy);
106147
- sqlite3ExprDelete(pParse->db, pLimit);
106148
- sqlite3ExprDelete(pParse->db, pOffset);
106149106367
return 0;
106150106368
}
106151106369
106152106370
/* We only need to generate a select expression if there
106153106371
** is a limit/offset term to enforce.
106154106372
*/
106155106373
if( pLimit == 0 ) {
106156
- /* if pLimit is null, pOffset will always be null as well. */
106157
- assert( pOffset == 0 );
106158106374
return pWhere;
106159106375
}
106160106376
106161106377
/* Generate a select expression tree to enforce the limit/offset
106162106378
** term for the DELETE or UPDATE statement. For example:
@@ -106199,11 +106415,11 @@
106199106415
pSrc->a[0].pTab = pTab;
106200106416
pSrc->a[0].pIBIndex = 0;
106201106417
106202106418
/* generate the SELECT expression tree. */
106203106419
pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
106204
- pOrderBy,0,pLimit,pOffset
106420
+ pOrderBy,0,pLimit
106205106421
);
106206106422
106207106423
/* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
106208106424
pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
106209106425
sqlite3PExprAddSelect(pParse, pInClause, pSelect);
@@ -106222,12 +106438,11 @@
106222106438
SQLITE_PRIVATE void sqlite3DeleteFrom(
106223106439
Parse *pParse, /* The parser context */
106224106440
SrcList *pTabList, /* The table from which we should delete things */
106225106441
Expr *pWhere, /* The WHERE clause. May be null */
106226106442
ExprList *pOrderBy, /* ORDER BY clause. May be null */
106227
- Expr *pLimit, /* LIMIT clause. May be null */
106228
- Expr *pOffset /* OFFSET clause. May be null */
106443
+ Expr *pLimit /* LIMIT clause. May be null */
106229106444
){
106230106445
Vdbe *v; /* The virtual database engine */
106231106446
Table *pTab; /* The table from which records will be deleted */
106232106447
int i; /* Loop counter */
106233106448
WhereInfo *pWInfo; /* Information about the WHERE clause */
@@ -106296,14 +106511,14 @@
106296106511
#endif
106297106512
106298106513
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
106299106514
if( !isView ){
106300106515
pWhere = sqlite3LimitWhere(
106301
- pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "DELETE"
106516
+ pParse, pTabList, pWhere, pOrderBy, pLimit, "DELETE"
106302106517
);
106303106518
pOrderBy = 0;
106304
- pLimit = pOffset = 0;
106519
+ pLimit = 0;
106305106520
}
106306106521
#endif
106307106522
106308106523
/* If pTab is really a view, make sure it has been initialized.
106309106524
*/
@@ -106351,15 +106566,15 @@
106351106566
** an ephemeral table.
106352106567
*/
106353106568
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
106354106569
if( isView ){
106355106570
sqlite3MaterializeView(pParse, pTab,
106356
- pWhere, pOrderBy, pLimit, pOffset, iTabCur
106571
+ pWhere, pOrderBy, pLimit, iTabCur
106357106572
);
106358106573
iDataCur = iIdxCur = iTabCur;
106359106574
pOrderBy = 0;
106360
- pLimit = pOffset = 0;
106575
+ pLimit = 0;
106361106576
}
106362106577
#endif
106363106578
106364106579
/* Resolve the column names in the WHERE clause.
106365106580
*/
@@ -106602,11 +106817,10 @@
106602106817
sqlite3SrcListDelete(db, pTabList);
106603106818
sqlite3ExprDelete(db, pWhere);
106604106819
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
106605106820
sqlite3ExprListDelete(db, pOrderBy);
106606106821
sqlite3ExprDelete(db, pLimit);
106607
- sqlite3ExprDelete(db, pOffset);
106608106822
#endif
106609106823
sqlite3DbFree(db, aToOpen);
106610106824
return;
106611106825
}
106612106826
/* Make sure "isView" and other macros defined above are undefined. Otherwise
@@ -109568,11 +109782,11 @@
109568109782
iSkip = sqlite3VdbeMakeLabel(v);
109569109783
sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
109570109784
}
109571109785
109572109786
pParse->disableTriggers = 1;
109573
- sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0, 0);
109787
+ sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
109574109788
pParse->disableTriggers = 0;
109575109789
109576109790
/* If the DELETE has generated immediate foreign key constraint
109577109791
** violations, halt the VDBE and return an error at this point, before
109578109792
** any modifications to the schema are made. This is because statement
@@ -110126,11 +110340,11 @@
110126110340
}
110127110341
pSelect = sqlite3SelectNew(pParse,
110128110342
sqlite3ExprListAppend(pParse, 0, pRaise),
110129110343
sqlite3SrcListAppend(db, 0, &tFrom, 0),
110130110344
pWhere,
110131
- 0, 0, 0, 0, 0, 0
110345
+ 0, 0, 0, 0, 0
110132110346
);
110133110347
pWhere = 0;
110134110348
}
110135110349
110136110350
/* Disable lookaside memory allocation */
@@ -112274,11 +112488,10 @@
112274112488
return 0; /* SELECT may not have a GROUP BY clause */
112275112489
}
112276112490
if( pSelect->pLimit ){
112277112491
return 0; /* SELECT may not have a LIMIT clause */
112278112492
}
112279
- assert( pSelect->pOffset==0 ); /* Must be so if pLimit==0 */
112280112493
if( pSelect->pPrior ){
112281112494
return 0; /* SELECT may not be a compound query */
112282112495
}
112283112496
if( pSelect->selFlags & SF_Distinct ){
112284112497
return 0; /* SELECT may not be DISTINCT */
@@ -118173,11 +118386,10 @@
118173118386
sqlite3ExprDelete(db, p->pWhere);
118174118387
sqlite3ExprListDelete(db, p->pGroupBy);
118175118388
sqlite3ExprDelete(db, p->pHaving);
118176118389
sqlite3ExprListDelete(db, p->pOrderBy);
118177118390
sqlite3ExprDelete(db, p->pLimit);
118178
- sqlite3ExprDelete(db, p->pOffset);
118179118391
if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
118180118392
if( bFree ) sqlite3DbFreeNN(db, p);
118181118393
p = pPrior;
118182118394
bFree = 1;
118183118395
}
@@ -118206,12 +118418,11 @@
118206118418
Expr *pWhere, /* the WHERE clause */
118207118419
ExprList *pGroupBy, /* the GROUP BY clause */
118208118420
Expr *pHaving, /* the HAVING clause */
118209118421
ExprList *pOrderBy, /* the ORDER BY clause */
118210118422
u32 selFlags, /* Flag parameters, such as SF_Distinct */
118211
- Expr *pLimit, /* LIMIT value. NULL means not used */
118212
- Expr *pOffset /* OFFSET value. NULL means no offset */
118423
+ Expr *pLimit /* LIMIT value. NULL means not used */
118213118424
){
118214118425
Select *pNew;
118215118426
Select standin;
118216118427
pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
118217118428
if( pNew==0 ){
@@ -118240,14 +118451,11 @@
118240118451
pNew->pHaving = pHaving;
118241118452
pNew->pOrderBy = pOrderBy;
118242118453
pNew->pPrior = 0;
118243118454
pNew->pNext = 0;
118244118455
pNew->pLimit = pLimit;
118245
- pNew->pOffset = pOffset;
118246118456
pNew->pWith = 0;
118247
- assert( pOffset==0 || pLimit!=0 || pParse->nErr>0
118248
- || pParse->db->mallocFailed!=0 );
118249118457
if( pParse->db->mallocFailed ) {
118250118458
clearSelect(pParse->db, pNew, pNew!=&standin);
118251118459
pNew = 0;
118252118460
}else{
118253118461
assert( pNew->pSrc!=0 || pParse->nErr>0 );
@@ -119973,69 +120181,72 @@
119973120181
}
119974120182
119975120183
119976120184
/*
119977120185
** Compute the iLimit and iOffset fields of the SELECT based on the
119978
-** pLimit and pOffset expressions. pLimit and pOffset hold the expressions
120186
+** pLimit expressions. pLimit->pLeft and pLimit->pRight hold the expressions
119979120187
** that appear in the original SQL statement after the LIMIT and OFFSET
119980120188
** keywords. Or NULL if those keywords are omitted. iLimit and iOffset
119981120189
** are the integer memory register numbers for counters used to compute
119982120190
** the limit and offset. If there is no limit and/or offset, then
119983120191
** iLimit and iOffset are negative.
119984120192
**
119985120193
** This routine changes the values of iLimit and iOffset only if
119986
-** a limit or offset is defined by pLimit and pOffset. iLimit and
119987
-** iOffset should have been preset to appropriate default values (zero)
120194
+** a limit or offset is defined by pLimit->pLeft and pLimit->pRight. iLimit
120195
+** and iOffset should have been preset to appropriate default values (zero)
119988120196
** prior to calling this routine.
119989120197
**
119990120198
** The iOffset register (if it exists) is initialized to the value
119991120199
** of the OFFSET. The iLimit register is initialized to LIMIT. Register
119992120200
** iOffset+1 is initialized to LIMIT+OFFSET.
119993120201
**
119994
-** Only if pLimit!=0 or pOffset!=0 do the limit registers get
120202
+** Only if pLimit->pLeft!=0 do the limit registers get
119995120203
** redefined. The UNION ALL operator uses this property to force
119996120204
** the reuse of the same limit and offset registers across multiple
119997120205
** SELECT statements.
119998120206
*/
119999120207
static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
120000120208
Vdbe *v = 0;
120001120209
int iLimit = 0;
120002120210
int iOffset;
120003120211
int n;
120212
+ Expr *pLimit = p->pLimit;
120213
+
120004120214
if( p->iLimit ) return;
120005120215
120006120216
/*
120007120217
** "LIMIT -1" always shows all rows. There is some
120008120218
** controversy about what the correct behavior should be.
120009120219
** The current implementation interprets "LIMIT 0" to mean
120010120220
** no rows.
120011120221
*/
120012120222
sqlite3ExprCacheClear(pParse);
120013
- assert( p->pOffset==0 || p->pLimit!=0 );
120014
- if( p->pLimit ){
120223
+ if( pLimit ){
120224
+ assert( pLimit->op==TK_LIMIT );
120225
+ assert( pLimit->pLeft!=0 );
120015120226
p->iLimit = iLimit = ++pParse->nMem;
120016120227
v = sqlite3GetVdbe(pParse);
120017120228
assert( v!=0 );
120018
- if( sqlite3ExprIsInteger(p->pLimit, &n) ){
120229
+ if( sqlite3ExprIsInteger(pLimit->pLeft, &n) ){
120019120230
sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
120020120231
VdbeComment((v, "LIMIT counter"));
120021120232
if( n==0 ){
120022120233
sqlite3VdbeGoto(v, iBreak);
120023120234
}else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
120024120235
p->nSelectRow = sqlite3LogEst((u64)n);
120025120236
p->selFlags |= SF_FixedLimit;
120026120237
}
120027120238
}else{
120028
- sqlite3ExprCode(pParse, p->pLimit, iLimit);
120239
+ sqlite3ExprCode(pParse, pLimit->pLeft, iLimit);
120029120240
sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
120030120241
VdbeComment((v, "LIMIT counter"));
120031120242
sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
120032120243
}
120033
- if( p->pOffset ){
120244
+ if( pLimit->pRight ){
120034120245
p->iOffset = iOffset = ++pParse->nMem;
120035120246
pParse->nMem++; /* Allocate an extra register for limit+offset */
120036
- sqlite3ExprCode(pParse, p->pOffset, iOffset);
120247
+ sqlite3ExprCode(pParse, pLimit->pRight, iOffset);
120037120248
sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
120038120249
VdbeComment((v, "OFFSET counter"));
120039120250
sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset);
120040120251
VdbeComment((v, "LIMIT+OFFSET"));
120041120252
}
@@ -120161,11 +120372,11 @@
120161120372
int eDest = SRT_Fifo; /* How to write to Queue */
120162120373
SelectDest destQueue; /* SelectDest targetting the Queue table */
120163120374
int i; /* Loop counter */
120164120375
int rc; /* Result code */
120165120376
ExprList *pOrderBy; /* The ORDER BY clause */
120166
- Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */
120377
+ Expr *pLimit; /* Saved LIMIT and OFFSET */
120167120378
int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
120168120379
120169120380
/* Obtain authorization to do a recursive query */
120170120381
if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
120171120382
@@ -120172,14 +120383,13 @@
120172120383
/* Process the LIMIT and OFFSET clauses, if they exist */
120173120384
addrBreak = sqlite3VdbeMakeLabel(v);
120174120385
p->nSelectRow = 320; /* 4 billion rows */
120175120386
computeLimitRegisters(pParse, p, addrBreak);
120176120387
pLimit = p->pLimit;
120177
- pOffset = p->pOffset;
120178120388
regLimit = p->iLimit;
120179120389
regOffset = p->iOffset;
120180
- p->pLimit = p->pOffset = 0;
120390
+ p->pLimit = 0;
120181120391
p->iLimit = p->iOffset = 0;
120182120392
pOrderBy = p->pOrderBy;
120183120393
120184120394
/* Locate the cursor number of the Current table */
120185120395
for(i=0; ALWAYS(i<pSrc->nSrc); i++){
@@ -120268,11 +120478,10 @@
120268120478
120269120479
end_of_recursive_query:
120270120480
sqlite3ExprListDelete(pParse->db, p->pOrderBy);
120271120481
p->pOrderBy = pOrderBy;
120272120482
p->pLimit = pLimit;
120273
- p->pOffset = pOffset;
120274120483
return;
120275120484
}
120276120485
#endif /* SQLITE_OMIT_CTE */
120277120486
120278120487
/* Forward references */
@@ -120304,11 +120513,10 @@
120304120513
assert( p->selFlags & SF_MultiValue );
120305120514
do{
120306120515
assert( p->selFlags & SF_Values );
120307120516
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
120308120517
assert( p->pLimit==0 );
120309
- assert( p->pOffset==0 );
120310120518
assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
120311120519
if( p->pPrior==0 ) break;
120312120520
assert( p->pPrior->pNext==p );
120313120521
p = p->pPrior;
120314120522
nRow++;
@@ -120431,15 +120639,13 @@
120431120639
int nLimit;
120432120640
assert( !pPrior->pLimit );
120433120641
pPrior->iLimit = p->iLimit;
120434120642
pPrior->iOffset = p->iOffset;
120435120643
pPrior->pLimit = p->pLimit;
120436
- pPrior->pOffset = p->pOffset;
120437120644
explainSetInteger(iSub1, pParse->iNextSelectId);
120438120645
rc = sqlite3Select(pParse, pPrior, &dest);
120439120646
p->pLimit = 0;
120440
- p->pOffset = 0;
120441120647
if( rc ){
120442120648
goto multi_select_end;
120443120649
}
120444120650
p->pPrior = 0;
120445120651
p->iLimit = pPrior->iLimit;
@@ -120457,11 +120663,11 @@
120457120663
testcase( rc!=SQLITE_OK );
120458120664
pDelete = p->pPrior;
120459120665
p->pPrior = pPrior;
120460120666
p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
120461120667
if( pPrior->pLimit
120462
- && sqlite3ExprIsInteger(pPrior->pLimit, &nLimit)
120668
+ && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit)
120463120669
&& nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
120464120670
){
120465120671
p->nSelectRow = sqlite3LogEst((u64)nLimit);
120466120672
}
120467120673
if( addr ){
@@ -120472,11 +120678,11 @@
120472120678
case TK_EXCEPT:
120473120679
case TK_UNION: {
120474120680
int unionTab; /* Cursor number of the temporary table holding result */
120475120681
u8 op = 0; /* One of the SRT_ operations to apply to self */
120476120682
int priorOp; /* The SRT_ operation to apply to prior selects */
120477
- Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
120683
+ Expr *pLimit; /* Saved values of p->nLimit */
120478120684
int addr;
120479120685
SelectDest uniondest;
120480120686
120481120687
testcase( p->op==TK_EXCEPT );
120482120688
testcase( p->op==TK_UNION );
@@ -120484,11 +120690,10 @@
120484120690
if( dest.eDest==priorOp ){
120485120691
/* We can reuse a temporary table generated by a SELECT to our
120486120692
** right.
120487120693
*/
120488120694
assert( p->pLimit==0 ); /* Not allowed on leftward elements */
120489
- assert( p->pOffset==0 ); /* Not allowed on leftward elements */
120490120695
unionTab = dest.iSDParm;
120491120696
}else{
120492120697
/* We will need to create our own temporary table to hold the
120493120698
** intermediate results.
120494120699
*/
@@ -120520,12 +120725,10 @@
120520120725
op = SRT_Union;
120521120726
}
120522120727
p->pPrior = 0;
120523120728
pLimit = p->pLimit;
120524120729
p->pLimit = 0;
120525
- pOffset = p->pOffset;
120526
- p->pOffset = 0;
120527120730
uniondest.eDest = op;
120528120731
explainSetInteger(iSub2, pParse->iNextSelectId);
120529120732
rc = sqlite3Select(pParse, p, &uniondest);
120530120733
testcase( rc!=SQLITE_OK );
120531120734
/* Query flattening in sqlite3Select() might refill p->pOrderBy.
@@ -120537,11 +120740,10 @@
120537120740
if( p->op==TK_UNION ){
120538120741
p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
120539120742
}
120540120743
sqlite3ExprDelete(db, p->pLimit);
120541120744
p->pLimit = pLimit;
120542
- p->pOffset = pOffset;
120543120745
p->iLimit = 0;
120544120746
p->iOffset = 0;
120545120747
120546120748
/* Convert the data in the temporary table into whatever form
120547120749
** it is that we currently need.
@@ -120565,11 +120767,11 @@
120565120767
break;
120566120768
}
120567120769
default: assert( p->op==TK_INTERSECT ); {
120568120770
int tab1, tab2;
120569120771
int iCont, iBreak, iStart;
120570
- Expr *pLimit, *pOffset;
120772
+ Expr *pLimit;
120571120773
int addr;
120572120774
SelectDest intersectdest;
120573120775
int r1;
120574120776
120575120777
/* INTERSECT is different from the others since it requires
@@ -120601,22 +120803,19 @@
120601120803
assert( p->addrOpenEphm[1] == -1 );
120602120804
p->addrOpenEphm[1] = addr;
120603120805
p->pPrior = 0;
120604120806
pLimit = p->pLimit;
120605120807
p->pLimit = 0;
120606
- pOffset = p->pOffset;
120607
- p->pOffset = 0;
120608120808
intersectdest.iSDParm = tab2;
120609120809
explainSetInteger(iSub2, pParse->iNextSelectId);
120610120810
rc = sqlite3Select(pParse, p, &intersectdest);
120611120811
testcase( rc!=SQLITE_OK );
120612120812
pDelete = p->pPrior;
120613120813
p->pPrior = pPrior;
120614120814
if( p->nSelectRow>pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
120615120815
sqlite3ExprDelete(db, p->pLimit);
120616120816
p->pLimit = pLimit;
120617
- p->pOffset = pOffset;
120618120817
120619120818
/* Generate code to take the intersection of the two temporary
120620120819
** tables.
120621120820
*/
120622120821
assert( p->pEList );
@@ -121091,12 +121290,10 @@
121091121290
}else{
121092121291
regLimitA = regLimitB = 0;
121093121292
}
121094121293
sqlite3ExprDelete(db, p->pLimit);
121095121294
p->pLimit = 0;
121096
- sqlite3ExprDelete(db, p->pOffset);
121097
- p->pOffset = 0;
121098121295
121099121296
regAddrA = ++pParse->nMem;
121100121297
regAddrB = ++pParse->nMem;
121101121298
regOutA = ++pParse->nMem;
121102121299
regOutB = ++pParse->nMem;
@@ -121556,11 +121753,11 @@
121556121753
** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
121557121754
** because they could be computed at compile-time. But when LIMIT and OFFSET
121558121755
** became arbitrary expressions, we were forced to add restrictions (13)
121559121756
** and (14). */
121560121757
if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
121561
- if( pSub->pOffset ) return 0; /* Restriction (14) */
121758
+ if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */
121562121759
if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
121563121760
return 0; /* Restriction (15) */
121564121761
}
121565121762
if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
121566121763
if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
@@ -121704,20 +121901,17 @@
121704121901
*/
121705121902
for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){
121706121903
Select *pNew;
121707121904
ExprList *pOrderBy = p->pOrderBy;
121708121905
Expr *pLimit = p->pLimit;
121709
- Expr *pOffset = p->pOffset;
121710121906
Select *pPrior = p->pPrior;
121711121907
p->pOrderBy = 0;
121712121908
p->pSrc = 0;
121713121909
p->pPrior = 0;
121714121910
p->pLimit = 0;
121715
- p->pOffset = 0;
121716121911
pNew = sqlite3SelectDup(db, p, 0);
121717121912
sqlite3SelectSetName(pNew, pSub->zSelName);
121718
- p->pOffset = pOffset;
121719121913
p->pLimit = pLimit;
121720121914
p->pOrderBy = pOrderBy;
121721121915
p->pSrc = pSrc;
121722121916
p->op = TK_ALL;
121723121917
if( pNew==0 ){
@@ -122179,11 +122373,10 @@
122179122373
assert( (p->selFlags & SF_Converted)==0 );
122180122374
p->selFlags |= SF_Converted;
122181122375
assert( pNew->pPrior!=0 );
122182122376
pNew->pPrior->pNext = pNew;
122183122377
pNew->pLimit = 0;
122184
- pNew->pOffset = 0;
122185122378
return WRC_Continue;
122186122379
}
122187122380
122188122381
/*
122189122382
** Check to see if the FROM clause term pFrom has table-valued function
@@ -125077,11 +125270,11 @@
125077125270
case TK_UPDATE: {
125078125271
sqlite3Update(pParse,
125079125272
targetSrcList(pParse, pStep),
125080125273
sqlite3ExprListDup(db, pStep->pExprList, 0),
125081125274
sqlite3ExprDup(db, pStep->pWhere, 0),
125082
- pParse->eOrconf, 0, 0, 0
125275
+ pParse->eOrconf, 0, 0
125083125276
);
125084125277
break;
125085125278
}
125086125279
case TK_INSERT: {
125087125280
sqlite3Insert(pParse,
@@ -125093,11 +125286,11 @@
125093125286
break;
125094125287
}
125095125288
case TK_DELETE: {
125096125289
sqlite3DeleteFrom(pParse,
125097125290
targetSrcList(pParse, pStep),
125098
- sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0, 0
125291
+ sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
125099125292
);
125100125293
break;
125101125294
}
125102125295
default: assert( pStep->op==TK_SELECT ); {
125103125296
SelectDest sDest;
@@ -125241,11 +125434,11 @@
125241125434
}
125242125435
sqlite3VdbeAddOp0(v, OP_Halt);
125243125436
VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
125244125437
125245125438
transferParseError(pParse, pSubParse);
125246
- if( db->mallocFailed==0 ){
125439
+ if( db->mallocFailed==0 && pParse->nErr==0 ){
125247125440
pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
125248125441
}
125249125442
pProgram->nMem = pSubParse->nMem;
125250125443
pProgram->nCsr = pSubParse->nTab;
125251125444
pProgram->token = (void *)pTrigger;
@@ -125562,12 +125755,11 @@
125562125755
SrcList *pTabList, /* The table in which we should change things */
125563125756
ExprList *pChanges, /* Things to be changed */
125564125757
Expr *pWhere, /* The WHERE clause. May be null */
125565125758
int onError, /* How to handle constraint errors */
125566125759
ExprList *pOrderBy, /* ORDER BY clause. May be null */
125567
- Expr *pLimit, /* LIMIT clause. May be null */
125568
- Expr *pOffset /* OFFSET clause. May be null */
125760
+ Expr *pLimit /* LIMIT clause. May be null */
125569125761
){
125570125762
int i, j; /* Loop counters */
125571125763
Table *pTab; /* The table to be updated */
125572125764
int addrTop = 0; /* VDBE instruction address of the start of the loop */
125573125765
WhereInfo *pWInfo; /* Information about the WHERE clause */
@@ -125651,14 +125843,14 @@
125651125843
#endif
125652125844
125653125845
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
125654125846
if( !isView ){
125655125847
pWhere = sqlite3LimitWhere(
125656
- pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "UPDATE"
125848
+ pParse, pTabList, pWhere, pOrderBy, pLimit, "UPDATE"
125657125849
);
125658125850
pOrderBy = 0;
125659
- pLimit = pOffset = 0;
125851
+ pLimit = 0;
125660125852
}
125661125853
#endif
125662125854
125663125855
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
125664125856
goto update_cleanup;
@@ -125827,14 +126019,14 @@
125827126019
** an ephemeral table.
125828126020
*/
125829126021
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
125830126022
if( isView ){
125831126023
sqlite3MaterializeView(pParse, pTab,
125832
- pWhere, pOrderBy, pLimit, pOffset, iDataCur
126024
+ pWhere, pOrderBy, pLimit, iDataCur
125833126025
);
125834126026
pOrderBy = 0;
125835
- pLimit = pOffset = 0;
126027
+ pLimit = 0;
125836126028
}
125837126029
#endif
125838126030
125839126031
/* Resolve the column names in all the expressions in the
125840126032
** WHERE clause.
@@ -126217,11 +126409,10 @@
126217126409
sqlite3ExprListDelete(db, pChanges);
126218126410
sqlite3ExprDelete(db, pWhere);
126219126411
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
126220126412
sqlite3ExprListDelete(db, pOrderBy);
126221126413
sqlite3ExprDelete(db, pLimit);
126222
- sqlite3ExprDelete(db, pOffset);
126223126414
#endif
126224126415
return;
126225126416
}
126226126417
/* Make sure "isView" and other macros defined above are undefined. Otherwise
126227126418
** they may interfere with compilation of other functions in this file
@@ -128931,10 +129122,106 @@
128931129122
){
128932129123
zAff[i] = SQLITE_AFF_BLOB;
128933129124
}
128934129125
}
128935129126
}
129127
+
129128
+
129129
+/*
129130
+** pX is an expression of the form: (vector) IN (SELECT ...)
129131
+** In other words, it is a vector IN operator with a SELECT clause on the
129132
+** LHS. But not all terms in the vector are indexable and the terms might
129133
+** not be in the correct order for indexing.
129134
+**
129135
+** This routine makes a copy of the input pX expression and then adjusts
129136
+** the vector on the LHS with corresponding changes to the SELECT so that
129137
+** the vector contains only index terms and those terms are in the correct
129138
+** order. The modified IN expression is returned. The caller is responsible
129139
+** for deleting the returned expression.
129140
+**
129141
+** Example:
129142
+**
129143
+** CREATE TABLE t1(a,b,c,d,e,f);
129144
+** CREATE INDEX t1x1 ON t1(e,c);
129145
+** SELECT * FROM t1 WHERE (a,b,c,d,e) IN (SELECT v,w,x,y,z FROM t2)
129146
+** \_______________________________________/
129147
+** The pX expression
129148
+**
129149
+** Since only columns e and c can be used with the index, in that order,
129150
+** the modified IN expression that is returned will be:
129151
+**
129152
+** (e,c) IN (SELECT z,x FROM t2)
129153
+**
129154
+** The reduced pX is different from the original (obviously) and thus is
129155
+** only used for indexing, to improve performance. The original unaltered
129156
+** IN expression must also be run on each output row for correctness.
129157
+*/
129158
+static Expr *removeUnindexableInClauseTerms(
129159
+ Parse *pParse, /* The parsing context */
129160
+ int iEq, /* Look at loop terms starting here */
129161
+ WhereLoop *pLoop, /* The current loop */
129162
+ Expr *pX /* The IN expression to be reduced */
129163
+){
129164
+ sqlite3 *db = pParse->db;
129165
+ Expr *pNew = sqlite3ExprDup(db, pX, 0);
129166
+ if( db->mallocFailed==0 ){
129167
+ ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
129168
+ ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
129169
+ ExprList *pRhs = 0; /* New RHS after modifications */
129170
+ ExprList *pLhs = 0; /* New LHS after mods */
129171
+ int i; /* Loop counter */
129172
+ Select *pSelect; /* Pointer to the SELECT on the RHS */
129173
+
129174
+ for(i=iEq; i<pLoop->nLTerm; i++){
129175
+ if( pLoop->aLTerm[i]->pExpr==pX ){
129176
+ int iField = pLoop->aLTerm[i]->iField - 1;
129177
+ assert( pOrigRhs->a[iField].pExpr!=0 );
129178
+ pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
129179
+ pOrigRhs->a[iField].pExpr = 0;
129180
+ assert( pOrigLhs->a[iField].pExpr!=0 );
129181
+ pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
129182
+ pOrigLhs->a[iField].pExpr = 0;
129183
+ }
129184
+ }
129185
+ sqlite3ExprListDelete(db, pOrigRhs);
129186
+ sqlite3ExprListDelete(db, pOrigLhs);
129187
+ pNew->pLeft->x.pList = pLhs;
129188
+ pNew->x.pSelect->pEList = pRhs;
129189
+ if( pLhs && pLhs->nExpr==1 ){
129190
+ /* Take care here not to generate a TK_VECTOR containing only a
129191
+ ** single value. Since the parser never creates such a vector, some
129192
+ ** of the subroutines do not handle this case. */
129193
+ Expr *p = pLhs->a[0].pExpr;
129194
+ pLhs->a[0].pExpr = 0;
129195
+ sqlite3ExprDelete(db, pNew->pLeft);
129196
+ pNew->pLeft = p;
129197
+ }
129198
+ pSelect = pNew->x.pSelect;
129199
+ if( pSelect->pOrderBy ){
129200
+ /* If the SELECT statement has an ORDER BY clause, zero the
129201
+ ** iOrderByCol variables. These are set to non-zero when an
129202
+ ** ORDER BY term exactly matches one of the terms of the
129203
+ ** result-set. Since the result-set of the SELECT statement may
129204
+ ** have been modified or reordered, these variables are no longer
129205
+ ** set correctly. Since setting them is just an optimization,
129206
+ ** it's easiest just to zero them here. */
129207
+ ExprList *pOrderBy = pSelect->pOrderBy;
129208
+ for(i=0; i<pOrderBy->nExpr; i++){
129209
+ pOrderBy->a[i].u.x.iOrderByCol = 0;
129210
+ }
129211
+ }
129212
+
129213
+#if 0
129214
+ printf("For indexing, change the IN expr:\n");
129215
+ sqlite3TreeViewExpr(0, pX, 0);
129216
+ printf("Into:\n");
129217
+ sqlite3TreeViewExpr(0, pNew, 0);
129218
+#endif
129219
+ }
129220
+ return pNew;
129221
+}
129222
+
128936129223
128937129224
/*
128938129225
** Generate code for a single equality term of the WHERE clause. An equality
128939129226
** term can be either X=expr or X IN (...). pTerm is the term to be
128940129227
** coded.
@@ -128994,72 +129281,27 @@
128994129281
disableTerm(pLevel, pTerm);
128995129282
return iTarget;
128996129283
}
128997129284
}
128998129285
for(i=iEq;i<pLoop->nLTerm; i++){
128999
- if( ALWAYS(pLoop->aLTerm[i]) && pLoop->aLTerm[i]->pExpr==pX ) nEq++;
129286
+ assert( pLoop->aLTerm[i]!=0 );
129287
+ if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
129000129288
}
129001129289
129002129290
if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
129003129291
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
129004129292
}else{
129005
- Select *pSelect = pX->x.pSelect;
129006129293
sqlite3 *db = pParse->db;
129007
- u16 savedDbOptFlags = db->dbOptFlags;
129008
- ExprList *pOrigRhs = pSelect->pEList;
129009
- ExprList *pOrigLhs = pX->pLeft->x.pList;
129010
- ExprList *pRhs = 0; /* New Select.pEList for RHS */
129011
- ExprList *pLhs = 0; /* New pX->pLeft vector */
129012
-
129013
- for(i=iEq;i<pLoop->nLTerm; i++){
129014
- if( pLoop->aLTerm[i]->pExpr==pX ){
129015
- int iField = pLoop->aLTerm[i]->iField - 1;
129016
- Expr *pNewRhs = sqlite3ExprDup(db, pOrigRhs->a[iField].pExpr, 0);
129017
- Expr *pNewLhs = sqlite3ExprDup(db, pOrigLhs->a[iField].pExpr, 0);
129018
-
129019
- pRhs = sqlite3ExprListAppend(pParse, pRhs, pNewRhs);
129020
- pLhs = sqlite3ExprListAppend(pParse, pLhs, pNewLhs);
129021
- }
129022
- }
129294
+ pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
129295
+
129023129296
if( !db->mallocFailed ){
129024
- Expr *pLeft = pX->pLeft;
129025
-
129026
- if( pSelect->pOrderBy ){
129027
- /* If the SELECT statement has an ORDER BY clause, zero the
129028
- ** iOrderByCol variables. These are set to non-zero when an
129029
- ** ORDER BY term exactly matches one of the terms of the
129030
- ** result-set. Since the result-set of the SELECT statement may
129031
- ** have been modified or reordered, these variables are no longer
129032
- ** set correctly. Since setting them is just an optimization,
129033
- ** it's easiest just to zero them here. */
129034
- ExprList *pOrderBy = pSelect->pOrderBy;
129035
- for(i=0; i<pOrderBy->nExpr; i++){
129036
- pOrderBy->a[i].u.x.iOrderByCol = 0;
129037
- }
129038
- }
129039
-
129040
- /* Take care here not to generate a TK_VECTOR containing only a
129041
- ** single value. Since the parser never creates such a vector, some
129042
- ** of the subroutines do not handle this case. */
129043
- if( pLhs->nExpr==1 ){
129044
- pX->pLeft = pLhs->a[0].pExpr;
129045
- }else{
129046
- pLeft->x.pList = pLhs;
129047
- aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
129048
- testcase( aiMap==0 );
129049
- }
129050
- pSelect->pEList = pRhs;
129051
- db->dbOptFlags |= SQLITE_QueryFlattener;
129297
+ aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
129052129298
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
129053
- db->dbOptFlags = savedDbOptFlags;
129054
- testcase( aiMap!=0 && aiMap[0]!=0 );
129055
- pSelect->pEList = pOrigRhs;
129056
- pLeft->x.pList = pOrigLhs;
129057
- pX->pLeft = pLeft;
129058
- }
129059
- sqlite3ExprListDelete(pParse->db, pLhs);
129060
- sqlite3ExprListDelete(pParse->db, pRhs);
129299
+ pTerm->pExpr->iTable = pX->iTable;
129300
+ }
129301
+ sqlite3ExprDelete(db, pX);
129302
+ pX = pTerm->pExpr;
129061129303
}
129062129304
129063129305
if( eType==IN_INDEX_INDEX_DESC ){
129064129306
testcase( bRev );
129065129307
bRev = !bRev;
@@ -134703,11 +134945,11 @@
134703134945
}else if( eOp & (WO_EQ|WO_IS) ){
134704134946
int iCol = pProbe->aiColumn[saved_nEq];
134705134947
pNew->wsFlags |= WHERE_COLUMN_EQ;
134706134948
assert( saved_nEq==pNew->u.btree.nEq );
134707134949
if( iCol==XN_ROWID
134708
- || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
134950
+ || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
134709134951
){
134710134952
if( iCol>=0 && pProbe->uniqNotNull==0 ){
134711134953
pNew->wsFlags |= WHERE_UNQ_WANTED;
134712134954
}else{
134713134955
pNew->wsFlags |= WHERE_ONEROW;
@@ -136920,39 +137162,84 @@
136920137162
for(ii=0; ii<pWInfo->nLevel; ii++){
136921137163
whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
136922137164
}
136923137165
}
136924137166
#endif
136925
- /* Attempt to omit tables from the join that do not effect the result */
137167
+
137168
+ /* Attempt to omit tables from the join that do not affect the result.
137169
+ ** For a table to not affect the result, the following must be true:
137170
+ **
137171
+ ** 1) The query must not be an aggregate.
137172
+ ** 2) The table must be the RHS of a LEFT JOIN.
137173
+ ** 3) Either the query must be DISTINCT, or else the ON or USING clause
137174
+ ** must contain a constraint that limits the scan of the table to
137175
+ ** at most a single row.
137176
+ ** 4) The table must not be referenced by any part of the query apart
137177
+ ** from its own USING or ON clause.
137178
+ **
137179
+ ** For example, given:
137180
+ **
137181
+ ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
137182
+ ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
137183
+ ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
137184
+ **
137185
+ ** then table t2 can be omitted from the following:
137186
+ **
137187
+ ** SELECT v1, v3 FROM t1
137188
+ ** LEFT JOIN t2 USING (t1.ipk=t2.ipk)
137189
+ ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
137190
+ **
137191
+ ** or from:
137192
+ **
137193
+ ** SELECT DISTINCT v1, v3 FROM t1
137194
+ ** LEFT JOIN t2
137195
+ ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
137196
+ */
137197
+ notReady = ~(Bitmask)0;
136926137198
if( pWInfo->nLevel>=2
136927
- && pResultSet!=0
137199
+ && pResultSet!=0 /* guarantees condition (1) above */
136928137200
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
136929137201
){
137202
+ int i;
136930137203
Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
136931137204
if( sWLB.pOrderBy ){
136932137205
tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
136933137206
}
136934
- while( pWInfo->nLevel>=2 ){
137207
+ for(i=pWInfo->nLevel-1; i>=1; i--){
136935137208
WhereTerm *pTerm, *pEnd;
136936
- pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
136937
- if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break;
137209
+ struct SrcList_item *pItem;
137210
+ pLoop = pWInfo->a[i].pWLoop;
137211
+ pItem = &pWInfo->pTabList->a[pLoop->iTab];
137212
+ if( (pItem->fg.jointype & JT_LEFT)==0 ) continue;
136938137213
if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
136939137214
&& (pLoop->wsFlags & WHERE_ONEROW)==0
136940137215
){
136941
- break;
137216
+ continue;
136942137217
}
136943
- if( (tabUsed & pLoop->maskSelf)!=0 ) break;
137218
+ if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
136944137219
pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
136945137220
for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
136946
- if( (pTerm->prereqAll & pLoop->maskSelf)!=0
136947
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
136948
- ){
136949
- break;
137221
+ if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
137222
+ if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
137223
+ || pTerm->pExpr->iRightJoinTable!=pItem->iCursor
137224
+ ){
137225
+ break;
137226
+ }
136950137227
}
136951137228
}
136952
- if( pTerm<pEnd ) break;
137229
+ if( pTerm<pEnd ) continue;
136953137230
WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
137231
+ notReady &= ~pLoop->maskSelf;
137232
+ for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
137233
+ if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
137234
+ pTerm->wtFlags |= TERM_CODED;
137235
+ }
137236
+ }
137237
+ if( i!=pWInfo->nLevel-1 ){
137238
+ int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel);
137239
+ memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte);
137240
+ }
136954137241
pWInfo->nLevel--;
136955137242
nTabList--;
136956137243
}
136957137244
}
136958137245
WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
@@ -137103,11 +137390,10 @@
137103137390
137104137391
/* Generate the code to do the search. Each iteration of the for
137105137392
** loop below generates code for a single nested loop of the VM
137106137393
** program.
137107137394
*/
137108
- notReady = ~(Bitmask)0;
137109137395
for(ii=0; ii<nTabList; ii++){
137110137396
int addrExplain;
137111137397
int wsFlags;
137112137398
pLevel = &pWInfo->a[ii];
137113137399
wsFlags = pLevel->pWLoop->wsFlags;
@@ -137167,10 +137453,11 @@
137167137453
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
137168137454
int addrSeek = 0;
137169137455
Index *pIdx;
137170137456
int n;
137171137457
if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
137458
+ && i==pWInfo->nLevel-1 /* Ticket [ef9318757b152e3] 2017-10-21 */
137172137459
&& (pLoop->wsFlags & WHERE_INDEXED)!=0
137173137460
&& (pIdx = pLoop->u.btree.pIndex)->hasStat1
137174137461
&& (n = pLoop->u.btree.nIdxCol)>0
137175137462
&& pIdx->aiRowLogEst[n]>=36
137176137463
){
@@ -137233,11 +137520,12 @@
137233137520
if( pLevel->iLeftJoin ){
137234137521
int ws = pLoop->wsFlags;
137235137522
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
137236137523
assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
137237137524
if( (ws & WHERE_IDX_ONLY)==0 ){
137238
- sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
137525
+ assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
137526
+ sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
137239137527
}
137240137528
if( (ws & WHERE_INDEXED)
137241137529
|| ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
137242137530
){
137243137531
sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -137401,19 +137689,10 @@
137401137689
** Alternative datatype for the argument to the malloc() routine passed
137402137690
** into sqlite3ParserAlloc(). The default is size_t.
137403137691
*/
137404137692
#define YYMALLOCARGTYPE u64
137405137693
137406
-/*
137407
-** An instance of this structure holds information about the
137408
-** LIMIT clause of a SELECT statement.
137409
-*/
137410
-struct LimitVal {
137411
- Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */
137412
- Expr *pOffset; /* The OFFSET expression. NULL if there is none */
137413
-};
137414
-
137415137694
/*
137416137695
** An instance of the following structure describes the event of a
137417137696
** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
137418137697
** TK_DELETE, or TK_INSTEAD. If the event is of the form
137419137698
**
@@ -137647,11 +137926,10 @@
137647137926
int yy194;
137648137927
Select* yy243;
137649137928
IdList* yy254;
137650137929
With* yy285;
137651137930
struct TrigEvent yy332;
137652
- struct LimitVal yy354;
137653137931
struct {int value; int mask;} yy497;
137654137932
} YYMINORTYPE;
137655137933
#ifndef YYSTACKDEPTH
137656137934
#define YYSTACKDEPTH 100
137657137935
#endif
@@ -139903,11 +140181,11 @@
139903140181
SrcList *pFrom;
139904140182
Token x;
139905140183
x.n = 0;
139906140184
parserDoubleLinkSelect(pParse, pRhs);
139907140185
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
139908
- pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
140186
+ pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
139909140187
}
139910140188
if( pRhs ){
139911140189
pRhs->op = (u8)yymsp[-1].minor.yy194;
139912140190
pRhs->pPrior = pLhs;
139913140191
if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
@@ -139929,11 +140207,11 @@
139929140207
case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
139930140208
{
139931140209
#if SELECTTRACE_ENABLED
139932140210
Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/
139933140211
#endif
139934
- yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy354.pLimit,yymsp[0].minor.yy354.pOffset);
140212
+ yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy72);
139935140213
#if SELECTTRACE_ENABLED
139936140214
/* Populate the Select.zSelName[] string that is used to help with
139937140215
** query planner debugging, to differentiate between multiple Select
139938140216
** objects in a complex query.
139939140217
**
@@ -139958,17 +140236,17 @@
139958140236
#endif /* SELECTRACE_ENABLED */
139959140237
}
139960140238
break;
139961140239
case 85: /* values ::= VALUES LP nexprlist RP */
139962140240
{
139963
- yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0,0);
140241
+ yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0);
139964140242
}
139965140243
break;
139966140244
case 86: /* values ::= values COMMA LP exprlist RP */
139967140245
{
139968140246
Select *pRight, *pLeft = yymsp[-4].minor.yy243;
139969
- pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
140247
+ pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0);
139970140248
if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
139971140249
if( pRight ){
139972140250
pRight->op = TK_ALL;
139973140251
pRight->pPrior = pLeft;
139974140252
yymsp[-4].minor.yy243 = pRight;
@@ -140069,11 +140347,11 @@
140069140347
}
140070140348
sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185);
140071140349
}else{
140072140350
Select *pSubquery;
140073140351
sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy185);
140074
- pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0,0);
140352
+ pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0);
140075140353
yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140076140354
}
140077140355
}
140078140356
break;
140079140357
case 104: /* dbnm ::= */
@@ -140101,10 +140379,11 @@
140101140379
case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196);
140102140380
{yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
140103140381
break;
140104140382
case 112: /* on_opt ::= */
140105140383
case 127: /* having_opt ::= */ yytestcase(yyruleno==127);
140384
+ case 129: /* limit_opt ::= */ yytestcase(yyruleno==129);
140106140385
case 134: /* where_opt ::= */ yytestcase(yyruleno==134);
140107140386
case 197: /* case_else ::= */ yytestcase(yyruleno==197);
140108140387
case 199: /* case_operand ::= */ yytestcase(yyruleno==199);
140109140388
{yymsp[1].minor.yy72 = 0;}
140110140389
break;
@@ -140144,35 +140423,32 @@
140144140423
{yymsp[0].minor.yy194 = SQLITE_SO_DESC;}
140145140424
break;
140146140425
case 124: /* sortorder ::= */
140147140426
{yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;}
140148140427
break;
140149
- case 129: /* limit_opt ::= */
140150
-{yymsp[1].minor.yy354.pLimit = 0; yymsp[1].minor.yy354.pOffset = 0;}
140151
- break;
140152140428
case 130: /* limit_opt ::= LIMIT expr */
140153
-{yymsp[-1].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr; yymsp[-1].minor.yy354.pOffset = 0;}
140429
+{yymsp[-1].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,0);}
140154140430
break;
140155140431
case 131: /* limit_opt ::= LIMIT expr OFFSET expr */
140156
-{yymsp[-3].minor.yy354.pLimit = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pOffset = yymsp[0].minor.yy190.pExpr;}
140432
+{yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy190.pExpr,yymsp[0].minor.yy190.pExpr);}
140157140433
break;
140158140434
case 132: /* limit_opt ::= LIMIT expr COMMA expr */
140159
-{yymsp[-3].minor.yy354.pOffset = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr;}
140435
+{yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,yymsp[-2].minor.yy190.pExpr);}
140160140436
break;
140161140437
case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140162140438
{
140163140439
sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140164140440
sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0);
140165
- sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0,0);
140441
+ sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0);
140166140442
}
140167140443
break;
140168140444
case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140169140445
{
140170140446
sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1);
140171140447
sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0);
140172140448
sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list");
140173
- sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0,0);
140449
+ sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0);
140174140450
}
140175140451
break;
140176140452
case 137: /* setlist ::= setlist COMMA nm EQ expr */
140177140453
{
140178140454
yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
@@ -140485,11 +140761,11 @@
140485140761
}
140486140762
break;
140487140763
case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */
140488140764
{
140489140765
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
140490
- Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
140766
+ Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
140491140767
if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
140492140768
yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140493140769
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
140494140770
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140495140771
yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
@@ -145232,10 +145508,11 @@
145232145508
}else if( flags & SQLITE_OPEN_FULLMUTEX ){
145233145509
isThreadsafe = 1;
145234145510
}else{
145235145511
isThreadsafe = sqlite3GlobalConfig.bFullMutex;
145236145512
}
145513
+
145237145514
if( flags & SQLITE_OPEN_PRIVATECACHE ){
145238145515
flags &= ~SQLITE_OPEN_SHAREDCACHE;
145239145516
}else if( sqlite3GlobalConfig.sharedCacheEnabled ){
145240145517
flags |= SQLITE_OPEN_SHAREDCACHE;
145241145518
}
@@ -145264,17 +145541,24 @@
145264145541
);
145265145542
145266145543
/* Allocate the sqlite data structure */
145267145544
db = sqlite3MallocZero( sizeof(sqlite3) );
145268145545
if( db==0 ) goto opendb_out;
145269
- if( isThreadsafe ){
145546
+ if( isThreadsafe
145547
+#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
145548
+ || sqlite3GlobalConfig.bCoreMutex
145549
+#endif
145550
+ ){
145270145551
db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
145271145552
if( db->mutex==0 ){
145272145553
sqlite3_free(db);
145273145554
db = 0;
145274145555
goto opendb_out;
145275145556
}
145557
+ if( isThreadsafe==0 ){
145558
+ sqlite3MutexWarnOnContention(db->mutex);
145559
+ }
145276145560
}
145277145561
sqlite3_mutex_enter(db->mutex);
145278145562
db->errMask = 0xff;
145279145563
db->nDb = 2;
145280145564
db->magic = SQLITE_MAGIC_BUSY;
@@ -145754,41 +146038,41 @@
145754146038
** to detect when version error conditions occurs.
145755146039
**
145756146040
** 2. Invoke sqlite3_log() to provide the source code location where
145757146041
** a low-level error is first detected.
145758146042
*/
145759
-static int reportError(int iErr, int lineno, const char *zType){
146043
+SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType){
145760146044
sqlite3_log(iErr, "%s at line %d of [%.10s]",
145761146045
zType, lineno, 20+sqlite3_sourceid());
145762146046
return iErr;
145763146047
}
145764146048
SQLITE_PRIVATE int sqlite3CorruptError(int lineno){
145765146049
testcase( sqlite3GlobalConfig.xLog!=0 );
145766
- return reportError(SQLITE_CORRUPT, lineno, "database corruption");
146050
+ return sqlite3ReportError(SQLITE_CORRUPT, lineno, "database corruption");
145767146051
}
145768146052
SQLITE_PRIVATE int sqlite3MisuseError(int lineno){
145769146053
testcase( sqlite3GlobalConfig.xLog!=0 );
145770
- return reportError(SQLITE_MISUSE, lineno, "misuse");
146054
+ return sqlite3ReportError(SQLITE_MISUSE, lineno, "misuse");
145771146055
}
145772146056
SQLITE_PRIVATE int sqlite3CantopenError(int lineno){
145773146057
testcase( sqlite3GlobalConfig.xLog!=0 );
145774
- return reportError(SQLITE_CANTOPEN, lineno, "cannot open file");
146058
+ return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file");
145775146059
}
145776146060
#ifdef SQLITE_DEBUG
145777146061
SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){
145778146062
char zMsg[100];
145779146063
sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno);
145780146064
testcase( sqlite3GlobalConfig.xLog!=0 );
145781
- return reportError(SQLITE_CORRUPT, lineno, zMsg);
146065
+ return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg);
145782146066
}
145783146067
SQLITE_PRIVATE int sqlite3NomemError(int lineno){
145784146068
testcase( sqlite3GlobalConfig.xLog!=0 );
145785
- return reportError(SQLITE_NOMEM, lineno, "OOM");
146069
+ return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM");
145786146070
}
145787146071
SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){
145788146072
testcase( sqlite3GlobalConfig.xLog!=0 );
145789
- return reportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error");
146073
+ return sqlite3ReportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error");
145790146074
}
145791146075
#endif
145792146076
145793146077
#ifndef SQLITE_OMIT_DEPRECATED
145794146078
/*
@@ -186122,10 +186406,12 @@
186122186406
Fts5ExprPhrase *pPhrase,
186123186407
Fts5Token *pToken,
186124186408
int bPrefix
186125186409
);
186126186410
186411
+static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase*);
186412
+
186127186413
static Fts5ExprNearset *sqlite3Fts5ParseNearset(
186128186414
Fts5Parse*,
186129186415
Fts5ExprNearset*,
186130186416
Fts5ExprPhrase*
186131186417
);
@@ -186202,13 +186488,14 @@
186202186488
#define FTS5_LCP 7
186203186489
#define FTS5_RCP 8
186204186490
#define FTS5_STRING 9
186205186491
#define FTS5_LP 10
186206186492
#define FTS5_RP 11
186207
-#define FTS5_COMMA 12
186208
-#define FTS5_PLUS 13
186209
-#define FTS5_STAR 14
186493
+#define FTS5_CARET 12
186494
+#define FTS5_COMMA 13
186495
+#define FTS5_PLUS 14
186496
+#define FTS5_STAR 15
186210186497
186211186498
/*
186212186499
** 2000-05-29
186213186500
**
186214186501
** The author disclaims copyright to this source code. In place of
@@ -186319,39 +186606,39 @@
186319186606
#ifndef INTERFACE
186320186607
# define INTERFACE 1
186321186608
#endif
186322186609
/************* Begin control #defines *****************************************/
186323186610
#define fts5YYCODETYPE unsigned char
186324
-#define fts5YYNOCODE 28
186611
+#define fts5YYNOCODE 29
186325186612
#define fts5YYACTIONTYPE unsigned char
186326186613
#define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
186327186614
typedef union {
186328186615
int fts5yyinit;
186329186616
sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
186330186617
int fts5yy4;
186331
- Fts5Colset* fts5yy11;
186332
- Fts5ExprNode* fts5yy24;
186333
- Fts5ExprNearset* fts5yy46;
186334
- Fts5ExprPhrase* fts5yy53;
186618
+ Fts5ExprPhrase* fts5yy11;
186619
+ Fts5ExprNearset* fts5yy14;
186620
+ Fts5Colset* fts5yy43;
186621
+ Fts5ExprNode* fts5yy54;
186335186622
} fts5YYMINORTYPE;
186336186623
#ifndef fts5YYSTACKDEPTH
186337186624
#define fts5YYSTACKDEPTH 100
186338186625
#endif
186339186626
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
186340186627
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
186341186628
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
186342186629
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
186343
-#define fts5YYNSTATE 33
186344
-#define fts5YYNRULE 27
186345
-#define fts5YY_MAX_SHIFT 32
186346
-#define fts5YY_MIN_SHIFTREDUCE 50
186347
-#define fts5YY_MAX_SHIFTREDUCE 76
186348
-#define fts5YY_MIN_REDUCE 77
186349
-#define fts5YY_MAX_REDUCE 103
186350
-#define fts5YY_ERROR_ACTION 104
186351
-#define fts5YY_ACCEPT_ACTION 105
186352
-#define fts5YY_NO_ACTION 106
186630
+#define fts5YYNSTATE 35
186631
+#define fts5YYNRULE 28
186632
+#define fts5YY_MAX_SHIFT 34
186633
+#define fts5YY_MIN_SHIFTREDUCE 52
186634
+#define fts5YY_MAX_SHIFTREDUCE 79
186635
+#define fts5YY_MIN_REDUCE 80
186636
+#define fts5YY_MAX_REDUCE 107
186637
+#define fts5YY_ERROR_ACTION 108
186638
+#define fts5YY_ACCEPT_ACTION 109
186639
+#define fts5YY_NO_ACTION 110
186353186640
/************* End control #defines *******************************************/
186354186641
186355186642
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
186356186643
** otherwise.
186357186644
**
@@ -186419,58 +186706,60 @@
186419186706
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
186420186707
** shifting non-terminals after a reduce.
186421186708
** fts5yy_default[] Default action for each state.
186422186709
**
186423186710
*********** Begin parsing tables **********************************************/
186424
-#define fts5YY_ACTTAB_COUNT (98)
186711
+#define fts5YY_ACTTAB_COUNT (105)
186425186712
static const fts5YYACTIONTYPE fts5yy_action[] = {
186426
- /* 0 */ 105, 19, 90, 6, 26, 93, 92, 24, 24, 17,
186427
- /* 10 */ 90, 6, 26, 16, 92, 54, 24, 18, 90, 6,
186428
- /* 20 */ 26, 10, 92, 12, 24, 75, 86, 90, 6, 26,
186429
- /* 30 */ 13, 92, 75, 24, 20, 90, 6, 26, 101, 92,
186430
- /* 40 */ 56, 24, 27, 90, 6, 26, 100, 92, 21, 24,
186431
- /* 50 */ 23, 15, 30, 11, 1, 91, 22, 25, 9, 92,
186432
- /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77,
186433
- /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12,
186434
- /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32,
186435
- /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14,
186713
+ /* 0 */ 109, 20, 93, 6, 28, 96, 95, 26, 26, 18,
186714
+ /* 10 */ 93, 6, 28, 17, 95, 56, 26, 19, 93, 6,
186715
+ /* 20 */ 28, 14, 95, 105, 26, 89, 93, 6, 28, 25,
186716
+ /* 30 */ 95, 78, 26, 21, 93, 6, 28, 104, 95, 58,
186717
+ /* 40 */ 26, 29, 93, 6, 28, 32, 95, 22, 26, 24,
186718
+ /* 50 */ 16, 23, 11, 1, 14, 13, 24, 16, 31, 11,
186719
+ /* 60 */ 3, 94, 13, 27, 8, 95, 82, 26, 7, 4,
186720
+ /* 70 */ 5, 3, 4, 5, 3, 80, 4, 5, 3, 63,
186721
+ /* 80 */ 33, 34, 62, 12, 2, 83, 13, 10, 12, 71,
186722
+ /* 90 */ 10, 13, 78, 5, 3, 78, 9, 30, 75, 82,
186723
+ /* 100 */ 54, 57, 53, 57, 15,
186436186724
};
186437186725
static const fts5YYCODETYPE fts5yy_lookahead[] = {
186438
- /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
186439
- /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,
186440
- /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20,
186441
- /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22,
186442
- /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,
186443
- /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22,
186444
- /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0,
186445
- /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9,
186446
- /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25,
186447
- /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9,
186726
+ /* 0 */ 17, 18, 19, 20, 21, 23, 23, 25, 25, 18,
186727
+ /* 10 */ 19, 20, 21, 7, 23, 9, 25, 18, 19, 20,
186728
+ /* 20 */ 21, 9, 23, 27, 25, 18, 19, 20, 21, 25,
186729
+ /* 30 */ 23, 15, 25, 18, 19, 20, 21, 27, 23, 9,
186730
+ /* 40 */ 25, 18, 19, 20, 21, 14, 23, 22, 25, 6,
186731
+ /* 50 */ 7, 22, 9, 10, 9, 12, 6, 7, 13, 9,
186732
+ /* 60 */ 3, 19, 12, 21, 5, 23, 28, 25, 5, 1,
186733
+ /* 70 */ 2, 3, 1, 2, 3, 0, 1, 2, 3, 11,
186734
+ /* 80 */ 25, 26, 11, 9, 10, 5, 12, 10, 9, 11,
186735
+ /* 90 */ 10, 12, 15, 2, 3, 15, 24, 25, 9, 28,
186736
+ /* 100 */ 8, 9, 8, 9, 9,
186448186737
};
186449
-#define fts5YY_SHIFT_USE_DFLT (98)
186450
-#define fts5YY_SHIFT_COUNT (32)
186738
+#define fts5YY_SHIFT_USE_DFLT (105)
186739
+#define fts5YY_SHIFT_COUNT (34)
186451186740
#define fts5YY_SHIFT_MIN (0)
186452
-#define fts5YY_SHIFT_MAX (90)
186741
+#define fts5YY_SHIFT_MAX (95)
186453186742
static const unsigned char fts5yy_shift_ofst[] = {
186454
- /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14,
186455
- /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69,
186456
- /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87,
186457
- /* 30 */ 88, 39, 71,
186743
+ /* 0 */ 43, 43, 43, 43, 43, 43, 50, 74, 79, 45,
186744
+ /* 10 */ 12, 80, 77, 12, 16, 16, 30, 30, 68, 71,
186745
+ /* 20 */ 75, 91, 92, 94, 6, 31, 31, 59, 63, 57,
186746
+ /* 30 */ 31, 89, 95, 31, 78,
186458186747
};
186459
-#define fts5YY_REDUCE_USE_DFLT (-18)
186460
-#define fts5YY_REDUCE_COUNT (16)
186461
-#define fts5YY_REDUCE_MIN (-17)
186462
-#define fts5YY_REDUCE_MAX (67)
186748
+#define fts5YY_REDUCE_USE_DFLT (-19)
186749
+#define fts5YY_REDUCE_COUNT (17)
186750
+#define fts5YY_REDUCE_MIN (-18)
186751
+#define fts5YY_REDUCE_MAX (72)
186463186752
static const signed char fts5yy_reduce_ofst[] = {
186464
- /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17,
186465
- /* 10 */ 67, 12, 12, 12, 20, 27, 35,
186753
+ /* 0 */ -17, -9, -1, 7, 15, 23, 42, -18, -18, 55,
186754
+ /* 10 */ 72, -4, -4, 4, -4, 10, 25, 29,
186466186755
};
186467186756
static const fts5YYACTIONTYPE fts5yy_default[] = {
186468
- /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104,
186469
- /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104,
186470
- /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104,
186471
- /* 30 */ 104, 97, 104,
186757
+ /* 0 */ 108, 108, 108, 108, 108, 108, 92, 108, 108, 102,
186758
+ /* 10 */ 108, 107, 107, 108, 107, 107, 108, 108, 108, 108,
186759
+ /* 20 */ 108, 88, 108, 108, 108, 98, 97, 108, 108, 87,
186760
+ /* 30 */ 100, 108, 108, 101, 108,
186472186761
};
186473186762
/********** End of lemon-generated parsing tables *****************************/
186474186763
186475186764
/* The next table maps tokens (terminal symbols) into fallback tokens.
186476186765
** If a construct like the following:
@@ -186575,14 +186864,14 @@
186575186864
** are required. The following table supplies these names */
186576186865
static const char *const fts5yyTokenName[] = {
186577186866
"$", "OR", "AND", "NOT",
186578186867
"TERM", "COLON", "MINUS", "LCP",
186579186868
"RCP", "STRING", "LP", "RP",
186580
- "COMMA", "PLUS", "STAR", "error",
186581
- "input", "expr", "cnearset", "exprlist",
186582
- "colset", "colsetlist", "nearset", "nearphrases",
186583
- "phrase", "neardist_opt", "star_opt",
186869
+ "CARET", "COMMA", "PLUS", "STAR",
186870
+ "error", "input", "expr", "cnearset",
186871
+ "exprlist", "colset", "colsetlist", "nearset",
186872
+ "nearphrases", "phrase", "neardist_opt", "star_opt",
186584186873
};
186585186874
#endif /* NDEBUG */
186586186875
186587186876
#ifndef NDEBUG
186588186877
/* For tracing reduce actions, the names of all rules are required.
@@ -186604,19 +186893,20 @@
186604186893
/* 13 */ "exprlist ::= cnearset",
186605186894
/* 14 */ "exprlist ::= exprlist cnearset",
186606186895
/* 15 */ "cnearset ::= nearset",
186607186896
/* 16 */ "cnearset ::= colset COLON nearset",
186608186897
/* 17 */ "nearset ::= phrase",
186609
- /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
186610
- /* 19 */ "nearphrases ::= phrase",
186611
- /* 20 */ "nearphrases ::= nearphrases phrase",
186612
- /* 21 */ "neardist_opt ::=",
186613
- /* 22 */ "neardist_opt ::= COMMA STRING",
186614
- /* 23 */ "phrase ::= phrase PLUS STRING star_opt",
186615
- /* 24 */ "phrase ::= STRING star_opt",
186616
- /* 25 */ "star_opt ::= STAR",
186617
- /* 26 */ "star_opt ::=",
186898
+ /* 18 */ "nearset ::= CARET phrase",
186899
+ /* 19 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
186900
+ /* 20 */ "nearphrases ::= phrase",
186901
+ /* 21 */ "nearphrases ::= nearphrases phrase",
186902
+ /* 22 */ "neardist_opt ::=",
186903
+ /* 23 */ "neardist_opt ::= COMMA STRING",
186904
+ /* 24 */ "phrase ::= phrase PLUS STRING star_opt",
186905
+ /* 25 */ "phrase ::= STRING star_opt",
186906
+ /* 26 */ "star_opt ::= STAR",
186907
+ /* 27 */ "star_opt ::=",
186618186908
};
186619186909
#endif /* NDEBUG */
186620186910
186621186911
186622186912
#if fts5YYSTACKDEPTH<=0
@@ -186733,37 +187023,37 @@
186733187023
** Note: during a reduce, the only symbols destroyed are those
186734187024
** which appear on the RHS of the rule, but which are *not* used
186735187025
** inside the C code.
186736187026
*/
186737187027
/********* Begin destructor definitions ***************************************/
186738
- case 16: /* input */
187028
+ case 17: /* input */
186739187029
{
186740187030
(void)pParse;
186741187031
}
186742187032
break;
186743
- case 17: /* expr */
186744
- case 18: /* cnearset */
186745
- case 19: /* exprlist */
186746
-{
186747
- sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
186748
-}
186749
- break;
186750
- case 20: /* colset */
186751
- case 21: /* colsetlist */
186752
-{
186753
- sqlite3_free((fts5yypminor->fts5yy11));
186754
-}
186755
- break;
186756
- case 22: /* nearset */
186757
- case 23: /* nearphrases */
186758
-{
186759
- sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
186760
-}
186761
- break;
186762
- case 24: /* phrase */
186763
-{
186764
- sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
187033
+ case 18: /* expr */
187034
+ case 19: /* cnearset */
187035
+ case 20: /* exprlist */
187036
+{
187037
+ sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy54));
187038
+}
187039
+ break;
187040
+ case 21: /* colset */
187041
+ case 22: /* colsetlist */
187042
+{
187043
+ sqlite3_free((fts5yypminor->fts5yy43));
187044
+}
187045
+ break;
187046
+ case 23: /* nearset */
187047
+ case 24: /* nearphrases */
187048
+{
187049
+ sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy14));
187050
+}
187051
+ break;
187052
+ case 25: /* phrase */
187053
+{
187054
+ sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11));
186765187055
}
186766187056
break;
186767187057
/********* End destructor definitions *****************************************/
186768187058
default: break; /* If no destructor action specified: do nothing */
186769187059
}
@@ -187013,37 +187303,38 @@
187013187303
*/
187014187304
static const struct {
187015187305
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
187016187306
signed char nrhs; /* Negative of the number of RHS symbols in the rule */
187017187307
} fts5yyRuleInfo[] = {
187018
- { 16, -1 },
187019
- { 20, -4 },
187020
- { 20, -3 },
187308
+ { 17, -1 },
187309
+ { 21, -4 },
187310
+ { 21, -3 },
187311
+ { 21, -1 },
187312
+ { 21, -2 },
187313
+ { 22, -2 },
187314
+ { 22, -1 },
187315
+ { 18, -3 },
187316
+ { 18, -3 },
187317
+ { 18, -3 },
187318
+ { 18, -5 },
187319
+ { 18, -3 },
187320
+ { 18, -1 },
187021187321
{ 20, -1 },
187022187322
{ 20, -2 },
187023
- { 21, -2 },
187024
- { 21, -1 },
187025
- { 17, -3 },
187026
- { 17, -3 },
187027
- { 17, -3 },
187028
- { 17, -5 },
187029
- { 17, -3 },
187030
- { 17, -1 },
187031187323
{ 19, -1 },
187032
- { 19, -2 },
187033
- { 18, -1 },
187034
- { 18, -3 },
187035
- { 22, -1 },
187036
- { 22, -5 },
187324
+ { 19, -3 },
187037187325
{ 23, -1 },
187038187326
{ 23, -2 },
187039
- { 25, 0 },
187040
- { 25, -2 },
187041
- { 24, -4 },
187327
+ { 23, -5 },
187328
+ { 24, -1 },
187042187329
{ 24, -2 },
187043
- { 26, -1 },
187044187330
{ 26, 0 },
187331
+ { 26, -2 },
187332
+ { 25, -4 },
187333
+ { 25, -2 },
187334
+ { 27, -1 },
187335
+ { 27, 0 },
187045187336
};
187046187337
187047187338
static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
187048187339
187049187340
/*
@@ -187104,141 +187395,147 @@
187104187395
** break;
187105187396
*/
187106187397
/********** Begin reduce actions **********************************************/
187107187398
fts5YYMINORTYPE fts5yylhsminor;
187108187399
case 0: /* input ::= expr */
187109
-{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
187400
+{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy54); }
187110187401
break;
187111187402
case 1: /* colset ::= MINUS LCP colsetlist RCP */
187112187403
{
187113
- fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
187404
+ fts5yymsp[-3].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43);
187114187405
}
187115187406
break;
187116187407
case 2: /* colset ::= LCP colsetlist RCP */
187117
-{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
187408
+{ fts5yymsp[-2].minor.fts5yy43 = fts5yymsp[-1].minor.fts5yy43; }
187118187409
break;
187119187410
case 3: /* colset ::= STRING */
187120187411
{
187121
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187412
+ fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187122187413
}
187123
- fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187414
+ fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43;
187124187415
break;
187125187416
case 4: /* colset ::= MINUS STRING */
187126187417
{
187127
- fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187128
- fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
187418
+ fts5yymsp[-1].minor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187419
+ fts5yymsp[-1].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43);
187129187420
}
187130187421
break;
187131187422
case 5: /* colsetlist ::= colsetlist STRING */
187132187423
{
187133
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
187134
- fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187424
+ fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy43, &fts5yymsp[0].minor.fts5yy0); }
187425
+ fts5yymsp[-1].minor.fts5yy43 = fts5yylhsminor.fts5yy43;
187135187426
break;
187136187427
case 6: /* colsetlist ::= STRING */
187137187428
{
187138
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187429
+ fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187139187430
}
187140
- fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187431
+ fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43;
187141187432
break;
187142187433
case 7: /* expr ::= expr AND expr */
187143187434
{
187144
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
187435
+ fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0);
187145187436
}
187146
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187437
+ fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187147187438
break;
187148187439
case 8: /* expr ::= expr OR expr */
187149187440
{
187150
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
187441
+ fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0);
187151187442
}
187152
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187443
+ fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187153187444
break;
187154187445
case 9: /* expr ::= expr NOT expr */
187155187446
{
187156
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
187447
+ fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0);
187157187448
}
187158
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187449
+ fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187159187450
break;
187160187451
case 10: /* expr ::= colset COLON LP expr RP */
187161187452
{
187162
- sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
187163
- fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
187453
+ sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy54, fts5yymsp[-4].minor.fts5yy43);
187454
+ fts5yylhsminor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54;
187164187455
}
187165
- fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187456
+ fts5yymsp[-4].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187166187457
break;
187167187458
case 11: /* expr ::= LP expr RP */
187168
-{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
187459
+{fts5yymsp[-2].minor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54;}
187169187460
break;
187170187461
case 12: /* expr ::= exprlist */
187171187462
case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
187172
-{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
187173
- fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187463
+{fts5yylhsminor.fts5yy54 = fts5yymsp[0].minor.fts5yy54;}
187464
+ fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187174187465
break;
187175187466
case 14: /* exprlist ::= exprlist cnearset */
187176187467
{
187177
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
187468
+ fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54);
187178187469
}
187179
- fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187470
+ fts5yymsp[-1].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187180187471
break;
187181187472
case 15: /* cnearset ::= nearset */
187182187473
{
187183
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
187474
+ fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy14);
187184187475
}
187185
- fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187476
+ fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187186187477
break;
187187187478
case 16: /* cnearset ::= colset COLON nearset */
187188187479
{
187189
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
187190
- sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
187480
+ fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy14);
187481
+ sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy54, fts5yymsp[-2].minor.fts5yy43);
187191187482
}
187192
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187483
+ fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187193187484
break;
187194187485
case 17: /* nearset ::= phrase */
187195
-{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
187196
- fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187486
+{ fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
187487
+ fts5yymsp[0].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187488
+ break;
187489
+ case 18: /* nearset ::= CARET phrase */
187490
+{
187491
+ sqlite3Fts5ParseSetCaret(fts5yymsp[0].minor.fts5yy11);
187492
+ fts5yymsp[-1].minor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
187493
+}
187197187494
break;
187198
- case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
187495
+ case 19: /* nearset ::= STRING LP nearphrases neardist_opt RP */
187199187496
{
187200187497
sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
187201
- sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
187202
- fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
187203
-}
187204
- fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187205
- break;
187206
- case 19: /* nearphrases ::= phrase */
187207
-{
187208
- fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
187209
-}
187210
- fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187211
- break;
187212
- case 20: /* nearphrases ::= nearphrases phrase */
187213
-{
187214
- fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
187215
-}
187216
- fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187217
- break;
187218
- case 21: /* neardist_opt ::= */
187498
+ sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy14, &fts5yymsp[-1].minor.fts5yy0);
187499
+ fts5yylhsminor.fts5yy14 = fts5yymsp[-2].minor.fts5yy14;
187500
+}
187501
+ fts5yymsp[-4].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187502
+ break;
187503
+ case 20: /* nearphrases ::= phrase */
187504
+{
187505
+ fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
187506
+}
187507
+ fts5yymsp[0].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187508
+ break;
187509
+ case 21: /* nearphrases ::= nearphrases phrase */
187510
+{
187511
+ fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy14, fts5yymsp[0].minor.fts5yy11);
187512
+}
187513
+ fts5yymsp[-1].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187514
+ break;
187515
+ case 22: /* neardist_opt ::= */
187219187516
{ fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
187220187517
break;
187221
- case 22: /* neardist_opt ::= COMMA STRING */
187518
+ case 23: /* neardist_opt ::= COMMA STRING */
187222187519
{ fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
187223187520
break;
187224
- case 23: /* phrase ::= phrase PLUS STRING star_opt */
187225
-{
187226
- fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187227
-}
187228
- fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
187229
- break;
187230
- case 24: /* phrase ::= STRING star_opt */
187231
-{
187232
- fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187233
-}
187234
- fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
187235
- break;
187236
- case 25: /* star_opt ::= STAR */
187521
+ case 24: /* phrase ::= phrase PLUS STRING star_opt */
187522
+{
187523
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187524
+}
187525
+ fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187526
+ break;
187527
+ case 25: /* phrase ::= STRING star_opt */
187528
+{
187529
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187530
+}
187531
+ fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187532
+ break;
187533
+ case 26: /* star_opt ::= STAR */
187237187534
{ fts5yymsp[0].minor.fts5yy4 = 1; }
187238187535
break;
187239
- case 26: /* star_opt ::= */
187536
+ case 27: /* star_opt ::= */
187240187537
{ fts5yymsp[1].minor.fts5yy4 = 0; }
187241187538
break;
187242187539
default:
187243187540
break;
187244187541
/********** End reduce actions ************************************************/
@@ -189657,11 +189954,12 @@
189657189954
/*
189658189955
** An instance of the following structure represents a single search term
189659189956
** or term prefix.
189660189957
*/
189661189958
struct Fts5ExprTerm {
189662
- int bPrefix; /* True for a prefix term */
189959
+ u8 bPrefix; /* True for a prefix term */
189960
+ u8 bFirst; /* True if token must be first in column */
189663189961
char *zTerm; /* nul-terminated term */
189664189962
Fts5IndexIter *pIter; /* Iterator for this term */
189665189963
Fts5ExprTerm *pSynonym; /* Pointer to first in list of synonyms */
189666189964
};
189667189965
@@ -189738,10 +190036,11 @@
189738190036
case ':': tok = FTS5_COLON; break;
189739190037
case ',': tok = FTS5_COMMA; break;
189740190038
case '+': tok = FTS5_PLUS; break;
189741190039
case '*': tok = FTS5_STAR; break;
189742190040
case '-': tok = FTS5_MINUS; break;
190041
+ case '^': tok = FTS5_CARET; break;
189743190042
case '\0': tok = FTS5_EOF; break;
189744190043
189745190044
case '"': {
189746190045
const char *z2;
189747190046
tok = FTS5_STRING;
@@ -189997,10 +190296,11 @@
189997190296
Fts5PoslistWriter writer = {0};
189998190297
Fts5PoslistReader aStatic[4];
189999190298
Fts5PoslistReader *aIter = aStatic;
190000190299
int i;
190001190300
int rc = SQLITE_OK;
190301
+ int bFirst = pPhrase->aTerm[0].bFirst;
190002190302
190003190303
fts5BufferZero(&pPhrase->poslist);
190004190304
190005190305
/* If the aStatic[] array is not large enough, allocate a large array
190006190306
** using sqlite3_malloc(). This approach could be improved upon. */
@@ -190051,12 +190351,14 @@
190051190351
}
190052190352
}
190053190353
}while( bMatch==0 );
190054190354
190055190355
/* Append position iPos to the output */
190056
- rc = sqlite3Fts5PoslistWriterAppend(&pPhrase->poslist, &writer, iPos);
190057
- if( rc!=SQLITE_OK ) goto ismatch_out;
190356
+ if( bFirst==0 || FTS5_POS2OFFSET(iPos)==0 ){
190357
+ rc = sqlite3Fts5PoslistWriterAppend(&pPhrase->poslist, &writer, iPos);
190358
+ if( rc!=SQLITE_OK ) goto ismatch_out;
190359
+ }
190058190360
190059190361
for(i=0; i<pPhrase->nTerm; i++){
190060190362
if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) goto ismatch_out;
190061190363
}
190062190364
}
@@ -190306,11 +190608,13 @@
190306190608
/* Check that each phrase in the nearset matches the current row.
190307190609
** Populate the pPhrase->poslist buffers at the same time. If any
190308190610
** phrase is not a match, break out of the loop early. */
190309190611
for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
190310190612
Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
190311
- if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym || pNear->pColset ){
190613
+ if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym
190614
+ || pNear->pColset || pPhrase->aTerm[0].bFirst
190615
+ ){
190312190616
int bMatch = 0;
190313190617
rc = fts5ExprPhraseIsMatch(pNode, pPhrase, &bMatch);
190314190618
if( bMatch==0 ) break;
190315190619
}else{
190316190620
Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
@@ -190487,10 +190791,11 @@
190487190791
190488190792
/* Check that this node should not be FTS5_TERM */
190489190793
assert( pNear->nPhrase>1
190490190794
|| pNear->apPhrase[0]->nTerm>1
190491190795
|| pNear->apPhrase[0]->aTerm[0].pSynonym
190796
+ || pNear->apPhrase[0]->aTerm[0].bFirst
190492190797
);
190493190798
190494190799
/* Initialize iLast, the "lastest" rowid any iterator points to. If the
190495190800
** iterator skips through rowids in the default ascending order, this means
190496190801
** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
@@ -191010,10 +191315,20 @@
191010191315
}
191011191316
if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
191012191317
sqlite3_free(pPhrase);
191013191318
}
191014191319
}
191320
+
191321
+/*
191322
+** Set the "bFirst" flag on the first token of the phrase passed as the
191323
+** only argument.
191324
+*/
191325
+static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase *pPhrase){
191326
+ if( pPhrase && pPhrase->nTerm ){
191327
+ pPhrase->aTerm[0].bFirst = 1;
191328
+ }
191329
+}
191015191330
191016191331
/*
191017191332
** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated
191018191333
** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is
191019191334
** appended to it and the results returned.
@@ -191289,10 +191604,11 @@
191289191604
0, 0);
191290191605
tflags = FTS5_TOKEN_COLOCATED;
191291191606
}
191292191607
if( rc==SQLITE_OK ){
191293191608
sCtx.pPhrase->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix;
191609
+ sCtx.pPhrase->aTerm[i].bFirst = pOrig->aTerm[i].bFirst;
191294191610
}
191295191611
}
191296191612
}else{
191297191613
/* This happens when parsing a token or quoted phrase that contains
191298191614
** no token characters at all. (e.g ... MATCH '""'). */
@@ -191307,11 +191623,14 @@
191307191623
pNew->apExprPhrase[0] = sCtx.pPhrase;
191308191624
pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
191309191625
pNew->pRoot->pNear->nPhrase = 1;
191310191626
sCtx.pPhrase->pNode = pNew->pRoot;
191311191627
191312
- if( pOrig->nTerm==1 && pOrig->aTerm[0].pSynonym==0 ){
191628
+ if( pOrig->nTerm==1
191629
+ && pOrig->aTerm[0].pSynonym==0
191630
+ && pOrig->aTerm[0].bFirst==0
191631
+ ){
191313191632
pNew->pRoot->eType = FTS5_TERM;
191314191633
pNew->pRoot->xNext = fts5ExprNodeNext_TERM;
191315191634
}else{
191316191635
pNew->pRoot->eType = FTS5_STRING;
191317191636
pNew->pRoot->xNext = fts5ExprNodeNext_STRING;
@@ -191581,10 +191900,11 @@
191581191900
switch( pNode->eType ){
191582191901
case FTS5_STRING: {
191583191902
Fts5ExprNearset *pNear = pNode->pNear;
191584191903
if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1
191585191904
&& pNear->apPhrase[0]->aTerm[0].pSynonym==0
191905
+ && pNear->apPhrase[0]->aTerm[0].bFirst==0
191586191906
){
191587191907
pNode->eType = FTS5_TERM;
191588191908
pNode->xNext = fts5ExprNodeNext_TERM;
191589191909
}else{
191590191910
pNode->xNext = fts5ExprNodeNext_STRING;
@@ -191667,24 +191987,27 @@
191667191987
pRet->xNext = 0;
191668191988
pRet->eType = FTS5_EOF;
191669191989
}
191670191990
}
191671191991
191672
- if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL
191673
- && (pNear->nPhrase!=1 || pNear->apPhrase[0]->nTerm>1)
191674
- ){
191675
- assert( pParse->rc==SQLITE_OK );
191676
- pParse->rc = SQLITE_ERROR;
191677
- assert( pParse->zErr==0 );
191678
- pParse->zErr = sqlite3_mprintf(
191679
- "fts5: %s queries are not supported (detail!=full)",
191680
- pNear->nPhrase==1 ? "phrase": "NEAR"
191681
- );
191682
- sqlite3_free(pRet);
191683
- pRet = 0;
191684
- }
191685
-
191992
+ if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL ){
191993
+ Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
191994
+ if( pNear->nPhrase!=1
191995
+ || pPhrase->nTerm>1
191996
+ || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst)
191997
+ ){
191998
+ assert( pParse->rc==SQLITE_OK );
191999
+ pParse->rc = SQLITE_ERROR;
192000
+ assert( pParse->zErr==0 );
192001
+ pParse->zErr = sqlite3_mprintf(
192002
+ "fts5: %s queries are not supported (detail!=full)",
192003
+ pNear->nPhrase==1 ? "phrase": "NEAR"
192004
+ );
192005
+ sqlite3_free(pRet);
192006
+ pRet = 0;
192007
+ }
192008
+ }
191686192009
}else{
191687192010
fts5ExprAddChildren(pRet, pLeft);
191688192011
fts5ExprAddChildren(pRet, pRight);
191689192012
}
191690192013
}
@@ -202049,11 +202372,11 @@
202049202372
int nArg, /* Number of args */
202050202373
sqlite3_value **apUnused /* Function arguments */
202051202374
){
202052202375
assert( nArg==0 );
202053202376
UNUSED_PARAM2(nArg, apUnused);
202054
- sqlite3_result_text(pCtx, "fts5: 2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3", -1, SQLITE_TRANSIENT);
202377
+ sqlite3_result_text(pCtx, "fts5: 2017-12-01 18:40:18 5771b1d611b3562ea6c040f3f893073c4d0ee58c35b37ae211520d9aee8ed547", -1, SQLITE_TRANSIENT);
202055202378
}
202056202379
202057202380
static int fts5Init(sqlite3 *db){
202058202381
static const sqlite3_module fts5Mod = {
202059202382
/* iVersion */ 2,
@@ -206317,12 +206640,12 @@
206317206640
}
206318206641
#endif /* SQLITE_CORE */
206319206642
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
206320206643
206321206644
/************** End of stmt.c ************************************************/
206322
-#if __LINE__!=206322
206645
+#if __LINE__!=206645
206323206646
#undef SQLITE_SOURCE_ID
206324
-#define SQLITE_SOURCE_ID "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b832alt2"
206647
+#define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbalt2"
206325206648
#endif
206326206649
/* Return the source-id for this library */
206327206650
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
206328206651
/************************** End of sqlite3.c ******************************/
206329206652
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -16532,11 +16532,10 @@
16532 Expr *pHaving; /* The HAVING clause */
16533 ExprList *pOrderBy; /* The ORDER BY clause */
16534 Select *pPrior; /* Prior select in a compound select statement */
16535 Select *pNext; /* Next select to the left in a compound */
16536 Expr *pLimit; /* LIMIT expression. NULL means not used. */
16537 Expr *pOffset; /* OFFSET expression. NULL means not used. */
16538 With *pWith; /* WITH clause attached to this select. Or NULL. */
16539 };
16540
16541 /*
16542 ** Allowed values for Select.selFlags. The "SF" prefix stands for
@@ -17215,10 +17214,11 @@
17215 ** the same name but without the _BKPT suffix. These macros invoke
17216 ** routines that report the line-number on which the error originated
17217 ** using sqlite3_log(). The routines also provide a convenient place
17218 ** to set a debugger breakpoint.
17219 */
 
17220 SQLITE_PRIVATE int sqlite3CorruptError(int);
17221 SQLITE_PRIVATE int sqlite3MisuseError(int);
17222 SQLITE_PRIVATE int sqlite3CantopenError(int);
17223 #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
17224 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
@@ -17372,10 +17372,16 @@
17372 SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*);
17373
17374 /* Access to mutexes used by sqlite3_status() */
17375 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
17376 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
 
 
 
 
 
 
17377
17378 #ifndef SQLITE_OMIT_FLOATING_POINT
17379 SQLITE_PRIVATE int sqlite3IsNaN(double);
17380 #else
17381 # define sqlite3IsNaN(X) 0
@@ -17539,20 +17545,20 @@
17539 SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
17540 Expr*, int, int, u8);
17541 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
17542 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
17543 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
17544 Expr*,ExprList*,u32,Expr*,Expr*);
17545 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
17546 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
17547 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
17548 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
17549 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
17550 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*);
17551 #endif
17552 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*, Expr*);
17553 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,Expr*);
17554 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
17555 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
17556 SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
17557 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
17558 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
@@ -17672,11 +17678,11 @@
17672 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*);
17673 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*);
17674 SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
17675
17676 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
17677 SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,Expr*,int);
17678 #endif
17679
17680 #ifndef SQLITE_OMIT_TRIGGER
17681 SQLITE_PRIVATE void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
17682 Expr*,int, int);
@@ -23393,10 +23399,197 @@
23393 static SQLITE_WSD int mutexIsInit = 0;
23394 #endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */
23395
23396
23397 #ifndef SQLITE_MUTEX_OMIT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23398 /*
23399 ** Initialize the mutex system.
23400 */
23401 SQLITE_PRIVATE int sqlite3MutexInit(void){
23402 int rc = SQLITE_OK;
@@ -23408,11 +23601,15 @@
23408 */
23409 sqlite3_mutex_methods const *pFrom;
23410 sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
23411
23412 if( sqlite3GlobalConfig.bCoreMutex ){
 
 
 
23413 pFrom = sqlite3DefaultMutex();
 
23414 }else{
23415 pFrom = sqlite3NoopMutex();
23416 }
23417 pTo->xMutexInit = pFrom->xMutexInit;
23418 pTo->xMutexEnd = pFrom->xMutexEnd;
@@ -23534,10 +23731,11 @@
23534 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
23535 }
23536 #endif
23537
23538 #endif /* !defined(SQLITE_MUTEX_OMIT) */
 
23539
23540 /************** End of mutex.c ***********************************************/
23541 /************** Begin file mutex_noop.c **************************************/
23542 /*
23543 ** 2008 October 07
@@ -26817,11 +27015,10 @@
26817 if( p->pWhere ) n++;
26818 if( p->pGroupBy ) n++;
26819 if( p->pHaving ) n++;
26820 if( p->pOrderBy ) n++;
26821 if( p->pLimit ) n++;
26822 if( p->pOffset ) n++;
26823 }
26824 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
26825 if( p->pSrc && p->pSrc->nSrc ){
26826 int i;
26827 pView = sqlite3TreeViewPush(pView, (n--)>0);
@@ -26874,16 +27071,16 @@
26874 if( p->pOrderBy ){
26875 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
26876 }
26877 if( p->pLimit ){
26878 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
26879 sqlite3TreeViewExpr(pView, p->pLimit, 0);
26880 sqlite3TreeViewPop(pView);
26881 }
26882 if( p->pOffset ){
26883 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
26884 sqlite3TreeViewExpr(pView, p->pOffset, 0);
26885 sqlite3TreeViewPop(pView);
26886 }
26887 if( p->pPrior ){
26888 const char *zOp = "UNION";
26889 switch( p->op ){
@@ -57728,12 +57925,11 @@
57728 assert( pWal->nWiData>0 );
57729 assert( pWal->apWiData[0]!=0 );
57730 pInfo = walCkptInfo(pWal);
57731 if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
57732 #ifdef SQLITE_ENABLE_SNAPSHOT
57733 && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0
57734 || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr)))
57735 #endif
57736 ){
57737 /* The WAL has been completely backfilled (or it is empty).
57738 ** and can be safely ignored.
57739 */
@@ -60149,10 +60345,35 @@
60149 #define downgradeAllSharedCacheTableLocks(a)
60150 #define hasSharedCacheTableLock(a,b,c,d) 1
60151 #define hasReadConflicts(a, b) 0
60152 #endif
60153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60154 #ifndef SQLITE_OMIT_SHARED_CACHE
60155
60156 #ifdef SQLITE_DEBUG
60157 /*
60158 **** This function is only used as part of an assert() statement. ***
@@ -61437,11 +61658,11 @@
61437 u8 *pAddr;
61438 int sz2 = 0;
61439 int sz = get2byte(&data[iFree+2]);
61440 int top = get2byte(&data[hdr+5]);
61441 if( top>=iFree ){
61442 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61443 }
61444 if( iFree2 ){
61445 assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */
61446 sz2 = get2byte(&data[iFree2+2]);
61447 assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
@@ -61471,17 +61692,17 @@
61471 testcase( pc==iCellLast );
61472 /* These conditions have already been verified in btreeInitPage()
61473 ** if PRAGMA cell_size_check=ON.
61474 */
61475 if( pc<iCellFirst || pc>iCellLast ){
61476 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61477 }
61478 assert( pc>=iCellFirst && pc<=iCellLast );
61479 size = pPage->xCellSize(pPage, &src[pc]);
61480 cbrk -= size;
61481 if( cbrk<iCellFirst || pc+size>usableSize ){
61482 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61483 }
61484 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
61485 testcase( cbrk+size==usableSize );
61486 testcase( pc+size==usableSize );
61487 put2byte(pAddr, cbrk);
@@ -61497,11 +61718,11 @@
61497 }
61498 data[hdr+7] = 0;
61499
61500 defragment_out:
61501 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
61502 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61503 }
61504 assert( cbrk>=iCellFirst );
61505 put2byte(&data[hdr+5], cbrk);
61506 data[hdr+1] = 0;
61507 data[hdr+2] = 0;
@@ -61541,11 +61762,11 @@
61541 size = get2byte(&aData[pc+2]);
61542 if( (x = size - nByte)>=0 ){
61543 testcase( x==4 );
61544 testcase( x==3 );
61545 if( size+pc > usableSize ){
61546 *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61547 return 0;
61548 }else if( x<4 ){
61549 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
61550 ** number of bytes in fragments may not exceed 60. */
61551 if( aData[hdr+7]>57 ) return 0;
@@ -61564,11 +61785,11 @@
61564 iAddr = pc;
61565 pc = get2byte(&aData[pc]);
61566 if( pc<iAddr+size ) break;
61567 }
61568 if( pc ){
61569 *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61570 }
61571
61572 return 0;
61573 }
61574
@@ -61612,11 +61833,11 @@
61612 assert( top<=(int)pPage->pBt->usableSize ); /* Prevent by getAndInitPage() */
61613 if( gap>top ){
61614 if( top==0 && pPage->pBt->usableSize==65536 ){
61615 top = 65536;
61616 }else{
61617 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61618 }
61619 }
61620
61621 /* If there is enough space between gap and top for one more cell pointer
61622 ** array entry offset, and if the freelist is not empty, then search the
@@ -61702,16 +61923,16 @@
61702 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
61703 }else{
61704 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
61705 if( iFreeBlk<iPtr+4 ){
61706 if( iFreeBlk==0 ) break;
61707 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61708 }
61709 iPtr = iFreeBlk;
61710 }
61711 if( iFreeBlk>pPage->pBt->usableSize-4 ){
61712 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61713 }
61714 assert( iFreeBlk>iPtr || iFreeBlk==0 );
61715
61716 /* At this point:
61717 ** iFreeBlk: First freeblock after iStart, or zero if none
@@ -61719,14 +61940,14 @@
61719 **
61720 ** Check to see if iFreeBlk should be coalesced onto the end of iStart.
61721 */
61722 if( iFreeBlk && iEnd+3>=iFreeBlk ){
61723 nFrag = iFreeBlk - iEnd;
61724 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61725 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
61726 if( iEnd > pPage->pBt->usableSize ){
61727 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61728 }
61729 iSize = iEnd - iStart;
61730 iFreeBlk = get2byte(&data[iFreeBlk]);
61731 }
61732
@@ -61735,25 +61956,25 @@
61735 ** coalesced onto the end of iPtr.
61736 */
61737 if( iPtr>hdr+1 ){
61738 int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
61739 if( iPtrEnd+3>=iStart ){
61740 if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61741 nFrag += iStart - iPtrEnd;
61742 iSize = iEnd - iPtr;
61743 iStart = iPtr;
61744 }
61745 }
61746 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61747 data[hdr+7] -= nFrag;
61748 }
61749 x = get2byte(&data[hdr+5]);
61750 if( iStart<=x ){
61751 /* The new freeblock is at the beginning of the cell content area,
61752 ** so just extend the cell content area rather than create another
61753 ** freelist entry */
61754 if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61755 put2byte(&data[hdr+1], iFreeBlk);
61756 put2byte(&data[hdr+5], iEnd);
61757 }else{
61758 /* Insert the new freeblock into the freelist */
61759 put2byte(&data[iPtr], iStart);
@@ -61822,11 +62043,11 @@
61822 pPage->maxLocal = pBt->maxLocal;
61823 pPage->minLocal = pBt->minLocal;
61824 }else{
61825 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
61826 ** an error. */
61827 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61828 }
61829 pPage->max1bytePayload = pBt->max1bytePayload;
61830 return SQLITE_OK;
61831 }
61832
@@ -61863,11 +62084,11 @@
61863 hdr = pPage->hdrOffset;
61864 data = pPage->aData;
61865 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
61866 ** the b-tree page type. */
61867 if( decodeFlags(pPage, data[hdr]) ){
61868 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61869 }
61870 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
61871 pPage->maskPage = (u16)(pBt->pageSize - 1);
61872 pPage->nOverflow = 0;
61873 usableSize = pBt->usableSize;
@@ -61882,11 +62103,11 @@
61882 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61883 ** number of cells on the page. */
61884 pPage->nCell = get2byte(&data[hdr+3]);
61885 if( pPage->nCell>MX_CELL(pBt) ){
61886 /* To many cells for a single page. The page must be corrupt */
61887 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61888 }
61889 testcase( pPage->nCell==MX_CELL(pBt) );
61890 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
61891 ** possible for a root page of a table that contains no rows) then the
61892 ** offset to the cell content area will equal the page size minus the
@@ -61910,16 +62131,16 @@
61910 for(i=0; i<pPage->nCell; i++){
61911 pc = get2byteAligned(&data[cellOffset+i*2]);
61912 testcase( pc==iCellFirst );
61913 testcase( pc==iCellLast );
61914 if( pc<iCellFirst || pc>iCellLast ){
61915 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61916 }
61917 sz = pPage->xCellSize(pPage, &data[pc]);
61918 testcase( pc+sz==usableSize );
61919 if( pc+sz>usableSize ){
61920 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61921 }
61922 }
61923 if( !pPage->leaf ) iCellLast++;
61924 }
61925
@@ -61933,30 +62154,30 @@
61933 u32 next, size;
61934 if( pc<iCellFirst ){
61935 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
61936 ** always be at least one cell before the first freeblock.
61937 */
61938 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61939 }
61940 while( 1 ){
61941 if( pc>iCellLast ){
61942 /* Freeblock off the end of the page */
61943 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61944 }
61945 next = get2byte(&data[pc]);
61946 size = get2byte(&data[pc+2]);
61947 nFree = nFree + size;
61948 if( next<=pc+size+3 ) break;
61949 pc = next;
61950 }
61951 if( next>0 ){
61952 /* Freeblock not in ascending order */
61953 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61954 }
61955 if( pc+size>(unsigned int)usableSize ){
61956 /* Last freeblock extends past page end */
61957 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61958 }
61959 }
61960
61961 /* At this point, nFree contains the sum of the offset to the start
61962 ** of the cell-content area plus the number of free bytes within
@@ -61964,11 +62185,11 @@
61964 ** of the page, then the page must be corrupted. This check also
61965 ** serves to verify that the offset to the start of the cell-content
61966 ** area, according to the page header, lies within the page.
61967 */
61968 if( nFree>usableSize ){
61969 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61970 }
61971 pPage->nFree = (u16)(nFree - iCellFirst);
61972 pPage->isInit = 1;
61973 return SQLITE_OK;
61974 }
@@ -63495,11 +63716,11 @@
63495 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
63496 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
63497 if( eType==PTRMAP_OVERFLOW2 ){
63498 /* The pointer is always the first 4 bytes of the page in this case. */
63499 if( get4byte(pPage->aData)!=iFrom ){
63500 return SQLITE_CORRUPT_PGNO(pPage->pgno);
63501 }
63502 put4byte(pPage->aData, iTo);
63503 }else{
63504 int i;
63505 int nCell;
@@ -63514,11 +63735,11 @@
63514 if( eType==PTRMAP_OVERFLOW1 ){
63515 CellInfo info;
63516 pPage->xParseCell(pPage, pCell, &info);
63517 if( info.nLocal<info.nPayload ){
63518 if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
63519 return SQLITE_CORRUPT_PGNO(pPage->pgno);
63520 }
63521 if( iFrom==get4byte(pCell+info.nSize-4) ){
63522 put4byte(pCell+info.nSize-4, iTo);
63523 break;
63524 }
@@ -63532,11 +63753,11 @@
63532 }
63533
63534 if( i==nCell ){
63535 if( eType!=PTRMAP_BTREE ||
63536 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
63537 return SQLITE_CORRUPT_PGNO(pPage->pgno);
63538 }
63539 put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
63540 }
63541 }
63542 return SQLITE_OK;
@@ -64630,11 +64851,11 @@
64630 /* Trying to read or write past the end of the data is an error. The
64631 ** conditional above is really:
64632 ** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
64633 ** but is recast into its current form to avoid integer overflow problems
64634 */
64635 return SQLITE_CORRUPT_PGNO(pPage->pgno);
64636 }
64637
64638 /* Check if data must be read/written to/from the btree page itself. */
64639 if( offset<pCur->info.nLocal ){
64640 int a = amt;
@@ -64778,11 +64999,11 @@
64778 }
64779 }
64780
64781 if( rc==SQLITE_OK && amt>0 ){
64782 /* Overflow chain ends prematurely */
64783 return SQLITE_CORRUPT_PGNO(pPage->pgno);
64784 }
64785 return rc;
64786 }
64787
64788 /*
@@ -65056,11 +65277,11 @@
65056 ** if pCur->iPage>=0). But this is not so if the database is corrupted
65057 ** in such a way that page pRoot is linked into a second b-tree table
65058 ** (or the freelist). */
65059 assert( pRoot->intKey==1 || pRoot->intKey==0 );
65060 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
65061 return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno);
65062 }
65063
65064 skip_init:
65065 pCur->ix = 0;
65066 pCur->info.nSize = 0;
@@ -65329,11 +65550,11 @@
65329 i64 nCellKey;
65330 pCell = findCellPastPtr(pPage, idx);
65331 if( pPage->intKeyLeaf ){
65332 while( 0x80 <= *(pCell++) ){
65333 if( pCell>=pPage->aDataEnd ){
65334 return SQLITE_CORRUPT_PGNO(pPage->pgno);
65335 }
65336 }
65337 }
65338 getVarint(pCell, (u64*)&nCellKey);
65339 if( nCellKey<intKey ){
@@ -65403,11 +65624,11 @@
65403 testcase( nCell<0 ); /* True if key size is 2^32 or more */
65404 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
65405 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
65406 testcase( nCell==2 ); /* Minimum legal index key size */
65407 if( nCell<2 ){
65408 rc = SQLITE_CORRUPT_PGNO(pPage->pgno);
65409 goto moveto_finish;
65410 }
65411 pCellKey = sqlite3Malloc( nCell+18 );
65412 if( pCellKey==0 ){
65413 rc = SQLITE_NOMEM_BKPT;
@@ -66206,11 +66427,11 @@
66206 if( pInfo->nLocal==pInfo->nPayload ){
66207 return SQLITE_OK; /* No overflow pages. Return without doing anything */
66208 }
66209 if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
66210 /* Cell extends past end of page */
66211 return SQLITE_CORRUPT_PGNO(pPage->pgno);
66212 }
66213 ovflPgno = get4byte(pCell + pInfo->nSize - 4);
66214 pBt = pPage->pBt;
66215 assert( pBt->usableSize > 4 );
66216 ovflPageSize = pBt->usableSize - 4;
@@ -72103,11 +72324,15 @@
72103 const char *zNeg = "";
72104 int rc = SQLITE_OK;
72105
72106 assert( pExpr!=0 );
72107 while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
 
 
 
72108 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
 
72109
72110 /* Compressed expressions only appear when parsing the DEFAULT clause
72111 ** on a table column definition, and hence only when pCtx==0. This
72112 ** check ensures that an EP_TokenOnly expression is never passed down
72113 ** into valueFromFunction(). */
@@ -74813,10 +75038,11 @@
74813 needXcommit = 1;
74814 sqlite3BtreeEnter(pBt);
74815 pPager = sqlite3BtreePager(pBt);
74816 if( db->aDb[i].safety_level!=PAGER_SYNCHRONOUS_OFF
74817 && aMJNeeded[sqlite3PagerGetJournalMode(pPager)]
 
74818 ){
74819 assert( i!=1 );
74820 nTrans++;
74821 }
74822 rc = sqlite3PagerExclusiveLock(pPager);
@@ -90556,11 +90782,10 @@
90556 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
90557 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
90558 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
90559 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
90560 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
90561 if( sqlite3WalkExpr(pWalker, p->pOffset) ) return WRC_Abort;
90562 return WRC_Continue;
90563 }
90564
90565 /*
90566 ** Walk the parse trees associated with all subqueries in the
@@ -91824,12 +92049,11 @@
91824 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
91825 ** are not allowed to refer to any names, so pass an empty NameContext.
91826 */
91827 memset(&sNC, 0, sizeof(sNC));
91828 sNC.pParse = pParse;
91829 if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
91830 sqlite3ResolveExprNames(&sNC, p->pOffset) ){
91831 return WRC_Abort;
91832 }
91833
91834 /* If the SF_Converted flags is set, then this Select object was
91835 ** was created by the convertCompoundSelectToSubquery() function.
@@ -92826,11 +93050,10 @@
92826 static void heightOfSelect(Select *p, int *pnHeight){
92827 if( p ){
92828 heightOfExpr(p->pWhere, pnHeight);
92829 heightOfExpr(p->pHaving, pnHeight);
92830 heightOfExpr(p->pLimit, pnHeight);
92831 heightOfExpr(p->pOffset, pnHeight);
92832 heightOfExprList(p->pEList, pnHeight);
92833 heightOfExprList(p->pGroupBy, pnHeight);
92834 heightOfExprList(p->pOrderBy, pnHeight);
92835 heightOfSelect(p->pPrior, pnHeight);
92836 }
@@ -93625,11 +93848,10 @@
93625 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
93626 pNew->op = p->op;
93627 pNew->pNext = pNext;
93628 pNew->pPrior = 0;
93629 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
93630 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
93631 pNew->iLimit = 0;
93632 pNew->iOffset = 0;
93633 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
93634 pNew->addrOpenEphm[0] = -1;
93635 pNew->addrOpenEphm[1] = -1;
@@ -94262,11 +94484,10 @@
94262 testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate );
94263 return 0; /* No DISTINCT keyword and no aggregate functions */
94264 }
94265 assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
94266 if( p->pLimit ) return 0; /* Has no LIMIT clause */
94267 assert( p->pOffset==0 ); /* No LIMIT means no OFFSET */
94268 if( p->pWhere ) return 0; /* Has no WHERE clause */
94269 pSrc = p->pSrc;
94270 assert( pSrc!=0 );
94271 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
94272 if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
@@ -94352,20 +94573,19 @@
94352 ** If the RHS of the IN operator is a list or a more complex subquery, then
94353 ** an ephemeral table might need to be generated from the RHS and then
94354 ** pX->iTable made to point to the ephemeral table instead of an
94355 ** existing table.
94356 **
94357 ** The inFlags parameter must contain exactly one of the bits
94358 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains
94359 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
94360 ** fast membership test. When the IN_INDEX_LOOP bit is set, the
94361 ** IN index will be used to loop over all values of the RHS of the
94362 ** IN operator.
94363 **
94364 ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
94365 ** through the set members) then the b-tree must not contain duplicates.
94366 ** An epheremal table must be used unless the selected columns are guaranteed
94367 ** to be unique - either because it is an INTEGER PRIMARY KEY or due to
94368 ** a UNIQUE constraint or index.
94369 **
94370 ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
94371 ** for fast set membership tests) then an epheremal table must
@@ -94902,10 +95122,11 @@
94902 ** preexisting limit is discarded in place of the new LIMIT 1.
94903 */
94904 Select *pSel; /* SELECT statement to encode */
94905 SelectDest dest; /* How to deal with SELECT result */
94906 int nReg; /* Registers to allocate */
 
94907
94908 testcase( pExpr->op==TK_EXISTS );
94909 testcase( pExpr->op==TK_SELECT );
94910 assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
94911 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
@@ -94923,13 +95144,17 @@
94923 }else{
94924 dest.eDest = SRT_Exists;
94925 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
94926 VdbeComment((v, "Init EXISTS result"));
94927 }
94928 sqlite3ExprDelete(pParse->db, pSel->pLimit);
94929 pSel->pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,
94930 &sqlite3IntTokens[1], 0);
 
 
 
 
94931 pSel->iLimit = 0;
94932 pSel->selFlags &= ~SF_MultiValue;
94933 if( sqlite3Select(pParse, pSel, &dest) ){
94934 return 0;
94935 }
@@ -100713,13 +100938,10 @@
100713 return 1;
100714 }
100715 if( sqlite3FixExpr(pFix, pSelect->pLimit) ){
100716 return 1;
100717 }
100718 if( sqlite3FixExpr(pFix, pSelect->pOffset) ){
100719 return 1;
100720 }
100721 pSelect = pSelect->pPrior;
100722 }
100723 return 0;
100724 }
100725 SQLITE_PRIVATE int sqlite3FixExpr(
@@ -106085,11 +106307,10 @@
106085 Parse *pParse, /* Parsing context */
106086 Table *pView, /* View definition */
106087 Expr *pWhere, /* Optional WHERE clause to be added */
106088 ExprList *pOrderBy, /* Optional ORDER BY clause */
106089 Expr *pLimit, /* Optional LIMIT clause */
106090 Expr *pOffset, /* Optional OFFSET clause */
106091 int iCur /* Cursor number for ephemeral table */
106092 ){
106093 SelectDest dest;
106094 Select *pSel;
106095 SrcList *pFrom;
@@ -106103,11 +106324,11 @@
106103 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
106104 assert( pFrom->a[0].pOn==0 );
106105 assert( pFrom->a[0].pUsing==0 );
106106 }
106107 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
106108 SF_IncludeHidden, pLimit, pOffset);
106109 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
106110 sqlite3Select(pParse, pSel, &dest);
106111 sqlite3SelectDelete(db, pSel);
106112 }
106113 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -106125,11 +106346,10 @@
106125 Parse *pParse, /* The parser context */
106126 SrcList *pSrc, /* the FROM clause -- which tables to scan */
106127 Expr *pWhere, /* The WHERE clause. May be null */
106128 ExprList *pOrderBy, /* The ORDER BY clause. May be null */
106129 Expr *pLimit, /* The LIMIT clause. May be null */
106130 Expr *pOffset, /* The OFFSET clause. May be null */
106131 char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
106132 ){
106133 sqlite3 *db = pParse->db;
106134 Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */
106135 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
@@ -106142,21 +106362,17 @@
106142 */
106143 if( pOrderBy && pLimit==0 ) {
106144 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
106145 sqlite3ExprDelete(pParse->db, pWhere);
106146 sqlite3ExprListDelete(pParse->db, pOrderBy);
106147 sqlite3ExprDelete(pParse->db, pLimit);
106148 sqlite3ExprDelete(pParse->db, pOffset);
106149 return 0;
106150 }
106151
106152 /* We only need to generate a select expression if there
106153 ** is a limit/offset term to enforce.
106154 */
106155 if( pLimit == 0 ) {
106156 /* if pLimit is null, pOffset will always be null as well. */
106157 assert( pOffset == 0 );
106158 return pWhere;
106159 }
106160
106161 /* Generate a select expression tree to enforce the limit/offset
106162 ** term for the DELETE or UPDATE statement. For example:
@@ -106199,11 +106415,11 @@
106199 pSrc->a[0].pTab = pTab;
106200 pSrc->a[0].pIBIndex = 0;
106201
106202 /* generate the SELECT expression tree. */
106203 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
106204 pOrderBy,0,pLimit,pOffset
106205 );
106206
106207 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
106208 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
106209 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
@@ -106222,12 +106438,11 @@
106222 SQLITE_PRIVATE void sqlite3DeleteFrom(
106223 Parse *pParse, /* The parser context */
106224 SrcList *pTabList, /* The table from which we should delete things */
106225 Expr *pWhere, /* The WHERE clause. May be null */
106226 ExprList *pOrderBy, /* ORDER BY clause. May be null */
106227 Expr *pLimit, /* LIMIT clause. May be null */
106228 Expr *pOffset /* OFFSET clause. May be null */
106229 ){
106230 Vdbe *v; /* The virtual database engine */
106231 Table *pTab; /* The table from which records will be deleted */
106232 int i; /* Loop counter */
106233 WhereInfo *pWInfo; /* Information about the WHERE clause */
@@ -106296,14 +106511,14 @@
106296 #endif
106297
106298 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
106299 if( !isView ){
106300 pWhere = sqlite3LimitWhere(
106301 pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "DELETE"
106302 );
106303 pOrderBy = 0;
106304 pLimit = pOffset = 0;
106305 }
106306 #endif
106307
106308 /* If pTab is really a view, make sure it has been initialized.
106309 */
@@ -106351,15 +106566,15 @@
106351 ** an ephemeral table.
106352 */
106353 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
106354 if( isView ){
106355 sqlite3MaterializeView(pParse, pTab,
106356 pWhere, pOrderBy, pLimit, pOffset, iTabCur
106357 );
106358 iDataCur = iIdxCur = iTabCur;
106359 pOrderBy = 0;
106360 pLimit = pOffset = 0;
106361 }
106362 #endif
106363
106364 /* Resolve the column names in the WHERE clause.
106365 */
@@ -106602,11 +106817,10 @@
106602 sqlite3SrcListDelete(db, pTabList);
106603 sqlite3ExprDelete(db, pWhere);
106604 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
106605 sqlite3ExprListDelete(db, pOrderBy);
106606 sqlite3ExprDelete(db, pLimit);
106607 sqlite3ExprDelete(db, pOffset);
106608 #endif
106609 sqlite3DbFree(db, aToOpen);
106610 return;
106611 }
106612 /* Make sure "isView" and other macros defined above are undefined. Otherwise
@@ -109568,11 +109782,11 @@
109568 iSkip = sqlite3VdbeMakeLabel(v);
109569 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
109570 }
109571
109572 pParse->disableTriggers = 1;
109573 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0, 0);
109574 pParse->disableTriggers = 0;
109575
109576 /* If the DELETE has generated immediate foreign key constraint
109577 ** violations, halt the VDBE and return an error at this point, before
109578 ** any modifications to the schema are made. This is because statement
@@ -110126,11 +110340,11 @@
110126 }
110127 pSelect = sqlite3SelectNew(pParse,
110128 sqlite3ExprListAppend(pParse, 0, pRaise),
110129 sqlite3SrcListAppend(db, 0, &tFrom, 0),
110130 pWhere,
110131 0, 0, 0, 0, 0, 0
110132 );
110133 pWhere = 0;
110134 }
110135
110136 /* Disable lookaside memory allocation */
@@ -112274,11 +112488,10 @@
112274 return 0; /* SELECT may not have a GROUP BY clause */
112275 }
112276 if( pSelect->pLimit ){
112277 return 0; /* SELECT may not have a LIMIT clause */
112278 }
112279 assert( pSelect->pOffset==0 ); /* Must be so if pLimit==0 */
112280 if( pSelect->pPrior ){
112281 return 0; /* SELECT may not be a compound query */
112282 }
112283 if( pSelect->selFlags & SF_Distinct ){
112284 return 0; /* SELECT may not be DISTINCT */
@@ -118173,11 +118386,10 @@
118173 sqlite3ExprDelete(db, p->pWhere);
118174 sqlite3ExprListDelete(db, p->pGroupBy);
118175 sqlite3ExprDelete(db, p->pHaving);
118176 sqlite3ExprListDelete(db, p->pOrderBy);
118177 sqlite3ExprDelete(db, p->pLimit);
118178 sqlite3ExprDelete(db, p->pOffset);
118179 if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
118180 if( bFree ) sqlite3DbFreeNN(db, p);
118181 p = pPrior;
118182 bFree = 1;
118183 }
@@ -118206,12 +118418,11 @@
118206 Expr *pWhere, /* the WHERE clause */
118207 ExprList *pGroupBy, /* the GROUP BY clause */
118208 Expr *pHaving, /* the HAVING clause */
118209 ExprList *pOrderBy, /* the ORDER BY clause */
118210 u32 selFlags, /* Flag parameters, such as SF_Distinct */
118211 Expr *pLimit, /* LIMIT value. NULL means not used */
118212 Expr *pOffset /* OFFSET value. NULL means no offset */
118213 ){
118214 Select *pNew;
118215 Select standin;
118216 pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
118217 if( pNew==0 ){
@@ -118240,14 +118451,11 @@
118240 pNew->pHaving = pHaving;
118241 pNew->pOrderBy = pOrderBy;
118242 pNew->pPrior = 0;
118243 pNew->pNext = 0;
118244 pNew->pLimit = pLimit;
118245 pNew->pOffset = pOffset;
118246 pNew->pWith = 0;
118247 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0
118248 || pParse->db->mallocFailed!=0 );
118249 if( pParse->db->mallocFailed ) {
118250 clearSelect(pParse->db, pNew, pNew!=&standin);
118251 pNew = 0;
118252 }else{
118253 assert( pNew->pSrc!=0 || pParse->nErr>0 );
@@ -119973,69 +120181,72 @@
119973 }
119974
119975
119976 /*
119977 ** Compute the iLimit and iOffset fields of the SELECT based on the
119978 ** pLimit and pOffset expressions. pLimit and pOffset hold the expressions
119979 ** that appear in the original SQL statement after the LIMIT and OFFSET
119980 ** keywords. Or NULL if those keywords are omitted. iLimit and iOffset
119981 ** are the integer memory register numbers for counters used to compute
119982 ** the limit and offset. If there is no limit and/or offset, then
119983 ** iLimit and iOffset are negative.
119984 **
119985 ** This routine changes the values of iLimit and iOffset only if
119986 ** a limit or offset is defined by pLimit and pOffset. iLimit and
119987 ** iOffset should have been preset to appropriate default values (zero)
119988 ** prior to calling this routine.
119989 **
119990 ** The iOffset register (if it exists) is initialized to the value
119991 ** of the OFFSET. The iLimit register is initialized to LIMIT. Register
119992 ** iOffset+1 is initialized to LIMIT+OFFSET.
119993 **
119994 ** Only if pLimit!=0 or pOffset!=0 do the limit registers get
119995 ** redefined. The UNION ALL operator uses this property to force
119996 ** the reuse of the same limit and offset registers across multiple
119997 ** SELECT statements.
119998 */
119999 static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
120000 Vdbe *v = 0;
120001 int iLimit = 0;
120002 int iOffset;
120003 int n;
 
 
120004 if( p->iLimit ) return;
120005
120006 /*
120007 ** "LIMIT -1" always shows all rows. There is some
120008 ** controversy about what the correct behavior should be.
120009 ** The current implementation interprets "LIMIT 0" to mean
120010 ** no rows.
120011 */
120012 sqlite3ExprCacheClear(pParse);
120013 assert( p->pOffset==0 || p->pLimit!=0 );
120014 if( p->pLimit ){
 
120015 p->iLimit = iLimit = ++pParse->nMem;
120016 v = sqlite3GetVdbe(pParse);
120017 assert( v!=0 );
120018 if( sqlite3ExprIsInteger(p->pLimit, &n) ){
120019 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
120020 VdbeComment((v, "LIMIT counter"));
120021 if( n==0 ){
120022 sqlite3VdbeGoto(v, iBreak);
120023 }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
120024 p->nSelectRow = sqlite3LogEst((u64)n);
120025 p->selFlags |= SF_FixedLimit;
120026 }
120027 }else{
120028 sqlite3ExprCode(pParse, p->pLimit, iLimit);
120029 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
120030 VdbeComment((v, "LIMIT counter"));
120031 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
120032 }
120033 if( p->pOffset ){
120034 p->iOffset = iOffset = ++pParse->nMem;
120035 pParse->nMem++; /* Allocate an extra register for limit+offset */
120036 sqlite3ExprCode(pParse, p->pOffset, iOffset);
120037 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
120038 VdbeComment((v, "OFFSET counter"));
120039 sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset);
120040 VdbeComment((v, "LIMIT+OFFSET"));
120041 }
@@ -120161,11 +120372,11 @@
120161 int eDest = SRT_Fifo; /* How to write to Queue */
120162 SelectDest destQueue; /* SelectDest targetting the Queue table */
120163 int i; /* Loop counter */
120164 int rc; /* Result code */
120165 ExprList *pOrderBy; /* The ORDER BY clause */
120166 Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */
120167 int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
120168
120169 /* Obtain authorization to do a recursive query */
120170 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
120171
@@ -120172,14 +120383,13 @@
120172 /* Process the LIMIT and OFFSET clauses, if they exist */
120173 addrBreak = sqlite3VdbeMakeLabel(v);
120174 p->nSelectRow = 320; /* 4 billion rows */
120175 computeLimitRegisters(pParse, p, addrBreak);
120176 pLimit = p->pLimit;
120177 pOffset = p->pOffset;
120178 regLimit = p->iLimit;
120179 regOffset = p->iOffset;
120180 p->pLimit = p->pOffset = 0;
120181 p->iLimit = p->iOffset = 0;
120182 pOrderBy = p->pOrderBy;
120183
120184 /* Locate the cursor number of the Current table */
120185 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
@@ -120268,11 +120478,10 @@
120268
120269 end_of_recursive_query:
120270 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
120271 p->pOrderBy = pOrderBy;
120272 p->pLimit = pLimit;
120273 p->pOffset = pOffset;
120274 return;
120275 }
120276 #endif /* SQLITE_OMIT_CTE */
120277
120278 /* Forward references */
@@ -120304,11 +120513,10 @@
120304 assert( p->selFlags & SF_MultiValue );
120305 do{
120306 assert( p->selFlags & SF_Values );
120307 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
120308 assert( p->pLimit==0 );
120309 assert( p->pOffset==0 );
120310 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
120311 if( p->pPrior==0 ) break;
120312 assert( p->pPrior->pNext==p );
120313 p = p->pPrior;
120314 nRow++;
@@ -120431,15 +120639,13 @@
120431 int nLimit;
120432 assert( !pPrior->pLimit );
120433 pPrior->iLimit = p->iLimit;
120434 pPrior->iOffset = p->iOffset;
120435 pPrior->pLimit = p->pLimit;
120436 pPrior->pOffset = p->pOffset;
120437 explainSetInteger(iSub1, pParse->iNextSelectId);
120438 rc = sqlite3Select(pParse, pPrior, &dest);
120439 p->pLimit = 0;
120440 p->pOffset = 0;
120441 if( rc ){
120442 goto multi_select_end;
120443 }
120444 p->pPrior = 0;
120445 p->iLimit = pPrior->iLimit;
@@ -120457,11 +120663,11 @@
120457 testcase( rc!=SQLITE_OK );
120458 pDelete = p->pPrior;
120459 p->pPrior = pPrior;
120460 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
120461 if( pPrior->pLimit
120462 && sqlite3ExprIsInteger(pPrior->pLimit, &nLimit)
120463 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
120464 ){
120465 p->nSelectRow = sqlite3LogEst((u64)nLimit);
120466 }
120467 if( addr ){
@@ -120472,11 +120678,11 @@
120472 case TK_EXCEPT:
120473 case TK_UNION: {
120474 int unionTab; /* Cursor number of the temporary table holding result */
120475 u8 op = 0; /* One of the SRT_ operations to apply to self */
120476 int priorOp; /* The SRT_ operation to apply to prior selects */
120477 Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
120478 int addr;
120479 SelectDest uniondest;
120480
120481 testcase( p->op==TK_EXCEPT );
120482 testcase( p->op==TK_UNION );
@@ -120484,11 +120690,10 @@
120484 if( dest.eDest==priorOp ){
120485 /* We can reuse a temporary table generated by a SELECT to our
120486 ** right.
120487 */
120488 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
120489 assert( p->pOffset==0 ); /* Not allowed on leftward elements */
120490 unionTab = dest.iSDParm;
120491 }else{
120492 /* We will need to create our own temporary table to hold the
120493 ** intermediate results.
120494 */
@@ -120520,12 +120725,10 @@
120520 op = SRT_Union;
120521 }
120522 p->pPrior = 0;
120523 pLimit = p->pLimit;
120524 p->pLimit = 0;
120525 pOffset = p->pOffset;
120526 p->pOffset = 0;
120527 uniondest.eDest = op;
120528 explainSetInteger(iSub2, pParse->iNextSelectId);
120529 rc = sqlite3Select(pParse, p, &uniondest);
120530 testcase( rc!=SQLITE_OK );
120531 /* Query flattening in sqlite3Select() might refill p->pOrderBy.
@@ -120537,11 +120740,10 @@
120537 if( p->op==TK_UNION ){
120538 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
120539 }
120540 sqlite3ExprDelete(db, p->pLimit);
120541 p->pLimit = pLimit;
120542 p->pOffset = pOffset;
120543 p->iLimit = 0;
120544 p->iOffset = 0;
120545
120546 /* Convert the data in the temporary table into whatever form
120547 ** it is that we currently need.
@@ -120565,11 +120767,11 @@
120565 break;
120566 }
120567 default: assert( p->op==TK_INTERSECT ); {
120568 int tab1, tab2;
120569 int iCont, iBreak, iStart;
120570 Expr *pLimit, *pOffset;
120571 int addr;
120572 SelectDest intersectdest;
120573 int r1;
120574
120575 /* INTERSECT is different from the others since it requires
@@ -120601,22 +120803,19 @@
120601 assert( p->addrOpenEphm[1] == -1 );
120602 p->addrOpenEphm[1] = addr;
120603 p->pPrior = 0;
120604 pLimit = p->pLimit;
120605 p->pLimit = 0;
120606 pOffset = p->pOffset;
120607 p->pOffset = 0;
120608 intersectdest.iSDParm = tab2;
120609 explainSetInteger(iSub2, pParse->iNextSelectId);
120610 rc = sqlite3Select(pParse, p, &intersectdest);
120611 testcase( rc!=SQLITE_OK );
120612 pDelete = p->pPrior;
120613 p->pPrior = pPrior;
120614 if( p->nSelectRow>pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
120615 sqlite3ExprDelete(db, p->pLimit);
120616 p->pLimit = pLimit;
120617 p->pOffset = pOffset;
120618
120619 /* Generate code to take the intersection of the two temporary
120620 ** tables.
120621 */
120622 assert( p->pEList );
@@ -121091,12 +121290,10 @@
121091 }else{
121092 regLimitA = regLimitB = 0;
121093 }
121094 sqlite3ExprDelete(db, p->pLimit);
121095 p->pLimit = 0;
121096 sqlite3ExprDelete(db, p->pOffset);
121097 p->pOffset = 0;
121098
121099 regAddrA = ++pParse->nMem;
121100 regAddrB = ++pParse->nMem;
121101 regOutA = ++pParse->nMem;
121102 regOutB = ++pParse->nMem;
@@ -121556,11 +121753,11 @@
121556 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
121557 ** because they could be computed at compile-time. But when LIMIT and OFFSET
121558 ** became arbitrary expressions, we were forced to add restrictions (13)
121559 ** and (14). */
121560 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
121561 if( pSub->pOffset ) return 0; /* Restriction (14) */
121562 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
121563 return 0; /* Restriction (15) */
121564 }
121565 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
121566 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
@@ -121704,20 +121901,17 @@
121704 */
121705 for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){
121706 Select *pNew;
121707 ExprList *pOrderBy = p->pOrderBy;
121708 Expr *pLimit = p->pLimit;
121709 Expr *pOffset = p->pOffset;
121710 Select *pPrior = p->pPrior;
121711 p->pOrderBy = 0;
121712 p->pSrc = 0;
121713 p->pPrior = 0;
121714 p->pLimit = 0;
121715 p->pOffset = 0;
121716 pNew = sqlite3SelectDup(db, p, 0);
121717 sqlite3SelectSetName(pNew, pSub->zSelName);
121718 p->pOffset = pOffset;
121719 p->pLimit = pLimit;
121720 p->pOrderBy = pOrderBy;
121721 p->pSrc = pSrc;
121722 p->op = TK_ALL;
121723 if( pNew==0 ){
@@ -122179,11 +122373,10 @@
122179 assert( (p->selFlags & SF_Converted)==0 );
122180 p->selFlags |= SF_Converted;
122181 assert( pNew->pPrior!=0 );
122182 pNew->pPrior->pNext = pNew;
122183 pNew->pLimit = 0;
122184 pNew->pOffset = 0;
122185 return WRC_Continue;
122186 }
122187
122188 /*
122189 ** Check to see if the FROM clause term pFrom has table-valued function
@@ -125077,11 +125270,11 @@
125077 case TK_UPDATE: {
125078 sqlite3Update(pParse,
125079 targetSrcList(pParse, pStep),
125080 sqlite3ExprListDup(db, pStep->pExprList, 0),
125081 sqlite3ExprDup(db, pStep->pWhere, 0),
125082 pParse->eOrconf, 0, 0, 0
125083 );
125084 break;
125085 }
125086 case TK_INSERT: {
125087 sqlite3Insert(pParse,
@@ -125093,11 +125286,11 @@
125093 break;
125094 }
125095 case TK_DELETE: {
125096 sqlite3DeleteFrom(pParse,
125097 targetSrcList(pParse, pStep),
125098 sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0, 0
125099 );
125100 break;
125101 }
125102 default: assert( pStep->op==TK_SELECT ); {
125103 SelectDest sDest;
@@ -125241,11 +125434,11 @@
125241 }
125242 sqlite3VdbeAddOp0(v, OP_Halt);
125243 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
125244
125245 transferParseError(pParse, pSubParse);
125246 if( db->mallocFailed==0 ){
125247 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
125248 }
125249 pProgram->nMem = pSubParse->nMem;
125250 pProgram->nCsr = pSubParse->nTab;
125251 pProgram->token = (void *)pTrigger;
@@ -125562,12 +125755,11 @@
125562 SrcList *pTabList, /* The table in which we should change things */
125563 ExprList *pChanges, /* Things to be changed */
125564 Expr *pWhere, /* The WHERE clause. May be null */
125565 int onError, /* How to handle constraint errors */
125566 ExprList *pOrderBy, /* ORDER BY clause. May be null */
125567 Expr *pLimit, /* LIMIT clause. May be null */
125568 Expr *pOffset /* OFFSET clause. May be null */
125569 ){
125570 int i, j; /* Loop counters */
125571 Table *pTab; /* The table to be updated */
125572 int addrTop = 0; /* VDBE instruction address of the start of the loop */
125573 WhereInfo *pWInfo; /* Information about the WHERE clause */
@@ -125651,14 +125843,14 @@
125651 #endif
125652
125653 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
125654 if( !isView ){
125655 pWhere = sqlite3LimitWhere(
125656 pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "UPDATE"
125657 );
125658 pOrderBy = 0;
125659 pLimit = pOffset = 0;
125660 }
125661 #endif
125662
125663 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
125664 goto update_cleanup;
@@ -125827,14 +126019,14 @@
125827 ** an ephemeral table.
125828 */
125829 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
125830 if( isView ){
125831 sqlite3MaterializeView(pParse, pTab,
125832 pWhere, pOrderBy, pLimit, pOffset, iDataCur
125833 );
125834 pOrderBy = 0;
125835 pLimit = pOffset = 0;
125836 }
125837 #endif
125838
125839 /* Resolve the column names in all the expressions in the
125840 ** WHERE clause.
@@ -126217,11 +126409,10 @@
126217 sqlite3ExprListDelete(db, pChanges);
126218 sqlite3ExprDelete(db, pWhere);
126219 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
126220 sqlite3ExprListDelete(db, pOrderBy);
126221 sqlite3ExprDelete(db, pLimit);
126222 sqlite3ExprDelete(db, pOffset);
126223 #endif
126224 return;
126225 }
126226 /* Make sure "isView" and other macros defined above are undefined. Otherwise
126227 ** they may interfere with compilation of other functions in this file
@@ -128931,10 +129122,106 @@
128931 ){
128932 zAff[i] = SQLITE_AFF_BLOB;
128933 }
128934 }
128935 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128936
128937 /*
128938 ** Generate code for a single equality term of the WHERE clause. An equality
128939 ** term can be either X=expr or X IN (...). pTerm is the term to be
128940 ** coded.
@@ -128994,72 +129281,27 @@
128994 disableTerm(pLevel, pTerm);
128995 return iTarget;
128996 }
128997 }
128998 for(i=iEq;i<pLoop->nLTerm; i++){
128999 if( ALWAYS(pLoop->aLTerm[i]) && pLoop->aLTerm[i]->pExpr==pX ) nEq++;
 
129000 }
129001
129002 if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
129003 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
129004 }else{
129005 Select *pSelect = pX->x.pSelect;
129006 sqlite3 *db = pParse->db;
129007 u16 savedDbOptFlags = db->dbOptFlags;
129008 ExprList *pOrigRhs = pSelect->pEList;
129009 ExprList *pOrigLhs = pX->pLeft->x.pList;
129010 ExprList *pRhs = 0; /* New Select.pEList for RHS */
129011 ExprList *pLhs = 0; /* New pX->pLeft vector */
129012
129013 for(i=iEq;i<pLoop->nLTerm; i++){
129014 if( pLoop->aLTerm[i]->pExpr==pX ){
129015 int iField = pLoop->aLTerm[i]->iField - 1;
129016 Expr *pNewRhs = sqlite3ExprDup(db, pOrigRhs->a[iField].pExpr, 0);
129017 Expr *pNewLhs = sqlite3ExprDup(db, pOrigLhs->a[iField].pExpr, 0);
129018
129019 pRhs = sqlite3ExprListAppend(pParse, pRhs, pNewRhs);
129020 pLhs = sqlite3ExprListAppend(pParse, pLhs, pNewLhs);
129021 }
129022 }
129023 if( !db->mallocFailed ){
129024 Expr *pLeft = pX->pLeft;
129025
129026 if( pSelect->pOrderBy ){
129027 /* If the SELECT statement has an ORDER BY clause, zero the
129028 ** iOrderByCol variables. These are set to non-zero when an
129029 ** ORDER BY term exactly matches one of the terms of the
129030 ** result-set. Since the result-set of the SELECT statement may
129031 ** have been modified or reordered, these variables are no longer
129032 ** set correctly. Since setting them is just an optimization,
129033 ** it's easiest just to zero them here. */
129034 ExprList *pOrderBy = pSelect->pOrderBy;
129035 for(i=0; i<pOrderBy->nExpr; i++){
129036 pOrderBy->a[i].u.x.iOrderByCol = 0;
129037 }
129038 }
129039
129040 /* Take care here not to generate a TK_VECTOR containing only a
129041 ** single value. Since the parser never creates such a vector, some
129042 ** of the subroutines do not handle this case. */
129043 if( pLhs->nExpr==1 ){
129044 pX->pLeft = pLhs->a[0].pExpr;
129045 }else{
129046 pLeft->x.pList = pLhs;
129047 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
129048 testcase( aiMap==0 );
129049 }
129050 pSelect->pEList = pRhs;
129051 db->dbOptFlags |= SQLITE_QueryFlattener;
129052 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
129053 db->dbOptFlags = savedDbOptFlags;
129054 testcase( aiMap!=0 && aiMap[0]!=0 );
129055 pSelect->pEList = pOrigRhs;
129056 pLeft->x.pList = pOrigLhs;
129057 pX->pLeft = pLeft;
129058 }
129059 sqlite3ExprListDelete(pParse->db, pLhs);
129060 sqlite3ExprListDelete(pParse->db, pRhs);
129061 }
129062
129063 if( eType==IN_INDEX_INDEX_DESC ){
129064 testcase( bRev );
129065 bRev = !bRev;
@@ -134703,11 +134945,11 @@
134703 }else if( eOp & (WO_EQ|WO_IS) ){
134704 int iCol = pProbe->aiColumn[saved_nEq];
134705 pNew->wsFlags |= WHERE_COLUMN_EQ;
134706 assert( saved_nEq==pNew->u.btree.nEq );
134707 if( iCol==XN_ROWID
134708 || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
134709 ){
134710 if( iCol>=0 && pProbe->uniqNotNull==0 ){
134711 pNew->wsFlags |= WHERE_UNQ_WANTED;
134712 }else{
134713 pNew->wsFlags |= WHERE_ONEROW;
@@ -136920,39 +137162,84 @@
136920 for(ii=0; ii<pWInfo->nLevel; ii++){
136921 whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
136922 }
136923 }
136924 #endif
136925 /* Attempt to omit tables from the join that do not effect the result */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136926 if( pWInfo->nLevel>=2
136927 && pResultSet!=0
136928 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
136929 ){
 
136930 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
136931 if( sWLB.pOrderBy ){
136932 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
136933 }
136934 while( pWInfo->nLevel>=2 ){
136935 WhereTerm *pTerm, *pEnd;
136936 pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
136937 if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break;
 
 
136938 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
136939 && (pLoop->wsFlags & WHERE_ONEROW)==0
136940 ){
136941 break;
136942 }
136943 if( (tabUsed & pLoop->maskSelf)!=0 ) break;
136944 pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
136945 for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
136946 if( (pTerm->prereqAll & pLoop->maskSelf)!=0
136947 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
136948 ){
136949 break;
 
 
136950 }
136951 }
136952 if( pTerm<pEnd ) break;
136953 WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
 
 
 
 
 
 
 
 
 
 
136954 pWInfo->nLevel--;
136955 nTabList--;
136956 }
136957 }
136958 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
@@ -137103,11 +137390,10 @@
137103
137104 /* Generate the code to do the search. Each iteration of the for
137105 ** loop below generates code for a single nested loop of the VM
137106 ** program.
137107 */
137108 notReady = ~(Bitmask)0;
137109 for(ii=0; ii<nTabList; ii++){
137110 int addrExplain;
137111 int wsFlags;
137112 pLevel = &pWInfo->a[ii];
137113 wsFlags = pLevel->pWLoop->wsFlags;
@@ -137167,10 +137453,11 @@
137167 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
137168 int addrSeek = 0;
137169 Index *pIdx;
137170 int n;
137171 if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
 
137172 && (pLoop->wsFlags & WHERE_INDEXED)!=0
137173 && (pIdx = pLoop->u.btree.pIndex)->hasStat1
137174 && (n = pLoop->u.btree.nIdxCol)>0
137175 && pIdx->aiRowLogEst[n]>=36
137176 ){
@@ -137233,11 +137520,12 @@
137233 if( pLevel->iLeftJoin ){
137234 int ws = pLoop->wsFlags;
137235 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
137236 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
137237 if( (ws & WHERE_IDX_ONLY)==0 ){
137238 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
 
137239 }
137240 if( (ws & WHERE_INDEXED)
137241 || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
137242 ){
137243 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -137401,19 +137689,10 @@
137401 ** Alternative datatype for the argument to the malloc() routine passed
137402 ** into sqlite3ParserAlloc(). The default is size_t.
137403 */
137404 #define YYMALLOCARGTYPE u64
137405
137406 /*
137407 ** An instance of this structure holds information about the
137408 ** LIMIT clause of a SELECT statement.
137409 */
137410 struct LimitVal {
137411 Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */
137412 Expr *pOffset; /* The OFFSET expression. NULL if there is none */
137413 };
137414
137415 /*
137416 ** An instance of the following structure describes the event of a
137417 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
137418 ** TK_DELETE, or TK_INSTEAD. If the event is of the form
137419 **
@@ -137647,11 +137926,10 @@
137647 int yy194;
137648 Select* yy243;
137649 IdList* yy254;
137650 With* yy285;
137651 struct TrigEvent yy332;
137652 struct LimitVal yy354;
137653 struct {int value; int mask;} yy497;
137654 } YYMINORTYPE;
137655 #ifndef YYSTACKDEPTH
137656 #define YYSTACKDEPTH 100
137657 #endif
@@ -139903,11 +140181,11 @@
139903 SrcList *pFrom;
139904 Token x;
139905 x.n = 0;
139906 parserDoubleLinkSelect(pParse, pRhs);
139907 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
139908 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
139909 }
139910 if( pRhs ){
139911 pRhs->op = (u8)yymsp[-1].minor.yy194;
139912 pRhs->pPrior = pLhs;
139913 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
@@ -139929,11 +140207,11 @@
139929 case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
139930 {
139931 #if SELECTTRACE_ENABLED
139932 Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/
139933 #endif
139934 yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy354.pLimit,yymsp[0].minor.yy354.pOffset);
139935 #if SELECTTRACE_ENABLED
139936 /* Populate the Select.zSelName[] string that is used to help with
139937 ** query planner debugging, to differentiate between multiple Select
139938 ** objects in a complex query.
139939 **
@@ -139958,17 +140236,17 @@
139958 #endif /* SELECTRACE_ENABLED */
139959 }
139960 break;
139961 case 85: /* values ::= VALUES LP nexprlist RP */
139962 {
139963 yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0,0);
139964 }
139965 break;
139966 case 86: /* values ::= values COMMA LP exprlist RP */
139967 {
139968 Select *pRight, *pLeft = yymsp[-4].minor.yy243;
139969 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
139970 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
139971 if( pRight ){
139972 pRight->op = TK_ALL;
139973 pRight->pPrior = pLeft;
139974 yymsp[-4].minor.yy243 = pRight;
@@ -140069,11 +140347,11 @@
140069 }
140070 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185);
140071 }else{
140072 Select *pSubquery;
140073 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy185);
140074 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0,0);
140075 yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140076 }
140077 }
140078 break;
140079 case 104: /* dbnm ::= */
@@ -140101,10 +140379,11 @@
140101 case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196);
140102 {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
140103 break;
140104 case 112: /* on_opt ::= */
140105 case 127: /* having_opt ::= */ yytestcase(yyruleno==127);
 
140106 case 134: /* where_opt ::= */ yytestcase(yyruleno==134);
140107 case 197: /* case_else ::= */ yytestcase(yyruleno==197);
140108 case 199: /* case_operand ::= */ yytestcase(yyruleno==199);
140109 {yymsp[1].minor.yy72 = 0;}
140110 break;
@@ -140144,35 +140423,32 @@
140144 {yymsp[0].minor.yy194 = SQLITE_SO_DESC;}
140145 break;
140146 case 124: /* sortorder ::= */
140147 {yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;}
140148 break;
140149 case 129: /* limit_opt ::= */
140150 {yymsp[1].minor.yy354.pLimit = 0; yymsp[1].minor.yy354.pOffset = 0;}
140151 break;
140152 case 130: /* limit_opt ::= LIMIT expr */
140153 {yymsp[-1].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr; yymsp[-1].minor.yy354.pOffset = 0;}
140154 break;
140155 case 131: /* limit_opt ::= LIMIT expr OFFSET expr */
140156 {yymsp[-3].minor.yy354.pLimit = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pOffset = yymsp[0].minor.yy190.pExpr;}
140157 break;
140158 case 132: /* limit_opt ::= LIMIT expr COMMA expr */
140159 {yymsp[-3].minor.yy354.pOffset = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr;}
140160 break;
140161 case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140162 {
140163 sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140164 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0);
140165 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0,0);
140166 }
140167 break;
140168 case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140169 {
140170 sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1);
140171 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0);
140172 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list");
140173 sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0,0);
140174 }
140175 break;
140176 case 137: /* setlist ::= setlist COMMA nm EQ expr */
140177 {
140178 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
@@ -140485,11 +140761,11 @@
140485 }
140486 break;
140487 case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */
140488 {
140489 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
140490 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
140491 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
140492 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140493 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
140494 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140495 yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
@@ -145232,10 +145508,11 @@
145232 }else if( flags & SQLITE_OPEN_FULLMUTEX ){
145233 isThreadsafe = 1;
145234 }else{
145235 isThreadsafe = sqlite3GlobalConfig.bFullMutex;
145236 }
 
145237 if( flags & SQLITE_OPEN_PRIVATECACHE ){
145238 flags &= ~SQLITE_OPEN_SHAREDCACHE;
145239 }else if( sqlite3GlobalConfig.sharedCacheEnabled ){
145240 flags |= SQLITE_OPEN_SHAREDCACHE;
145241 }
@@ -145264,17 +145541,24 @@
145264 );
145265
145266 /* Allocate the sqlite data structure */
145267 db = sqlite3MallocZero( sizeof(sqlite3) );
145268 if( db==0 ) goto opendb_out;
145269 if( isThreadsafe ){
 
 
 
 
145270 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
145271 if( db->mutex==0 ){
145272 sqlite3_free(db);
145273 db = 0;
145274 goto opendb_out;
145275 }
 
 
 
145276 }
145277 sqlite3_mutex_enter(db->mutex);
145278 db->errMask = 0xff;
145279 db->nDb = 2;
145280 db->magic = SQLITE_MAGIC_BUSY;
@@ -145754,41 +146038,41 @@
145754 ** to detect when version error conditions occurs.
145755 **
145756 ** 2. Invoke sqlite3_log() to provide the source code location where
145757 ** a low-level error is first detected.
145758 */
145759 static int reportError(int iErr, int lineno, const char *zType){
145760 sqlite3_log(iErr, "%s at line %d of [%.10s]",
145761 zType, lineno, 20+sqlite3_sourceid());
145762 return iErr;
145763 }
145764 SQLITE_PRIVATE int sqlite3CorruptError(int lineno){
145765 testcase( sqlite3GlobalConfig.xLog!=0 );
145766 return reportError(SQLITE_CORRUPT, lineno, "database corruption");
145767 }
145768 SQLITE_PRIVATE int sqlite3MisuseError(int lineno){
145769 testcase( sqlite3GlobalConfig.xLog!=0 );
145770 return reportError(SQLITE_MISUSE, lineno, "misuse");
145771 }
145772 SQLITE_PRIVATE int sqlite3CantopenError(int lineno){
145773 testcase( sqlite3GlobalConfig.xLog!=0 );
145774 return reportError(SQLITE_CANTOPEN, lineno, "cannot open file");
145775 }
145776 #ifdef SQLITE_DEBUG
145777 SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){
145778 char zMsg[100];
145779 sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno);
145780 testcase( sqlite3GlobalConfig.xLog!=0 );
145781 return reportError(SQLITE_CORRUPT, lineno, zMsg);
145782 }
145783 SQLITE_PRIVATE int sqlite3NomemError(int lineno){
145784 testcase( sqlite3GlobalConfig.xLog!=0 );
145785 return reportError(SQLITE_NOMEM, lineno, "OOM");
145786 }
145787 SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){
145788 testcase( sqlite3GlobalConfig.xLog!=0 );
145789 return reportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error");
145790 }
145791 #endif
145792
145793 #ifndef SQLITE_OMIT_DEPRECATED
145794 /*
@@ -186122,10 +186406,12 @@
186122 Fts5ExprPhrase *pPhrase,
186123 Fts5Token *pToken,
186124 int bPrefix
186125 );
186126
 
 
186127 static Fts5ExprNearset *sqlite3Fts5ParseNearset(
186128 Fts5Parse*,
186129 Fts5ExprNearset*,
186130 Fts5ExprPhrase*
186131 );
@@ -186202,13 +186488,14 @@
186202 #define FTS5_LCP 7
186203 #define FTS5_RCP 8
186204 #define FTS5_STRING 9
186205 #define FTS5_LP 10
186206 #define FTS5_RP 11
186207 #define FTS5_COMMA 12
186208 #define FTS5_PLUS 13
186209 #define FTS5_STAR 14
 
186210
186211 /*
186212 ** 2000-05-29
186213 **
186214 ** The author disclaims copyright to this source code. In place of
@@ -186319,39 +186606,39 @@
186319 #ifndef INTERFACE
186320 # define INTERFACE 1
186321 #endif
186322 /************* Begin control #defines *****************************************/
186323 #define fts5YYCODETYPE unsigned char
186324 #define fts5YYNOCODE 28
186325 #define fts5YYACTIONTYPE unsigned char
186326 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
186327 typedef union {
186328 int fts5yyinit;
186329 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
186330 int fts5yy4;
186331 Fts5Colset* fts5yy11;
186332 Fts5ExprNode* fts5yy24;
186333 Fts5ExprNearset* fts5yy46;
186334 Fts5ExprPhrase* fts5yy53;
186335 } fts5YYMINORTYPE;
186336 #ifndef fts5YYSTACKDEPTH
186337 #define fts5YYSTACKDEPTH 100
186338 #endif
186339 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
186340 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
186341 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
186342 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
186343 #define fts5YYNSTATE 33
186344 #define fts5YYNRULE 27
186345 #define fts5YY_MAX_SHIFT 32
186346 #define fts5YY_MIN_SHIFTREDUCE 50
186347 #define fts5YY_MAX_SHIFTREDUCE 76
186348 #define fts5YY_MIN_REDUCE 77
186349 #define fts5YY_MAX_REDUCE 103
186350 #define fts5YY_ERROR_ACTION 104
186351 #define fts5YY_ACCEPT_ACTION 105
186352 #define fts5YY_NO_ACTION 106
186353 /************* End control #defines *******************************************/
186354
186355 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
186356 ** otherwise.
186357 **
@@ -186419,58 +186706,60 @@
186419 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
186420 ** shifting non-terminals after a reduce.
186421 ** fts5yy_default[] Default action for each state.
186422 **
186423 *********** Begin parsing tables **********************************************/
186424 #define fts5YY_ACTTAB_COUNT (98)
186425 static const fts5YYACTIONTYPE fts5yy_action[] = {
186426 /* 0 */ 105, 19, 90, 6, 26, 93, 92, 24, 24, 17,
186427 /* 10 */ 90, 6, 26, 16, 92, 54, 24, 18, 90, 6,
186428 /* 20 */ 26, 10, 92, 12, 24, 75, 86, 90, 6, 26,
186429 /* 30 */ 13, 92, 75, 24, 20, 90, 6, 26, 101, 92,
186430 /* 40 */ 56, 24, 27, 90, 6, 26, 100, 92, 21, 24,
186431 /* 50 */ 23, 15, 30, 11, 1, 91, 22, 25, 9, 92,
186432 /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77,
186433 /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12,
186434 /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32,
186435 /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14,
 
186436 };
186437 static const fts5YYCODETYPE fts5yy_lookahead[] = {
186438 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
186439 /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,
186440 /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20,
186441 /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22,
186442 /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,
186443 /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22,
186444 /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0,
186445 /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9,
186446 /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25,
186447 /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9,
 
186448 };
186449 #define fts5YY_SHIFT_USE_DFLT (98)
186450 #define fts5YY_SHIFT_COUNT (32)
186451 #define fts5YY_SHIFT_MIN (0)
186452 #define fts5YY_SHIFT_MAX (90)
186453 static const unsigned char fts5yy_shift_ofst[] = {
186454 /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14,
186455 /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69,
186456 /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87,
186457 /* 30 */ 88, 39, 71,
186458 };
186459 #define fts5YY_REDUCE_USE_DFLT (-18)
186460 #define fts5YY_REDUCE_COUNT (16)
186461 #define fts5YY_REDUCE_MIN (-17)
186462 #define fts5YY_REDUCE_MAX (67)
186463 static const signed char fts5yy_reduce_ofst[] = {
186464 /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17,
186465 /* 10 */ 67, 12, 12, 12, 20, 27, 35,
186466 };
186467 static const fts5YYACTIONTYPE fts5yy_default[] = {
186468 /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104,
186469 /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104,
186470 /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104,
186471 /* 30 */ 104, 97, 104,
186472 };
186473 /********** End of lemon-generated parsing tables *****************************/
186474
186475 /* The next table maps tokens (terminal symbols) into fallback tokens.
186476 ** If a construct like the following:
@@ -186575,14 +186864,14 @@
186575 ** are required. The following table supplies these names */
186576 static const char *const fts5yyTokenName[] = {
186577 "$", "OR", "AND", "NOT",
186578 "TERM", "COLON", "MINUS", "LCP",
186579 "RCP", "STRING", "LP", "RP",
186580 "COMMA", "PLUS", "STAR", "error",
186581 "input", "expr", "cnearset", "exprlist",
186582 "colset", "colsetlist", "nearset", "nearphrases",
186583 "phrase", "neardist_opt", "star_opt",
186584 };
186585 #endif /* NDEBUG */
186586
186587 #ifndef NDEBUG
186588 /* For tracing reduce actions, the names of all rules are required.
@@ -186604,19 +186893,20 @@
186604 /* 13 */ "exprlist ::= cnearset",
186605 /* 14 */ "exprlist ::= exprlist cnearset",
186606 /* 15 */ "cnearset ::= nearset",
186607 /* 16 */ "cnearset ::= colset COLON nearset",
186608 /* 17 */ "nearset ::= phrase",
186609 /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
186610 /* 19 */ "nearphrases ::= phrase",
186611 /* 20 */ "nearphrases ::= nearphrases phrase",
186612 /* 21 */ "neardist_opt ::=",
186613 /* 22 */ "neardist_opt ::= COMMA STRING",
186614 /* 23 */ "phrase ::= phrase PLUS STRING star_opt",
186615 /* 24 */ "phrase ::= STRING star_opt",
186616 /* 25 */ "star_opt ::= STAR",
186617 /* 26 */ "star_opt ::=",
 
186618 };
186619 #endif /* NDEBUG */
186620
186621
186622 #if fts5YYSTACKDEPTH<=0
@@ -186733,37 +187023,37 @@
186733 ** Note: during a reduce, the only symbols destroyed are those
186734 ** which appear on the RHS of the rule, but which are *not* used
186735 ** inside the C code.
186736 */
186737 /********* Begin destructor definitions ***************************************/
186738 case 16: /* input */
186739 {
186740 (void)pParse;
186741 }
186742 break;
186743 case 17: /* expr */
186744 case 18: /* cnearset */
186745 case 19: /* exprlist */
186746 {
186747 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
186748 }
186749 break;
186750 case 20: /* colset */
186751 case 21: /* colsetlist */
186752 {
186753 sqlite3_free((fts5yypminor->fts5yy11));
186754 }
186755 break;
186756 case 22: /* nearset */
186757 case 23: /* nearphrases */
186758 {
186759 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
186760 }
186761 break;
186762 case 24: /* phrase */
186763 {
186764 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
186765 }
186766 break;
186767 /********* End destructor definitions *****************************************/
186768 default: break; /* If no destructor action specified: do nothing */
186769 }
@@ -187013,37 +187303,38 @@
187013 */
187014 static const struct {
187015 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
187016 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
187017 } fts5yyRuleInfo[] = {
187018 { 16, -1 },
187019 { 20, -4 },
187020 { 20, -3 },
 
 
 
 
 
 
 
 
 
 
187021 { 20, -1 },
187022 { 20, -2 },
187023 { 21, -2 },
187024 { 21, -1 },
187025 { 17, -3 },
187026 { 17, -3 },
187027 { 17, -3 },
187028 { 17, -5 },
187029 { 17, -3 },
187030 { 17, -1 },
187031 { 19, -1 },
187032 { 19, -2 },
187033 { 18, -1 },
187034 { 18, -3 },
187035 { 22, -1 },
187036 { 22, -5 },
187037 { 23, -1 },
187038 { 23, -2 },
187039 { 25, 0 },
187040 { 25, -2 },
187041 { 24, -4 },
187042 { 24, -2 },
187043 { 26, -1 },
187044 { 26, 0 },
 
 
 
 
 
187045 };
187046
187047 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
187048
187049 /*
@@ -187104,141 +187395,147 @@
187104 ** break;
187105 */
187106 /********** Begin reduce actions **********************************************/
187107 fts5YYMINORTYPE fts5yylhsminor;
187108 case 0: /* input ::= expr */
187109 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
187110 break;
187111 case 1: /* colset ::= MINUS LCP colsetlist RCP */
187112 {
187113 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
187114 }
187115 break;
187116 case 2: /* colset ::= LCP colsetlist RCP */
187117 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
187118 break;
187119 case 3: /* colset ::= STRING */
187120 {
187121 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187122 }
187123 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187124 break;
187125 case 4: /* colset ::= MINUS STRING */
187126 {
187127 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187128 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
187129 }
187130 break;
187131 case 5: /* colsetlist ::= colsetlist STRING */
187132 {
187133 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
187134 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187135 break;
187136 case 6: /* colsetlist ::= STRING */
187137 {
187138 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187139 }
187140 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187141 break;
187142 case 7: /* expr ::= expr AND expr */
187143 {
187144 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
187145 }
187146 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187147 break;
187148 case 8: /* expr ::= expr OR expr */
187149 {
187150 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
187151 }
187152 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187153 break;
187154 case 9: /* expr ::= expr NOT expr */
187155 {
187156 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
187157 }
187158 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187159 break;
187160 case 10: /* expr ::= colset COLON LP expr RP */
187161 {
187162 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
187163 fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
187164 }
187165 fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187166 break;
187167 case 11: /* expr ::= LP expr RP */
187168 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
187169 break;
187170 case 12: /* expr ::= exprlist */
187171 case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
187172 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
187173 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187174 break;
187175 case 14: /* exprlist ::= exprlist cnearset */
187176 {
187177 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
187178 }
187179 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187180 break;
187181 case 15: /* cnearset ::= nearset */
187182 {
187183 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
187184 }
187185 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187186 break;
187187 case 16: /* cnearset ::= colset COLON nearset */
187188 {
187189 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
187190 sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
187191 }
187192 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
187193 break;
187194 case 17: /* nearset ::= phrase */
187195 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
187196 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
 
 
 
 
 
 
187197 break;
187198 case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
187199 {
187200 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
187201 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
187202 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
187203 }
187204 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187205 break;
187206 case 19: /* nearphrases ::= phrase */
187207 {
187208 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
187209 }
187210 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187211 break;
187212 case 20: /* nearphrases ::= nearphrases phrase */
187213 {
187214 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
187215 }
187216 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
187217 break;
187218 case 21: /* neardist_opt ::= */
187219 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
187220 break;
187221 case 22: /* neardist_opt ::= COMMA STRING */
187222 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
187223 break;
187224 case 23: /* phrase ::= phrase PLUS STRING star_opt */
187225 {
187226 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187227 }
187228 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
187229 break;
187230 case 24: /* phrase ::= STRING star_opt */
187231 {
187232 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187233 }
187234 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
187235 break;
187236 case 25: /* star_opt ::= STAR */
187237 { fts5yymsp[0].minor.fts5yy4 = 1; }
187238 break;
187239 case 26: /* star_opt ::= */
187240 { fts5yymsp[1].minor.fts5yy4 = 0; }
187241 break;
187242 default:
187243 break;
187244 /********** End reduce actions ************************************************/
@@ -189657,11 +189954,12 @@
189657 /*
189658 ** An instance of the following structure represents a single search term
189659 ** or term prefix.
189660 */
189661 struct Fts5ExprTerm {
189662 int bPrefix; /* True for a prefix term */
 
189663 char *zTerm; /* nul-terminated term */
189664 Fts5IndexIter *pIter; /* Iterator for this term */
189665 Fts5ExprTerm *pSynonym; /* Pointer to first in list of synonyms */
189666 };
189667
@@ -189738,10 +190036,11 @@
189738 case ':': tok = FTS5_COLON; break;
189739 case ',': tok = FTS5_COMMA; break;
189740 case '+': tok = FTS5_PLUS; break;
189741 case '*': tok = FTS5_STAR; break;
189742 case '-': tok = FTS5_MINUS; break;
 
189743 case '\0': tok = FTS5_EOF; break;
189744
189745 case '"': {
189746 const char *z2;
189747 tok = FTS5_STRING;
@@ -189997,10 +190296,11 @@
189997 Fts5PoslistWriter writer = {0};
189998 Fts5PoslistReader aStatic[4];
189999 Fts5PoslistReader *aIter = aStatic;
190000 int i;
190001 int rc = SQLITE_OK;
 
190002
190003 fts5BufferZero(&pPhrase->poslist);
190004
190005 /* If the aStatic[] array is not large enough, allocate a large array
190006 ** using sqlite3_malloc(). This approach could be improved upon. */
@@ -190051,12 +190351,14 @@
190051 }
190052 }
190053 }while( bMatch==0 );
190054
190055 /* Append position iPos to the output */
190056 rc = sqlite3Fts5PoslistWriterAppend(&pPhrase->poslist, &writer, iPos);
190057 if( rc!=SQLITE_OK ) goto ismatch_out;
 
 
190058
190059 for(i=0; i<pPhrase->nTerm; i++){
190060 if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) goto ismatch_out;
190061 }
190062 }
@@ -190306,11 +190608,13 @@
190306 /* Check that each phrase in the nearset matches the current row.
190307 ** Populate the pPhrase->poslist buffers at the same time. If any
190308 ** phrase is not a match, break out of the loop early. */
190309 for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
190310 Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
190311 if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym || pNear->pColset ){
 
 
190312 int bMatch = 0;
190313 rc = fts5ExprPhraseIsMatch(pNode, pPhrase, &bMatch);
190314 if( bMatch==0 ) break;
190315 }else{
190316 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
@@ -190487,10 +190791,11 @@
190487
190488 /* Check that this node should not be FTS5_TERM */
190489 assert( pNear->nPhrase>1
190490 || pNear->apPhrase[0]->nTerm>1
190491 || pNear->apPhrase[0]->aTerm[0].pSynonym
 
190492 );
190493
190494 /* Initialize iLast, the "lastest" rowid any iterator points to. If the
190495 ** iterator skips through rowids in the default ascending order, this means
190496 ** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
@@ -191010,10 +191315,20 @@
191010 }
191011 if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
191012 sqlite3_free(pPhrase);
191013 }
191014 }
 
 
 
 
 
 
 
 
 
 
191015
191016 /*
191017 ** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated
191018 ** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is
191019 ** appended to it and the results returned.
@@ -191289,10 +191604,11 @@
191289 0, 0);
191290 tflags = FTS5_TOKEN_COLOCATED;
191291 }
191292 if( rc==SQLITE_OK ){
191293 sCtx.pPhrase->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix;
 
191294 }
191295 }
191296 }else{
191297 /* This happens when parsing a token or quoted phrase that contains
191298 ** no token characters at all. (e.g ... MATCH '""'). */
@@ -191307,11 +191623,14 @@
191307 pNew->apExprPhrase[0] = sCtx.pPhrase;
191308 pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
191309 pNew->pRoot->pNear->nPhrase = 1;
191310 sCtx.pPhrase->pNode = pNew->pRoot;
191311
191312 if( pOrig->nTerm==1 && pOrig->aTerm[0].pSynonym==0 ){
 
 
 
191313 pNew->pRoot->eType = FTS5_TERM;
191314 pNew->pRoot->xNext = fts5ExprNodeNext_TERM;
191315 }else{
191316 pNew->pRoot->eType = FTS5_STRING;
191317 pNew->pRoot->xNext = fts5ExprNodeNext_STRING;
@@ -191581,10 +191900,11 @@
191581 switch( pNode->eType ){
191582 case FTS5_STRING: {
191583 Fts5ExprNearset *pNear = pNode->pNear;
191584 if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1
191585 && pNear->apPhrase[0]->aTerm[0].pSynonym==0
 
191586 ){
191587 pNode->eType = FTS5_TERM;
191588 pNode->xNext = fts5ExprNodeNext_TERM;
191589 }else{
191590 pNode->xNext = fts5ExprNodeNext_STRING;
@@ -191667,24 +191987,27 @@
191667 pRet->xNext = 0;
191668 pRet->eType = FTS5_EOF;
191669 }
191670 }
191671
191672 if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL
191673 && (pNear->nPhrase!=1 || pNear->apPhrase[0]->nTerm>1)
191674 ){
191675 assert( pParse->rc==SQLITE_OK );
191676 pParse->rc = SQLITE_ERROR;
191677 assert( pParse->zErr==0 );
191678 pParse->zErr = sqlite3_mprintf(
191679 "fts5: %s queries are not supported (detail!=full)",
191680 pNear->nPhrase==1 ? "phrase": "NEAR"
191681 );
191682 sqlite3_free(pRet);
191683 pRet = 0;
191684 }
191685
 
 
 
191686 }else{
191687 fts5ExprAddChildren(pRet, pLeft);
191688 fts5ExprAddChildren(pRet, pRight);
191689 }
191690 }
@@ -202049,11 +202372,11 @@
202049 int nArg, /* Number of args */
202050 sqlite3_value **apUnused /* Function arguments */
202051 ){
202052 assert( nArg==0 );
202053 UNUSED_PARAM2(nArg, apUnused);
202054 sqlite3_result_text(pCtx, "fts5: 2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3", -1, SQLITE_TRANSIENT);
202055 }
202056
202057 static int fts5Init(sqlite3 *db){
202058 static const sqlite3_module fts5Mod = {
202059 /* iVersion */ 2,
@@ -206317,12 +206640,12 @@
206317 }
206318 #endif /* SQLITE_CORE */
206319 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
206320
206321 /************** End of stmt.c ************************************************/
206322 #if __LINE__!=206322
206323 #undef SQLITE_SOURCE_ID
206324 #define SQLITE_SOURCE_ID "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b832alt2"
206325 #endif
206326 /* Return the source-id for this library */
206327 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
206328 /************************** End of sqlite3.c ******************************/
206329
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbcc71"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -16532,11 +16532,10 @@
16532 Expr *pHaving; /* The HAVING clause */
16533 ExprList *pOrderBy; /* The ORDER BY clause */
16534 Select *pPrior; /* Prior select in a compound select statement */
16535 Select *pNext; /* Next select to the left in a compound */
16536 Expr *pLimit; /* LIMIT expression. NULL means not used. */
 
16537 With *pWith; /* WITH clause attached to this select. Or NULL. */
16538 };
16539
16540 /*
16541 ** Allowed values for Select.selFlags. The "SF" prefix stands for
@@ -17215,10 +17214,11 @@
17214 ** the same name but without the _BKPT suffix. These macros invoke
17215 ** routines that report the line-number on which the error originated
17216 ** using sqlite3_log(). The routines also provide a convenient place
17217 ** to set a debugger breakpoint.
17218 */
17219 SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType);
17220 SQLITE_PRIVATE int sqlite3CorruptError(int);
17221 SQLITE_PRIVATE int sqlite3MisuseError(int);
17222 SQLITE_PRIVATE int sqlite3CantopenError(int);
17223 #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
17224 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
@@ -17372,10 +17372,16 @@
17372 SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*);
17373
17374 /* Access to mutexes used by sqlite3_status() */
17375 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
17376 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
17377
17378 #if defined(SQLITE_ENABLE_MULTITHREADED_CHECKS) && !defined(SQLITE_MUTEX_OMIT)
17379 SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex*);
17380 #else
17381 # define sqlite3MutexWarnOnContention(x)
17382 #endif
17383
17384 #ifndef SQLITE_OMIT_FLOATING_POINT
17385 SQLITE_PRIVATE int sqlite3IsNaN(double);
17386 #else
17387 # define sqlite3IsNaN(X) 0
@@ -17539,20 +17545,20 @@
17545 SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
17546 Expr*, int, int, u8);
17547 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
17548 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
17549 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
17550 Expr*,ExprList*,u32,Expr*);
17551 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
17552 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
17553 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
17554 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
17555 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
17556 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
17557 #endif
17558 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
17559 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*);
17560 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
17561 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
17562 SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
17563 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
17564 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
@@ -17672,11 +17678,11 @@
17678 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*);
17679 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*);
17680 SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
17681
17682 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
17683 SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int);
17684 #endif
17685
17686 #ifndef SQLITE_OMIT_TRIGGER
17687 SQLITE_PRIVATE void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
17688 Expr*,int, int);
@@ -23393,10 +23399,197 @@
23399 static SQLITE_WSD int mutexIsInit = 0;
23400 #endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */
23401
23402
23403 #ifndef SQLITE_MUTEX_OMIT
23404
23405 #ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
23406 /*
23407 ** This block (enclosed by SQLITE_ENABLE_MULTITHREADED_CHECKS) contains
23408 ** the implementation of a wrapper around the system default mutex
23409 ** implementation (sqlite3DefaultMutex()).
23410 **
23411 ** Most calls are passed directly through to the underlying default
23412 ** mutex implementation. Except, if a mutex is configured by calling
23413 ** sqlite3MutexWarnOnContention() on it, then if contention is ever
23414 ** encountered within xMutexEnter() a warning is emitted via sqlite3_log().
23415 **
23416 ** This type of mutex is used as the database handle mutex when testing
23417 ** apps that usually use SQLITE_CONFIG_MULTITHREAD mode.
23418 */
23419
23420 /*
23421 ** Type for all mutexes used when SQLITE_ENABLE_MULTITHREADED_CHECKS
23422 ** is defined. Variable CheckMutex.mutex is a pointer to the real mutex
23423 ** allocated by the system mutex implementation. Variable iType is usually set
23424 ** to the type of mutex requested - SQLITE_MUTEX_RECURSIVE, SQLITE_MUTEX_FAST
23425 ** or one of the static mutex identifiers. Or, if this is a recursive mutex
23426 ** that has been configured using sqlite3MutexWarnOnContention(), it is
23427 ** set to SQLITE_MUTEX_WARNONCONTENTION.
23428 */
23429 typedef struct CheckMutex CheckMutex;
23430 struct CheckMutex {
23431 int iType;
23432 sqlite3_mutex *mutex;
23433 };
23434
23435 #define SQLITE_MUTEX_WARNONCONTENTION (-1)
23436
23437 /*
23438 ** Pointer to real mutex methods object used by the CheckMutex
23439 ** implementation. Set by checkMutexInit().
23440 */
23441 static SQLITE_WSD const sqlite3_mutex_methods *pGlobalMutexMethods;
23442
23443 #ifdef SQLITE_DEBUG
23444 static int checkMutexHeld(sqlite3_mutex *p){
23445 return pGlobalMutexMethods->xMutexHeld(((CheckMutex*)p)->mutex);
23446 }
23447 static int checkMutexNotheld(sqlite3_mutex *p){
23448 return pGlobalMutexMethods->xMutexNotheld(((CheckMutex*)p)->mutex);
23449 }
23450 #endif
23451
23452 /*
23453 ** Initialize and deinitialize the mutex subsystem.
23454 */
23455 static int checkMutexInit(void){
23456 pGlobalMutexMethods = sqlite3DefaultMutex();
23457 return SQLITE_OK;
23458 }
23459 static int checkMutexEnd(void){
23460 pGlobalMutexMethods = 0;
23461 return SQLITE_OK;
23462 }
23463
23464 /*
23465 ** Allocate a mutex.
23466 */
23467 static sqlite3_mutex *checkMutexAlloc(int iType){
23468 static CheckMutex staticMutexes[] = {
23469 {2, 0}, {3, 0}, {4, 0}, {5, 0},
23470 {6, 0}, {7, 0}, {8, 0}, {9, 0},
23471 {10, 0}, {11, 0}, {12, 0}, {13, 0}
23472 };
23473 CheckMutex *p = 0;
23474
23475 assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 );
23476 if( iType<2 ){
23477 p = sqlite3MallocZero(sizeof(CheckMutex));
23478 if( p==0 ) return 0;
23479 p->iType = iType;
23480 }else{
23481 #ifdef SQLITE_ENABLE_API_ARMOR
23482 if( iType-2>=ArraySize(staticMutexes) ){
23483 (void)SQLITE_MISUSE_BKPT;
23484 return 0;
23485 }
23486 #endif
23487 p = &staticMutexes[iType-2];
23488 }
23489
23490 if( p->mutex==0 ){
23491 p->mutex = pGlobalMutexMethods->xMutexAlloc(iType);
23492 if( p->mutex==0 ){
23493 if( iType<2 ){
23494 sqlite3_free(p);
23495 }
23496 p = 0;
23497 }
23498 }
23499
23500 return (sqlite3_mutex*)p;
23501 }
23502
23503 /*
23504 ** Free a mutex.
23505 */
23506 static void checkMutexFree(sqlite3_mutex *p){
23507 assert( SQLITE_MUTEX_RECURSIVE<2 );
23508 assert( SQLITE_MUTEX_FAST<2 );
23509 assert( SQLITE_MUTEX_WARNONCONTENTION<2 );
23510
23511 #if SQLITE_ENABLE_API_ARMOR
23512 if( ((CheckMutex*)p)->iType<2 )
23513 #endif
23514 {
23515 CheckMutex *pCheck = (CheckMutex*)p;
23516 pGlobalMutexMethods->xMutexFree(pCheck->mutex);
23517 sqlite3_free(pCheck);
23518 }
23519 #ifdef SQLITE_ENABLE_API_ARMOR
23520 else{
23521 (void)SQLITE_MISUSE_BKPT;
23522 }
23523 #endif
23524 }
23525
23526 /*
23527 ** Enter the mutex.
23528 */
23529 static void checkMutexEnter(sqlite3_mutex *p){
23530 CheckMutex *pCheck = (CheckMutex*)p;
23531 if( pCheck->iType==SQLITE_MUTEX_WARNONCONTENTION ){
23532 if( SQLITE_OK==pGlobalMutexMethods->xMutexTry(pCheck->mutex) ){
23533 return;
23534 }
23535 sqlite3_log(SQLITE_MISUSE,
23536 "illegal multi-threaded access to database connection"
23537 );
23538 }
23539 pGlobalMutexMethods->xMutexEnter(pCheck->mutex);
23540 }
23541
23542 /*
23543 ** Enter the mutex (do not block).
23544 */
23545 static int checkMutexTry(sqlite3_mutex *p){
23546 CheckMutex *pCheck = (CheckMutex*)p;
23547 return pGlobalMutexMethods->xMutexTry(pCheck->mutex);
23548 }
23549
23550 /*
23551 ** Leave the mutex.
23552 */
23553 static void checkMutexLeave(sqlite3_mutex *p){
23554 CheckMutex *pCheck = (CheckMutex*)p;
23555 pGlobalMutexMethods->xMutexLeave(pCheck->mutex);
23556 }
23557
23558 sqlite3_mutex_methods const *multiThreadedCheckMutex(void){
23559 static const sqlite3_mutex_methods sMutex = {
23560 checkMutexInit,
23561 checkMutexEnd,
23562 checkMutexAlloc,
23563 checkMutexFree,
23564 checkMutexEnter,
23565 checkMutexTry,
23566 checkMutexLeave,
23567 #ifdef SQLITE_DEBUG
23568 checkMutexHeld,
23569 checkMutexNotheld
23570 #else
23571 0,
23572 0
23573 #endif
23574 };
23575 return &sMutex;
23576 }
23577
23578 /*
23579 ** Mark the SQLITE_MUTEX_RECURSIVE mutex passed as the only argument as
23580 ** one on which there should be no contention.
23581 */
23582 SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex *p){
23583 if( sqlite3GlobalConfig.mutex.xMutexAlloc==checkMutexAlloc ){
23584 CheckMutex *pCheck = (CheckMutex*)p;
23585 assert( pCheck->iType==SQLITE_MUTEX_RECURSIVE );
23586 pCheck->iType = SQLITE_MUTEX_WARNONCONTENTION;
23587 }
23588 }
23589 #endif /* ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS */
23590
23591 /*
23592 ** Initialize the mutex system.
23593 */
23594 SQLITE_PRIVATE int sqlite3MutexInit(void){
23595 int rc = SQLITE_OK;
@@ -23408,11 +23601,15 @@
23601 */
23602 sqlite3_mutex_methods const *pFrom;
23603 sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
23604
23605 if( sqlite3GlobalConfig.bCoreMutex ){
23606 #ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
23607 pFrom = multiThreadedCheckMutex();
23608 #else
23609 pFrom = sqlite3DefaultMutex();
23610 #endif
23611 }else{
23612 pFrom = sqlite3NoopMutex();
23613 }
23614 pTo->xMutexInit = pFrom->xMutexInit;
23615 pTo->xMutexEnd = pFrom->xMutexEnd;
@@ -23534,10 +23731,11 @@
23731 return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
23732 }
23733 #endif
23734
23735 #endif /* !defined(SQLITE_MUTEX_OMIT) */
23736
23737
23738 /************** End of mutex.c ***********************************************/
23739 /************** Begin file mutex_noop.c **************************************/
23740 /*
23741 ** 2008 October 07
@@ -26817,11 +27015,10 @@
27015 if( p->pWhere ) n++;
27016 if( p->pGroupBy ) n++;
27017 if( p->pHaving ) n++;
27018 if( p->pOrderBy ) n++;
27019 if( p->pLimit ) n++;
 
27020 }
27021 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
27022 if( p->pSrc && p->pSrc->nSrc ){
27023 int i;
27024 pView = sqlite3TreeViewPush(pView, (n--)>0);
@@ -26874,16 +27071,16 @@
27071 if( p->pOrderBy ){
27072 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
27073 }
27074 if( p->pLimit ){
27075 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
27076 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0);
27077 if( p->pLimit->pRight ){
27078 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
27079 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
27080 sqlite3TreeViewPop(pView);
27081 }
27082 sqlite3TreeViewPop(pView);
27083 }
27084 if( p->pPrior ){
27085 const char *zOp = "UNION";
27086 switch( p->op ){
@@ -57728,12 +57925,11 @@
57925 assert( pWal->nWiData>0 );
57926 assert( pWal->apWiData[0]!=0 );
57927 pInfo = walCkptInfo(pWal);
57928 if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
57929 #ifdef SQLITE_ENABLE_SNAPSHOT
57930 && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
 
57931 #endif
57932 ){
57933 /* The WAL has been completely backfilled (or it is empty).
57934 ** and can be safely ignored.
57935 */
@@ -60149,10 +60345,35 @@
60345 #define downgradeAllSharedCacheTableLocks(a)
60346 #define hasSharedCacheTableLock(a,b,c,d) 1
60347 #define hasReadConflicts(a, b) 0
60348 #endif
60349
60350 /*
60351 ** Implementation of the SQLITE_CORRUPT_PAGE() macro. Takes a single
60352 ** (MemPage*) as an argument. The (MemPage*) must not be NULL.
60353 **
60354 ** If SQLITE_DEBUG is not defined, then this macro is equivalent to
60355 ** SQLITE_CORRUPT_BKPT. Or, if SQLITE_DEBUG is set, then the log message
60356 ** normally produced as a side-effect of SQLITE_CORRUPT_BKPT is augmented
60357 ** with the page number and filename associated with the (MemPage*).
60358 */
60359 #ifdef SQLITE_DEBUG
60360 int corruptPageError(int lineno, MemPage *p){
60361 char *zMsg = sqlite3_mprintf("database corruption page %d of %s",
60362 (int)p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0)
60363 );
60364 if( zMsg ){
60365 sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg);
60366 }
60367 sqlite3_free(zMsg);
60368 return SQLITE_CORRUPT_BKPT;
60369 }
60370 # define SQLITE_CORRUPT_PAGE(pMemPage) corruptPageError(__LINE__, pMemPage)
60371 #else
60372 # define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno)
60373 #endif
60374
60375 #ifndef SQLITE_OMIT_SHARED_CACHE
60376
60377 #ifdef SQLITE_DEBUG
60378 /*
60379 **** This function is only used as part of an assert() statement. ***
@@ -61437,11 +61658,11 @@
61658 u8 *pAddr;
61659 int sz2 = 0;
61660 int sz = get2byte(&data[iFree+2]);
61661 int top = get2byte(&data[hdr+5]);
61662 if( top>=iFree ){
61663 return SQLITE_CORRUPT_PAGE(pPage);
61664 }
61665 if( iFree2 ){
61666 assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */
61667 sz2 = get2byte(&data[iFree2+2]);
61668 assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
@@ -61471,17 +61692,17 @@
61692 testcase( pc==iCellLast );
61693 /* These conditions have already been verified in btreeInitPage()
61694 ** if PRAGMA cell_size_check=ON.
61695 */
61696 if( pc<iCellFirst || pc>iCellLast ){
61697 return SQLITE_CORRUPT_PAGE(pPage);
61698 }
61699 assert( pc>=iCellFirst && pc<=iCellLast );
61700 size = pPage->xCellSize(pPage, &src[pc]);
61701 cbrk -= size;
61702 if( cbrk<iCellFirst || pc+size>usableSize ){
61703 return SQLITE_CORRUPT_PAGE(pPage);
61704 }
61705 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
61706 testcase( cbrk+size==usableSize );
61707 testcase( pc+size==usableSize );
61708 put2byte(pAddr, cbrk);
@@ -61497,11 +61718,11 @@
61718 }
61719 data[hdr+7] = 0;
61720
61721 defragment_out:
61722 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
61723 return SQLITE_CORRUPT_PAGE(pPage);
61724 }
61725 assert( cbrk>=iCellFirst );
61726 put2byte(&data[hdr+5], cbrk);
61727 data[hdr+1] = 0;
61728 data[hdr+2] = 0;
@@ -61541,11 +61762,11 @@
61762 size = get2byte(&aData[pc+2]);
61763 if( (x = size - nByte)>=0 ){
61764 testcase( x==4 );
61765 testcase( x==3 );
61766 if( size+pc > usableSize ){
61767 *pRc = SQLITE_CORRUPT_PAGE(pPg);
61768 return 0;
61769 }else if( x<4 ){
61770 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
61771 ** number of bytes in fragments may not exceed 60. */
61772 if( aData[hdr+7]>57 ) return 0;
@@ -61564,11 +61785,11 @@
61785 iAddr = pc;
61786 pc = get2byte(&aData[pc]);
61787 if( pc<iAddr+size ) break;
61788 }
61789 if( pc ){
61790 *pRc = SQLITE_CORRUPT_PAGE(pPg);
61791 }
61792
61793 return 0;
61794 }
61795
@@ -61612,11 +61833,11 @@
61833 assert( top<=(int)pPage->pBt->usableSize ); /* Prevent by getAndInitPage() */
61834 if( gap>top ){
61835 if( top==0 && pPage->pBt->usableSize==65536 ){
61836 top = 65536;
61837 }else{
61838 return SQLITE_CORRUPT_PAGE(pPage);
61839 }
61840 }
61841
61842 /* If there is enough space between gap and top for one more cell pointer
61843 ** array entry offset, and if the freelist is not empty, then search the
@@ -61702,16 +61923,16 @@
61923 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
61924 }else{
61925 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
61926 if( iFreeBlk<iPtr+4 ){
61927 if( iFreeBlk==0 ) break;
61928 return SQLITE_CORRUPT_PAGE(pPage);
61929 }
61930 iPtr = iFreeBlk;
61931 }
61932 if( iFreeBlk>pPage->pBt->usableSize-4 ){
61933 return SQLITE_CORRUPT_PAGE(pPage);
61934 }
61935 assert( iFreeBlk>iPtr || iFreeBlk==0 );
61936
61937 /* At this point:
61938 ** iFreeBlk: First freeblock after iStart, or zero if none
@@ -61719,14 +61940,14 @@
61940 **
61941 ** Check to see if iFreeBlk should be coalesced onto the end of iStart.
61942 */
61943 if( iFreeBlk && iEnd+3>=iFreeBlk ){
61944 nFrag = iFreeBlk - iEnd;
61945 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
61946 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
61947 if( iEnd > pPage->pBt->usableSize ){
61948 return SQLITE_CORRUPT_PAGE(pPage);
61949 }
61950 iSize = iEnd - iStart;
61951 iFreeBlk = get2byte(&data[iFreeBlk]);
61952 }
61953
@@ -61735,25 +61956,25 @@
61956 ** coalesced onto the end of iPtr.
61957 */
61958 if( iPtr>hdr+1 ){
61959 int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
61960 if( iPtrEnd+3>=iStart ){
61961 if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage);
61962 nFrag += iStart - iPtrEnd;
61963 iSize = iEnd - iPtr;
61964 iStart = iPtr;
61965 }
61966 }
61967 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
61968 data[hdr+7] -= nFrag;
61969 }
61970 x = get2byte(&data[hdr+5]);
61971 if( iStart<=x ){
61972 /* The new freeblock is at the beginning of the cell content area,
61973 ** so just extend the cell content area rather than create another
61974 ** freelist entry */
61975 if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
61976 put2byte(&data[hdr+1], iFreeBlk);
61977 put2byte(&data[hdr+5], iEnd);
61978 }else{
61979 /* Insert the new freeblock into the freelist */
61980 put2byte(&data[iPtr], iStart);
@@ -61822,11 +62043,11 @@
62043 pPage->maxLocal = pBt->maxLocal;
62044 pPage->minLocal = pBt->minLocal;
62045 }else{
62046 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
62047 ** an error. */
62048 return SQLITE_CORRUPT_PAGE(pPage);
62049 }
62050 pPage->max1bytePayload = pBt->max1bytePayload;
62051 return SQLITE_OK;
62052 }
62053
@@ -61863,11 +62084,11 @@
62084 hdr = pPage->hdrOffset;
62085 data = pPage->aData;
62086 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
62087 ** the b-tree page type. */
62088 if( decodeFlags(pPage, data[hdr]) ){
62089 return SQLITE_CORRUPT_PAGE(pPage);
62090 }
62091 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
62092 pPage->maskPage = (u16)(pBt->pageSize - 1);
62093 pPage->nOverflow = 0;
62094 usableSize = pBt->usableSize;
@@ -61882,11 +62103,11 @@
62103 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
62104 ** number of cells on the page. */
62105 pPage->nCell = get2byte(&data[hdr+3]);
62106 if( pPage->nCell>MX_CELL(pBt) ){
62107 /* To many cells for a single page. The page must be corrupt */
62108 return SQLITE_CORRUPT_PAGE(pPage);
62109 }
62110 testcase( pPage->nCell==MX_CELL(pBt) );
62111 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
62112 ** possible for a root page of a table that contains no rows) then the
62113 ** offset to the cell content area will equal the page size minus the
@@ -61910,16 +62131,16 @@
62131 for(i=0; i<pPage->nCell; i++){
62132 pc = get2byteAligned(&data[cellOffset+i*2]);
62133 testcase( pc==iCellFirst );
62134 testcase( pc==iCellLast );
62135 if( pc<iCellFirst || pc>iCellLast ){
62136 return SQLITE_CORRUPT_PAGE(pPage);
62137 }
62138 sz = pPage->xCellSize(pPage, &data[pc]);
62139 testcase( pc+sz==usableSize );
62140 if( pc+sz>usableSize ){
62141 return SQLITE_CORRUPT_PAGE(pPage);
62142 }
62143 }
62144 if( !pPage->leaf ) iCellLast++;
62145 }
62146
@@ -61933,30 +62154,30 @@
62154 u32 next, size;
62155 if( pc<iCellFirst ){
62156 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
62157 ** always be at least one cell before the first freeblock.
62158 */
62159 return SQLITE_CORRUPT_PAGE(pPage);
62160 }
62161 while( 1 ){
62162 if( pc>iCellLast ){
62163 /* Freeblock off the end of the page */
62164 return SQLITE_CORRUPT_PAGE(pPage);
62165 }
62166 next = get2byte(&data[pc]);
62167 size = get2byte(&data[pc+2]);
62168 nFree = nFree + size;
62169 if( next<=pc+size+3 ) break;
62170 pc = next;
62171 }
62172 if( next>0 ){
62173 /* Freeblock not in ascending order */
62174 return SQLITE_CORRUPT_PAGE(pPage);
62175 }
62176 if( pc+size>(unsigned int)usableSize ){
62177 /* Last freeblock extends past page end */
62178 return SQLITE_CORRUPT_PAGE(pPage);
62179 }
62180 }
62181
62182 /* At this point, nFree contains the sum of the offset to the start
62183 ** of the cell-content area plus the number of free bytes within
@@ -61964,11 +62185,11 @@
62185 ** of the page, then the page must be corrupted. This check also
62186 ** serves to verify that the offset to the start of the cell-content
62187 ** area, according to the page header, lies within the page.
62188 */
62189 if( nFree>usableSize ){
62190 return SQLITE_CORRUPT_PAGE(pPage);
62191 }
62192 pPage->nFree = (u16)(nFree - iCellFirst);
62193 pPage->isInit = 1;
62194 return SQLITE_OK;
62195 }
@@ -63495,11 +63716,11 @@
63716 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
63717 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
63718 if( eType==PTRMAP_OVERFLOW2 ){
63719 /* The pointer is always the first 4 bytes of the page in this case. */
63720 if( get4byte(pPage->aData)!=iFrom ){
63721 return SQLITE_CORRUPT_PAGE(pPage);
63722 }
63723 put4byte(pPage->aData, iTo);
63724 }else{
63725 int i;
63726 int nCell;
@@ -63514,11 +63735,11 @@
63735 if( eType==PTRMAP_OVERFLOW1 ){
63736 CellInfo info;
63737 pPage->xParseCell(pPage, pCell, &info);
63738 if( info.nLocal<info.nPayload ){
63739 if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
63740 return SQLITE_CORRUPT_PAGE(pPage);
63741 }
63742 if( iFrom==get4byte(pCell+info.nSize-4) ){
63743 put4byte(pCell+info.nSize-4, iTo);
63744 break;
63745 }
@@ -63532,11 +63753,11 @@
63753 }
63754
63755 if( i==nCell ){
63756 if( eType!=PTRMAP_BTREE ||
63757 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
63758 return SQLITE_CORRUPT_PAGE(pPage);
63759 }
63760 put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
63761 }
63762 }
63763 return SQLITE_OK;
@@ -64630,11 +64851,11 @@
64851 /* Trying to read or write past the end of the data is an error. The
64852 ** conditional above is really:
64853 ** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
64854 ** but is recast into its current form to avoid integer overflow problems
64855 */
64856 return SQLITE_CORRUPT_PAGE(pPage);
64857 }
64858
64859 /* Check if data must be read/written to/from the btree page itself. */
64860 if( offset<pCur->info.nLocal ){
64861 int a = amt;
@@ -64778,11 +64999,11 @@
64999 }
65000 }
65001
65002 if( rc==SQLITE_OK && amt>0 ){
65003 /* Overflow chain ends prematurely */
65004 return SQLITE_CORRUPT_PAGE(pPage);
65005 }
65006 return rc;
65007 }
65008
65009 /*
@@ -65056,11 +65277,11 @@
65277 ** if pCur->iPage>=0). But this is not so if the database is corrupted
65278 ** in such a way that page pRoot is linked into a second b-tree table
65279 ** (or the freelist). */
65280 assert( pRoot->intKey==1 || pRoot->intKey==0 );
65281 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
65282 return SQLITE_CORRUPT_PAGE(pCur->pPage);
65283 }
65284
65285 skip_init:
65286 pCur->ix = 0;
65287 pCur->info.nSize = 0;
@@ -65329,11 +65550,11 @@
65550 i64 nCellKey;
65551 pCell = findCellPastPtr(pPage, idx);
65552 if( pPage->intKeyLeaf ){
65553 while( 0x80 <= *(pCell++) ){
65554 if( pCell>=pPage->aDataEnd ){
65555 return SQLITE_CORRUPT_PAGE(pPage);
65556 }
65557 }
65558 }
65559 getVarint(pCell, (u64*)&nCellKey);
65560 if( nCellKey<intKey ){
@@ -65403,11 +65624,11 @@
65624 testcase( nCell<0 ); /* True if key size is 2^32 or more */
65625 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
65626 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
65627 testcase( nCell==2 ); /* Minimum legal index key size */
65628 if( nCell<2 ){
65629 rc = SQLITE_CORRUPT_PAGE(pPage);
65630 goto moveto_finish;
65631 }
65632 pCellKey = sqlite3Malloc( nCell+18 );
65633 if( pCellKey==0 ){
65634 rc = SQLITE_NOMEM_BKPT;
@@ -66206,11 +66427,11 @@
66427 if( pInfo->nLocal==pInfo->nPayload ){
66428 return SQLITE_OK; /* No overflow pages. Return without doing anything */
66429 }
66430 if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
66431 /* Cell extends past end of page */
66432 return SQLITE_CORRUPT_PAGE(pPage);
66433 }
66434 ovflPgno = get4byte(pCell + pInfo->nSize - 4);
66435 pBt = pPage->pBt;
66436 assert( pBt->usableSize > 4 );
66437 ovflPageSize = pBt->usableSize - 4;
@@ -72103,11 +72324,15 @@
72324 const char *zNeg = "";
72325 int rc = SQLITE_OK;
72326
72327 assert( pExpr!=0 );
72328 while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
72329 #if defined(SQLITE_ENABLE_STAT3_OR_STAT4)
72330 if( op==TK_REGISTER ) op = pExpr->op2;
72331 #else
72332 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
72333 #endif
72334
72335 /* Compressed expressions only appear when parsing the DEFAULT clause
72336 ** on a table column definition, and hence only when pCtx==0. This
72337 ** check ensures that an EP_TokenOnly expression is never passed down
72338 ** into valueFromFunction(). */
@@ -74813,10 +75038,11 @@
75038 needXcommit = 1;
75039 sqlite3BtreeEnter(pBt);
75040 pPager = sqlite3BtreePager(pBt);
75041 if( db->aDb[i].safety_level!=PAGER_SYNCHRONOUS_OFF
75042 && aMJNeeded[sqlite3PagerGetJournalMode(pPager)]
75043 && sqlite3PagerIsMemdb(pPager)==0
75044 ){
75045 assert( i!=1 );
75046 nTrans++;
75047 }
75048 rc = sqlite3PagerExclusiveLock(pPager);
@@ -90556,11 +90782,10 @@
90782 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
90783 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
90784 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
90785 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
90786 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
 
90787 return WRC_Continue;
90788 }
90789
90790 /*
90791 ** Walk the parse trees associated with all subqueries in the
@@ -91824,12 +92049,11 @@
92049 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
92050 ** are not allowed to refer to any names, so pass an empty NameContext.
92051 */
92052 memset(&sNC, 0, sizeof(sNC));
92053 sNC.pParse = pParse;
92054 if( sqlite3ResolveExprNames(&sNC, p->pLimit) ){
 
92055 return WRC_Abort;
92056 }
92057
92058 /* If the SF_Converted flags is set, then this Select object was
92059 ** was created by the convertCompoundSelectToSubquery() function.
@@ -92826,11 +93050,10 @@
93050 static void heightOfSelect(Select *p, int *pnHeight){
93051 if( p ){
93052 heightOfExpr(p->pWhere, pnHeight);
93053 heightOfExpr(p->pHaving, pnHeight);
93054 heightOfExpr(p->pLimit, pnHeight);
 
93055 heightOfExprList(p->pEList, pnHeight);
93056 heightOfExprList(p->pGroupBy, pnHeight);
93057 heightOfExprList(p->pOrderBy, pnHeight);
93058 heightOfSelect(p->pPrior, pnHeight);
93059 }
@@ -93625,11 +93848,10 @@
93848 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
93849 pNew->op = p->op;
93850 pNew->pNext = pNext;
93851 pNew->pPrior = 0;
93852 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
 
93853 pNew->iLimit = 0;
93854 pNew->iOffset = 0;
93855 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
93856 pNew->addrOpenEphm[0] = -1;
93857 pNew->addrOpenEphm[1] = -1;
@@ -94262,11 +94484,10 @@
94484 testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate );
94485 return 0; /* No DISTINCT keyword and no aggregate functions */
94486 }
94487 assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */
94488 if( p->pLimit ) return 0; /* Has no LIMIT clause */
 
94489 if( p->pWhere ) return 0; /* Has no WHERE clause */
94490 pSrc = p->pSrc;
94491 assert( pSrc!=0 );
94492 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
94493 if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
@@ -94352,20 +94573,19 @@
94573 ** If the RHS of the IN operator is a list or a more complex subquery, then
94574 ** an ephemeral table might need to be generated from the RHS and then
94575 ** pX->iTable made to point to the ephemeral table instead of an
94576 ** existing table.
94577 **
94578 ** The inFlags parameter must contain, at a minimum, one of the bits
94579 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
94580 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
94581 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
94582 ** be used to loop over all values of the RHS of the IN operator.
 
94583 **
94584 ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
94585 ** through the set members) then the b-tree must not contain duplicates.
94586 ** An epheremal table will be created unless the selected columns are guaranteed
94587 ** to be unique - either because it is an INTEGER PRIMARY KEY or due to
94588 ** a UNIQUE constraint or index.
94589 **
94590 ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
94591 ** for fast set membership tests) then an epheremal table must
@@ -94902,10 +95122,11 @@
95122 ** preexisting limit is discarded in place of the new LIMIT 1.
95123 */
95124 Select *pSel; /* SELECT statement to encode */
95125 SelectDest dest; /* How to deal with SELECT result */
95126 int nReg; /* Registers to allocate */
95127 Expr *pLimit; /* New limit expression */
95128
95129 testcase( pExpr->op==TK_EXISTS );
95130 testcase( pExpr->op==TK_SELECT );
95131 assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
95132 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
@@ -94923,13 +95144,17 @@
95144 }else{
95145 dest.eDest = SRT_Exists;
95146 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
95147 VdbeComment((v, "Init EXISTS result"));
95148 }
95149 pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
95150 if( pSel->pLimit ){
95151 sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
95152 pSel->pLimit->pLeft = pLimit;
95153 }else{
95154 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
95155 }
95156 pSel->iLimit = 0;
95157 pSel->selFlags &= ~SF_MultiValue;
95158 if( sqlite3Select(pParse, pSel, &dest) ){
95159 return 0;
95160 }
@@ -100713,13 +100938,10 @@
100938 return 1;
100939 }
100940 if( sqlite3FixExpr(pFix, pSelect->pLimit) ){
100941 return 1;
100942 }
 
 
 
100943 pSelect = pSelect->pPrior;
100944 }
100945 return 0;
100946 }
100947 SQLITE_PRIVATE int sqlite3FixExpr(
@@ -106085,11 +106307,10 @@
106307 Parse *pParse, /* Parsing context */
106308 Table *pView, /* View definition */
106309 Expr *pWhere, /* Optional WHERE clause to be added */
106310 ExprList *pOrderBy, /* Optional ORDER BY clause */
106311 Expr *pLimit, /* Optional LIMIT clause */
 
106312 int iCur /* Cursor number for ephemeral table */
106313 ){
106314 SelectDest dest;
106315 Select *pSel;
106316 SrcList *pFrom;
@@ -106103,11 +106324,11 @@
106324 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
106325 assert( pFrom->a[0].pOn==0 );
106326 assert( pFrom->a[0].pUsing==0 );
106327 }
106328 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
106329 SF_IncludeHidden, pLimit);
106330 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
106331 sqlite3Select(pParse, pSel, &dest);
106332 sqlite3SelectDelete(db, pSel);
106333 }
106334 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -106125,11 +106346,10 @@
106346 Parse *pParse, /* The parser context */
106347 SrcList *pSrc, /* the FROM clause -- which tables to scan */
106348 Expr *pWhere, /* The WHERE clause. May be null */
106349 ExprList *pOrderBy, /* The ORDER BY clause. May be null */
106350 Expr *pLimit, /* The LIMIT clause. May be null */
 
106351 char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
106352 ){
106353 sqlite3 *db = pParse->db;
106354 Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */
106355 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
@@ -106142,21 +106362,17 @@
106362 */
106363 if( pOrderBy && pLimit==0 ) {
106364 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
106365 sqlite3ExprDelete(pParse->db, pWhere);
106366 sqlite3ExprListDelete(pParse->db, pOrderBy);
 
 
106367 return 0;
106368 }
106369
106370 /* We only need to generate a select expression if there
106371 ** is a limit/offset term to enforce.
106372 */
106373 if( pLimit == 0 ) {
 
 
106374 return pWhere;
106375 }
106376
106377 /* Generate a select expression tree to enforce the limit/offset
106378 ** term for the DELETE or UPDATE statement. For example:
@@ -106199,11 +106415,11 @@
106415 pSrc->a[0].pTab = pTab;
106416 pSrc->a[0].pIBIndex = 0;
106417
106418 /* generate the SELECT expression tree. */
106419 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
106420 pOrderBy,0,pLimit
106421 );
106422
106423 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
106424 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
106425 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
@@ -106222,12 +106438,11 @@
106438 SQLITE_PRIVATE void sqlite3DeleteFrom(
106439 Parse *pParse, /* The parser context */
106440 SrcList *pTabList, /* The table from which we should delete things */
106441 Expr *pWhere, /* The WHERE clause. May be null */
106442 ExprList *pOrderBy, /* ORDER BY clause. May be null */
106443 Expr *pLimit /* LIMIT clause. May be null */
 
106444 ){
106445 Vdbe *v; /* The virtual database engine */
106446 Table *pTab; /* The table from which records will be deleted */
106447 int i; /* Loop counter */
106448 WhereInfo *pWInfo; /* Information about the WHERE clause */
@@ -106296,14 +106511,14 @@
106511 #endif
106512
106513 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
106514 if( !isView ){
106515 pWhere = sqlite3LimitWhere(
106516 pParse, pTabList, pWhere, pOrderBy, pLimit, "DELETE"
106517 );
106518 pOrderBy = 0;
106519 pLimit = 0;
106520 }
106521 #endif
106522
106523 /* If pTab is really a view, make sure it has been initialized.
106524 */
@@ -106351,15 +106566,15 @@
106566 ** an ephemeral table.
106567 */
106568 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
106569 if( isView ){
106570 sqlite3MaterializeView(pParse, pTab,
106571 pWhere, pOrderBy, pLimit, iTabCur
106572 );
106573 iDataCur = iIdxCur = iTabCur;
106574 pOrderBy = 0;
106575 pLimit = 0;
106576 }
106577 #endif
106578
106579 /* Resolve the column names in the WHERE clause.
106580 */
@@ -106602,11 +106817,10 @@
106817 sqlite3SrcListDelete(db, pTabList);
106818 sqlite3ExprDelete(db, pWhere);
106819 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
106820 sqlite3ExprListDelete(db, pOrderBy);
106821 sqlite3ExprDelete(db, pLimit);
 
106822 #endif
106823 sqlite3DbFree(db, aToOpen);
106824 return;
106825 }
106826 /* Make sure "isView" and other macros defined above are undefined. Otherwise
@@ -109568,11 +109782,11 @@
109782 iSkip = sqlite3VdbeMakeLabel(v);
109783 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
109784 }
109785
109786 pParse->disableTriggers = 1;
109787 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
109788 pParse->disableTriggers = 0;
109789
109790 /* If the DELETE has generated immediate foreign key constraint
109791 ** violations, halt the VDBE and return an error at this point, before
109792 ** any modifications to the schema are made. This is because statement
@@ -110126,11 +110340,11 @@
110340 }
110341 pSelect = sqlite3SelectNew(pParse,
110342 sqlite3ExprListAppend(pParse, 0, pRaise),
110343 sqlite3SrcListAppend(db, 0, &tFrom, 0),
110344 pWhere,
110345 0, 0, 0, 0, 0
110346 );
110347 pWhere = 0;
110348 }
110349
110350 /* Disable lookaside memory allocation */
@@ -112274,11 +112488,10 @@
112488 return 0; /* SELECT may not have a GROUP BY clause */
112489 }
112490 if( pSelect->pLimit ){
112491 return 0; /* SELECT may not have a LIMIT clause */
112492 }
 
112493 if( pSelect->pPrior ){
112494 return 0; /* SELECT may not be a compound query */
112495 }
112496 if( pSelect->selFlags & SF_Distinct ){
112497 return 0; /* SELECT may not be DISTINCT */
@@ -118173,11 +118386,10 @@
118386 sqlite3ExprDelete(db, p->pWhere);
118387 sqlite3ExprListDelete(db, p->pGroupBy);
118388 sqlite3ExprDelete(db, p->pHaving);
118389 sqlite3ExprListDelete(db, p->pOrderBy);
118390 sqlite3ExprDelete(db, p->pLimit);
 
118391 if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
118392 if( bFree ) sqlite3DbFreeNN(db, p);
118393 p = pPrior;
118394 bFree = 1;
118395 }
@@ -118206,12 +118418,11 @@
118418 Expr *pWhere, /* the WHERE clause */
118419 ExprList *pGroupBy, /* the GROUP BY clause */
118420 Expr *pHaving, /* the HAVING clause */
118421 ExprList *pOrderBy, /* the ORDER BY clause */
118422 u32 selFlags, /* Flag parameters, such as SF_Distinct */
118423 Expr *pLimit /* LIMIT value. NULL means not used */
 
118424 ){
118425 Select *pNew;
118426 Select standin;
118427 pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
118428 if( pNew==0 ){
@@ -118240,14 +118451,11 @@
118451 pNew->pHaving = pHaving;
118452 pNew->pOrderBy = pOrderBy;
118453 pNew->pPrior = 0;
118454 pNew->pNext = 0;
118455 pNew->pLimit = pLimit;
 
118456 pNew->pWith = 0;
 
 
118457 if( pParse->db->mallocFailed ) {
118458 clearSelect(pParse->db, pNew, pNew!=&standin);
118459 pNew = 0;
118460 }else{
118461 assert( pNew->pSrc!=0 || pParse->nErr>0 );
@@ -119973,69 +120181,72 @@
120181 }
120182
120183
120184 /*
120185 ** Compute the iLimit and iOffset fields of the SELECT based on the
120186 ** pLimit expressions. pLimit->pLeft and pLimit->pRight hold the expressions
120187 ** that appear in the original SQL statement after the LIMIT and OFFSET
120188 ** keywords. Or NULL if those keywords are omitted. iLimit and iOffset
120189 ** are the integer memory register numbers for counters used to compute
120190 ** the limit and offset. If there is no limit and/or offset, then
120191 ** iLimit and iOffset are negative.
120192 **
120193 ** This routine changes the values of iLimit and iOffset only if
120194 ** a limit or offset is defined by pLimit->pLeft and pLimit->pRight. iLimit
120195 ** and iOffset should have been preset to appropriate default values (zero)
120196 ** prior to calling this routine.
120197 **
120198 ** The iOffset register (if it exists) is initialized to the value
120199 ** of the OFFSET. The iLimit register is initialized to LIMIT. Register
120200 ** iOffset+1 is initialized to LIMIT+OFFSET.
120201 **
120202 ** Only if pLimit->pLeft!=0 do the limit registers get
120203 ** redefined. The UNION ALL operator uses this property to force
120204 ** the reuse of the same limit and offset registers across multiple
120205 ** SELECT statements.
120206 */
120207 static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
120208 Vdbe *v = 0;
120209 int iLimit = 0;
120210 int iOffset;
120211 int n;
120212 Expr *pLimit = p->pLimit;
120213
120214 if( p->iLimit ) return;
120215
120216 /*
120217 ** "LIMIT -1" always shows all rows. There is some
120218 ** controversy about what the correct behavior should be.
120219 ** The current implementation interprets "LIMIT 0" to mean
120220 ** no rows.
120221 */
120222 sqlite3ExprCacheClear(pParse);
120223 if( pLimit ){
120224 assert( pLimit->op==TK_LIMIT );
120225 assert( pLimit->pLeft!=0 );
120226 p->iLimit = iLimit = ++pParse->nMem;
120227 v = sqlite3GetVdbe(pParse);
120228 assert( v!=0 );
120229 if( sqlite3ExprIsInteger(pLimit->pLeft, &n) ){
120230 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
120231 VdbeComment((v, "LIMIT counter"));
120232 if( n==0 ){
120233 sqlite3VdbeGoto(v, iBreak);
120234 }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){
120235 p->nSelectRow = sqlite3LogEst((u64)n);
120236 p->selFlags |= SF_FixedLimit;
120237 }
120238 }else{
120239 sqlite3ExprCode(pParse, pLimit->pLeft, iLimit);
120240 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
120241 VdbeComment((v, "LIMIT counter"));
120242 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
120243 }
120244 if( pLimit->pRight ){
120245 p->iOffset = iOffset = ++pParse->nMem;
120246 pParse->nMem++; /* Allocate an extra register for limit+offset */
120247 sqlite3ExprCode(pParse, pLimit->pRight, iOffset);
120248 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
120249 VdbeComment((v, "OFFSET counter"));
120250 sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset);
120251 VdbeComment((v, "LIMIT+OFFSET"));
120252 }
@@ -120161,11 +120372,11 @@
120372 int eDest = SRT_Fifo; /* How to write to Queue */
120373 SelectDest destQueue; /* SelectDest targetting the Queue table */
120374 int i; /* Loop counter */
120375 int rc; /* Result code */
120376 ExprList *pOrderBy; /* The ORDER BY clause */
120377 Expr *pLimit; /* Saved LIMIT and OFFSET */
120378 int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
120379
120380 /* Obtain authorization to do a recursive query */
120381 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
120382
@@ -120172,14 +120383,13 @@
120383 /* Process the LIMIT and OFFSET clauses, if they exist */
120384 addrBreak = sqlite3VdbeMakeLabel(v);
120385 p->nSelectRow = 320; /* 4 billion rows */
120386 computeLimitRegisters(pParse, p, addrBreak);
120387 pLimit = p->pLimit;
 
120388 regLimit = p->iLimit;
120389 regOffset = p->iOffset;
120390 p->pLimit = 0;
120391 p->iLimit = p->iOffset = 0;
120392 pOrderBy = p->pOrderBy;
120393
120394 /* Locate the cursor number of the Current table */
120395 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
@@ -120268,11 +120478,10 @@
120478
120479 end_of_recursive_query:
120480 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
120481 p->pOrderBy = pOrderBy;
120482 p->pLimit = pLimit;
 
120483 return;
120484 }
120485 #endif /* SQLITE_OMIT_CTE */
120486
120487 /* Forward references */
@@ -120304,11 +120513,10 @@
120513 assert( p->selFlags & SF_MultiValue );
120514 do{
120515 assert( p->selFlags & SF_Values );
120516 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
120517 assert( p->pLimit==0 );
 
120518 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
120519 if( p->pPrior==0 ) break;
120520 assert( p->pPrior->pNext==p );
120521 p = p->pPrior;
120522 nRow++;
@@ -120431,15 +120639,13 @@
120639 int nLimit;
120640 assert( !pPrior->pLimit );
120641 pPrior->iLimit = p->iLimit;
120642 pPrior->iOffset = p->iOffset;
120643 pPrior->pLimit = p->pLimit;
 
120644 explainSetInteger(iSub1, pParse->iNextSelectId);
120645 rc = sqlite3Select(pParse, pPrior, &dest);
120646 p->pLimit = 0;
 
120647 if( rc ){
120648 goto multi_select_end;
120649 }
120650 p->pPrior = 0;
120651 p->iLimit = pPrior->iLimit;
@@ -120457,11 +120663,11 @@
120663 testcase( rc!=SQLITE_OK );
120664 pDelete = p->pPrior;
120665 p->pPrior = pPrior;
120666 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
120667 if( pPrior->pLimit
120668 && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit)
120669 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
120670 ){
120671 p->nSelectRow = sqlite3LogEst((u64)nLimit);
120672 }
120673 if( addr ){
@@ -120472,11 +120678,11 @@
120678 case TK_EXCEPT:
120679 case TK_UNION: {
120680 int unionTab; /* Cursor number of the temporary table holding result */
120681 u8 op = 0; /* One of the SRT_ operations to apply to self */
120682 int priorOp; /* The SRT_ operation to apply to prior selects */
120683 Expr *pLimit; /* Saved values of p->nLimit */
120684 int addr;
120685 SelectDest uniondest;
120686
120687 testcase( p->op==TK_EXCEPT );
120688 testcase( p->op==TK_UNION );
@@ -120484,11 +120690,10 @@
120690 if( dest.eDest==priorOp ){
120691 /* We can reuse a temporary table generated by a SELECT to our
120692 ** right.
120693 */
120694 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
 
120695 unionTab = dest.iSDParm;
120696 }else{
120697 /* We will need to create our own temporary table to hold the
120698 ** intermediate results.
120699 */
@@ -120520,12 +120725,10 @@
120725 op = SRT_Union;
120726 }
120727 p->pPrior = 0;
120728 pLimit = p->pLimit;
120729 p->pLimit = 0;
 
 
120730 uniondest.eDest = op;
120731 explainSetInteger(iSub2, pParse->iNextSelectId);
120732 rc = sqlite3Select(pParse, p, &uniondest);
120733 testcase( rc!=SQLITE_OK );
120734 /* Query flattening in sqlite3Select() might refill p->pOrderBy.
@@ -120537,11 +120740,10 @@
120740 if( p->op==TK_UNION ){
120741 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
120742 }
120743 sqlite3ExprDelete(db, p->pLimit);
120744 p->pLimit = pLimit;
 
120745 p->iLimit = 0;
120746 p->iOffset = 0;
120747
120748 /* Convert the data in the temporary table into whatever form
120749 ** it is that we currently need.
@@ -120565,11 +120767,11 @@
120767 break;
120768 }
120769 default: assert( p->op==TK_INTERSECT ); {
120770 int tab1, tab2;
120771 int iCont, iBreak, iStart;
120772 Expr *pLimit;
120773 int addr;
120774 SelectDest intersectdest;
120775 int r1;
120776
120777 /* INTERSECT is different from the others since it requires
@@ -120601,22 +120803,19 @@
120803 assert( p->addrOpenEphm[1] == -1 );
120804 p->addrOpenEphm[1] = addr;
120805 p->pPrior = 0;
120806 pLimit = p->pLimit;
120807 p->pLimit = 0;
 
 
120808 intersectdest.iSDParm = tab2;
120809 explainSetInteger(iSub2, pParse->iNextSelectId);
120810 rc = sqlite3Select(pParse, p, &intersectdest);
120811 testcase( rc!=SQLITE_OK );
120812 pDelete = p->pPrior;
120813 p->pPrior = pPrior;
120814 if( p->nSelectRow>pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
120815 sqlite3ExprDelete(db, p->pLimit);
120816 p->pLimit = pLimit;
 
120817
120818 /* Generate code to take the intersection of the two temporary
120819 ** tables.
120820 */
120821 assert( p->pEList );
@@ -121091,12 +121290,10 @@
121290 }else{
121291 regLimitA = regLimitB = 0;
121292 }
121293 sqlite3ExprDelete(db, p->pLimit);
121294 p->pLimit = 0;
 
 
121295
121296 regAddrA = ++pParse->nMem;
121297 regAddrB = ++pParse->nMem;
121298 regOutA = ++pParse->nMem;
121299 regOutB = ++pParse->nMem;
@@ -121556,11 +121753,11 @@
121753 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
121754 ** because they could be computed at compile-time. But when LIMIT and OFFSET
121755 ** became arbitrary expressions, we were forced to add restrictions (13)
121756 ** and (14). */
121757 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
121758 if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */
121759 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
121760 return 0; /* Restriction (15) */
121761 }
121762 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
121763 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */
@@ -121704,20 +121901,17 @@
121901 */
121902 for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){
121903 Select *pNew;
121904 ExprList *pOrderBy = p->pOrderBy;
121905 Expr *pLimit = p->pLimit;
 
121906 Select *pPrior = p->pPrior;
121907 p->pOrderBy = 0;
121908 p->pSrc = 0;
121909 p->pPrior = 0;
121910 p->pLimit = 0;
 
121911 pNew = sqlite3SelectDup(db, p, 0);
121912 sqlite3SelectSetName(pNew, pSub->zSelName);
 
121913 p->pLimit = pLimit;
121914 p->pOrderBy = pOrderBy;
121915 p->pSrc = pSrc;
121916 p->op = TK_ALL;
121917 if( pNew==0 ){
@@ -122179,11 +122373,10 @@
122373 assert( (p->selFlags & SF_Converted)==0 );
122374 p->selFlags |= SF_Converted;
122375 assert( pNew->pPrior!=0 );
122376 pNew->pPrior->pNext = pNew;
122377 pNew->pLimit = 0;
 
122378 return WRC_Continue;
122379 }
122380
122381 /*
122382 ** Check to see if the FROM clause term pFrom has table-valued function
@@ -125077,11 +125270,11 @@
125270 case TK_UPDATE: {
125271 sqlite3Update(pParse,
125272 targetSrcList(pParse, pStep),
125273 sqlite3ExprListDup(db, pStep->pExprList, 0),
125274 sqlite3ExprDup(db, pStep->pWhere, 0),
125275 pParse->eOrconf, 0, 0
125276 );
125277 break;
125278 }
125279 case TK_INSERT: {
125280 sqlite3Insert(pParse,
@@ -125093,11 +125286,11 @@
125286 break;
125287 }
125288 case TK_DELETE: {
125289 sqlite3DeleteFrom(pParse,
125290 targetSrcList(pParse, pStep),
125291 sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
125292 );
125293 break;
125294 }
125295 default: assert( pStep->op==TK_SELECT ); {
125296 SelectDest sDest;
@@ -125241,11 +125434,11 @@
125434 }
125435 sqlite3VdbeAddOp0(v, OP_Halt);
125436 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
125437
125438 transferParseError(pParse, pSubParse);
125439 if( db->mallocFailed==0 && pParse->nErr==0 ){
125440 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
125441 }
125442 pProgram->nMem = pSubParse->nMem;
125443 pProgram->nCsr = pSubParse->nTab;
125444 pProgram->token = (void *)pTrigger;
@@ -125562,12 +125755,11 @@
125755 SrcList *pTabList, /* The table in which we should change things */
125756 ExprList *pChanges, /* Things to be changed */
125757 Expr *pWhere, /* The WHERE clause. May be null */
125758 int onError, /* How to handle constraint errors */
125759 ExprList *pOrderBy, /* ORDER BY clause. May be null */
125760 Expr *pLimit /* LIMIT clause. May be null */
 
125761 ){
125762 int i, j; /* Loop counters */
125763 Table *pTab; /* The table to be updated */
125764 int addrTop = 0; /* VDBE instruction address of the start of the loop */
125765 WhereInfo *pWInfo; /* Information about the WHERE clause */
@@ -125651,14 +125843,14 @@
125843 #endif
125844
125845 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
125846 if( !isView ){
125847 pWhere = sqlite3LimitWhere(
125848 pParse, pTabList, pWhere, pOrderBy, pLimit, "UPDATE"
125849 );
125850 pOrderBy = 0;
125851 pLimit = 0;
125852 }
125853 #endif
125854
125855 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
125856 goto update_cleanup;
@@ -125827,14 +126019,14 @@
126019 ** an ephemeral table.
126020 */
126021 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
126022 if( isView ){
126023 sqlite3MaterializeView(pParse, pTab,
126024 pWhere, pOrderBy, pLimit, iDataCur
126025 );
126026 pOrderBy = 0;
126027 pLimit = 0;
126028 }
126029 #endif
126030
126031 /* Resolve the column names in all the expressions in the
126032 ** WHERE clause.
@@ -126217,11 +126409,10 @@
126409 sqlite3ExprListDelete(db, pChanges);
126410 sqlite3ExprDelete(db, pWhere);
126411 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
126412 sqlite3ExprListDelete(db, pOrderBy);
126413 sqlite3ExprDelete(db, pLimit);
 
126414 #endif
126415 return;
126416 }
126417 /* Make sure "isView" and other macros defined above are undefined. Otherwise
126418 ** they may interfere with compilation of other functions in this file
@@ -128931,10 +129122,106 @@
129122 ){
129123 zAff[i] = SQLITE_AFF_BLOB;
129124 }
129125 }
129126 }
129127
129128
129129 /*
129130 ** pX is an expression of the form: (vector) IN (SELECT ...)
129131 ** In other words, it is a vector IN operator with a SELECT clause on the
129132 ** LHS. But not all terms in the vector are indexable and the terms might
129133 ** not be in the correct order for indexing.
129134 **
129135 ** This routine makes a copy of the input pX expression and then adjusts
129136 ** the vector on the LHS with corresponding changes to the SELECT so that
129137 ** the vector contains only index terms and those terms are in the correct
129138 ** order. The modified IN expression is returned. The caller is responsible
129139 ** for deleting the returned expression.
129140 **
129141 ** Example:
129142 **
129143 ** CREATE TABLE t1(a,b,c,d,e,f);
129144 ** CREATE INDEX t1x1 ON t1(e,c);
129145 ** SELECT * FROM t1 WHERE (a,b,c,d,e) IN (SELECT v,w,x,y,z FROM t2)
129146 ** \_______________________________________/
129147 ** The pX expression
129148 **
129149 ** Since only columns e and c can be used with the index, in that order,
129150 ** the modified IN expression that is returned will be:
129151 **
129152 ** (e,c) IN (SELECT z,x FROM t2)
129153 **
129154 ** The reduced pX is different from the original (obviously) and thus is
129155 ** only used for indexing, to improve performance. The original unaltered
129156 ** IN expression must also be run on each output row for correctness.
129157 */
129158 static Expr *removeUnindexableInClauseTerms(
129159 Parse *pParse, /* The parsing context */
129160 int iEq, /* Look at loop terms starting here */
129161 WhereLoop *pLoop, /* The current loop */
129162 Expr *pX /* The IN expression to be reduced */
129163 ){
129164 sqlite3 *db = pParse->db;
129165 Expr *pNew = sqlite3ExprDup(db, pX, 0);
129166 if( db->mallocFailed==0 ){
129167 ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
129168 ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
129169 ExprList *pRhs = 0; /* New RHS after modifications */
129170 ExprList *pLhs = 0; /* New LHS after mods */
129171 int i; /* Loop counter */
129172 Select *pSelect; /* Pointer to the SELECT on the RHS */
129173
129174 for(i=iEq; i<pLoop->nLTerm; i++){
129175 if( pLoop->aLTerm[i]->pExpr==pX ){
129176 int iField = pLoop->aLTerm[i]->iField - 1;
129177 assert( pOrigRhs->a[iField].pExpr!=0 );
129178 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
129179 pOrigRhs->a[iField].pExpr = 0;
129180 assert( pOrigLhs->a[iField].pExpr!=0 );
129181 pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
129182 pOrigLhs->a[iField].pExpr = 0;
129183 }
129184 }
129185 sqlite3ExprListDelete(db, pOrigRhs);
129186 sqlite3ExprListDelete(db, pOrigLhs);
129187 pNew->pLeft->x.pList = pLhs;
129188 pNew->x.pSelect->pEList = pRhs;
129189 if( pLhs && pLhs->nExpr==1 ){
129190 /* Take care here not to generate a TK_VECTOR containing only a
129191 ** single value. Since the parser never creates such a vector, some
129192 ** of the subroutines do not handle this case. */
129193 Expr *p = pLhs->a[0].pExpr;
129194 pLhs->a[0].pExpr = 0;
129195 sqlite3ExprDelete(db, pNew->pLeft);
129196 pNew->pLeft = p;
129197 }
129198 pSelect = pNew->x.pSelect;
129199 if( pSelect->pOrderBy ){
129200 /* If the SELECT statement has an ORDER BY clause, zero the
129201 ** iOrderByCol variables. These are set to non-zero when an
129202 ** ORDER BY term exactly matches one of the terms of the
129203 ** result-set. Since the result-set of the SELECT statement may
129204 ** have been modified or reordered, these variables are no longer
129205 ** set correctly. Since setting them is just an optimization,
129206 ** it's easiest just to zero them here. */
129207 ExprList *pOrderBy = pSelect->pOrderBy;
129208 for(i=0; i<pOrderBy->nExpr; i++){
129209 pOrderBy->a[i].u.x.iOrderByCol = 0;
129210 }
129211 }
129212
129213 #if 0
129214 printf("For indexing, change the IN expr:\n");
129215 sqlite3TreeViewExpr(0, pX, 0);
129216 printf("Into:\n");
129217 sqlite3TreeViewExpr(0, pNew, 0);
129218 #endif
129219 }
129220 return pNew;
129221 }
129222
129223
129224 /*
129225 ** Generate code for a single equality term of the WHERE clause. An equality
129226 ** term can be either X=expr or X IN (...). pTerm is the term to be
129227 ** coded.
@@ -128994,72 +129281,27 @@
129281 disableTerm(pLevel, pTerm);
129282 return iTarget;
129283 }
129284 }
129285 for(i=iEq;i<pLoop->nLTerm; i++){
129286 assert( pLoop->aLTerm[i]!=0 );
129287 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
129288 }
129289
129290 if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
129291 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
129292 }else{
 
129293 sqlite3 *db = pParse->db;
129294 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
129295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129296 if( !db->mallocFailed ){
129297 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129298 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
129299 pTerm->pExpr->iTable = pX->iTable;
129300 }
129301 sqlite3ExprDelete(db, pX);
129302 pX = pTerm->pExpr;
 
 
 
 
129303 }
129304
129305 if( eType==IN_INDEX_INDEX_DESC ){
129306 testcase( bRev );
129307 bRev = !bRev;
@@ -134703,11 +134945,11 @@
134945 }else if( eOp & (WO_EQ|WO_IS) ){
134946 int iCol = pProbe->aiColumn[saved_nEq];
134947 pNew->wsFlags |= WHERE_COLUMN_EQ;
134948 assert( saved_nEq==pNew->u.btree.nEq );
134949 if( iCol==XN_ROWID
134950 || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1)
134951 ){
134952 if( iCol>=0 && pProbe->uniqNotNull==0 ){
134953 pNew->wsFlags |= WHERE_UNQ_WANTED;
134954 }else{
134955 pNew->wsFlags |= WHERE_ONEROW;
@@ -136920,39 +137162,84 @@
137162 for(ii=0; ii<pWInfo->nLevel; ii++){
137163 whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
137164 }
137165 }
137166 #endif
137167
137168 /* Attempt to omit tables from the join that do not affect the result.
137169 ** For a table to not affect the result, the following must be true:
137170 **
137171 ** 1) The query must not be an aggregate.
137172 ** 2) The table must be the RHS of a LEFT JOIN.
137173 ** 3) Either the query must be DISTINCT, or else the ON or USING clause
137174 ** must contain a constraint that limits the scan of the table to
137175 ** at most a single row.
137176 ** 4) The table must not be referenced by any part of the query apart
137177 ** from its own USING or ON clause.
137178 **
137179 ** For example, given:
137180 **
137181 ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
137182 ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
137183 ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
137184 **
137185 ** then table t2 can be omitted from the following:
137186 **
137187 ** SELECT v1, v3 FROM t1
137188 ** LEFT JOIN t2 USING (t1.ipk=t2.ipk)
137189 ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
137190 **
137191 ** or from:
137192 **
137193 ** SELECT DISTINCT v1, v3 FROM t1
137194 ** LEFT JOIN t2
137195 ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
137196 */
137197 notReady = ~(Bitmask)0;
137198 if( pWInfo->nLevel>=2
137199 && pResultSet!=0 /* guarantees condition (1) above */
137200 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
137201 ){
137202 int i;
137203 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
137204 if( sWLB.pOrderBy ){
137205 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
137206 }
137207 for(i=pWInfo->nLevel-1; i>=1; i--){
137208 WhereTerm *pTerm, *pEnd;
137209 struct SrcList_item *pItem;
137210 pLoop = pWInfo->a[i].pWLoop;
137211 pItem = &pWInfo->pTabList->a[pLoop->iTab];
137212 if( (pItem->fg.jointype & JT_LEFT)==0 ) continue;
137213 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
137214 && (pLoop->wsFlags & WHERE_ONEROW)==0
137215 ){
137216 continue;
137217 }
137218 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
137219 pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
137220 for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
137221 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
137222 if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
137223 || pTerm->pExpr->iRightJoinTable!=pItem->iCursor
137224 ){
137225 break;
137226 }
137227 }
137228 }
137229 if( pTerm<pEnd ) continue;
137230 WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
137231 notReady &= ~pLoop->maskSelf;
137232 for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
137233 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
137234 pTerm->wtFlags |= TERM_CODED;
137235 }
137236 }
137237 if( i!=pWInfo->nLevel-1 ){
137238 int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel);
137239 memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte);
137240 }
137241 pWInfo->nLevel--;
137242 nTabList--;
137243 }
137244 }
137245 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
@@ -137103,11 +137390,10 @@
137390
137391 /* Generate the code to do the search. Each iteration of the for
137392 ** loop below generates code for a single nested loop of the VM
137393 ** program.
137394 */
 
137395 for(ii=0; ii<nTabList; ii++){
137396 int addrExplain;
137397 int wsFlags;
137398 pLevel = &pWInfo->a[ii];
137399 wsFlags = pLevel->pWLoop->wsFlags;
@@ -137167,10 +137453,11 @@
137453 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
137454 int addrSeek = 0;
137455 Index *pIdx;
137456 int n;
137457 if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
137458 && i==pWInfo->nLevel-1 /* Ticket [ef9318757b152e3] 2017-10-21 */
137459 && (pLoop->wsFlags & WHERE_INDEXED)!=0
137460 && (pIdx = pLoop->u.btree.pIndex)->hasStat1
137461 && (n = pLoop->u.btree.nIdxCol)>0
137462 && pIdx->aiRowLogEst[n]>=36
137463 ){
@@ -137233,11 +137520,12 @@
137520 if( pLevel->iLeftJoin ){
137521 int ws = pLoop->wsFlags;
137522 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
137523 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
137524 if( (ws & WHERE_IDX_ONLY)==0 ){
137525 assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
137526 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
137527 }
137528 if( (ws & WHERE_INDEXED)
137529 || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
137530 ){
137531 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -137401,19 +137689,10 @@
137689 ** Alternative datatype for the argument to the malloc() routine passed
137690 ** into sqlite3ParserAlloc(). The default is size_t.
137691 */
137692 #define YYMALLOCARGTYPE u64
137693
 
 
 
 
 
 
 
 
 
137694 /*
137695 ** An instance of the following structure describes the event of a
137696 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
137697 ** TK_DELETE, or TK_INSTEAD. If the event is of the form
137698 **
@@ -137647,11 +137926,10 @@
137926 int yy194;
137927 Select* yy243;
137928 IdList* yy254;
137929 With* yy285;
137930 struct TrigEvent yy332;
 
137931 struct {int value; int mask;} yy497;
137932 } YYMINORTYPE;
137933 #ifndef YYSTACKDEPTH
137934 #define YYSTACKDEPTH 100
137935 #endif
@@ -139903,11 +140181,11 @@
140181 SrcList *pFrom;
140182 Token x;
140183 x.n = 0;
140184 parserDoubleLinkSelect(pParse, pRhs);
140185 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
140186 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
140187 }
140188 if( pRhs ){
140189 pRhs->op = (u8)yymsp[-1].minor.yy194;
140190 pRhs->pPrior = pLhs;
140191 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
@@ -139929,11 +140207,11 @@
140207 case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140208 {
140209 #if SELECTTRACE_ENABLED
140210 Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/
140211 #endif
140212 yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy72);
140213 #if SELECTTRACE_ENABLED
140214 /* Populate the Select.zSelName[] string that is used to help with
140215 ** query planner debugging, to differentiate between multiple Select
140216 ** objects in a complex query.
140217 **
@@ -139958,17 +140236,17 @@
140236 #endif /* SELECTRACE_ENABLED */
140237 }
140238 break;
140239 case 85: /* values ::= VALUES LP nexprlist RP */
140240 {
140241 yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0);
140242 }
140243 break;
140244 case 86: /* values ::= values COMMA LP exprlist RP */
140245 {
140246 Select *pRight, *pLeft = yymsp[-4].minor.yy243;
140247 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0);
140248 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
140249 if( pRight ){
140250 pRight->op = TK_ALL;
140251 pRight->pPrior = pLeft;
140252 yymsp[-4].minor.yy243 = pRight;
@@ -140069,11 +140347,11 @@
140347 }
140348 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185);
140349 }else{
140350 Select *pSubquery;
140351 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy185);
140352 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0);
140353 yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140354 }
140355 }
140356 break;
140357 case 104: /* dbnm ::= */
@@ -140101,10 +140379,11 @@
140379 case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196);
140380 {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
140381 break;
140382 case 112: /* on_opt ::= */
140383 case 127: /* having_opt ::= */ yytestcase(yyruleno==127);
140384 case 129: /* limit_opt ::= */ yytestcase(yyruleno==129);
140385 case 134: /* where_opt ::= */ yytestcase(yyruleno==134);
140386 case 197: /* case_else ::= */ yytestcase(yyruleno==197);
140387 case 199: /* case_operand ::= */ yytestcase(yyruleno==199);
140388 {yymsp[1].minor.yy72 = 0;}
140389 break;
@@ -140144,35 +140423,32 @@
140423 {yymsp[0].minor.yy194 = SQLITE_SO_DESC;}
140424 break;
140425 case 124: /* sortorder ::= */
140426 {yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;}
140427 break;
 
 
 
140428 case 130: /* limit_opt ::= LIMIT expr */
140429 {yymsp[-1].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,0);}
140430 break;
140431 case 131: /* limit_opt ::= LIMIT expr OFFSET expr */
140432 {yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy190.pExpr,yymsp[0].minor.yy190.pExpr);}
140433 break;
140434 case 132: /* limit_opt ::= LIMIT expr COMMA expr */
140435 {yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,yymsp[-2].minor.yy190.pExpr);}
140436 break;
140437 case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140438 {
140439 sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140440 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0);
140441 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0);
140442 }
140443 break;
140444 case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140445 {
140446 sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1);
140447 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0);
140448 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list");
140449 sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0);
140450 }
140451 break;
140452 case 137: /* setlist ::= setlist COMMA nm EQ expr */
140453 {
140454 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
@@ -140485,11 +140761,11 @@
140761 }
140762 break;
140763 case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */
140764 {
140765 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
140766 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
140767 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
140768 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140769 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
140770 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140771 yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
@@ -145232,10 +145508,11 @@
145508 }else if( flags & SQLITE_OPEN_FULLMUTEX ){
145509 isThreadsafe = 1;
145510 }else{
145511 isThreadsafe = sqlite3GlobalConfig.bFullMutex;
145512 }
145513
145514 if( flags & SQLITE_OPEN_PRIVATECACHE ){
145515 flags &= ~SQLITE_OPEN_SHAREDCACHE;
145516 }else if( sqlite3GlobalConfig.sharedCacheEnabled ){
145517 flags |= SQLITE_OPEN_SHAREDCACHE;
145518 }
@@ -145264,17 +145541,24 @@
145541 );
145542
145543 /* Allocate the sqlite data structure */
145544 db = sqlite3MallocZero( sizeof(sqlite3) );
145545 if( db==0 ) goto opendb_out;
145546 if( isThreadsafe
145547 #ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
145548 || sqlite3GlobalConfig.bCoreMutex
145549 #endif
145550 ){
145551 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
145552 if( db->mutex==0 ){
145553 sqlite3_free(db);
145554 db = 0;
145555 goto opendb_out;
145556 }
145557 if( isThreadsafe==0 ){
145558 sqlite3MutexWarnOnContention(db->mutex);
145559 }
145560 }
145561 sqlite3_mutex_enter(db->mutex);
145562 db->errMask = 0xff;
145563 db->nDb = 2;
145564 db->magic = SQLITE_MAGIC_BUSY;
@@ -145754,41 +146038,41 @@
146038 ** to detect when version error conditions occurs.
146039 **
146040 ** 2. Invoke sqlite3_log() to provide the source code location where
146041 ** a low-level error is first detected.
146042 */
146043 SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType){
146044 sqlite3_log(iErr, "%s at line %d of [%.10s]",
146045 zType, lineno, 20+sqlite3_sourceid());
146046 return iErr;
146047 }
146048 SQLITE_PRIVATE int sqlite3CorruptError(int lineno){
146049 testcase( sqlite3GlobalConfig.xLog!=0 );
146050 return sqlite3ReportError(SQLITE_CORRUPT, lineno, "database corruption");
146051 }
146052 SQLITE_PRIVATE int sqlite3MisuseError(int lineno){
146053 testcase( sqlite3GlobalConfig.xLog!=0 );
146054 return sqlite3ReportError(SQLITE_MISUSE, lineno, "misuse");
146055 }
146056 SQLITE_PRIVATE int sqlite3CantopenError(int lineno){
146057 testcase( sqlite3GlobalConfig.xLog!=0 );
146058 return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file");
146059 }
146060 #ifdef SQLITE_DEBUG
146061 SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){
146062 char zMsg[100];
146063 sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno);
146064 testcase( sqlite3GlobalConfig.xLog!=0 );
146065 return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg);
146066 }
146067 SQLITE_PRIVATE int sqlite3NomemError(int lineno){
146068 testcase( sqlite3GlobalConfig.xLog!=0 );
146069 return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM");
146070 }
146071 SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){
146072 testcase( sqlite3GlobalConfig.xLog!=0 );
146073 return sqlite3ReportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error");
146074 }
146075 #endif
146076
146077 #ifndef SQLITE_OMIT_DEPRECATED
146078 /*
@@ -186122,10 +186406,12 @@
186406 Fts5ExprPhrase *pPhrase,
186407 Fts5Token *pToken,
186408 int bPrefix
186409 );
186410
186411 static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase*);
186412
186413 static Fts5ExprNearset *sqlite3Fts5ParseNearset(
186414 Fts5Parse*,
186415 Fts5ExprNearset*,
186416 Fts5ExprPhrase*
186417 );
@@ -186202,13 +186488,14 @@
186488 #define FTS5_LCP 7
186489 #define FTS5_RCP 8
186490 #define FTS5_STRING 9
186491 #define FTS5_LP 10
186492 #define FTS5_RP 11
186493 #define FTS5_CARET 12
186494 #define FTS5_COMMA 13
186495 #define FTS5_PLUS 14
186496 #define FTS5_STAR 15
186497
186498 /*
186499 ** 2000-05-29
186500 **
186501 ** The author disclaims copyright to this source code. In place of
@@ -186319,39 +186606,39 @@
186606 #ifndef INTERFACE
186607 # define INTERFACE 1
186608 #endif
186609 /************* Begin control #defines *****************************************/
186610 #define fts5YYCODETYPE unsigned char
186611 #define fts5YYNOCODE 29
186612 #define fts5YYACTIONTYPE unsigned char
186613 #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
186614 typedef union {
186615 int fts5yyinit;
186616 sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0;
186617 int fts5yy4;
186618 Fts5ExprPhrase* fts5yy11;
186619 Fts5ExprNearset* fts5yy14;
186620 Fts5Colset* fts5yy43;
186621 Fts5ExprNode* fts5yy54;
186622 } fts5YYMINORTYPE;
186623 #ifndef fts5YYSTACKDEPTH
186624 #define fts5YYSTACKDEPTH 100
186625 #endif
186626 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
186627 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
186628 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
186629 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
186630 #define fts5YYNSTATE 35
186631 #define fts5YYNRULE 28
186632 #define fts5YY_MAX_SHIFT 34
186633 #define fts5YY_MIN_SHIFTREDUCE 52
186634 #define fts5YY_MAX_SHIFTREDUCE 79
186635 #define fts5YY_MIN_REDUCE 80
186636 #define fts5YY_MAX_REDUCE 107
186637 #define fts5YY_ERROR_ACTION 108
186638 #define fts5YY_ACCEPT_ACTION 109
186639 #define fts5YY_NO_ACTION 110
186640 /************* End control #defines *******************************************/
186641
186642 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
186643 ** otherwise.
186644 **
@@ -186419,58 +186706,60 @@
186706 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
186707 ** shifting non-terminals after a reduce.
186708 ** fts5yy_default[] Default action for each state.
186709 **
186710 *********** Begin parsing tables **********************************************/
186711 #define fts5YY_ACTTAB_COUNT (105)
186712 static const fts5YYACTIONTYPE fts5yy_action[] = {
186713 /* 0 */ 109, 20, 93, 6, 28, 96, 95, 26, 26, 18,
186714 /* 10 */ 93, 6, 28, 17, 95, 56, 26, 19, 93, 6,
186715 /* 20 */ 28, 14, 95, 105, 26, 89, 93, 6, 28, 25,
186716 /* 30 */ 95, 78, 26, 21, 93, 6, 28, 104, 95, 58,
186717 /* 40 */ 26, 29, 93, 6, 28, 32, 95, 22, 26, 24,
186718 /* 50 */ 16, 23, 11, 1, 14, 13, 24, 16, 31, 11,
186719 /* 60 */ 3, 94, 13, 27, 8, 95, 82, 26, 7, 4,
186720 /* 70 */ 5, 3, 4, 5, 3, 80, 4, 5, 3, 63,
186721 /* 80 */ 33, 34, 62, 12, 2, 83, 13, 10, 12, 71,
186722 /* 90 */ 10, 13, 78, 5, 3, 78, 9, 30, 75, 82,
186723 /* 100 */ 54, 57, 53, 57, 15,
186724 };
186725 static const fts5YYCODETYPE fts5yy_lookahead[] = {
186726 /* 0 */ 17, 18, 19, 20, 21, 23, 23, 25, 25, 18,
186727 /* 10 */ 19, 20, 21, 7, 23, 9, 25, 18, 19, 20,
186728 /* 20 */ 21, 9, 23, 27, 25, 18, 19, 20, 21, 25,
186729 /* 30 */ 23, 15, 25, 18, 19, 20, 21, 27, 23, 9,
186730 /* 40 */ 25, 18, 19, 20, 21, 14, 23, 22, 25, 6,
186731 /* 50 */ 7, 22, 9, 10, 9, 12, 6, 7, 13, 9,
186732 /* 60 */ 3, 19, 12, 21, 5, 23, 28, 25, 5, 1,
186733 /* 70 */ 2, 3, 1, 2, 3, 0, 1, 2, 3, 11,
186734 /* 80 */ 25, 26, 11, 9, 10, 5, 12, 10, 9, 11,
186735 /* 90 */ 10, 12, 15, 2, 3, 15, 24, 25, 9, 28,
186736 /* 100 */ 8, 9, 8, 9, 9,
186737 };
186738 #define fts5YY_SHIFT_USE_DFLT (105)
186739 #define fts5YY_SHIFT_COUNT (34)
186740 #define fts5YY_SHIFT_MIN (0)
186741 #define fts5YY_SHIFT_MAX (95)
186742 static const unsigned char fts5yy_shift_ofst[] = {
186743 /* 0 */ 43, 43, 43, 43, 43, 43, 50, 74, 79, 45,
186744 /* 10 */ 12, 80, 77, 12, 16, 16, 30, 30, 68, 71,
186745 /* 20 */ 75, 91, 92, 94, 6, 31, 31, 59, 63, 57,
186746 /* 30 */ 31, 89, 95, 31, 78,
186747 };
186748 #define fts5YY_REDUCE_USE_DFLT (-19)
186749 #define fts5YY_REDUCE_COUNT (17)
186750 #define fts5YY_REDUCE_MIN (-18)
186751 #define fts5YY_REDUCE_MAX (72)
186752 static const signed char fts5yy_reduce_ofst[] = {
186753 /* 0 */ -17, -9, -1, 7, 15, 23, 42, -18, -18, 55,
186754 /* 10 */ 72, -4, -4, 4, -4, 10, 25, 29,
186755 };
186756 static const fts5YYACTIONTYPE fts5yy_default[] = {
186757 /* 0 */ 108, 108, 108, 108, 108, 108, 92, 108, 108, 102,
186758 /* 10 */ 108, 107, 107, 108, 107, 107, 108, 108, 108, 108,
186759 /* 20 */ 108, 88, 108, 108, 108, 98, 97, 108, 108, 87,
186760 /* 30 */ 100, 108, 108, 101, 108,
186761 };
186762 /********** End of lemon-generated parsing tables *****************************/
186763
186764 /* The next table maps tokens (terminal symbols) into fallback tokens.
186765 ** If a construct like the following:
@@ -186575,14 +186864,14 @@
186864 ** are required. The following table supplies these names */
186865 static const char *const fts5yyTokenName[] = {
186866 "$", "OR", "AND", "NOT",
186867 "TERM", "COLON", "MINUS", "LCP",
186868 "RCP", "STRING", "LP", "RP",
186869 "CARET", "COMMA", "PLUS", "STAR",
186870 "error", "input", "expr", "cnearset",
186871 "exprlist", "colset", "colsetlist", "nearset",
186872 "nearphrases", "phrase", "neardist_opt", "star_opt",
186873 };
186874 #endif /* NDEBUG */
186875
186876 #ifndef NDEBUG
186877 /* For tracing reduce actions, the names of all rules are required.
@@ -186604,19 +186893,20 @@
186893 /* 13 */ "exprlist ::= cnearset",
186894 /* 14 */ "exprlist ::= exprlist cnearset",
186895 /* 15 */ "cnearset ::= nearset",
186896 /* 16 */ "cnearset ::= colset COLON nearset",
186897 /* 17 */ "nearset ::= phrase",
186898 /* 18 */ "nearset ::= CARET phrase",
186899 /* 19 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
186900 /* 20 */ "nearphrases ::= phrase",
186901 /* 21 */ "nearphrases ::= nearphrases phrase",
186902 /* 22 */ "neardist_opt ::=",
186903 /* 23 */ "neardist_opt ::= COMMA STRING",
186904 /* 24 */ "phrase ::= phrase PLUS STRING star_opt",
186905 /* 25 */ "phrase ::= STRING star_opt",
186906 /* 26 */ "star_opt ::= STAR",
186907 /* 27 */ "star_opt ::=",
186908 };
186909 #endif /* NDEBUG */
186910
186911
186912 #if fts5YYSTACKDEPTH<=0
@@ -186733,37 +187023,37 @@
187023 ** Note: during a reduce, the only symbols destroyed are those
187024 ** which appear on the RHS of the rule, but which are *not* used
187025 ** inside the C code.
187026 */
187027 /********* Begin destructor definitions ***************************************/
187028 case 17: /* input */
187029 {
187030 (void)pParse;
187031 }
187032 break;
187033 case 18: /* expr */
187034 case 19: /* cnearset */
187035 case 20: /* exprlist */
187036 {
187037 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy54));
187038 }
187039 break;
187040 case 21: /* colset */
187041 case 22: /* colsetlist */
187042 {
187043 sqlite3_free((fts5yypminor->fts5yy43));
187044 }
187045 break;
187046 case 23: /* nearset */
187047 case 24: /* nearphrases */
187048 {
187049 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy14));
187050 }
187051 break;
187052 case 25: /* phrase */
187053 {
187054 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11));
187055 }
187056 break;
187057 /********* End destructor definitions *****************************************/
187058 default: break; /* If no destructor action specified: do nothing */
187059 }
@@ -187013,37 +187303,38 @@
187303 */
187304 static const struct {
187305 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
187306 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
187307 } fts5yyRuleInfo[] = {
187308 { 17, -1 },
187309 { 21, -4 },
187310 { 21, -3 },
187311 { 21, -1 },
187312 { 21, -2 },
187313 { 22, -2 },
187314 { 22, -1 },
187315 { 18, -3 },
187316 { 18, -3 },
187317 { 18, -3 },
187318 { 18, -5 },
187319 { 18, -3 },
187320 { 18, -1 },
187321 { 20, -1 },
187322 { 20, -2 },
 
 
 
 
 
 
 
 
187323 { 19, -1 },
187324 { 19, -3 },
 
 
 
 
187325 { 23, -1 },
187326 { 23, -2 },
187327 { 23, -5 },
187328 { 24, -1 },
 
187329 { 24, -2 },
 
187330 { 26, 0 },
187331 { 26, -2 },
187332 { 25, -4 },
187333 { 25, -2 },
187334 { 27, -1 },
187335 { 27, 0 },
187336 };
187337
187338 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
187339
187340 /*
@@ -187104,141 +187395,147 @@
187395 ** break;
187396 */
187397 /********** Begin reduce actions **********************************************/
187398 fts5YYMINORTYPE fts5yylhsminor;
187399 case 0: /* input ::= expr */
187400 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy54); }
187401 break;
187402 case 1: /* colset ::= MINUS LCP colsetlist RCP */
187403 {
187404 fts5yymsp[-3].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43);
187405 }
187406 break;
187407 case 2: /* colset ::= LCP colsetlist RCP */
187408 { fts5yymsp[-2].minor.fts5yy43 = fts5yymsp[-1].minor.fts5yy43; }
187409 break;
187410 case 3: /* colset ::= STRING */
187411 {
187412 fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187413 }
187414 fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43;
187415 break;
187416 case 4: /* colset ::= MINUS STRING */
187417 {
187418 fts5yymsp[-1].minor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187419 fts5yymsp[-1].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43);
187420 }
187421 break;
187422 case 5: /* colsetlist ::= colsetlist STRING */
187423 {
187424 fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy43, &fts5yymsp[0].minor.fts5yy0); }
187425 fts5yymsp[-1].minor.fts5yy43 = fts5yylhsminor.fts5yy43;
187426 break;
187427 case 6: /* colsetlist ::= STRING */
187428 {
187429 fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
187430 }
187431 fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43;
187432 break;
187433 case 7: /* expr ::= expr AND expr */
187434 {
187435 fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0);
187436 }
187437 fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187438 break;
187439 case 8: /* expr ::= expr OR expr */
187440 {
187441 fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0);
187442 }
187443 fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187444 break;
187445 case 9: /* expr ::= expr NOT expr */
187446 {
187447 fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0);
187448 }
187449 fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187450 break;
187451 case 10: /* expr ::= colset COLON LP expr RP */
187452 {
187453 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy54, fts5yymsp[-4].minor.fts5yy43);
187454 fts5yylhsminor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54;
187455 }
187456 fts5yymsp[-4].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187457 break;
187458 case 11: /* expr ::= LP expr RP */
187459 {fts5yymsp[-2].minor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54;}
187460 break;
187461 case 12: /* expr ::= exprlist */
187462 case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
187463 {fts5yylhsminor.fts5yy54 = fts5yymsp[0].minor.fts5yy54;}
187464 fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187465 break;
187466 case 14: /* exprlist ::= exprlist cnearset */
187467 {
187468 fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54);
187469 }
187470 fts5yymsp[-1].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187471 break;
187472 case 15: /* cnearset ::= nearset */
187473 {
187474 fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy14);
187475 }
187476 fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187477 break;
187478 case 16: /* cnearset ::= colset COLON nearset */
187479 {
187480 fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy14);
187481 sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy54, fts5yymsp[-2].minor.fts5yy43);
187482 }
187483 fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54;
187484 break;
187485 case 17: /* nearset ::= phrase */
187486 { fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
187487 fts5yymsp[0].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187488 break;
187489 case 18: /* nearset ::= CARET phrase */
187490 {
187491 sqlite3Fts5ParseSetCaret(fts5yymsp[0].minor.fts5yy11);
187492 fts5yymsp[-1].minor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
187493 }
187494 break;
187495 case 19: /* nearset ::= STRING LP nearphrases neardist_opt RP */
187496 {
187497 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
187498 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy14, &fts5yymsp[-1].minor.fts5yy0);
187499 fts5yylhsminor.fts5yy14 = fts5yymsp[-2].minor.fts5yy14;
187500 }
187501 fts5yymsp[-4].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187502 break;
187503 case 20: /* nearphrases ::= phrase */
187504 {
187505 fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11);
187506 }
187507 fts5yymsp[0].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187508 break;
187509 case 21: /* nearphrases ::= nearphrases phrase */
187510 {
187511 fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy14, fts5yymsp[0].minor.fts5yy11);
187512 }
187513 fts5yymsp[-1].minor.fts5yy14 = fts5yylhsminor.fts5yy14;
187514 break;
187515 case 22: /* neardist_opt ::= */
187516 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
187517 break;
187518 case 23: /* neardist_opt ::= COMMA STRING */
187519 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
187520 break;
187521 case 24: /* phrase ::= phrase PLUS STRING star_opt */
187522 {
187523 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187524 }
187525 fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187526 break;
187527 case 25: /* phrase ::= STRING star_opt */
187528 {
187529 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
187530 }
187531 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
187532 break;
187533 case 26: /* star_opt ::= STAR */
187534 { fts5yymsp[0].minor.fts5yy4 = 1; }
187535 break;
187536 case 27: /* star_opt ::= */
187537 { fts5yymsp[1].minor.fts5yy4 = 0; }
187538 break;
187539 default:
187540 break;
187541 /********** End reduce actions ************************************************/
@@ -189657,11 +189954,12 @@
189954 /*
189955 ** An instance of the following structure represents a single search term
189956 ** or term prefix.
189957 */
189958 struct Fts5ExprTerm {
189959 u8 bPrefix; /* True for a prefix term */
189960 u8 bFirst; /* True if token must be first in column */
189961 char *zTerm; /* nul-terminated term */
189962 Fts5IndexIter *pIter; /* Iterator for this term */
189963 Fts5ExprTerm *pSynonym; /* Pointer to first in list of synonyms */
189964 };
189965
@@ -189738,10 +190036,11 @@
190036 case ':': tok = FTS5_COLON; break;
190037 case ',': tok = FTS5_COMMA; break;
190038 case '+': tok = FTS5_PLUS; break;
190039 case '*': tok = FTS5_STAR; break;
190040 case '-': tok = FTS5_MINUS; break;
190041 case '^': tok = FTS5_CARET; break;
190042 case '\0': tok = FTS5_EOF; break;
190043
190044 case '"': {
190045 const char *z2;
190046 tok = FTS5_STRING;
@@ -189997,10 +190296,11 @@
190296 Fts5PoslistWriter writer = {0};
190297 Fts5PoslistReader aStatic[4];
190298 Fts5PoslistReader *aIter = aStatic;
190299 int i;
190300 int rc = SQLITE_OK;
190301 int bFirst = pPhrase->aTerm[0].bFirst;
190302
190303 fts5BufferZero(&pPhrase->poslist);
190304
190305 /* If the aStatic[] array is not large enough, allocate a large array
190306 ** using sqlite3_malloc(). This approach could be improved upon. */
@@ -190051,12 +190351,14 @@
190351 }
190352 }
190353 }while( bMatch==0 );
190354
190355 /* Append position iPos to the output */
190356 if( bFirst==0 || FTS5_POS2OFFSET(iPos)==0 ){
190357 rc = sqlite3Fts5PoslistWriterAppend(&pPhrase->poslist, &writer, iPos);
190358 if( rc!=SQLITE_OK ) goto ismatch_out;
190359 }
190360
190361 for(i=0; i<pPhrase->nTerm; i++){
190362 if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) goto ismatch_out;
190363 }
190364 }
@@ -190306,11 +190608,13 @@
190608 /* Check that each phrase in the nearset matches the current row.
190609 ** Populate the pPhrase->poslist buffers at the same time. If any
190610 ** phrase is not a match, break out of the loop early. */
190611 for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
190612 Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
190613 if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym
190614 || pNear->pColset || pPhrase->aTerm[0].bFirst
190615 ){
190616 int bMatch = 0;
190617 rc = fts5ExprPhraseIsMatch(pNode, pPhrase, &bMatch);
190618 if( bMatch==0 ) break;
190619 }else{
190620 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
@@ -190487,10 +190791,11 @@
190791
190792 /* Check that this node should not be FTS5_TERM */
190793 assert( pNear->nPhrase>1
190794 || pNear->apPhrase[0]->nTerm>1
190795 || pNear->apPhrase[0]->aTerm[0].pSynonym
190796 || pNear->apPhrase[0]->aTerm[0].bFirst
190797 );
190798
190799 /* Initialize iLast, the "lastest" rowid any iterator points to. If the
190800 ** iterator skips through rowids in the default ascending order, this means
190801 ** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
@@ -191010,10 +191315,20 @@
191315 }
191316 if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
191317 sqlite3_free(pPhrase);
191318 }
191319 }
191320
191321 /*
191322 ** Set the "bFirst" flag on the first token of the phrase passed as the
191323 ** only argument.
191324 */
191325 static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase *pPhrase){
191326 if( pPhrase && pPhrase->nTerm ){
191327 pPhrase->aTerm[0].bFirst = 1;
191328 }
191329 }
191330
191331 /*
191332 ** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated
191333 ** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is
191334 ** appended to it and the results returned.
@@ -191289,10 +191604,11 @@
191604 0, 0);
191605 tflags = FTS5_TOKEN_COLOCATED;
191606 }
191607 if( rc==SQLITE_OK ){
191608 sCtx.pPhrase->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix;
191609 sCtx.pPhrase->aTerm[i].bFirst = pOrig->aTerm[i].bFirst;
191610 }
191611 }
191612 }else{
191613 /* This happens when parsing a token or quoted phrase that contains
191614 ** no token characters at all. (e.g ... MATCH '""'). */
@@ -191307,11 +191623,14 @@
191623 pNew->apExprPhrase[0] = sCtx.pPhrase;
191624 pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
191625 pNew->pRoot->pNear->nPhrase = 1;
191626 sCtx.pPhrase->pNode = pNew->pRoot;
191627
191628 if( pOrig->nTerm==1
191629 && pOrig->aTerm[0].pSynonym==0
191630 && pOrig->aTerm[0].bFirst==0
191631 ){
191632 pNew->pRoot->eType = FTS5_TERM;
191633 pNew->pRoot->xNext = fts5ExprNodeNext_TERM;
191634 }else{
191635 pNew->pRoot->eType = FTS5_STRING;
191636 pNew->pRoot->xNext = fts5ExprNodeNext_STRING;
@@ -191581,10 +191900,11 @@
191900 switch( pNode->eType ){
191901 case FTS5_STRING: {
191902 Fts5ExprNearset *pNear = pNode->pNear;
191903 if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1
191904 && pNear->apPhrase[0]->aTerm[0].pSynonym==0
191905 && pNear->apPhrase[0]->aTerm[0].bFirst==0
191906 ){
191907 pNode->eType = FTS5_TERM;
191908 pNode->xNext = fts5ExprNodeNext_TERM;
191909 }else{
191910 pNode->xNext = fts5ExprNodeNext_STRING;
@@ -191667,24 +191987,27 @@
191987 pRet->xNext = 0;
191988 pRet->eType = FTS5_EOF;
191989 }
191990 }
191991
191992 if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL ){
191993 Fts5ExprPhrase *pPhrase = pNear->apPhrase[0];
191994 if( pNear->nPhrase!=1
191995 || pPhrase->nTerm>1
191996 || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst)
191997 ){
191998 assert( pParse->rc==SQLITE_OK );
191999 pParse->rc = SQLITE_ERROR;
192000 assert( pParse->zErr==0 );
192001 pParse->zErr = sqlite3_mprintf(
192002 "fts5: %s queries are not supported (detail!=full)",
192003 pNear->nPhrase==1 ? "phrase": "NEAR"
192004 );
192005 sqlite3_free(pRet);
192006 pRet = 0;
192007 }
192008 }
192009 }else{
192010 fts5ExprAddChildren(pRet, pLeft);
192011 fts5ExprAddChildren(pRet, pRight);
192012 }
192013 }
@@ -202049,11 +202372,11 @@
202372 int nArg, /* Number of args */
202373 sqlite3_value **apUnused /* Function arguments */
202374 ){
202375 assert( nArg==0 );
202376 UNUSED_PARAM2(nArg, apUnused);
202377 sqlite3_result_text(pCtx, "fts5: 2017-12-01 18:40:18 5771b1d611b3562ea6c040f3f893073c4d0ee58c35b37ae211520d9aee8ed547", -1, SQLITE_TRANSIENT);
202378 }
202379
202380 static int fts5Init(sqlite3 *db){
202381 static const sqlite3_module fts5Mod = {
202382 /* iVersion */ 2,
@@ -206317,12 +206640,12 @@
206640 }
206641 #endif /* SQLITE_CORE */
206642 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
206643
206644 /************** End of stmt.c ************************************************/
206645 #if __LINE__!=206645
206646 #undef SQLITE_SOURCE_ID
206647 #define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbalt2"
206648 #endif
206649 /* Return the source-id for this library */
206650 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
206651 /************************** End of sqlite3.c ******************************/
206652
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.22.0"
127127
#define SQLITE_VERSION_NUMBER 3022000
128
-#define SQLITE_SOURCE_ID "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3"
128
+#define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbcc71"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbcc71"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134

Keyboard Shortcuts

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