| | @@ -1147,11 +1147,11 @@ |
| 1147 | 1147 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1148 | 1148 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1149 | 1149 | */ |
| 1150 | 1150 | #define SQLITE_VERSION "3.22.0" |
| 1151 | 1151 | #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" |
| 1153 | 1153 | |
| 1154 | 1154 | /* |
| 1155 | 1155 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1156 | 1156 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1157 | 1157 | ** |
| | @@ -16532,11 +16532,10 @@ |
| 16532 | 16532 | Expr *pHaving; /* The HAVING clause */ |
| 16533 | 16533 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 16534 | 16534 | Select *pPrior; /* Prior select in a compound select statement */ |
| 16535 | 16535 | Select *pNext; /* Next select to the left in a compound */ |
| 16536 | 16536 | Expr *pLimit; /* LIMIT expression. NULL means not used. */ |
| 16537 | | - Expr *pOffset; /* OFFSET expression. NULL means not used. */ |
| 16538 | 16537 | With *pWith; /* WITH clause attached to this select. Or NULL. */ |
| 16539 | 16538 | }; |
| 16540 | 16539 | |
| 16541 | 16540 | /* |
| 16542 | 16541 | ** Allowed values for Select.selFlags. The "SF" prefix stands for |
| | @@ -17215,10 +17214,11 @@ |
| 17215 | 17214 | ** the same name but without the _BKPT suffix. These macros invoke |
| 17216 | 17215 | ** routines that report the line-number on which the error originated |
| 17217 | 17216 | ** using sqlite3_log(). The routines also provide a convenient place |
| 17218 | 17217 | ** to set a debugger breakpoint. |
| 17219 | 17218 | */ |
| 17219 | +SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType); |
| 17220 | 17220 | SQLITE_PRIVATE int sqlite3CorruptError(int); |
| 17221 | 17221 | SQLITE_PRIVATE int sqlite3MisuseError(int); |
| 17222 | 17222 | SQLITE_PRIVATE int sqlite3CantopenError(int); |
| 17223 | 17223 | #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__) |
| 17224 | 17224 | #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) |
| | @@ -17372,10 +17372,16 @@ |
| 17372 | 17372 | SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*); |
| 17373 | 17373 | |
| 17374 | 17374 | /* Access to mutexes used by sqlite3_status() */ |
| 17375 | 17375 | SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void); |
| 17376 | 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 |
| 17377 | 17383 | |
| 17378 | 17384 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 17379 | 17385 | SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 17380 | 17386 | #else |
| 17381 | 17387 | # define sqlite3IsNaN(X) 0 |
| | @@ -17539,20 +17545,20 @@ |
| 17539 | 17545 | SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, |
| 17540 | 17546 | Expr*, int, int, u8); |
| 17541 | 17547 | SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int); |
| 17542 | 17548 | SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*); |
| 17543 | 17549 | SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, |
| 17544 | | - Expr*,ExprList*,u32,Expr*,Expr*); |
| 17550 | + Expr*,ExprList*,u32,Expr*); |
| 17545 | 17551 | SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*); |
| 17546 | 17552 | SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*); |
| 17547 | 17553 | SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int); |
| 17548 | 17554 | SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); |
| 17549 | 17555 | #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*); |
| 17551 | 17557 | #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*); |
| 17554 | 17560 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); |
| 17555 | 17561 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| 17556 | 17562 | SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*); |
| 17557 | 17563 | SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*); |
| 17558 | 17564 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| | @@ -17672,11 +17678,11 @@ |
| 17672 | 17678 | SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*); |
| 17673 | 17679 | SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*); |
| 17674 | 17680 | SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int); |
| 17675 | 17681 | |
| 17676 | 17682 | #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); |
| 17678 | 17684 | #endif |
| 17679 | 17685 | |
| 17680 | 17686 | #ifndef SQLITE_OMIT_TRIGGER |
| 17681 | 17687 | SQLITE_PRIVATE void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*, |
| 17682 | 17688 | Expr*,int, int); |
| | @@ -23393,10 +23399,197 @@ |
| 23393 | 23399 | static SQLITE_WSD int mutexIsInit = 0; |
| 23394 | 23400 | #endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */ |
| 23395 | 23401 | |
| 23396 | 23402 | |
| 23397 | 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 | + |
| 23398 | 23591 | /* |
| 23399 | 23592 | ** Initialize the mutex system. |
| 23400 | 23593 | */ |
| 23401 | 23594 | SQLITE_PRIVATE int sqlite3MutexInit(void){ |
| 23402 | 23595 | int rc = SQLITE_OK; |
| | @@ -23408,11 +23601,15 @@ |
| 23408 | 23601 | */ |
| 23409 | 23602 | sqlite3_mutex_methods const *pFrom; |
| 23410 | 23603 | sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex; |
| 23411 | 23604 | |
| 23412 | 23605 | if( sqlite3GlobalConfig.bCoreMutex ){ |
| 23606 | +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS |
| 23607 | + pFrom = multiThreadedCheckMutex(); |
| 23608 | +#else |
| 23413 | 23609 | pFrom = sqlite3DefaultMutex(); |
| 23610 | +#endif |
| 23414 | 23611 | }else{ |
| 23415 | 23612 | pFrom = sqlite3NoopMutex(); |
| 23416 | 23613 | } |
| 23417 | 23614 | pTo->xMutexInit = pFrom->xMutexInit; |
| 23418 | 23615 | pTo->xMutexEnd = pFrom->xMutexEnd; |
| | @@ -23534,10 +23731,11 @@ |
| 23534 | 23731 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
| 23535 | 23732 | } |
| 23536 | 23733 | #endif |
| 23537 | 23734 | |
| 23538 | 23735 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| 23736 | + |
| 23539 | 23737 | |
| 23540 | 23738 | /************** End of mutex.c ***********************************************/ |
| 23541 | 23739 | /************** Begin file mutex_noop.c **************************************/ |
| 23542 | 23740 | /* |
| 23543 | 23741 | ** 2008 October 07 |
| | @@ -26817,11 +27015,10 @@ |
| 26817 | 27015 | if( p->pWhere ) n++; |
| 26818 | 27016 | if( p->pGroupBy ) n++; |
| 26819 | 27017 | if( p->pHaving ) n++; |
| 26820 | 27018 | if( p->pOrderBy ) n++; |
| 26821 | 27019 | if( p->pLimit ) n++; |
| 26822 | | - if( p->pOffset ) n++; |
| 26823 | 27020 | } |
| 26824 | 27021 | sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set"); |
| 26825 | 27022 | if( p->pSrc && p->pSrc->nSrc ){ |
| 26826 | 27023 | int i; |
| 26827 | 27024 | pView = sqlite3TreeViewPush(pView, (n--)>0); |
| | @@ -26874,16 +27071,16 @@ |
| 26874 | 27071 | if( p->pOrderBy ){ |
| 26875 | 27072 | sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); |
| 26876 | 27073 | } |
| 26877 | 27074 | if( p->pLimit ){ |
| 26878 | 27075 | 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 | + } |
| 26885 | 27082 | sqlite3TreeViewPop(pView); |
| 26886 | 27083 | } |
| 26887 | 27084 | if( p->pPrior ){ |
| 26888 | 27085 | const char *zOp = "UNION"; |
| 26889 | 27086 | switch( p->op ){ |
| | @@ -57728,12 +57925,11 @@ |
| 57728 | 57925 | assert( pWal->nWiData>0 ); |
| 57729 | 57926 | assert( pWal->apWiData[0]!=0 ); |
| 57730 | 57927 | pInfo = walCkptInfo(pWal); |
| 57731 | 57928 | if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame |
| 57732 | 57929 | #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) |
| 57735 | 57931 | #endif |
| 57736 | 57932 | ){ |
| 57737 | 57933 | /* The WAL has been completely backfilled (or it is empty). |
| 57738 | 57934 | ** and can be safely ignored. |
| 57739 | 57935 | */ |
| | @@ -60149,10 +60345,35 @@ |
| 60149 | 60345 | #define downgradeAllSharedCacheTableLocks(a) |
| 60150 | 60346 | #define hasSharedCacheTableLock(a,b,c,d) 1 |
| 60151 | 60347 | #define hasReadConflicts(a, b) 0 |
| 60152 | 60348 | #endif |
| 60153 | 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 | + |
| 60154 | 60375 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 60155 | 60376 | |
| 60156 | 60377 | #ifdef SQLITE_DEBUG |
| 60157 | 60378 | /* |
| 60158 | 60379 | **** This function is only used as part of an assert() statement. *** |
| | @@ -61437,11 +61658,11 @@ |
| 61437 | 61658 | u8 *pAddr; |
| 61438 | 61659 | int sz2 = 0; |
| 61439 | 61660 | int sz = get2byte(&data[iFree+2]); |
| 61440 | 61661 | int top = get2byte(&data[hdr+5]); |
| 61441 | 61662 | if( top>=iFree ){ |
| 61442 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61663 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61443 | 61664 | } |
| 61444 | 61665 | if( iFree2 ){ |
| 61445 | 61666 | assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */ |
| 61446 | 61667 | sz2 = get2byte(&data[iFree2+2]); |
| 61447 | 61668 | assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize ); |
| | @@ -61471,17 +61692,17 @@ |
| 61471 | 61692 | testcase( pc==iCellLast ); |
| 61472 | 61693 | /* These conditions have already been verified in btreeInitPage() |
| 61473 | 61694 | ** if PRAGMA cell_size_check=ON. |
| 61474 | 61695 | */ |
| 61475 | 61696 | if( pc<iCellFirst || pc>iCellLast ){ |
| 61476 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61697 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61477 | 61698 | } |
| 61478 | 61699 | assert( pc>=iCellFirst && pc<=iCellLast ); |
| 61479 | 61700 | size = pPage->xCellSize(pPage, &src[pc]); |
| 61480 | 61701 | cbrk -= size; |
| 61481 | 61702 | if( cbrk<iCellFirst || pc+size>usableSize ){ |
| 61482 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61703 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61483 | 61704 | } |
| 61484 | 61705 | assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); |
| 61485 | 61706 | testcase( cbrk+size==usableSize ); |
| 61486 | 61707 | testcase( pc+size==usableSize ); |
| 61487 | 61708 | put2byte(pAddr, cbrk); |
| | @@ -61497,11 +61718,11 @@ |
| 61497 | 61718 | } |
| 61498 | 61719 | data[hdr+7] = 0; |
| 61499 | 61720 | |
| 61500 | 61721 | defragment_out: |
| 61501 | 61722 | if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){ |
| 61502 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61723 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61503 | 61724 | } |
| 61504 | 61725 | assert( cbrk>=iCellFirst ); |
| 61505 | 61726 | put2byte(&data[hdr+5], cbrk); |
| 61506 | 61727 | data[hdr+1] = 0; |
| 61507 | 61728 | data[hdr+2] = 0; |
| | @@ -61541,11 +61762,11 @@ |
| 61541 | 61762 | size = get2byte(&aData[pc+2]); |
| 61542 | 61763 | if( (x = size - nByte)>=0 ){ |
| 61543 | 61764 | testcase( x==4 ); |
| 61544 | 61765 | testcase( x==3 ); |
| 61545 | 61766 | if( size+pc > usableSize ){ |
| 61546 | | - *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno); |
| 61767 | + *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 61547 | 61768 | return 0; |
| 61548 | 61769 | }else if( x<4 ){ |
| 61549 | 61770 | /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total |
| 61550 | 61771 | ** number of bytes in fragments may not exceed 60. */ |
| 61551 | 61772 | if( aData[hdr+7]>57 ) return 0; |
| | @@ -61564,11 +61785,11 @@ |
| 61564 | 61785 | iAddr = pc; |
| 61565 | 61786 | pc = get2byte(&aData[pc]); |
| 61566 | 61787 | if( pc<iAddr+size ) break; |
| 61567 | 61788 | } |
| 61568 | 61789 | if( pc ){ |
| 61569 | | - *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno); |
| 61790 | + *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 61570 | 61791 | } |
| 61571 | 61792 | |
| 61572 | 61793 | return 0; |
| 61573 | 61794 | } |
| 61574 | 61795 | |
| | @@ -61612,11 +61833,11 @@ |
| 61612 | 61833 | assert( top<=(int)pPage->pBt->usableSize ); /* Prevent by getAndInitPage() */ |
| 61613 | 61834 | if( gap>top ){ |
| 61614 | 61835 | if( top==0 && pPage->pBt->usableSize==65536 ){ |
| 61615 | 61836 | top = 65536; |
| 61616 | 61837 | }else{ |
| 61617 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61838 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61618 | 61839 | } |
| 61619 | 61840 | } |
| 61620 | 61841 | |
| 61621 | 61842 | /* If there is enough space between gap and top for one more cell pointer |
| 61622 | 61843 | ** array entry offset, and if the freelist is not empty, then search the |
| | @@ -61702,16 +61923,16 @@ |
| 61702 | 61923 | iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */ |
| 61703 | 61924 | }else{ |
| 61704 | 61925 | while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){ |
| 61705 | 61926 | if( iFreeBlk<iPtr+4 ){ |
| 61706 | 61927 | if( iFreeBlk==0 ) break; |
| 61707 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61928 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61708 | 61929 | } |
| 61709 | 61930 | iPtr = iFreeBlk; |
| 61710 | 61931 | } |
| 61711 | 61932 | if( iFreeBlk>pPage->pBt->usableSize-4 ){ |
| 61712 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61933 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61713 | 61934 | } |
| 61714 | 61935 | assert( iFreeBlk>iPtr || iFreeBlk==0 ); |
| 61715 | 61936 | |
| 61716 | 61937 | /* At this point: |
| 61717 | 61938 | ** iFreeBlk: First freeblock after iStart, or zero if none |
| | @@ -61719,14 +61940,14 @@ |
| 61719 | 61940 | ** |
| 61720 | 61941 | ** Check to see if iFreeBlk should be coalesced onto the end of iStart. |
| 61721 | 61942 | */ |
| 61722 | 61943 | if( iFreeBlk && iEnd+3>=iFreeBlk ){ |
| 61723 | 61944 | nFrag = iFreeBlk - iEnd; |
| 61724 | | - if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61945 | + if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage); |
| 61725 | 61946 | iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); |
| 61726 | 61947 | if( iEnd > pPage->pBt->usableSize ){ |
| 61727 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61948 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61728 | 61949 | } |
| 61729 | 61950 | iSize = iEnd - iStart; |
| 61730 | 61951 | iFreeBlk = get2byte(&data[iFreeBlk]); |
| 61731 | 61952 | } |
| 61732 | 61953 | |
| | @@ -61735,25 +61956,25 @@ |
| 61735 | 61956 | ** coalesced onto the end of iPtr. |
| 61736 | 61957 | */ |
| 61737 | 61958 | if( iPtr>hdr+1 ){ |
| 61738 | 61959 | int iPtrEnd = iPtr + get2byte(&data[iPtr+2]); |
| 61739 | 61960 | if( iPtrEnd+3>=iStart ){ |
| 61740 | | - if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61961 | + if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage); |
| 61741 | 61962 | nFrag += iStart - iPtrEnd; |
| 61742 | 61963 | iSize = iEnd - iPtr; |
| 61743 | 61964 | iStart = iPtr; |
| 61744 | 61965 | } |
| 61745 | 61966 | } |
| 61746 | | - if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61967 | + if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); |
| 61747 | 61968 | data[hdr+7] -= nFrag; |
| 61748 | 61969 | } |
| 61749 | 61970 | x = get2byte(&data[hdr+5]); |
| 61750 | 61971 | if( iStart<=x ){ |
| 61751 | 61972 | /* The new freeblock is at the beginning of the cell content area, |
| 61752 | 61973 | ** so just extend the cell content area rather than create another |
| 61753 | 61974 | ** 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); |
| 61755 | 61976 | put2byte(&data[hdr+1], iFreeBlk); |
| 61756 | 61977 | put2byte(&data[hdr+5], iEnd); |
| 61757 | 61978 | }else{ |
| 61758 | 61979 | /* Insert the new freeblock into the freelist */ |
| 61759 | 61980 | put2byte(&data[iPtr], iStart); |
| | @@ -61822,11 +62043,11 @@ |
| 61822 | 62043 | pPage->maxLocal = pBt->maxLocal; |
| 61823 | 62044 | pPage->minLocal = pBt->minLocal; |
| 61824 | 62045 | }else{ |
| 61825 | 62046 | /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is |
| 61826 | 62047 | ** an error. */ |
| 61827 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62048 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61828 | 62049 | } |
| 61829 | 62050 | pPage->max1bytePayload = pBt->max1bytePayload; |
| 61830 | 62051 | return SQLITE_OK; |
| 61831 | 62052 | } |
| 61832 | 62053 | |
| | @@ -61863,11 +62084,11 @@ |
| 61863 | 62084 | hdr = pPage->hdrOffset; |
| 61864 | 62085 | data = pPage->aData; |
| 61865 | 62086 | /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating |
| 61866 | 62087 | ** the b-tree page type. */ |
| 61867 | 62088 | if( decodeFlags(pPage, data[hdr]) ){ |
| 61868 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62089 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61869 | 62090 | } |
| 61870 | 62091 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 61871 | 62092 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| 61872 | 62093 | pPage->nOverflow = 0; |
| 61873 | 62094 | usableSize = pBt->usableSize; |
| | @@ -61882,11 +62103,11 @@ |
| 61882 | 62103 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 61883 | 62104 | ** number of cells on the page. */ |
| 61884 | 62105 | pPage->nCell = get2byte(&data[hdr+3]); |
| 61885 | 62106 | if( pPage->nCell>MX_CELL(pBt) ){ |
| 61886 | 62107 | /* 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); |
| 61888 | 62109 | } |
| 61889 | 62110 | testcase( pPage->nCell==MX_CELL(pBt) ); |
| 61890 | 62111 | /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only |
| 61891 | 62112 | ** possible for a root page of a table that contains no rows) then the |
| 61892 | 62113 | ** offset to the cell content area will equal the page size minus the |
| | @@ -61910,16 +62131,16 @@ |
| 61910 | 62131 | for(i=0; i<pPage->nCell; i++){ |
| 61911 | 62132 | pc = get2byteAligned(&data[cellOffset+i*2]); |
| 61912 | 62133 | testcase( pc==iCellFirst ); |
| 61913 | 62134 | testcase( pc==iCellLast ); |
| 61914 | 62135 | if( pc<iCellFirst || pc>iCellLast ){ |
| 61915 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62136 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61916 | 62137 | } |
| 61917 | 62138 | sz = pPage->xCellSize(pPage, &data[pc]); |
| 61918 | 62139 | testcase( pc+sz==usableSize ); |
| 61919 | 62140 | if( pc+sz>usableSize ){ |
| 61920 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62141 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61921 | 62142 | } |
| 61922 | 62143 | } |
| 61923 | 62144 | if( !pPage->leaf ) iCellLast++; |
| 61924 | 62145 | } |
| 61925 | 62146 | |
| | @@ -61933,30 +62154,30 @@ |
| 61933 | 62154 | u32 next, size; |
| 61934 | 62155 | if( pc<iCellFirst ){ |
| 61935 | 62156 | /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will |
| 61936 | 62157 | ** always be at least one cell before the first freeblock. |
| 61937 | 62158 | */ |
| 61938 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62159 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61939 | 62160 | } |
| 61940 | 62161 | while( 1 ){ |
| 61941 | 62162 | if( pc>iCellLast ){ |
| 61942 | 62163 | /* Freeblock off the end of the page */ |
| 61943 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62164 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61944 | 62165 | } |
| 61945 | 62166 | next = get2byte(&data[pc]); |
| 61946 | 62167 | size = get2byte(&data[pc+2]); |
| 61947 | 62168 | nFree = nFree + size; |
| 61948 | 62169 | if( next<=pc+size+3 ) break; |
| 61949 | 62170 | pc = next; |
| 61950 | 62171 | } |
| 61951 | 62172 | if( next>0 ){ |
| 61952 | 62173 | /* Freeblock not in ascending order */ |
| 61953 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62174 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61954 | 62175 | } |
| 61955 | 62176 | if( pc+size>(unsigned int)usableSize ){ |
| 61956 | 62177 | /* Last freeblock extends past page end */ |
| 61957 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62178 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61958 | 62179 | } |
| 61959 | 62180 | } |
| 61960 | 62181 | |
| 61961 | 62182 | /* At this point, nFree contains the sum of the offset to the start |
| 61962 | 62183 | ** of the cell-content area plus the number of free bytes within |
| | @@ -61964,11 +62185,11 @@ |
| 61964 | 62185 | ** of the page, then the page must be corrupted. This check also |
| 61965 | 62186 | ** serves to verify that the offset to the start of the cell-content |
| 61966 | 62187 | ** area, according to the page header, lies within the page. |
| 61967 | 62188 | */ |
| 61968 | 62189 | if( nFree>usableSize ){ |
| 61969 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 62190 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 61970 | 62191 | } |
| 61971 | 62192 | pPage->nFree = (u16)(nFree - iCellFirst); |
| 61972 | 62193 | pPage->isInit = 1; |
| 61973 | 62194 | return SQLITE_OK; |
| 61974 | 62195 | } |
| | @@ -63495,11 +63716,11 @@ |
| 63495 | 63716 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 63496 | 63717 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 63497 | 63718 | if( eType==PTRMAP_OVERFLOW2 ){ |
| 63498 | 63719 | /* The pointer is always the first 4 bytes of the page in this case. */ |
| 63499 | 63720 | if( get4byte(pPage->aData)!=iFrom ){ |
| 63500 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 63721 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 63501 | 63722 | } |
| 63502 | 63723 | put4byte(pPage->aData, iTo); |
| 63503 | 63724 | }else{ |
| 63504 | 63725 | int i; |
| 63505 | 63726 | int nCell; |
| | @@ -63514,11 +63735,11 @@ |
| 63514 | 63735 | if( eType==PTRMAP_OVERFLOW1 ){ |
| 63515 | 63736 | CellInfo info; |
| 63516 | 63737 | pPage->xParseCell(pPage, pCell, &info); |
| 63517 | 63738 | if( info.nLocal<info.nPayload ){ |
| 63518 | 63739 | if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){ |
| 63519 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 63740 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 63520 | 63741 | } |
| 63521 | 63742 | if( iFrom==get4byte(pCell+info.nSize-4) ){ |
| 63522 | 63743 | put4byte(pCell+info.nSize-4, iTo); |
| 63523 | 63744 | break; |
| 63524 | 63745 | } |
| | @@ -63532,11 +63753,11 @@ |
| 63532 | 63753 | } |
| 63533 | 63754 | |
| 63534 | 63755 | if( i==nCell ){ |
| 63535 | 63756 | if( eType!=PTRMAP_BTREE || |
| 63536 | 63757 | get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){ |
| 63537 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 63758 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 63538 | 63759 | } |
| 63539 | 63760 | put4byte(&pPage->aData[pPage->hdrOffset+8], iTo); |
| 63540 | 63761 | } |
| 63541 | 63762 | } |
| 63542 | 63763 | return SQLITE_OK; |
| | @@ -64630,11 +64851,11 @@ |
| 64630 | 64851 | /* Trying to read or write past the end of the data is an error. The |
| 64631 | 64852 | ** conditional above is really: |
| 64632 | 64853 | ** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] |
| 64633 | 64854 | ** but is recast into its current form to avoid integer overflow problems |
| 64634 | 64855 | */ |
| 64635 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 64856 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 64636 | 64857 | } |
| 64637 | 64858 | |
| 64638 | 64859 | /* Check if data must be read/written to/from the btree page itself. */ |
| 64639 | 64860 | if( offset<pCur->info.nLocal ){ |
| 64640 | 64861 | int a = amt; |
| | @@ -64778,11 +64999,11 @@ |
| 64778 | 64999 | } |
| 64779 | 65000 | } |
| 64780 | 65001 | |
| 64781 | 65002 | if( rc==SQLITE_OK && amt>0 ){ |
| 64782 | 65003 | /* Overflow chain ends prematurely */ |
| 64783 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 65004 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 64784 | 65005 | } |
| 64785 | 65006 | return rc; |
| 64786 | 65007 | } |
| 64787 | 65008 | |
| 64788 | 65009 | /* |
| | @@ -65056,11 +65277,11 @@ |
| 65056 | 65277 | ** if pCur->iPage>=0). But this is not so if the database is corrupted |
| 65057 | 65278 | ** in such a way that page pRoot is linked into a second b-tree table |
| 65058 | 65279 | ** (or the freelist). */ |
| 65059 | 65280 | assert( pRoot->intKey==1 || pRoot->intKey==0 ); |
| 65060 | 65281 | if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){ |
| 65061 | | - return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno); |
| 65282 | + return SQLITE_CORRUPT_PAGE(pCur->pPage); |
| 65062 | 65283 | } |
| 65063 | 65284 | |
| 65064 | 65285 | skip_init: |
| 65065 | 65286 | pCur->ix = 0; |
| 65066 | 65287 | pCur->info.nSize = 0; |
| | @@ -65329,11 +65550,11 @@ |
| 65329 | 65550 | i64 nCellKey; |
| 65330 | 65551 | pCell = findCellPastPtr(pPage, idx); |
| 65331 | 65552 | if( pPage->intKeyLeaf ){ |
| 65332 | 65553 | while( 0x80 <= *(pCell++) ){ |
| 65333 | 65554 | if( pCell>=pPage->aDataEnd ){ |
| 65334 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 65555 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 65335 | 65556 | } |
| 65336 | 65557 | } |
| 65337 | 65558 | } |
| 65338 | 65559 | getVarint(pCell, (u64*)&nCellKey); |
| 65339 | 65560 | if( nCellKey<intKey ){ |
| | @@ -65403,11 +65624,11 @@ |
| 65403 | 65624 | testcase( nCell<0 ); /* True if key size is 2^32 or more */ |
| 65404 | 65625 | testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */ |
| 65405 | 65626 | testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */ |
| 65406 | 65627 | testcase( nCell==2 ); /* Minimum legal index key size */ |
| 65407 | 65628 | if( nCell<2 ){ |
| 65408 | | - rc = SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 65629 | + rc = SQLITE_CORRUPT_PAGE(pPage); |
| 65409 | 65630 | goto moveto_finish; |
| 65410 | 65631 | } |
| 65411 | 65632 | pCellKey = sqlite3Malloc( nCell+18 ); |
| 65412 | 65633 | if( pCellKey==0 ){ |
| 65413 | 65634 | rc = SQLITE_NOMEM_BKPT; |
| | @@ -66206,11 +66427,11 @@ |
| 66206 | 66427 | if( pInfo->nLocal==pInfo->nPayload ){ |
| 66207 | 66428 | return SQLITE_OK; /* No overflow pages. Return without doing anything */ |
| 66208 | 66429 | } |
| 66209 | 66430 | if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){ |
| 66210 | 66431 | /* Cell extends past end of page */ |
| 66211 | | - return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 66432 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 66212 | 66433 | } |
| 66213 | 66434 | ovflPgno = get4byte(pCell + pInfo->nSize - 4); |
| 66214 | 66435 | pBt = pPage->pBt; |
| 66215 | 66436 | assert( pBt->usableSize > 4 ); |
| 66216 | 66437 | ovflPageSize = pBt->usableSize - 4; |
| | @@ -72103,11 +72324,15 @@ |
| 72103 | 72324 | const char *zNeg = ""; |
| 72104 | 72325 | int rc = SQLITE_OK; |
| 72105 | 72326 | |
| 72106 | 72327 | assert( pExpr!=0 ); |
| 72107 | 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 |
| 72108 | 72332 | if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; |
| 72333 | +#endif |
| 72109 | 72334 | |
| 72110 | 72335 | /* Compressed expressions only appear when parsing the DEFAULT clause |
| 72111 | 72336 | ** on a table column definition, and hence only when pCtx==0. This |
| 72112 | 72337 | ** check ensures that an EP_TokenOnly expression is never passed down |
| 72113 | 72338 | ** into valueFromFunction(). */ |
| | @@ -74813,10 +75038,11 @@ |
| 74813 | 75038 | needXcommit = 1; |
| 74814 | 75039 | sqlite3BtreeEnter(pBt); |
| 74815 | 75040 | pPager = sqlite3BtreePager(pBt); |
| 74816 | 75041 | if( db->aDb[i].safety_level!=PAGER_SYNCHRONOUS_OFF |
| 74817 | 75042 | && aMJNeeded[sqlite3PagerGetJournalMode(pPager)] |
| 75043 | + && sqlite3PagerIsMemdb(pPager)==0 |
| 74818 | 75044 | ){ |
| 74819 | 75045 | assert( i!=1 ); |
| 74820 | 75046 | nTrans++; |
| 74821 | 75047 | } |
| 74822 | 75048 | rc = sqlite3PagerExclusiveLock(pPager); |
| | @@ -90556,11 +90782,10 @@ |
| 90556 | 90782 | if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort; |
| 90557 | 90783 | if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort; |
| 90558 | 90784 | if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort; |
| 90559 | 90785 | if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort; |
| 90560 | 90786 | if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort; |
| 90561 | | - if( sqlite3WalkExpr(pWalker, p->pOffset) ) return WRC_Abort; |
| 90562 | 90787 | return WRC_Continue; |
| 90563 | 90788 | } |
| 90564 | 90789 | |
| 90565 | 90790 | /* |
| 90566 | 90791 | ** Walk the parse trees associated with all subqueries in the |
| | @@ -91824,12 +92049,11 @@ |
| 91824 | 92049 | /* Resolve the expressions in the LIMIT and OFFSET clauses. These |
| 91825 | 92050 | ** are not allowed to refer to any names, so pass an empty NameContext. |
| 91826 | 92051 | */ |
| 91827 | 92052 | memset(&sNC, 0, sizeof(sNC)); |
| 91828 | 92053 | sNC.pParse = pParse; |
| 91829 | | - if( sqlite3ResolveExprNames(&sNC, p->pLimit) || |
| 91830 | | - sqlite3ResolveExprNames(&sNC, p->pOffset) ){ |
| 92054 | + if( sqlite3ResolveExprNames(&sNC, p->pLimit) ){ |
| 91831 | 92055 | return WRC_Abort; |
| 91832 | 92056 | } |
| 91833 | 92057 | |
| 91834 | 92058 | /* If the SF_Converted flags is set, then this Select object was |
| 91835 | 92059 | ** was created by the convertCompoundSelectToSubquery() function. |
| | @@ -92826,11 +93050,10 @@ |
| 92826 | 93050 | static void heightOfSelect(Select *p, int *pnHeight){ |
| 92827 | 93051 | if( p ){ |
| 92828 | 93052 | heightOfExpr(p->pWhere, pnHeight); |
| 92829 | 93053 | heightOfExpr(p->pHaving, pnHeight); |
| 92830 | 93054 | heightOfExpr(p->pLimit, pnHeight); |
| 92831 | | - heightOfExpr(p->pOffset, pnHeight); |
| 92832 | 93055 | heightOfExprList(p->pEList, pnHeight); |
| 92833 | 93056 | heightOfExprList(p->pGroupBy, pnHeight); |
| 92834 | 93057 | heightOfExprList(p->pOrderBy, pnHeight); |
| 92835 | 93058 | heightOfSelect(p->pPrior, pnHeight); |
| 92836 | 93059 | } |
| | @@ -93625,11 +93848,10 @@ |
| 93625 | 93848 | pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags); |
| 93626 | 93849 | pNew->op = p->op; |
| 93627 | 93850 | pNew->pNext = pNext; |
| 93628 | 93851 | pNew->pPrior = 0; |
| 93629 | 93852 | pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); |
| 93630 | | - pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); |
| 93631 | 93853 | pNew->iLimit = 0; |
| 93632 | 93854 | pNew->iOffset = 0; |
| 93633 | 93855 | pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; |
| 93634 | 93856 | pNew->addrOpenEphm[0] = -1; |
| 93635 | 93857 | pNew->addrOpenEphm[1] = -1; |
| | @@ -94262,11 +94484,10 @@ |
| 94262 | 94484 | testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate ); |
| 94263 | 94485 | return 0; /* No DISTINCT keyword and no aggregate functions */ |
| 94264 | 94486 | } |
| 94265 | 94487 | assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */ |
| 94266 | 94488 | if( p->pLimit ) return 0; /* Has no LIMIT clause */ |
| 94267 | | - assert( p->pOffset==0 ); /* No LIMIT means no OFFSET */ |
| 94268 | 94489 | if( p->pWhere ) return 0; /* Has no WHERE clause */ |
| 94269 | 94490 | pSrc = p->pSrc; |
| 94270 | 94491 | assert( pSrc!=0 ); |
| 94271 | 94492 | if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */ |
| 94272 | 94493 | if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */ |
| | @@ -94352,20 +94573,19 @@ |
| 94352 | 94573 | ** If the RHS of the IN operator is a list or a more complex subquery, then |
| 94353 | 94574 | ** an ephemeral table might need to be generated from the RHS and then |
| 94354 | 94575 | ** pX->iTable made to point to the ephemeral table instead of an |
| 94355 | 94576 | ** existing table. |
| 94356 | 94577 | ** |
| 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. |
| 94363 | 94583 | ** |
| 94364 | 94584 | ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate |
| 94365 | 94585 | ** 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 |
| 94367 | 94587 | ** to be unique - either because it is an INTEGER PRIMARY KEY or due to |
| 94368 | 94588 | ** a UNIQUE constraint or index. |
| 94369 | 94589 | ** |
| 94370 | 94590 | ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used |
| 94371 | 94591 | ** for fast set membership tests) then an epheremal table must |
| | @@ -94902,10 +95122,11 @@ |
| 94902 | 95122 | ** preexisting limit is discarded in place of the new LIMIT 1. |
| 94903 | 95123 | */ |
| 94904 | 95124 | Select *pSel; /* SELECT statement to encode */ |
| 94905 | 95125 | SelectDest dest; /* How to deal with SELECT result */ |
| 94906 | 95126 | int nReg; /* Registers to allocate */ |
| 95127 | + Expr *pLimit; /* New limit expression */ |
| 94907 | 95128 | |
| 94908 | 95129 | testcase( pExpr->op==TK_EXISTS ); |
| 94909 | 95130 | testcase( pExpr->op==TK_SELECT ); |
| 94910 | 95131 | assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT ); |
| 94911 | 95132 | assert( ExprHasProperty(pExpr, EP_xIsSelect) ); |
| | @@ -94923,13 +95144,17 @@ |
| 94923 | 95144 | }else{ |
| 94924 | 95145 | dest.eDest = SRT_Exists; |
| 94925 | 95146 | sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm); |
| 94926 | 95147 | VdbeComment((v, "Init EXISTS result")); |
| 94927 | 95148 | } |
| 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 | + } |
| 94931 | 95156 | pSel->iLimit = 0; |
| 94932 | 95157 | pSel->selFlags &= ~SF_MultiValue; |
| 94933 | 95158 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 94934 | 95159 | return 0; |
| 94935 | 95160 | } |
| | @@ -100713,13 +100938,10 @@ |
| 100713 | 100938 | return 1; |
| 100714 | 100939 | } |
| 100715 | 100940 | if( sqlite3FixExpr(pFix, pSelect->pLimit) ){ |
| 100716 | 100941 | return 1; |
| 100717 | 100942 | } |
| 100718 | | - if( sqlite3FixExpr(pFix, pSelect->pOffset) ){ |
| 100719 | | - return 1; |
| 100720 | | - } |
| 100721 | 100943 | pSelect = pSelect->pPrior; |
| 100722 | 100944 | } |
| 100723 | 100945 | return 0; |
| 100724 | 100946 | } |
| 100725 | 100947 | SQLITE_PRIVATE int sqlite3FixExpr( |
| | @@ -106085,11 +106307,10 @@ |
| 106085 | 106307 | Parse *pParse, /* Parsing context */ |
| 106086 | 106308 | Table *pView, /* View definition */ |
| 106087 | 106309 | Expr *pWhere, /* Optional WHERE clause to be added */ |
| 106088 | 106310 | ExprList *pOrderBy, /* Optional ORDER BY clause */ |
| 106089 | 106311 | Expr *pLimit, /* Optional LIMIT clause */ |
| 106090 | | - Expr *pOffset, /* Optional OFFSET clause */ |
| 106091 | 106312 | int iCur /* Cursor number for ephemeral table */ |
| 106092 | 106313 | ){ |
| 106093 | 106314 | SelectDest dest; |
| 106094 | 106315 | Select *pSel; |
| 106095 | 106316 | SrcList *pFrom; |
| | @@ -106103,11 +106324,11 @@ |
| 106103 | 106324 | pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName); |
| 106104 | 106325 | assert( pFrom->a[0].pOn==0 ); |
| 106105 | 106326 | assert( pFrom->a[0].pUsing==0 ); |
| 106106 | 106327 | } |
| 106107 | 106328 | pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy, |
| 106108 | | - SF_IncludeHidden, pLimit, pOffset); |
| 106329 | + SF_IncludeHidden, pLimit); |
| 106109 | 106330 | sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); |
| 106110 | 106331 | sqlite3Select(pParse, pSel, &dest); |
| 106111 | 106332 | sqlite3SelectDelete(db, pSel); |
| 106112 | 106333 | } |
| 106113 | 106334 | #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ |
| | @@ -106125,11 +106346,10 @@ |
| 106125 | 106346 | Parse *pParse, /* The parser context */ |
| 106126 | 106347 | SrcList *pSrc, /* the FROM clause -- which tables to scan */ |
| 106127 | 106348 | Expr *pWhere, /* The WHERE clause. May be null */ |
| 106128 | 106349 | ExprList *pOrderBy, /* The ORDER BY clause. May be null */ |
| 106129 | 106350 | Expr *pLimit, /* The LIMIT clause. May be null */ |
| 106130 | | - Expr *pOffset, /* The OFFSET clause. May be null */ |
| 106131 | 106351 | char *zStmtType /* Either DELETE or UPDATE. For err msgs. */ |
| 106132 | 106352 | ){ |
| 106133 | 106353 | sqlite3 *db = pParse->db; |
| 106134 | 106354 | Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */ |
| 106135 | 106355 | Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */ |
| | @@ -106142,21 +106362,17 @@ |
| 106142 | 106362 | */ |
| 106143 | 106363 | if( pOrderBy && pLimit==0 ) { |
| 106144 | 106364 | sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType); |
| 106145 | 106365 | sqlite3ExprDelete(pParse->db, pWhere); |
| 106146 | 106366 | sqlite3ExprListDelete(pParse->db, pOrderBy); |
| 106147 | | - sqlite3ExprDelete(pParse->db, pLimit); |
| 106148 | | - sqlite3ExprDelete(pParse->db, pOffset); |
| 106149 | 106367 | return 0; |
| 106150 | 106368 | } |
| 106151 | 106369 | |
| 106152 | 106370 | /* We only need to generate a select expression if there |
| 106153 | 106371 | ** is a limit/offset term to enforce. |
| 106154 | 106372 | */ |
| 106155 | 106373 | if( pLimit == 0 ) { |
| 106156 | | - /* if pLimit is null, pOffset will always be null as well. */ |
| 106157 | | - assert( pOffset == 0 ); |
| 106158 | 106374 | return pWhere; |
| 106159 | 106375 | } |
| 106160 | 106376 | |
| 106161 | 106377 | /* Generate a select expression tree to enforce the limit/offset |
| 106162 | 106378 | ** term for the DELETE or UPDATE statement. For example: |
| | @@ -106199,11 +106415,11 @@ |
| 106199 | 106415 | pSrc->a[0].pTab = pTab; |
| 106200 | 106416 | pSrc->a[0].pIBIndex = 0; |
| 106201 | 106417 | |
| 106202 | 106418 | /* generate the SELECT expression tree. */ |
| 106203 | 106419 | pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0, |
| 106204 | | - pOrderBy,0,pLimit,pOffset |
| 106420 | + pOrderBy,0,pLimit |
| 106205 | 106421 | ); |
| 106206 | 106422 | |
| 106207 | 106423 | /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ |
| 106208 | 106424 | pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0); |
| 106209 | 106425 | sqlite3PExprAddSelect(pParse, pInClause, pSelect); |
| | @@ -106222,12 +106438,11 @@ |
| 106222 | 106438 | SQLITE_PRIVATE void sqlite3DeleteFrom( |
| 106223 | 106439 | Parse *pParse, /* The parser context */ |
| 106224 | 106440 | SrcList *pTabList, /* The table from which we should delete things */ |
| 106225 | 106441 | Expr *pWhere, /* The WHERE clause. May be null */ |
| 106226 | 106442 | 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 */ |
| 106229 | 106444 | ){ |
| 106230 | 106445 | Vdbe *v; /* The virtual database engine */ |
| 106231 | 106446 | Table *pTab; /* The table from which records will be deleted */ |
| 106232 | 106447 | int i; /* Loop counter */ |
| 106233 | 106448 | WhereInfo *pWInfo; /* Information about the WHERE clause */ |
| | @@ -106296,14 +106511,14 @@ |
| 106296 | 106511 | #endif |
| 106297 | 106512 | |
| 106298 | 106513 | #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 106299 | 106514 | if( !isView ){ |
| 106300 | 106515 | pWhere = sqlite3LimitWhere( |
| 106301 | | - pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "DELETE" |
| 106516 | + pParse, pTabList, pWhere, pOrderBy, pLimit, "DELETE" |
| 106302 | 106517 | ); |
| 106303 | 106518 | pOrderBy = 0; |
| 106304 | | - pLimit = pOffset = 0; |
| 106519 | + pLimit = 0; |
| 106305 | 106520 | } |
| 106306 | 106521 | #endif |
| 106307 | 106522 | |
| 106308 | 106523 | /* If pTab is really a view, make sure it has been initialized. |
| 106309 | 106524 | */ |
| | @@ -106351,15 +106566,15 @@ |
| 106351 | 106566 | ** an ephemeral table. |
| 106352 | 106567 | */ |
| 106353 | 106568 | #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) |
| 106354 | 106569 | if( isView ){ |
| 106355 | 106570 | sqlite3MaterializeView(pParse, pTab, |
| 106356 | | - pWhere, pOrderBy, pLimit, pOffset, iTabCur |
| 106571 | + pWhere, pOrderBy, pLimit, iTabCur |
| 106357 | 106572 | ); |
| 106358 | 106573 | iDataCur = iIdxCur = iTabCur; |
| 106359 | 106574 | pOrderBy = 0; |
| 106360 | | - pLimit = pOffset = 0; |
| 106575 | + pLimit = 0; |
| 106361 | 106576 | } |
| 106362 | 106577 | #endif |
| 106363 | 106578 | |
| 106364 | 106579 | /* Resolve the column names in the WHERE clause. |
| 106365 | 106580 | */ |
| | @@ -106602,11 +106817,10 @@ |
| 106602 | 106817 | sqlite3SrcListDelete(db, pTabList); |
| 106603 | 106818 | sqlite3ExprDelete(db, pWhere); |
| 106604 | 106819 | #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) |
| 106605 | 106820 | sqlite3ExprListDelete(db, pOrderBy); |
| 106606 | 106821 | sqlite3ExprDelete(db, pLimit); |
| 106607 | | - sqlite3ExprDelete(db, pOffset); |
| 106608 | 106822 | #endif |
| 106609 | 106823 | sqlite3DbFree(db, aToOpen); |
| 106610 | 106824 | return; |
| 106611 | 106825 | } |
| 106612 | 106826 | /* Make sure "isView" and other macros defined above are undefined. Otherwise |
| | @@ -109568,11 +109782,11 @@ |
| 109568 | 109782 | iSkip = sqlite3VdbeMakeLabel(v); |
| 109569 | 109783 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v); |
| 109570 | 109784 | } |
| 109571 | 109785 | |
| 109572 | 109786 | pParse->disableTriggers = 1; |
| 109573 | | - sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0, 0); |
| 109787 | + sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0); |
| 109574 | 109788 | pParse->disableTriggers = 0; |
| 109575 | 109789 | |
| 109576 | 109790 | /* If the DELETE has generated immediate foreign key constraint |
| 109577 | 109791 | ** violations, halt the VDBE and return an error at this point, before |
| 109578 | 109792 | ** any modifications to the schema are made. This is because statement |
| | @@ -110126,11 +110340,11 @@ |
| 110126 | 110340 | } |
| 110127 | 110341 | pSelect = sqlite3SelectNew(pParse, |
| 110128 | 110342 | sqlite3ExprListAppend(pParse, 0, pRaise), |
| 110129 | 110343 | sqlite3SrcListAppend(db, 0, &tFrom, 0), |
| 110130 | 110344 | pWhere, |
| 110131 | | - 0, 0, 0, 0, 0, 0 |
| 110345 | + 0, 0, 0, 0, 0 |
| 110132 | 110346 | ); |
| 110133 | 110347 | pWhere = 0; |
| 110134 | 110348 | } |
| 110135 | 110349 | |
| 110136 | 110350 | /* Disable lookaside memory allocation */ |
| | @@ -112274,11 +112488,10 @@ |
| 112274 | 112488 | return 0; /* SELECT may not have a GROUP BY clause */ |
| 112275 | 112489 | } |
| 112276 | 112490 | if( pSelect->pLimit ){ |
| 112277 | 112491 | return 0; /* SELECT may not have a LIMIT clause */ |
| 112278 | 112492 | } |
| 112279 | | - assert( pSelect->pOffset==0 ); /* Must be so if pLimit==0 */ |
| 112280 | 112493 | if( pSelect->pPrior ){ |
| 112281 | 112494 | return 0; /* SELECT may not be a compound query */ |
| 112282 | 112495 | } |
| 112283 | 112496 | if( pSelect->selFlags & SF_Distinct ){ |
| 112284 | 112497 | return 0; /* SELECT may not be DISTINCT */ |
| | @@ -118173,11 +118386,10 @@ |
| 118173 | 118386 | sqlite3ExprDelete(db, p->pWhere); |
| 118174 | 118387 | sqlite3ExprListDelete(db, p->pGroupBy); |
| 118175 | 118388 | sqlite3ExprDelete(db, p->pHaving); |
| 118176 | 118389 | sqlite3ExprListDelete(db, p->pOrderBy); |
| 118177 | 118390 | sqlite3ExprDelete(db, p->pLimit); |
| 118178 | | - sqlite3ExprDelete(db, p->pOffset); |
| 118179 | 118391 | if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith); |
| 118180 | 118392 | if( bFree ) sqlite3DbFreeNN(db, p); |
| 118181 | 118393 | p = pPrior; |
| 118182 | 118394 | bFree = 1; |
| 118183 | 118395 | } |
| | @@ -118206,12 +118418,11 @@ |
| 118206 | 118418 | Expr *pWhere, /* the WHERE clause */ |
| 118207 | 118419 | ExprList *pGroupBy, /* the GROUP BY clause */ |
| 118208 | 118420 | Expr *pHaving, /* the HAVING clause */ |
| 118209 | 118421 | ExprList *pOrderBy, /* the ORDER BY clause */ |
| 118210 | 118422 | 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 */ |
| 118213 | 118424 | ){ |
| 118214 | 118425 | Select *pNew; |
| 118215 | 118426 | Select standin; |
| 118216 | 118427 | pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) ); |
| 118217 | 118428 | if( pNew==0 ){ |
| | @@ -118240,14 +118451,11 @@ |
| 118240 | 118451 | pNew->pHaving = pHaving; |
| 118241 | 118452 | pNew->pOrderBy = pOrderBy; |
| 118242 | 118453 | pNew->pPrior = 0; |
| 118243 | 118454 | pNew->pNext = 0; |
| 118244 | 118455 | pNew->pLimit = pLimit; |
| 118245 | | - pNew->pOffset = pOffset; |
| 118246 | 118456 | pNew->pWith = 0; |
| 118247 | | - assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 |
| 118248 | | - || pParse->db->mallocFailed!=0 ); |
| 118249 | 118457 | if( pParse->db->mallocFailed ) { |
| 118250 | 118458 | clearSelect(pParse->db, pNew, pNew!=&standin); |
| 118251 | 118459 | pNew = 0; |
| 118252 | 118460 | }else{ |
| 118253 | 118461 | assert( pNew->pSrc!=0 || pParse->nErr>0 ); |
| | @@ -119973,69 +120181,72 @@ |
| 119973 | 120181 | } |
| 119974 | 120182 | |
| 119975 | 120183 | |
| 119976 | 120184 | /* |
| 119977 | 120185 | ** 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 |
| 119979 | 120187 | ** that appear in the original SQL statement after the LIMIT and OFFSET |
| 119980 | 120188 | ** keywords. Or NULL if those keywords are omitted. iLimit and iOffset |
| 119981 | 120189 | ** are the integer memory register numbers for counters used to compute |
| 119982 | 120190 | ** the limit and offset. If there is no limit and/or offset, then |
| 119983 | 120191 | ** iLimit and iOffset are negative. |
| 119984 | 120192 | ** |
| 119985 | 120193 | ** 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) |
| 119988 | 120196 | ** prior to calling this routine. |
| 119989 | 120197 | ** |
| 119990 | 120198 | ** The iOffset register (if it exists) is initialized to the value |
| 119991 | 120199 | ** of the OFFSET. The iLimit register is initialized to LIMIT. Register |
| 119992 | 120200 | ** iOffset+1 is initialized to LIMIT+OFFSET. |
| 119993 | 120201 | ** |
| 119994 | | -** Only if pLimit!=0 or pOffset!=0 do the limit registers get |
| 120202 | +** Only if pLimit->pLeft!=0 do the limit registers get |
| 119995 | 120203 | ** redefined. The UNION ALL operator uses this property to force |
| 119996 | 120204 | ** the reuse of the same limit and offset registers across multiple |
| 119997 | 120205 | ** SELECT statements. |
| 119998 | 120206 | */ |
| 119999 | 120207 | static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ |
| 120000 | 120208 | Vdbe *v = 0; |
| 120001 | 120209 | int iLimit = 0; |
| 120002 | 120210 | int iOffset; |
| 120003 | 120211 | int n; |
| 120212 | + Expr *pLimit = p->pLimit; |
| 120213 | + |
| 120004 | 120214 | if( p->iLimit ) return; |
| 120005 | 120215 | |
| 120006 | 120216 | /* |
| 120007 | 120217 | ** "LIMIT -1" always shows all rows. There is some |
| 120008 | 120218 | ** controversy about what the correct behavior should be. |
| 120009 | 120219 | ** The current implementation interprets "LIMIT 0" to mean |
| 120010 | 120220 | ** no rows. |
| 120011 | 120221 | */ |
| 120012 | 120222 | 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 ); |
| 120015 | 120226 | p->iLimit = iLimit = ++pParse->nMem; |
| 120016 | 120227 | v = sqlite3GetVdbe(pParse); |
| 120017 | 120228 | assert( v!=0 ); |
| 120018 | | - if( sqlite3ExprIsInteger(p->pLimit, &n) ){ |
| 120229 | + if( sqlite3ExprIsInteger(pLimit->pLeft, &n) ){ |
| 120019 | 120230 | sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit); |
| 120020 | 120231 | VdbeComment((v, "LIMIT counter")); |
| 120021 | 120232 | if( n==0 ){ |
| 120022 | 120233 | sqlite3VdbeGoto(v, iBreak); |
| 120023 | 120234 | }else if( n>=0 && p->nSelectRow>sqlite3LogEst((u64)n) ){ |
| 120024 | 120235 | p->nSelectRow = sqlite3LogEst((u64)n); |
| 120025 | 120236 | p->selFlags |= SF_FixedLimit; |
| 120026 | 120237 | } |
| 120027 | 120238 | }else{ |
| 120028 | | - sqlite3ExprCode(pParse, p->pLimit, iLimit); |
| 120239 | + sqlite3ExprCode(pParse, pLimit->pLeft, iLimit); |
| 120029 | 120240 | sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v); |
| 120030 | 120241 | VdbeComment((v, "LIMIT counter")); |
| 120031 | 120242 | sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v); |
| 120032 | 120243 | } |
| 120033 | | - if( p->pOffset ){ |
| 120244 | + if( pLimit->pRight ){ |
| 120034 | 120245 | p->iOffset = iOffset = ++pParse->nMem; |
| 120035 | 120246 | pParse->nMem++; /* Allocate an extra register for limit+offset */ |
| 120036 | | - sqlite3ExprCode(pParse, p->pOffset, iOffset); |
| 120247 | + sqlite3ExprCode(pParse, pLimit->pRight, iOffset); |
| 120037 | 120248 | sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v); |
| 120038 | 120249 | VdbeComment((v, "OFFSET counter")); |
| 120039 | 120250 | sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset); |
| 120040 | 120251 | VdbeComment((v, "LIMIT+OFFSET")); |
| 120041 | 120252 | } |
| | @@ -120161,11 +120372,11 @@ |
| 120161 | 120372 | int eDest = SRT_Fifo; /* How to write to Queue */ |
| 120162 | 120373 | SelectDest destQueue; /* SelectDest targetting the Queue table */ |
| 120163 | 120374 | int i; /* Loop counter */ |
| 120164 | 120375 | int rc; /* Result code */ |
| 120165 | 120376 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 120166 | | - Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */ |
| 120377 | + Expr *pLimit; /* Saved LIMIT and OFFSET */ |
| 120167 | 120378 | int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */ |
| 120168 | 120379 | |
| 120169 | 120380 | /* Obtain authorization to do a recursive query */ |
| 120170 | 120381 | if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return; |
| 120171 | 120382 | |
| | @@ -120172,14 +120383,13 @@ |
| 120172 | 120383 | /* Process the LIMIT and OFFSET clauses, if they exist */ |
| 120173 | 120384 | addrBreak = sqlite3VdbeMakeLabel(v); |
| 120174 | 120385 | p->nSelectRow = 320; /* 4 billion rows */ |
| 120175 | 120386 | computeLimitRegisters(pParse, p, addrBreak); |
| 120176 | 120387 | pLimit = p->pLimit; |
| 120177 | | - pOffset = p->pOffset; |
| 120178 | 120388 | regLimit = p->iLimit; |
| 120179 | 120389 | regOffset = p->iOffset; |
| 120180 | | - p->pLimit = p->pOffset = 0; |
| 120390 | + p->pLimit = 0; |
| 120181 | 120391 | p->iLimit = p->iOffset = 0; |
| 120182 | 120392 | pOrderBy = p->pOrderBy; |
| 120183 | 120393 | |
| 120184 | 120394 | /* Locate the cursor number of the Current table */ |
| 120185 | 120395 | for(i=0; ALWAYS(i<pSrc->nSrc); i++){ |
| | @@ -120268,11 +120478,10 @@ |
| 120268 | 120478 | |
| 120269 | 120479 | end_of_recursive_query: |
| 120270 | 120480 | sqlite3ExprListDelete(pParse->db, p->pOrderBy); |
| 120271 | 120481 | p->pOrderBy = pOrderBy; |
| 120272 | 120482 | p->pLimit = pLimit; |
| 120273 | | - p->pOffset = pOffset; |
| 120274 | 120483 | return; |
| 120275 | 120484 | } |
| 120276 | 120485 | #endif /* SQLITE_OMIT_CTE */ |
| 120277 | 120486 | |
| 120278 | 120487 | /* Forward references */ |
| | @@ -120304,11 +120513,10 @@ |
| 120304 | 120513 | assert( p->selFlags & SF_MultiValue ); |
| 120305 | 120514 | do{ |
| 120306 | 120515 | assert( p->selFlags & SF_Values ); |
| 120307 | 120516 | assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 120308 | 120517 | assert( p->pLimit==0 ); |
| 120309 | | - assert( p->pOffset==0 ); |
| 120310 | 120518 | assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr ); |
| 120311 | 120519 | if( p->pPrior==0 ) break; |
| 120312 | 120520 | assert( p->pPrior->pNext==p ); |
| 120313 | 120521 | p = p->pPrior; |
| 120314 | 120522 | nRow++; |
| | @@ -120431,15 +120639,13 @@ |
| 120431 | 120639 | int nLimit; |
| 120432 | 120640 | assert( !pPrior->pLimit ); |
| 120433 | 120641 | pPrior->iLimit = p->iLimit; |
| 120434 | 120642 | pPrior->iOffset = p->iOffset; |
| 120435 | 120643 | pPrior->pLimit = p->pLimit; |
| 120436 | | - pPrior->pOffset = p->pOffset; |
| 120437 | 120644 | explainSetInteger(iSub1, pParse->iNextSelectId); |
| 120438 | 120645 | rc = sqlite3Select(pParse, pPrior, &dest); |
| 120439 | 120646 | p->pLimit = 0; |
| 120440 | | - p->pOffset = 0; |
| 120441 | 120647 | if( rc ){ |
| 120442 | 120648 | goto multi_select_end; |
| 120443 | 120649 | } |
| 120444 | 120650 | p->pPrior = 0; |
| 120445 | 120651 | p->iLimit = pPrior->iLimit; |
| | @@ -120457,11 +120663,11 @@ |
| 120457 | 120663 | testcase( rc!=SQLITE_OK ); |
| 120458 | 120664 | pDelete = p->pPrior; |
| 120459 | 120665 | p->pPrior = pPrior; |
| 120460 | 120666 | p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow); |
| 120461 | 120667 | if( pPrior->pLimit |
| 120462 | | - && sqlite3ExprIsInteger(pPrior->pLimit, &nLimit) |
| 120668 | + && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit) |
| 120463 | 120669 | && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit) |
| 120464 | 120670 | ){ |
| 120465 | 120671 | p->nSelectRow = sqlite3LogEst((u64)nLimit); |
| 120466 | 120672 | } |
| 120467 | 120673 | if( addr ){ |
| | @@ -120472,11 +120678,11 @@ |
| 120472 | 120678 | case TK_EXCEPT: |
| 120473 | 120679 | case TK_UNION: { |
| 120474 | 120680 | int unionTab; /* Cursor number of the temporary table holding result */ |
| 120475 | 120681 | u8 op = 0; /* One of the SRT_ operations to apply to self */ |
| 120476 | 120682 | 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 */ |
| 120478 | 120684 | int addr; |
| 120479 | 120685 | SelectDest uniondest; |
| 120480 | 120686 | |
| 120481 | 120687 | testcase( p->op==TK_EXCEPT ); |
| 120482 | 120688 | testcase( p->op==TK_UNION ); |
| | @@ -120484,11 +120690,10 @@ |
| 120484 | 120690 | if( dest.eDest==priorOp ){ |
| 120485 | 120691 | /* We can reuse a temporary table generated by a SELECT to our |
| 120486 | 120692 | ** right. |
| 120487 | 120693 | */ |
| 120488 | 120694 | assert( p->pLimit==0 ); /* Not allowed on leftward elements */ |
| 120489 | | - assert( p->pOffset==0 ); /* Not allowed on leftward elements */ |
| 120490 | 120695 | unionTab = dest.iSDParm; |
| 120491 | 120696 | }else{ |
| 120492 | 120697 | /* We will need to create our own temporary table to hold the |
| 120493 | 120698 | ** intermediate results. |
| 120494 | 120699 | */ |
| | @@ -120520,12 +120725,10 @@ |
| 120520 | 120725 | op = SRT_Union; |
| 120521 | 120726 | } |
| 120522 | 120727 | p->pPrior = 0; |
| 120523 | 120728 | pLimit = p->pLimit; |
| 120524 | 120729 | p->pLimit = 0; |
| 120525 | | - pOffset = p->pOffset; |
| 120526 | | - p->pOffset = 0; |
| 120527 | 120730 | uniondest.eDest = op; |
| 120528 | 120731 | explainSetInteger(iSub2, pParse->iNextSelectId); |
| 120529 | 120732 | rc = sqlite3Select(pParse, p, &uniondest); |
| 120530 | 120733 | testcase( rc!=SQLITE_OK ); |
| 120531 | 120734 | /* Query flattening in sqlite3Select() might refill p->pOrderBy. |
| | @@ -120537,11 +120740,10 @@ |
| 120537 | 120740 | if( p->op==TK_UNION ){ |
| 120538 | 120741 | p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow); |
| 120539 | 120742 | } |
| 120540 | 120743 | sqlite3ExprDelete(db, p->pLimit); |
| 120541 | 120744 | p->pLimit = pLimit; |
| 120542 | | - p->pOffset = pOffset; |
| 120543 | 120745 | p->iLimit = 0; |
| 120544 | 120746 | p->iOffset = 0; |
| 120545 | 120747 | |
| 120546 | 120748 | /* Convert the data in the temporary table into whatever form |
| 120547 | 120749 | ** it is that we currently need. |
| | @@ -120565,11 +120767,11 @@ |
| 120565 | 120767 | break; |
| 120566 | 120768 | } |
| 120567 | 120769 | default: assert( p->op==TK_INTERSECT ); { |
| 120568 | 120770 | int tab1, tab2; |
| 120569 | 120771 | int iCont, iBreak, iStart; |
| 120570 | | - Expr *pLimit, *pOffset; |
| 120772 | + Expr *pLimit; |
| 120571 | 120773 | int addr; |
| 120572 | 120774 | SelectDest intersectdest; |
| 120573 | 120775 | int r1; |
| 120574 | 120776 | |
| 120575 | 120777 | /* INTERSECT is different from the others since it requires |
| | @@ -120601,22 +120803,19 @@ |
| 120601 | 120803 | assert( p->addrOpenEphm[1] == -1 ); |
| 120602 | 120804 | p->addrOpenEphm[1] = addr; |
| 120603 | 120805 | p->pPrior = 0; |
| 120604 | 120806 | pLimit = p->pLimit; |
| 120605 | 120807 | p->pLimit = 0; |
| 120606 | | - pOffset = p->pOffset; |
| 120607 | | - p->pOffset = 0; |
| 120608 | 120808 | intersectdest.iSDParm = tab2; |
| 120609 | 120809 | explainSetInteger(iSub2, pParse->iNextSelectId); |
| 120610 | 120810 | rc = sqlite3Select(pParse, p, &intersectdest); |
| 120611 | 120811 | testcase( rc!=SQLITE_OK ); |
| 120612 | 120812 | pDelete = p->pPrior; |
| 120613 | 120813 | p->pPrior = pPrior; |
| 120614 | 120814 | if( p->nSelectRow>pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow; |
| 120615 | 120815 | sqlite3ExprDelete(db, p->pLimit); |
| 120616 | 120816 | p->pLimit = pLimit; |
| 120617 | | - p->pOffset = pOffset; |
| 120618 | 120817 | |
| 120619 | 120818 | /* Generate code to take the intersection of the two temporary |
| 120620 | 120819 | ** tables. |
| 120621 | 120820 | */ |
| 120622 | 120821 | assert( p->pEList ); |
| | @@ -121091,12 +121290,10 @@ |
| 121091 | 121290 | }else{ |
| 121092 | 121291 | regLimitA = regLimitB = 0; |
| 121093 | 121292 | } |
| 121094 | 121293 | sqlite3ExprDelete(db, p->pLimit); |
| 121095 | 121294 | p->pLimit = 0; |
| 121096 | | - sqlite3ExprDelete(db, p->pOffset); |
| 121097 | | - p->pOffset = 0; |
| 121098 | 121295 | |
| 121099 | 121296 | regAddrA = ++pParse->nMem; |
| 121100 | 121297 | regAddrB = ++pParse->nMem; |
| 121101 | 121298 | regOutA = ++pParse->nMem; |
| 121102 | 121299 | regOutB = ++pParse->nMem; |
| | @@ -121556,11 +121753,11 @@ |
| 121556 | 121753 | ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET |
| 121557 | 121754 | ** because they could be computed at compile-time. But when LIMIT and OFFSET |
| 121558 | 121755 | ** became arbitrary expressions, we were forced to add restrictions (13) |
| 121559 | 121756 | ** and (14). */ |
| 121560 | 121757 | 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) */ |
| 121562 | 121759 | if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){ |
| 121563 | 121760 | return 0; /* Restriction (15) */ |
| 121564 | 121761 | } |
| 121565 | 121762 | if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */ |
| 121566 | 121763 | if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (4) */ |
| | @@ -121704,20 +121901,17 @@ |
| 121704 | 121901 | */ |
| 121705 | 121902 | for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){ |
| 121706 | 121903 | Select *pNew; |
| 121707 | 121904 | ExprList *pOrderBy = p->pOrderBy; |
| 121708 | 121905 | Expr *pLimit = p->pLimit; |
| 121709 | | - Expr *pOffset = p->pOffset; |
| 121710 | 121906 | Select *pPrior = p->pPrior; |
| 121711 | 121907 | p->pOrderBy = 0; |
| 121712 | 121908 | p->pSrc = 0; |
| 121713 | 121909 | p->pPrior = 0; |
| 121714 | 121910 | p->pLimit = 0; |
| 121715 | | - p->pOffset = 0; |
| 121716 | 121911 | pNew = sqlite3SelectDup(db, p, 0); |
| 121717 | 121912 | sqlite3SelectSetName(pNew, pSub->zSelName); |
| 121718 | | - p->pOffset = pOffset; |
| 121719 | 121913 | p->pLimit = pLimit; |
| 121720 | 121914 | p->pOrderBy = pOrderBy; |
| 121721 | 121915 | p->pSrc = pSrc; |
| 121722 | 121916 | p->op = TK_ALL; |
| 121723 | 121917 | if( pNew==0 ){ |
| | @@ -122179,11 +122373,10 @@ |
| 122179 | 122373 | assert( (p->selFlags & SF_Converted)==0 ); |
| 122180 | 122374 | p->selFlags |= SF_Converted; |
| 122181 | 122375 | assert( pNew->pPrior!=0 ); |
| 122182 | 122376 | pNew->pPrior->pNext = pNew; |
| 122183 | 122377 | pNew->pLimit = 0; |
| 122184 | | - pNew->pOffset = 0; |
| 122185 | 122378 | return WRC_Continue; |
| 122186 | 122379 | } |
| 122187 | 122380 | |
| 122188 | 122381 | /* |
| 122189 | 122382 | ** Check to see if the FROM clause term pFrom has table-valued function |
| | @@ -125077,11 +125270,11 @@ |
| 125077 | 125270 | case TK_UPDATE: { |
| 125078 | 125271 | sqlite3Update(pParse, |
| 125079 | 125272 | targetSrcList(pParse, pStep), |
| 125080 | 125273 | sqlite3ExprListDup(db, pStep->pExprList, 0), |
| 125081 | 125274 | sqlite3ExprDup(db, pStep->pWhere, 0), |
| 125082 | | - pParse->eOrconf, 0, 0, 0 |
| 125275 | + pParse->eOrconf, 0, 0 |
| 125083 | 125276 | ); |
| 125084 | 125277 | break; |
| 125085 | 125278 | } |
| 125086 | 125279 | case TK_INSERT: { |
| 125087 | 125280 | sqlite3Insert(pParse, |
| | @@ -125093,11 +125286,11 @@ |
| 125093 | 125286 | break; |
| 125094 | 125287 | } |
| 125095 | 125288 | case TK_DELETE: { |
| 125096 | 125289 | sqlite3DeleteFrom(pParse, |
| 125097 | 125290 | targetSrcList(pParse, pStep), |
| 125098 | | - sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0, 0 |
| 125291 | + sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0 |
| 125099 | 125292 | ); |
| 125100 | 125293 | break; |
| 125101 | 125294 | } |
| 125102 | 125295 | default: assert( pStep->op==TK_SELECT ); { |
| 125103 | 125296 | SelectDest sDest; |
| | @@ -125241,11 +125434,11 @@ |
| 125241 | 125434 | } |
| 125242 | 125435 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 125243 | 125436 | VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf))); |
| 125244 | 125437 | |
| 125245 | 125438 | transferParseError(pParse, pSubParse); |
| 125246 | | - if( db->mallocFailed==0 ){ |
| 125439 | + if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 125247 | 125440 | pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); |
| 125248 | 125441 | } |
| 125249 | 125442 | pProgram->nMem = pSubParse->nMem; |
| 125250 | 125443 | pProgram->nCsr = pSubParse->nTab; |
| 125251 | 125444 | pProgram->token = (void *)pTrigger; |
| | @@ -125562,12 +125755,11 @@ |
| 125562 | 125755 | SrcList *pTabList, /* The table in which we should change things */ |
| 125563 | 125756 | ExprList *pChanges, /* Things to be changed */ |
| 125564 | 125757 | Expr *pWhere, /* The WHERE clause. May be null */ |
| 125565 | 125758 | int onError, /* How to handle constraint errors */ |
| 125566 | 125759 | 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 */ |
| 125569 | 125761 | ){ |
| 125570 | 125762 | int i, j; /* Loop counters */ |
| 125571 | 125763 | Table *pTab; /* The table to be updated */ |
| 125572 | 125764 | int addrTop = 0; /* VDBE instruction address of the start of the loop */ |
| 125573 | 125765 | WhereInfo *pWInfo; /* Information about the WHERE clause */ |
| | @@ -125651,14 +125843,14 @@ |
| 125651 | 125843 | #endif |
| 125652 | 125844 | |
| 125653 | 125845 | #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 125654 | 125846 | if( !isView ){ |
| 125655 | 125847 | pWhere = sqlite3LimitWhere( |
| 125656 | | - pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "UPDATE" |
| 125848 | + pParse, pTabList, pWhere, pOrderBy, pLimit, "UPDATE" |
| 125657 | 125849 | ); |
| 125658 | 125850 | pOrderBy = 0; |
| 125659 | | - pLimit = pOffset = 0; |
| 125851 | + pLimit = 0; |
| 125660 | 125852 | } |
| 125661 | 125853 | #endif |
| 125662 | 125854 | |
| 125663 | 125855 | if( sqlite3ViewGetColumnNames(pParse, pTab) ){ |
| 125664 | 125856 | goto update_cleanup; |
| | @@ -125827,14 +126019,14 @@ |
| 125827 | 126019 | ** an ephemeral table. |
| 125828 | 126020 | */ |
| 125829 | 126021 | #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) |
| 125830 | 126022 | if( isView ){ |
| 125831 | 126023 | sqlite3MaterializeView(pParse, pTab, |
| 125832 | | - pWhere, pOrderBy, pLimit, pOffset, iDataCur |
| 126024 | + pWhere, pOrderBy, pLimit, iDataCur |
| 125833 | 126025 | ); |
| 125834 | 126026 | pOrderBy = 0; |
| 125835 | | - pLimit = pOffset = 0; |
| 126027 | + pLimit = 0; |
| 125836 | 126028 | } |
| 125837 | 126029 | #endif |
| 125838 | 126030 | |
| 125839 | 126031 | /* Resolve the column names in all the expressions in the |
| 125840 | 126032 | ** WHERE clause. |
| | @@ -126217,11 +126409,10 @@ |
| 126217 | 126409 | sqlite3ExprListDelete(db, pChanges); |
| 126218 | 126410 | sqlite3ExprDelete(db, pWhere); |
| 126219 | 126411 | #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) |
| 126220 | 126412 | sqlite3ExprListDelete(db, pOrderBy); |
| 126221 | 126413 | sqlite3ExprDelete(db, pLimit); |
| 126222 | | - sqlite3ExprDelete(db, pOffset); |
| 126223 | 126414 | #endif |
| 126224 | 126415 | return; |
| 126225 | 126416 | } |
| 126226 | 126417 | /* Make sure "isView" and other macros defined above are undefined. Otherwise |
| 126227 | 126418 | ** they may interfere with compilation of other functions in this file |
| | @@ -128931,10 +129122,106 @@ |
| 128931 | 129122 | ){ |
| 128932 | 129123 | zAff[i] = SQLITE_AFF_BLOB; |
| 128933 | 129124 | } |
| 128934 | 129125 | } |
| 128935 | 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 | + |
| 128936 | 129223 | |
| 128937 | 129224 | /* |
| 128938 | 129225 | ** Generate code for a single equality term of the WHERE clause. An equality |
| 128939 | 129226 | ** term can be either X=expr or X IN (...). pTerm is the term to be |
| 128940 | 129227 | ** coded. |
| | @@ -128994,72 +129281,27 @@ |
| 128994 | 129281 | disableTerm(pLevel, pTerm); |
| 128995 | 129282 | return iTarget; |
| 128996 | 129283 | } |
| 128997 | 129284 | } |
| 128998 | 129285 | 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++; |
| 129000 | 129288 | } |
| 129001 | 129289 | |
| 129002 | 129290 | if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){ |
| 129003 | 129291 | eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0); |
| 129004 | 129292 | }else{ |
| 129005 | | - Select *pSelect = pX->x.pSelect; |
| 129006 | 129293 | 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 | + |
| 129023 | 129296 | 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); |
| 129052 | 129298 | 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; |
| 129061 | 129303 | } |
| 129062 | 129304 | |
| 129063 | 129305 | if( eType==IN_INDEX_INDEX_DESC ){ |
| 129064 | 129306 | testcase( bRev ); |
| 129065 | 129307 | bRev = !bRev; |
| | @@ -134703,11 +134945,11 @@ |
| 134703 | 134945 | }else if( eOp & (WO_EQ|WO_IS) ){ |
| 134704 | 134946 | int iCol = pProbe->aiColumn[saved_nEq]; |
| 134705 | 134947 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 134706 | 134948 | assert( saved_nEq==pNew->u.btree.nEq ); |
| 134707 | 134949 | if( iCol==XN_ROWID |
| 134708 | | - || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) |
| 134950 | + || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) |
| 134709 | 134951 | ){ |
| 134710 | 134952 | if( iCol>=0 && pProbe->uniqNotNull==0 ){ |
| 134711 | 134953 | pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 134712 | 134954 | }else{ |
| 134713 | 134955 | pNew->wsFlags |= WHERE_ONEROW; |
| | @@ -136920,39 +137162,84 @@ |
| 136920 | 137162 | for(ii=0; ii<pWInfo->nLevel; ii++){ |
| 136921 | 137163 | whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC); |
| 136922 | 137164 | } |
| 136923 | 137165 | } |
| 136924 | 137166 | #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; |
| 136926 | 137198 | if( pWInfo->nLevel>=2 |
| 136927 | | - && pResultSet!=0 |
| 137199 | + && pResultSet!=0 /* guarantees condition (1) above */ |
| 136928 | 137200 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| 136929 | 137201 | ){ |
| 137202 | + int i; |
| 136930 | 137203 | Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); |
| 136931 | 137204 | if( sWLB.pOrderBy ){ |
| 136932 | 137205 | tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy); |
| 136933 | 137206 | } |
| 136934 | | - while( pWInfo->nLevel>=2 ){ |
| 137207 | + for(i=pWInfo->nLevel-1; i>=1; i--){ |
| 136935 | 137208 | 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; |
| 136938 | 137213 | if( (wctrlFlags & WHERE_WANT_DISTINCT)==0 |
| 136939 | 137214 | && (pLoop->wsFlags & WHERE_ONEROW)==0 |
| 136940 | 137215 | ){ |
| 136941 | | - break; |
| 137216 | + continue; |
| 136942 | 137217 | } |
| 136943 | | - if( (tabUsed & pLoop->maskSelf)!=0 ) break; |
| 137218 | + if( (tabUsed & pLoop->maskSelf)!=0 ) continue; |
| 136944 | 137219 | pEnd = sWLB.pWC->a + sWLB.pWC->nTerm; |
| 136945 | 137220 | 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 | + } |
| 136950 | 137227 | } |
| 136951 | 137228 | } |
| 136952 | | - if( pTerm<pEnd ) break; |
| 137229 | + if( pTerm<pEnd ) continue; |
| 136953 | 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 | + } |
| 136954 | 137241 | pWInfo->nLevel--; |
| 136955 | 137242 | nTabList--; |
| 136956 | 137243 | } |
| 136957 | 137244 | } |
| 136958 | 137245 | WHERETRACE(0xffff,("*** Optimizer Finished ***\n")); |
| | @@ -137103,11 +137390,10 @@ |
| 137103 | 137390 | |
| 137104 | 137391 | /* Generate the code to do the search. Each iteration of the for |
| 137105 | 137392 | ** loop below generates code for a single nested loop of the VM |
| 137106 | 137393 | ** program. |
| 137107 | 137394 | */ |
| 137108 | | - notReady = ~(Bitmask)0; |
| 137109 | 137395 | for(ii=0; ii<nTabList; ii++){ |
| 137110 | 137396 | int addrExplain; |
| 137111 | 137397 | int wsFlags; |
| 137112 | 137398 | pLevel = &pWInfo->a[ii]; |
| 137113 | 137399 | wsFlags = pLevel->pWLoop->wsFlags; |
| | @@ -137167,10 +137453,11 @@ |
| 137167 | 137453 | #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT |
| 137168 | 137454 | int addrSeek = 0; |
| 137169 | 137455 | Index *pIdx; |
| 137170 | 137456 | int n; |
| 137171 | 137457 | if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED |
| 137458 | + && i==pWInfo->nLevel-1 /* Ticket [ef9318757b152e3] 2017-10-21 */ |
| 137172 | 137459 | && (pLoop->wsFlags & WHERE_INDEXED)!=0 |
| 137173 | 137460 | && (pIdx = pLoop->u.btree.pIndex)->hasStat1 |
| 137174 | 137461 | && (n = pLoop->u.btree.nIdxCol)>0 |
| 137175 | 137462 | && pIdx->aiRowLogEst[n]>=36 |
| 137176 | 137463 | ){ |
| | @@ -137233,11 +137520,12 @@ |
| 137233 | 137520 | if( pLevel->iLeftJoin ){ |
| 137234 | 137521 | int ws = pLoop->wsFlags; |
| 137235 | 137522 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v); |
| 137236 | 137523 | assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 ); |
| 137237 | 137524 | 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); |
| 137239 | 137527 | } |
| 137240 | 137528 | if( (ws & WHERE_INDEXED) |
| 137241 | 137529 | || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) |
| 137242 | 137530 | ){ |
| 137243 | 137531 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur); |
| | @@ -137401,19 +137689,10 @@ |
| 137401 | 137689 | ** Alternative datatype for the argument to the malloc() routine passed |
| 137402 | 137690 | ** into sqlite3ParserAlloc(). The default is size_t. |
| 137403 | 137691 | */ |
| 137404 | 137692 | #define YYMALLOCARGTYPE u64 |
| 137405 | 137693 | |
| 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 | 137694 | /* |
| 137416 | 137695 | ** An instance of the following structure describes the event of a |
| 137417 | 137696 | ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, |
| 137418 | 137697 | ** TK_DELETE, or TK_INSTEAD. If the event is of the form |
| 137419 | 137698 | ** |
| | @@ -137647,11 +137926,10 @@ |
| 137647 | 137926 | int yy194; |
| 137648 | 137927 | Select* yy243; |
| 137649 | 137928 | IdList* yy254; |
| 137650 | 137929 | With* yy285; |
| 137651 | 137930 | struct TrigEvent yy332; |
| 137652 | | - struct LimitVal yy354; |
| 137653 | 137931 | struct {int value; int mask;} yy497; |
| 137654 | 137932 | } YYMINORTYPE; |
| 137655 | 137933 | #ifndef YYSTACKDEPTH |
| 137656 | 137934 | #define YYSTACKDEPTH 100 |
| 137657 | 137935 | #endif |
| | @@ -139903,11 +140181,11 @@ |
| 139903 | 140181 | SrcList *pFrom; |
| 139904 | 140182 | Token x; |
| 139905 | 140183 | x.n = 0; |
| 139906 | 140184 | parserDoubleLinkSelect(pParse, pRhs); |
| 139907 | 140185 | 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); |
| 139909 | 140187 | } |
| 139910 | 140188 | if( pRhs ){ |
| 139911 | 140189 | pRhs->op = (u8)yymsp[-1].minor.yy194; |
| 139912 | 140190 | pRhs->pPrior = pLhs; |
| 139913 | 140191 | if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue; |
| | @@ -139929,11 +140207,11 @@ |
| 139929 | 140207 | case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ |
| 139930 | 140208 | { |
| 139931 | 140209 | #if SELECTTRACE_ENABLED |
| 139932 | 140210 | Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/ |
| 139933 | 140211 | #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); |
| 139935 | 140213 | #if SELECTTRACE_ENABLED |
| 139936 | 140214 | /* Populate the Select.zSelName[] string that is used to help with |
| 139937 | 140215 | ** query planner debugging, to differentiate between multiple Select |
| 139938 | 140216 | ** objects in a complex query. |
| 139939 | 140217 | ** |
| | @@ -139958,17 +140236,17 @@ |
| 139958 | 140236 | #endif /* SELECTRACE_ENABLED */ |
| 139959 | 140237 | } |
| 139960 | 140238 | break; |
| 139961 | 140239 | case 85: /* values ::= VALUES LP nexprlist RP */ |
| 139962 | 140240 | { |
| 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); |
| 139964 | 140242 | } |
| 139965 | 140243 | break; |
| 139966 | 140244 | case 86: /* values ::= values COMMA LP exprlist RP */ |
| 139967 | 140245 | { |
| 139968 | 140246 | 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); |
| 139970 | 140248 | if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; |
| 139971 | 140249 | if( pRight ){ |
| 139972 | 140250 | pRight->op = TK_ALL; |
| 139973 | 140251 | pRight->pPrior = pLeft; |
| 139974 | 140252 | yymsp[-4].minor.yy243 = pRight; |
| | @@ -140069,11 +140347,11 @@ |
| 140069 | 140347 | } |
| 140070 | 140348 | sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185); |
| 140071 | 140349 | }else{ |
| 140072 | 140350 | Select *pSubquery; |
| 140073 | 140351 | 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); |
| 140075 | 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); |
| 140076 | 140354 | } |
| 140077 | 140355 | } |
| 140078 | 140356 | break; |
| 140079 | 140357 | case 104: /* dbnm ::= */ |
| | @@ -140101,10 +140379,11 @@ |
| 140101 | 140379 | case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196); |
| 140102 | 140380 | {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;} |
| 140103 | 140381 | break; |
| 140104 | 140382 | case 112: /* on_opt ::= */ |
| 140105 | 140383 | case 127: /* having_opt ::= */ yytestcase(yyruleno==127); |
| 140384 | + case 129: /* limit_opt ::= */ yytestcase(yyruleno==129); |
| 140106 | 140385 | case 134: /* where_opt ::= */ yytestcase(yyruleno==134); |
| 140107 | 140386 | case 197: /* case_else ::= */ yytestcase(yyruleno==197); |
| 140108 | 140387 | case 199: /* case_operand ::= */ yytestcase(yyruleno==199); |
| 140109 | 140388 | {yymsp[1].minor.yy72 = 0;} |
| 140110 | 140389 | break; |
| | @@ -140144,35 +140423,32 @@ |
| 140144 | 140423 | {yymsp[0].minor.yy194 = SQLITE_SO_DESC;} |
| 140145 | 140424 | break; |
| 140146 | 140425 | case 124: /* sortorder ::= */ |
| 140147 | 140426 | {yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;} |
| 140148 | 140427 | break; |
| 140149 | | - case 129: /* limit_opt ::= */ |
| 140150 | | -{yymsp[1].minor.yy354.pLimit = 0; yymsp[1].minor.yy354.pOffset = 0;} |
| 140151 | | - break; |
| 140152 | 140428 | 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);} |
| 140154 | 140430 | break; |
| 140155 | 140431 | 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);} |
| 140157 | 140433 | break; |
| 140158 | 140434 | 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);} |
| 140160 | 140436 | break; |
| 140161 | 140437 | case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */ |
| 140162 | 140438 | { |
| 140163 | 140439 | sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1); |
| 140164 | 140440 | 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); |
| 140166 | 140442 | } |
| 140167 | 140443 | break; |
| 140168 | 140444 | case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */ |
| 140169 | 140445 | { |
| 140170 | 140446 | sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1); |
| 140171 | 140447 | sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0); |
| 140172 | 140448 | 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); |
| 140174 | 140450 | } |
| 140175 | 140451 | break; |
| 140176 | 140452 | case 137: /* setlist ::= setlist COMMA nm EQ expr */ |
| 140177 | 140453 | { |
| 140178 | 140454 | yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr); |
| | @@ -140485,11 +140761,11 @@ |
| 140485 | 140761 | } |
| 140486 | 140762 | break; |
| 140487 | 140763 | case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */ |
| 140488 | 140764 | { |
| 140489 | 140765 | 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); |
| 140491 | 140767 | if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148); |
| 140492 | 140768 | yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); |
| 140493 | 140769 | sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect); |
| 140494 | 140770 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 140495 | 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 @@ |
| 145232 | 145508 | }else if( flags & SQLITE_OPEN_FULLMUTEX ){ |
| 145233 | 145509 | isThreadsafe = 1; |
| 145234 | 145510 | }else{ |
| 145235 | 145511 | isThreadsafe = sqlite3GlobalConfig.bFullMutex; |
| 145236 | 145512 | } |
| 145513 | + |
| 145237 | 145514 | if( flags & SQLITE_OPEN_PRIVATECACHE ){ |
| 145238 | 145515 | flags &= ~SQLITE_OPEN_SHAREDCACHE; |
| 145239 | 145516 | }else if( sqlite3GlobalConfig.sharedCacheEnabled ){ |
| 145240 | 145517 | flags |= SQLITE_OPEN_SHAREDCACHE; |
| 145241 | 145518 | } |
| | @@ -145264,17 +145541,24 @@ |
| 145264 | 145541 | ); |
| 145265 | 145542 | |
| 145266 | 145543 | /* Allocate the sqlite data structure */ |
| 145267 | 145544 | db = sqlite3MallocZero( sizeof(sqlite3) ); |
| 145268 | 145545 | if( db==0 ) goto opendb_out; |
| 145269 | | - if( isThreadsafe ){ |
| 145546 | + if( isThreadsafe |
| 145547 | +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS |
| 145548 | + || sqlite3GlobalConfig.bCoreMutex |
| 145549 | +#endif |
| 145550 | + ){ |
| 145270 | 145551 | db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); |
| 145271 | 145552 | if( db->mutex==0 ){ |
| 145272 | 145553 | sqlite3_free(db); |
| 145273 | 145554 | db = 0; |
| 145274 | 145555 | goto opendb_out; |
| 145275 | 145556 | } |
| 145557 | + if( isThreadsafe==0 ){ |
| 145558 | + sqlite3MutexWarnOnContention(db->mutex); |
| 145559 | + } |
| 145276 | 145560 | } |
| 145277 | 145561 | sqlite3_mutex_enter(db->mutex); |
| 145278 | 145562 | db->errMask = 0xff; |
| 145279 | 145563 | db->nDb = 2; |
| 145280 | 145564 | db->magic = SQLITE_MAGIC_BUSY; |
| | @@ -145754,41 +146038,41 @@ |
| 145754 | 146038 | ** to detect when version error conditions occurs. |
| 145755 | 146039 | ** |
| 145756 | 146040 | ** 2. Invoke sqlite3_log() to provide the source code location where |
| 145757 | 146041 | ** a low-level error is first detected. |
| 145758 | 146042 | */ |
| 145759 | | -static int reportError(int iErr, int lineno, const char *zType){ |
| 146043 | +SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType){ |
| 145760 | 146044 | sqlite3_log(iErr, "%s at line %d of [%.10s]", |
| 145761 | 146045 | zType, lineno, 20+sqlite3_sourceid()); |
| 145762 | 146046 | return iErr; |
| 145763 | 146047 | } |
| 145764 | 146048 | SQLITE_PRIVATE int sqlite3CorruptError(int lineno){ |
| 145765 | 146049 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 145766 | | - return reportError(SQLITE_CORRUPT, lineno, "database corruption"); |
| 146050 | + return sqlite3ReportError(SQLITE_CORRUPT, lineno, "database corruption"); |
| 145767 | 146051 | } |
| 145768 | 146052 | SQLITE_PRIVATE int sqlite3MisuseError(int lineno){ |
| 145769 | 146053 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 145770 | | - return reportError(SQLITE_MISUSE, lineno, "misuse"); |
| 146054 | + return sqlite3ReportError(SQLITE_MISUSE, lineno, "misuse"); |
| 145771 | 146055 | } |
| 145772 | 146056 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 145773 | 146057 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 145774 | | - return reportError(SQLITE_CANTOPEN, lineno, "cannot open file"); |
| 146058 | + return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file"); |
| 145775 | 146059 | } |
| 145776 | 146060 | #ifdef SQLITE_DEBUG |
| 145777 | 146061 | SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){ |
| 145778 | 146062 | char zMsg[100]; |
| 145779 | 146063 | sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno); |
| 145780 | 146064 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 145781 | | - return reportError(SQLITE_CORRUPT, lineno, zMsg); |
| 146065 | + return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); |
| 145782 | 146066 | } |
| 145783 | 146067 | SQLITE_PRIVATE int sqlite3NomemError(int lineno){ |
| 145784 | 146068 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 145785 | | - return reportError(SQLITE_NOMEM, lineno, "OOM"); |
| 146069 | + return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM"); |
| 145786 | 146070 | } |
| 145787 | 146071 | SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){ |
| 145788 | 146072 | 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"); |
| 145790 | 146074 | } |
| 145791 | 146075 | #endif |
| 145792 | 146076 | |
| 145793 | 146077 | #ifndef SQLITE_OMIT_DEPRECATED |
| 145794 | 146078 | /* |
| | @@ -186122,10 +186406,12 @@ |
| 186122 | 186406 | Fts5ExprPhrase *pPhrase, |
| 186123 | 186407 | Fts5Token *pToken, |
| 186124 | 186408 | int bPrefix |
| 186125 | 186409 | ); |
| 186126 | 186410 | |
| 186411 | +static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase*); |
| 186412 | + |
| 186127 | 186413 | static Fts5ExprNearset *sqlite3Fts5ParseNearset( |
| 186128 | 186414 | Fts5Parse*, |
| 186129 | 186415 | Fts5ExprNearset*, |
| 186130 | 186416 | Fts5ExprPhrase* |
| 186131 | 186417 | ); |
| | @@ -186202,13 +186488,14 @@ |
| 186202 | 186488 | #define FTS5_LCP 7 |
| 186203 | 186489 | #define FTS5_RCP 8 |
| 186204 | 186490 | #define FTS5_STRING 9 |
| 186205 | 186491 | #define FTS5_LP 10 |
| 186206 | 186492 | #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 |
| 186210 | 186497 | |
| 186211 | 186498 | /* |
| 186212 | 186499 | ** 2000-05-29 |
| 186213 | 186500 | ** |
| 186214 | 186501 | ** The author disclaims copyright to this source code. In place of |
| | @@ -186319,39 +186606,39 @@ |
| 186319 | 186606 | #ifndef INTERFACE |
| 186320 | 186607 | # define INTERFACE 1 |
| 186321 | 186608 | #endif |
| 186322 | 186609 | /************* Begin control #defines *****************************************/ |
| 186323 | 186610 | #define fts5YYCODETYPE unsigned char |
| 186324 | | -#define fts5YYNOCODE 28 |
| 186611 | +#define fts5YYNOCODE 29 |
| 186325 | 186612 | #define fts5YYACTIONTYPE unsigned char |
| 186326 | 186613 | #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token |
| 186327 | 186614 | typedef union { |
| 186328 | 186615 | int fts5yyinit; |
| 186329 | 186616 | sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0; |
| 186330 | 186617 | 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; |
| 186335 | 186622 | } fts5YYMINORTYPE; |
| 186336 | 186623 | #ifndef fts5YYSTACKDEPTH |
| 186337 | 186624 | #define fts5YYSTACKDEPTH 100 |
| 186338 | 186625 | #endif |
| 186339 | 186626 | #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse; |
| 186340 | 186627 | #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse |
| 186341 | 186628 | #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse |
| 186342 | 186629 | #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 |
| 186353 | 186640 | /************* End control #defines *******************************************/ |
| 186354 | 186641 | |
| 186355 | 186642 | /* Define the fts5yytestcase() macro to be a no-op if is not already defined |
| 186356 | 186643 | ** otherwise. |
| 186357 | 186644 | ** |
| | @@ -186419,58 +186706,60 @@ |
| 186419 | 186706 | ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for |
| 186420 | 186707 | ** shifting non-terminals after a reduce. |
| 186421 | 186708 | ** fts5yy_default[] Default action for each state. |
| 186422 | 186709 | ** |
| 186423 | 186710 | *********** Begin parsing tables **********************************************/ |
| 186424 | | -#define fts5YY_ACTTAB_COUNT (98) |
| 186711 | +#define fts5YY_ACTTAB_COUNT (105) |
| 186425 | 186712 | 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, |
| 186436 | 186724 | }; |
| 186437 | 186725 | 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, |
| 186448 | 186737 | }; |
| 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) |
| 186451 | 186740 | #define fts5YY_SHIFT_MIN (0) |
| 186452 | | -#define fts5YY_SHIFT_MAX (90) |
| 186741 | +#define fts5YY_SHIFT_MAX (95) |
| 186453 | 186742 | 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, |
| 186458 | 186747 | }; |
| 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) |
| 186463 | 186752 | 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, |
| 186466 | 186755 | }; |
| 186467 | 186756 | 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, |
| 186472 | 186761 | }; |
| 186473 | 186762 | /********** End of lemon-generated parsing tables *****************************/ |
| 186474 | 186763 | |
| 186475 | 186764 | /* The next table maps tokens (terminal symbols) into fallback tokens. |
| 186476 | 186765 | ** If a construct like the following: |
| | @@ -186575,14 +186864,14 @@ |
| 186575 | 186864 | ** are required. The following table supplies these names */ |
| 186576 | 186865 | static const char *const fts5yyTokenName[] = { |
| 186577 | 186866 | "$", "OR", "AND", "NOT", |
| 186578 | 186867 | "TERM", "COLON", "MINUS", "LCP", |
| 186579 | 186868 | "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", |
| 186584 | 186873 | }; |
| 186585 | 186874 | #endif /* NDEBUG */ |
| 186586 | 186875 | |
| 186587 | 186876 | #ifndef NDEBUG |
| 186588 | 186877 | /* For tracing reduce actions, the names of all rules are required. |
| | @@ -186604,19 +186893,20 @@ |
| 186604 | 186893 | /* 13 */ "exprlist ::= cnearset", |
| 186605 | 186894 | /* 14 */ "exprlist ::= exprlist cnearset", |
| 186606 | 186895 | /* 15 */ "cnearset ::= nearset", |
| 186607 | 186896 | /* 16 */ "cnearset ::= colset COLON nearset", |
| 186608 | 186897 | /* 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 ::=", |
| 186618 | 186908 | }; |
| 186619 | 186909 | #endif /* NDEBUG */ |
| 186620 | 186910 | |
| 186621 | 186911 | |
| 186622 | 186912 | #if fts5YYSTACKDEPTH<=0 |
| | @@ -186733,37 +187023,37 @@ |
| 186733 | 187023 | ** Note: during a reduce, the only symbols destroyed are those |
| 186734 | 187024 | ** which appear on the RHS of the rule, but which are *not* used |
| 186735 | 187025 | ** inside the C code. |
| 186736 | 187026 | */ |
| 186737 | 187027 | /********* Begin destructor definitions ***************************************/ |
| 186738 | | - case 16: /* input */ |
| 187028 | + case 17: /* input */ |
| 186739 | 187029 | { |
| 186740 | 187030 | (void)pParse; |
| 186741 | 187031 | } |
| 186742 | 187032 | 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)); |
| 186765 | 187055 | } |
| 186766 | 187056 | break; |
| 186767 | 187057 | /********* End destructor definitions *****************************************/ |
| 186768 | 187058 | default: break; /* If no destructor action specified: do nothing */ |
| 186769 | 187059 | } |
| | @@ -187013,37 +187303,38 @@ |
| 187013 | 187303 | */ |
| 187014 | 187304 | static const struct { |
| 187015 | 187305 | fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ |
| 187016 | 187306 | signed char nrhs; /* Negative of the number of RHS symbols in the rule */ |
| 187017 | 187307 | } 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 }, |
| 187021 | 187321 | { 20, -1 }, |
| 187022 | 187322 | { 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 | 187323 | { 19, -1 }, |
| 187032 | | - { 19, -2 }, |
| 187033 | | - { 18, -1 }, |
| 187034 | | - { 18, -3 }, |
| 187035 | | - { 22, -1 }, |
| 187036 | | - { 22, -5 }, |
| 187324 | + { 19, -3 }, |
| 187037 | 187325 | { 23, -1 }, |
| 187038 | 187326 | { 23, -2 }, |
| 187039 | | - { 25, 0 }, |
| 187040 | | - { 25, -2 }, |
| 187041 | | - { 24, -4 }, |
| 187327 | + { 23, -5 }, |
| 187328 | + { 24, -1 }, |
| 187042 | 187329 | { 24, -2 }, |
| 187043 | | - { 26, -1 }, |
| 187044 | 187330 | { 26, 0 }, |
| 187331 | + { 26, -2 }, |
| 187332 | + { 25, -4 }, |
| 187333 | + { 25, -2 }, |
| 187334 | + { 27, -1 }, |
| 187335 | + { 27, 0 }, |
| 187045 | 187336 | }; |
| 187046 | 187337 | |
| 187047 | 187338 | static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */ |
| 187048 | 187339 | |
| 187049 | 187340 | /* |
| | @@ -187104,141 +187395,147 @@ |
| 187104 | 187395 | ** break; |
| 187105 | 187396 | */ |
| 187106 | 187397 | /********** Begin reduce actions **********************************************/ |
| 187107 | 187398 | fts5YYMINORTYPE fts5yylhsminor; |
| 187108 | 187399 | case 0: /* input ::= expr */ |
| 187109 | | -{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); } |
| 187400 | +{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy54); } |
| 187110 | 187401 | break; |
| 187111 | 187402 | case 1: /* colset ::= MINUS LCP colsetlist RCP */ |
| 187112 | 187403 | { |
| 187113 | | - fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11); |
| 187404 | + fts5yymsp[-3].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43); |
| 187114 | 187405 | } |
| 187115 | 187406 | break; |
| 187116 | 187407 | case 2: /* colset ::= LCP colsetlist RCP */ |
| 187117 | | -{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; } |
| 187408 | +{ fts5yymsp[-2].minor.fts5yy43 = fts5yymsp[-1].minor.fts5yy43; } |
| 187118 | 187409 | break; |
| 187119 | 187410 | case 3: /* colset ::= STRING */ |
| 187120 | 187411 | { |
| 187121 | | - fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); |
| 187412 | + fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); |
| 187122 | 187413 | } |
| 187123 | | - fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11; |
| 187414 | + fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43; |
| 187124 | 187415 | break; |
| 187125 | 187416 | case 4: /* colset ::= MINUS STRING */ |
| 187126 | 187417 | { |
| 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); |
| 187129 | 187420 | } |
| 187130 | 187421 | break; |
| 187131 | 187422 | case 5: /* colsetlist ::= colsetlist STRING */ |
| 187132 | 187423 | { |
| 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; |
| 187135 | 187426 | break; |
| 187136 | 187427 | case 6: /* colsetlist ::= STRING */ |
| 187137 | 187428 | { |
| 187138 | | - fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); |
| 187429 | + fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); |
| 187139 | 187430 | } |
| 187140 | | - fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11; |
| 187431 | + fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43; |
| 187141 | 187432 | break; |
| 187142 | 187433 | case 7: /* expr ::= expr AND expr */ |
| 187143 | 187434 | { |
| 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); |
| 187145 | 187436 | } |
| 187146 | | - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187437 | + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187147 | 187438 | break; |
| 187148 | 187439 | case 8: /* expr ::= expr OR expr */ |
| 187149 | 187440 | { |
| 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); |
| 187151 | 187442 | } |
| 187152 | | - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187443 | + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187153 | 187444 | break; |
| 187154 | 187445 | case 9: /* expr ::= expr NOT expr */ |
| 187155 | 187446 | { |
| 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); |
| 187157 | 187448 | } |
| 187158 | | - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187449 | + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187159 | 187450 | break; |
| 187160 | 187451 | case 10: /* expr ::= colset COLON LP expr RP */ |
| 187161 | 187452 | { |
| 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; |
| 187164 | 187455 | } |
| 187165 | | - fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187456 | + fts5yymsp[-4].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187166 | 187457 | break; |
| 187167 | 187458 | case 11: /* expr ::= LP expr RP */ |
| 187168 | | -{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;} |
| 187459 | +{fts5yymsp[-2].minor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54;} |
| 187169 | 187460 | break; |
| 187170 | 187461 | case 12: /* expr ::= exprlist */ |
| 187171 | 187462 | 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; |
| 187174 | 187465 | break; |
| 187175 | 187466 | case 14: /* exprlist ::= exprlist cnearset */ |
| 187176 | 187467 | { |
| 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); |
| 187178 | 187469 | } |
| 187179 | | - fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187470 | + fts5yymsp[-1].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187180 | 187471 | break; |
| 187181 | 187472 | case 15: /* cnearset ::= nearset */ |
| 187182 | 187473 | { |
| 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); |
| 187184 | 187475 | } |
| 187185 | | - fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187476 | + fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187186 | 187477 | break; |
| 187187 | 187478 | case 16: /* cnearset ::= colset COLON nearset */ |
| 187188 | 187479 | { |
| 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); |
| 187191 | 187482 | } |
| 187192 | | - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; |
| 187483 | + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; |
| 187193 | 187484 | break; |
| 187194 | 187485 | 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 | +} |
| 187197 | 187494 | break; |
| 187198 | | - case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */ |
| 187495 | + case 19: /* nearset ::= STRING LP nearphrases neardist_opt RP */ |
| 187199 | 187496 | { |
| 187200 | 187497 | 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 ::= */ |
| 187219 | 187516 | { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; } |
| 187220 | 187517 | break; |
| 187221 | | - case 22: /* neardist_opt ::= COMMA STRING */ |
| 187518 | + case 23: /* neardist_opt ::= COMMA STRING */ |
| 187222 | 187519 | { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; } |
| 187223 | 187520 | 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 */ |
| 187237 | 187534 | { fts5yymsp[0].minor.fts5yy4 = 1; } |
| 187238 | 187535 | break; |
| 187239 | | - case 26: /* star_opt ::= */ |
| 187536 | + case 27: /* star_opt ::= */ |
| 187240 | 187537 | { fts5yymsp[1].minor.fts5yy4 = 0; } |
| 187241 | 187538 | break; |
| 187242 | 187539 | default: |
| 187243 | 187540 | break; |
| 187244 | 187541 | /********** End reduce actions ************************************************/ |
| | @@ -189657,11 +189954,12 @@ |
| 189657 | 189954 | /* |
| 189658 | 189955 | ** An instance of the following structure represents a single search term |
| 189659 | 189956 | ** or term prefix. |
| 189660 | 189957 | */ |
| 189661 | 189958 | 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 */ |
| 189663 | 189961 | char *zTerm; /* nul-terminated term */ |
| 189664 | 189962 | Fts5IndexIter *pIter; /* Iterator for this term */ |
| 189665 | 189963 | Fts5ExprTerm *pSynonym; /* Pointer to first in list of synonyms */ |
| 189666 | 189964 | }; |
| 189667 | 189965 | |
| | @@ -189738,10 +190036,11 @@ |
| 189738 | 190036 | case ':': tok = FTS5_COLON; break; |
| 189739 | 190037 | case ',': tok = FTS5_COMMA; break; |
| 189740 | 190038 | case '+': tok = FTS5_PLUS; break; |
| 189741 | 190039 | case '*': tok = FTS5_STAR; break; |
| 189742 | 190040 | case '-': tok = FTS5_MINUS; break; |
| 190041 | + case '^': tok = FTS5_CARET; break; |
| 189743 | 190042 | case '\0': tok = FTS5_EOF; break; |
| 189744 | 190043 | |
| 189745 | 190044 | case '"': { |
| 189746 | 190045 | const char *z2; |
| 189747 | 190046 | tok = FTS5_STRING; |
| | @@ -189997,10 +190296,11 @@ |
| 189997 | 190296 | Fts5PoslistWriter writer = {0}; |
| 189998 | 190297 | Fts5PoslistReader aStatic[4]; |
| 189999 | 190298 | Fts5PoslistReader *aIter = aStatic; |
| 190000 | 190299 | int i; |
| 190001 | 190300 | int rc = SQLITE_OK; |
| 190301 | + int bFirst = pPhrase->aTerm[0].bFirst; |
| 190002 | 190302 | |
| 190003 | 190303 | fts5BufferZero(&pPhrase->poslist); |
| 190004 | 190304 | |
| 190005 | 190305 | /* If the aStatic[] array is not large enough, allocate a large array |
| 190006 | 190306 | ** using sqlite3_malloc(). This approach could be improved upon. */ |
| | @@ -190051,12 +190351,14 @@ |
| 190051 | 190351 | } |
| 190052 | 190352 | } |
| 190053 | 190353 | }while( bMatch==0 ); |
| 190054 | 190354 | |
| 190055 | 190355 | /* 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 | + } |
| 190058 | 190360 | |
| 190059 | 190361 | for(i=0; i<pPhrase->nTerm; i++){ |
| 190060 | 190362 | if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) goto ismatch_out; |
| 190061 | 190363 | } |
| 190062 | 190364 | } |
| | @@ -190306,11 +190608,13 @@ |
| 190306 | 190608 | /* Check that each phrase in the nearset matches the current row. |
| 190307 | 190609 | ** Populate the pPhrase->poslist buffers at the same time. If any |
| 190308 | 190610 | ** phrase is not a match, break out of the loop early. */ |
| 190309 | 190611 | for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){ |
| 190310 | 190612 | 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 | + ){ |
| 190312 | 190616 | int bMatch = 0; |
| 190313 | 190617 | rc = fts5ExprPhraseIsMatch(pNode, pPhrase, &bMatch); |
| 190314 | 190618 | if( bMatch==0 ) break; |
| 190315 | 190619 | }else{ |
| 190316 | 190620 | Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter; |
| | @@ -190487,10 +190791,11 @@ |
| 190487 | 190791 | |
| 190488 | 190792 | /* Check that this node should not be FTS5_TERM */ |
| 190489 | 190793 | assert( pNear->nPhrase>1 |
| 190490 | 190794 | || pNear->apPhrase[0]->nTerm>1 |
| 190491 | 190795 | || pNear->apPhrase[0]->aTerm[0].pSynonym |
| 190796 | + || pNear->apPhrase[0]->aTerm[0].bFirst |
| 190492 | 190797 | ); |
| 190493 | 190798 | |
| 190494 | 190799 | /* Initialize iLast, the "lastest" rowid any iterator points to. If the |
| 190495 | 190800 | ** iterator skips through rowids in the default ascending order, this means |
| 190496 | 190801 | ** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it |
| | @@ -191010,10 +191315,20 @@ |
| 191010 | 191315 | } |
| 191011 | 191316 | if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist); |
| 191012 | 191317 | sqlite3_free(pPhrase); |
| 191013 | 191318 | } |
| 191014 | 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 | +} |
| 191015 | 191330 | |
| 191016 | 191331 | /* |
| 191017 | 191332 | ** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated |
| 191018 | 191333 | ** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is |
| 191019 | 191334 | ** appended to it and the results returned. |
| | @@ -191289,10 +191604,11 @@ |
| 191289 | 191604 | 0, 0); |
| 191290 | 191605 | tflags = FTS5_TOKEN_COLOCATED; |
| 191291 | 191606 | } |
| 191292 | 191607 | if( rc==SQLITE_OK ){ |
| 191293 | 191608 | sCtx.pPhrase->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix; |
| 191609 | + sCtx.pPhrase->aTerm[i].bFirst = pOrig->aTerm[i].bFirst; |
| 191294 | 191610 | } |
| 191295 | 191611 | } |
| 191296 | 191612 | }else{ |
| 191297 | 191613 | /* This happens when parsing a token or quoted phrase that contains |
| 191298 | 191614 | ** no token characters at all. (e.g ... MATCH '""'). */ |
| | @@ -191307,11 +191623,14 @@ |
| 191307 | 191623 | pNew->apExprPhrase[0] = sCtx.pPhrase; |
| 191308 | 191624 | pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase; |
| 191309 | 191625 | pNew->pRoot->pNear->nPhrase = 1; |
| 191310 | 191626 | sCtx.pPhrase->pNode = pNew->pRoot; |
| 191311 | 191627 | |
| 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 | + ){ |
| 191313 | 191632 | pNew->pRoot->eType = FTS5_TERM; |
| 191314 | 191633 | pNew->pRoot->xNext = fts5ExprNodeNext_TERM; |
| 191315 | 191634 | }else{ |
| 191316 | 191635 | pNew->pRoot->eType = FTS5_STRING; |
| 191317 | 191636 | pNew->pRoot->xNext = fts5ExprNodeNext_STRING; |
| | @@ -191581,10 +191900,11 @@ |
| 191581 | 191900 | switch( pNode->eType ){ |
| 191582 | 191901 | case FTS5_STRING: { |
| 191583 | 191902 | Fts5ExprNearset *pNear = pNode->pNear; |
| 191584 | 191903 | if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 |
| 191585 | 191904 | && pNear->apPhrase[0]->aTerm[0].pSynonym==0 |
| 191905 | + && pNear->apPhrase[0]->aTerm[0].bFirst==0 |
| 191586 | 191906 | ){ |
| 191587 | 191907 | pNode->eType = FTS5_TERM; |
| 191588 | 191908 | pNode->xNext = fts5ExprNodeNext_TERM; |
| 191589 | 191909 | }else{ |
| 191590 | 191910 | pNode->xNext = fts5ExprNodeNext_STRING; |
| | @@ -191667,24 +191987,27 @@ |
| 191667 | 191987 | pRet->xNext = 0; |
| 191668 | 191988 | pRet->eType = FTS5_EOF; |
| 191669 | 191989 | } |
| 191670 | 191990 | } |
| 191671 | 191991 | |
| 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 | + } |
| 191686 | 192009 | }else{ |
| 191687 | 192010 | fts5ExprAddChildren(pRet, pLeft); |
| 191688 | 192011 | fts5ExprAddChildren(pRet, pRight); |
| 191689 | 192012 | } |
| 191690 | 192013 | } |
| | @@ -202049,11 +202372,11 @@ |
| 202049 | 202372 | int nArg, /* Number of args */ |
| 202050 | 202373 | sqlite3_value **apUnused /* Function arguments */ |
| 202051 | 202374 | ){ |
| 202052 | 202375 | assert( nArg==0 ); |
| 202053 | 202376 | 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); |
| 202055 | 202378 | } |
| 202056 | 202379 | |
| 202057 | 202380 | static int fts5Init(sqlite3 *db){ |
| 202058 | 202381 | static const sqlite3_module fts5Mod = { |
| 202059 | 202382 | /* iVersion */ 2, |
| | @@ -206317,12 +206640,12 @@ |
| 206317 | 206640 | } |
| 206318 | 206641 | #endif /* SQLITE_CORE */ |
| 206319 | 206642 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 206320 | 206643 | |
| 206321 | 206644 | /************** End of stmt.c ************************************************/ |
| 206322 | | -#if __LINE__!=206322 |
| 206645 | +#if __LINE__!=206645 |
| 206323 | 206646 | #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" |
| 206325 | 206648 | #endif |
| 206326 | 206649 | /* Return the source-id for this library */ |
| 206327 | 206650 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 206328 | 206651 | /************************** End of sqlite3.c ******************************/ |
| 206329 | 206652 | |