| | @@ -1156,11 +1156,11 @@ |
| 1156 | 1156 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1157 | 1157 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1158 | 1158 | */ |
| 1159 | 1159 | #define SQLITE_VERSION "3.25.0" |
| 1160 | 1160 | #define SQLITE_VERSION_NUMBER 3025000 |
| 1161 | | -#define SQLITE_SOURCE_ID "2018-09-06 18:56:36 91aab32e71fcb924e24c02d5f0901f7a474760fc993a7e7436e667512cf5d3c3" |
| 1161 | +#define SQLITE_SOURCE_ID "2018-09-10 19:34:06 74c381b573817d0212153278b5ee5d2238a27a727dcf7ee769365c47bb9fc40d" |
| 1162 | 1162 | |
| 1163 | 1163 | /* |
| 1164 | 1164 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1165 | 1165 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1166 | 1166 | ** |
| | @@ -18653,11 +18653,11 @@ |
| 18653 | 18653 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); |
| 18654 | 18654 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| 18655 | 18655 | SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*); |
| 18656 | 18656 | SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*); |
| 18657 | 18657 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| 18658 | | -SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*); |
| 18658 | +SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*); |
| 18659 | 18659 | SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*); |
| 18660 | 18660 | SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*); |
| 18661 | 18661 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); |
| 18662 | 18662 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); |
| 18663 | 18663 | #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ |
| | @@ -35271,11 +35271,11 @@ |
| 35271 | 35271 | assert( unixFileMutexNotheld(pFile) ); |
| 35272 | 35272 | unixEnterMutex(); |
| 35273 | 35273 | if( pFile->pInode ){ |
| 35274 | 35274 | unixInodeInfo *pInode = pFile->pInode; |
| 35275 | 35275 | sqlite3_mutex_enter(pInode->pLockMutex); |
| 35276 | | - if( pFile->pInode->nLock ){ |
| 35276 | + if( pInode->nLock ){ |
| 35277 | 35277 | /* If there are outstanding locks, do not actually close the file just |
| 35278 | 35278 | ** yet because that would clear those locks. Instead, add the file |
| 35279 | 35279 | ** descriptor to pInode->aPending. It will be automatically closed when |
| 35280 | 35280 | ** the last lock is cleared. |
| 35281 | 35281 | */ |
| | @@ -88405,10 +88405,11 @@ |
| 88405 | 88405 | { |
| 88406 | 88406 | zMaster = MASTER_NAME; |
| 88407 | 88407 | initData.db = db; |
| 88408 | 88408 | initData.iDb = pOp->p1; |
| 88409 | 88409 | initData.pzErrMsg = &p->zErrMsg; |
| 88410 | + initData.mInitFlags = 0; |
| 88410 | 88411 | zSql = sqlite3MPrintf(db, |
| 88411 | 88412 | "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid", |
| 88412 | 88413 | db->aDb[iDb].zDbSName, zMaster, pOp->p4.z); |
| 88413 | 88414 | if( zSql==0 ){ |
| 88414 | 88415 | rc = SQLITE_NOMEM_BKPT; |
| | @@ -102148,33 +102149,34 @@ |
| 102148 | 102149 | ** successful. Otherwise, return an SQLite error code and leave an error |
| 102149 | 102150 | ** message in the Parse object. |
| 102150 | 102151 | */ |
| 102151 | 102152 | static int renameResolveTrigger(Parse *pParse, const char *zDb){ |
| 102152 | 102153 | sqlite3 *db = pParse->db; |
| 102154 | + Trigger *pNew = pParse->pNewTrigger; |
| 102153 | 102155 | TriggerStep *pStep; |
| 102154 | 102156 | NameContext sNC; |
| 102155 | 102157 | int rc = SQLITE_OK; |
| 102156 | 102158 | |
| 102157 | 102159 | memset(&sNC, 0, sizeof(sNC)); |
| 102158 | 102160 | sNC.pParse = pParse; |
| 102159 | | - pParse->pTriggerTab = sqlite3FindTable(db, pParse->pNewTrigger->table, zDb); |
| 102160 | | - pParse->eTriggerOp = pParse->pNewTrigger->op; |
| 102161 | + assert( pNew->pTabSchema ); |
| 102162 | + pParse->pTriggerTab = sqlite3FindTable(db, pNew->table, |
| 102163 | + db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName |
| 102164 | + ); |
| 102165 | + pParse->eTriggerOp = pNew->op; |
| 102161 | 102166 | |
| 102162 | 102167 | /* Resolve symbols in WHEN clause */ |
| 102163 | | - if( pParse->pNewTrigger->pWhen ){ |
| 102164 | | - rc = sqlite3ResolveExprNames(&sNC, pParse->pNewTrigger->pWhen); |
| 102168 | + if( pNew->pWhen ){ |
| 102169 | + rc = sqlite3ResolveExprNames(&sNC, pNew->pWhen); |
| 102165 | 102170 | } |
| 102166 | 102171 | |
| 102167 | | - for(pStep=pParse->pNewTrigger->step_list; |
| 102168 | | - rc==SQLITE_OK && pStep; |
| 102169 | | - pStep=pStep->pNext |
| 102170 | | - ){ |
| 102172 | + for(pStep=pNew->step_list; rc==SQLITE_OK && pStep; pStep=pStep->pNext){ |
| 102171 | 102173 | if( pStep->pSelect ){ |
| 102172 | 102174 | sqlite3SelectPrep(pParse, pStep->pSelect, &sNC); |
| 102173 | 102175 | if( pParse->nErr ) rc = pParse->rc; |
| 102174 | 102176 | } |
| 102175 | | - if( rc==SQLITE_OK && pStep->zTarget ){ |
| 102177 | + if( rc==SQLITE_OK && pStep->zTarget ){ |
| 102176 | 102178 | Table *pTarget = sqlite3LocateTable(pParse, 0, pStep->zTarget, zDb); |
| 102177 | 102179 | if( pTarget==0 ){ |
| 102178 | 102180 | rc = SQLITE_ERROR; |
| 102179 | 102181 | }else{ |
| 102180 | 102182 | SrcList sSrc; |
| | @@ -102534,14 +102536,16 @@ |
| 102534 | 102536 | if( sParse.nErr ) rc = sParse.rc; |
| 102535 | 102537 | sqlite3WalkSelect(&sWalker, pTab->pSelect); |
| 102536 | 102538 | }else{ |
| 102537 | 102539 | /* Modify any FK definitions to point to the new table. */ |
| 102538 | 102540 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 102539 | | - FKey *pFKey; |
| 102540 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 102541 | | - if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 102542 | | - renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 102541 | + if( db->flags & SQLITE_ForeignKeys ){ |
| 102542 | + FKey *pFKey; |
| 102543 | + for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 102544 | + if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 102545 | + renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 102546 | + } |
| 102543 | 102547 | } |
| 102544 | 102548 | } |
| 102545 | 102549 | #endif |
| 102546 | 102550 | |
| 102547 | 102551 | /* If this is the table being altered, fix any table refs in CHECK |
| | @@ -109502,12 +109506,14 @@ |
| 109502 | 109506 | if( p==0 ){ |
| 109503 | 109507 | goto append_from_error; |
| 109504 | 109508 | } |
| 109505 | 109509 | assert( p->nSrc>0 ); |
| 109506 | 109510 | pItem = &p->a[p->nSrc-1]; |
| 109511 | + assert( (pTable==0)==(pDatabase==0) ); |
| 109512 | + assert( pItem->zName==0 || pDatabase!=0 ); |
| 109507 | 109513 | if( IN_RENAME_OBJECT && pItem->zName ){ |
| 109508 | | - Token *pToken = (pDatabase && pDatabase->z) ? pDatabase : pTable; |
| 109514 | + Token *pToken = (ALWAYS(pDatabase) && pDatabase->z) ? pDatabase : pTable; |
| 109509 | 109515 | sqlite3RenameTokenMap(pParse, pItem->zName, pToken); |
| 109510 | 109516 | } |
| 109511 | 109517 | assert( pAlias!=0 ); |
| 109512 | 109518 | if( pAlias->n ){ |
| 109513 | 109519 | pItem->zAlias = sqlite3NameFromToken(db, pAlias); |
| | @@ -117881,10 +117887,16 @@ |
| 117881 | 117887 | void (*str_appendchar)(sqlite3_str*, int N, char C); |
| 117882 | 117888 | void (*str_reset)(sqlite3_str*); |
| 117883 | 117889 | int (*str_errcode)(sqlite3_str*); |
| 117884 | 117890 | int (*str_length)(sqlite3_str*); |
| 117885 | 117891 | char *(*str_value)(sqlite3_str*); |
| 117892 | + int (*create_window_function)(sqlite3*,const char*,int,int,void*, |
| 117893 | + void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 117894 | + void (*xFinal)(sqlite3_context*), |
| 117895 | + void (*xValue)(sqlite3_context*), |
| 117896 | + void (*xInv)(sqlite3_context*,int,sqlite3_value**), |
| 117897 | + void(*xDestroy)(void*)); |
| 117886 | 117898 | }; |
| 117887 | 117899 | |
| 117888 | 117900 | /* |
| 117889 | 117901 | ** This is the function signature used for all extension entry points. It |
| 117890 | 117902 | ** is also defined in the file "loadext.c". |
| | @@ -118166,10 +118178,12 @@ |
| 118166 | 118178 | #define sqlite3_str_appendchar sqlite3_api->str_appendchar |
| 118167 | 118179 | #define sqlite3_str_reset sqlite3_api->str_reset |
| 118168 | 118180 | #define sqlite3_str_errcode sqlite3_api->str_errcode |
| 118169 | 118181 | #define sqlite3_str_length sqlite3_api->str_length |
| 118170 | 118182 | #define sqlite3_str_value sqlite3_api->str_value |
| 118183 | +/* Version 3.25.0 and later */ |
| 118184 | +#define sqlite3_create_window_function sqlite3_api->create_window_function |
| 118171 | 118185 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 118172 | 118186 | |
| 118173 | 118187 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 118174 | 118188 | /* This case when the file really is being compiled as a loadable |
| 118175 | 118189 | ** extension */ |
| | @@ -118619,11 +118633,13 @@ |
| 118619 | 118633 | sqlite3_str_appendall, |
| 118620 | 118634 | sqlite3_str_appendchar, |
| 118621 | 118635 | sqlite3_str_reset, |
| 118622 | 118636 | sqlite3_str_errcode, |
| 118623 | 118637 | sqlite3_str_length, |
| 118624 | | - sqlite3_str_value |
| 118638 | + sqlite3_str_value, |
| 118639 | + /* Version 3.25.0 and later */ |
| 118640 | + sqlite3_create_window_function |
| 118625 | 118641 | }; |
| 118626 | 118642 | |
| 118627 | 118643 | /* |
| 118628 | 118644 | ** Attempt to load an SQLite extension library contained in the file |
| 118629 | 118645 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| | @@ -123117,12 +123133,12 @@ |
| 123117 | 123133 | int iECursor; /* Cursor number for the sorter */ |
| 123118 | 123134 | int regReturn; /* Register holding block-output return address */ |
| 123119 | 123135 | int labelBkOut; /* Start label for the block-output subroutine */ |
| 123120 | 123136 | int addrSortIndex; /* Address of the OP_SorterOpen or OP_OpenEphemeral */ |
| 123121 | 123137 | int labelDone; /* Jump here when done, ex: LIMIT reached */ |
| 123138 | + int labelOBLopt; /* Jump here when sorter is full */ |
| 123122 | 123139 | u8 sortFlags; /* Zero or more SORTFLAG_* bits */ |
| 123123 | | - u8 bOrderedInnerLoop; /* ORDER BY correctly sorts the inner loop */ |
| 123124 | 123140 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 123125 | 123141 | u8 nDefer; /* Number of valid entries in aDefer[] */ |
| 123126 | 123142 | struct DeferredCsr { |
| 123127 | 123143 | Table *pTab; /* Table definition */ |
| 123128 | 123144 | int iCsr; /* Cursor number for table */ |
| | @@ -123742,14 +123758,14 @@ |
| 123742 | 123758 | ** are already LIMIT+OFFSET items in the sorter, delete the largest |
| 123743 | 123759 | ** entry before inserting the new one. This way there are never more |
| 123744 | 123760 | ** than LIMIT+OFFSET items in the sorter. |
| 123745 | 123761 | ** |
| 123746 | 123762 | ** If the new record does not need to be inserted into the sorter, |
| 123747 | | - ** jump to the next iteration of the loop. Or, if the |
| 123748 | | - ** pSort->bOrderedInnerLoop flag is set to indicate that the inner |
| 123749 | | - ** loop delivers items in sorted order, jump to the next iteration |
| 123750 | | - ** of the outer loop. |
| 123763 | + ** jump to the next iteration of the loop. If the pSort->labelOBLopt |
| 123764 | + ** value is not zero, then it is a label of where to jump. Otherwise, |
| 123765 | + ** just bypass the row insert logic. See the header comment on the |
| 123766 | + ** sqlite3WhereOrderByLimitOptLabel() function for additional info. |
| 123751 | 123767 | */ |
| 123752 | 123768 | int iCsr = pSort->iECursor; |
| 123753 | 123769 | sqlite3VdbeAddOp2(v, OP_IfNotZero, iLimit, sqlite3VdbeCurrentAddr(v)+4); |
| 123754 | 123770 | VdbeCoverage(v); |
| 123755 | 123771 | sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0); |
| | @@ -123767,13 +123783,12 @@ |
| 123767 | 123783 | op = OP_IdxInsert; |
| 123768 | 123784 | } |
| 123769 | 123785 | sqlite3VdbeAddOp4Int(v, op, pSort->iECursor, regRecord, |
| 123770 | 123786 | regBase+nOBSat, nBase-nOBSat); |
| 123771 | 123787 | if( iSkip ){ |
| 123772 | | - assert( pSort->bOrderedInnerLoop==0 || pSort->bOrderedInnerLoop==1 ); |
| 123773 | 123788 | sqlite3VdbeChangeP2(v, iSkip, |
| 123774 | | - sqlite3VdbeCurrentAddr(v) + pSort->bOrderedInnerLoop); |
| 123789 | + pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v)); |
| 123775 | 123790 | } |
| 123776 | 123791 | } |
| 123777 | 123792 | |
| 123778 | 123793 | /* |
| 123779 | 123794 | ** Add code to implement the OFFSET |
| | @@ -129109,11 +129124,11 @@ |
| 129109 | 129124 | if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){ |
| 129110 | 129125 | sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo); |
| 129111 | 129126 | } |
| 129112 | 129127 | if( sSort.pOrderBy ){ |
| 129113 | 129128 | sSort.nOBSat = sqlite3WhereIsOrdered(pWInfo); |
| 129114 | | - sSort.bOrderedInnerLoop = sqlite3WhereOrderedInnerLoop(pWInfo); |
| 129129 | + sSort.labelOBLopt = sqlite3WhereOrderByLimitOptLabel(pWInfo); |
| 129115 | 129130 | if( sSort.nOBSat==sSort.pOrderBy->nExpr ){ |
| 129116 | 129131 | sSort.pOrderBy = 0; |
| 129117 | 129132 | } |
| 129118 | 129133 | } |
| 129119 | 129134 | |
| | @@ -135312,11 +135327,11 @@ |
| 135312 | 135327 | ** an access of the index rather than the original table. |
| 135313 | 135328 | */ |
| 135314 | 135329 | static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){ |
| 135315 | 135330 | int rc = WRC_Continue; |
| 135316 | 135331 | struct CCurHint *pHint = pWalker->u.pCCurHint; |
| 135317 | | - if( pExpr->op==TK_COLUMN && !ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 135332 | + if( pExpr->op==TK_COLUMN ){ |
| 135318 | 135333 | if( pExpr->iTable!=pHint->iTabCur ){ |
| 135319 | 135334 | Vdbe *v = pWalker->pParse->pVdbe; |
| 135320 | 135335 | int reg = ++pWalker->pParse->nMem; /* Register for column value */ |
| 135321 | 135336 | sqlite3ExprCodeGetColumnOfTable( |
| 135322 | 135337 | v, pExpr->pTab, pExpr->iTable, pExpr->iColumn, reg |
| | @@ -136899,27 +136914,10 @@ |
| 136899 | 136914 | }else if( op==TK_STRING ){ |
| 136900 | 136915 | z = (u8*)pRight->u.zToken; |
| 136901 | 136916 | } |
| 136902 | 136917 | if( z ){ |
| 136903 | 136918 | |
| 136904 | | - /* If the RHS begins with a digit or a minus sign, then the LHS must |
| 136905 | | - ** be an ordinary column (not a virtual table column) with TEXT affinity. |
| 136906 | | - ** Otherwise the LHS might be numeric and "lhs >= rhs" would be false |
| 136907 | | - ** even though "lhs LIKE rhs" is true. But if the RHS does not start |
| 136908 | | - ** with a digit or '-', then "lhs LIKE rhs" will always be false if |
| 136909 | | - ** the LHS is numeric and so the optimization still works. |
| 136910 | | - */ |
| 136911 | | - if( sqlite3Isdigit(z[0]) || z[0]=='-' ){ |
| 136912 | | - if( pLeft->op!=TK_COLUMN |
| 136913 | | - || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 136914 | | - || IsVirtual(pLeft->pTab) /* Value might be numeric */ |
| 136915 | | - ){ |
| 136916 | | - sqlite3ValueFree(pVal); |
| 136917 | | - return 0; |
| 136918 | | - } |
| 136919 | | - } |
| 136920 | | - |
| 136921 | 136919 | /* Count the number of prefix characters prior to the first wildcard */ |
| 136922 | 136920 | cnt = 0; |
| 136923 | 136921 | while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ |
| 136924 | 136922 | cnt++; |
| 136925 | 136923 | if( c==wc[3] && z[cnt]!=0 ) cnt++; |
| | @@ -136948,10 +136946,36 @@ |
| 136948 | 136946 | for(iFrom=iTo=0; iFrom<cnt; iFrom++){ |
| 136949 | 136947 | if( zNew[iFrom]==wc[3] ) iFrom++; |
| 136950 | 136948 | zNew[iTo++] = zNew[iFrom]; |
| 136951 | 136949 | } |
| 136952 | 136950 | zNew[iTo] = 0; |
| 136951 | + |
| 136952 | + /* If the RHS begins with a digit or a minus sign, then the LHS must be |
| 136953 | + ** an ordinary column (not a virtual table column) with TEXT affinity. |
| 136954 | + ** Otherwise the LHS might be numeric and "lhs >= rhs" would be false |
| 136955 | + ** even though "lhs LIKE rhs" is true. But if the RHS does not start |
| 136956 | + ** with a digit or '-', then "lhs LIKE rhs" will always be false if |
| 136957 | + ** the LHS is numeric and so the optimization still works. |
| 136958 | + ** |
| 136959 | + ** 2018-09-10 ticket c94369cae9b561b1f996d0054bfab11389f9d033 |
| 136960 | + ** The RHS pattern must not be '/%' because the termination condition |
| 136961 | + ** will then become "x<'0'" and if the affinity is numeric, will then |
| 136962 | + ** be converted into "x<0", which is incorrect. |
| 136963 | + */ |
| 136964 | + if( sqlite3Isdigit(zNew[0]) |
| 136965 | + || zNew[0]=='-' |
| 136966 | + || (zNew[0]+1=='0' && iTo==1) |
| 136967 | + ){ |
| 136968 | + if( pLeft->op!=TK_COLUMN |
| 136969 | + || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 136970 | + || IsVirtual(pLeft->pTab) /* Value might be numeric */ |
| 136971 | + ){ |
| 136972 | + sqlite3ExprDelete(db, pPrefix); |
| 136973 | + sqlite3ValueFree(pVal); |
| 136974 | + return 0; |
| 136975 | + } |
| 136976 | + } |
| 136953 | 136977 | } |
| 136954 | 136978 | *ppPrefix = pPrefix; |
| 136955 | 136979 | |
| 136956 | 136980 | /* If the RHS pattern is a bound parameter, make arrangements to |
| 136957 | 136981 | ** reprepare the statement when that parameter is rebound */ |
| | @@ -138321,19 +138345,42 @@ |
| 138321 | 138345 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo *pWInfo){ |
| 138322 | 138346 | return pWInfo->nOBSat; |
| 138323 | 138347 | } |
| 138324 | 138348 | |
| 138325 | 138349 | /* |
| 138326 | | -** Return TRUE if the innermost loop of the WHERE clause implementation |
| 138327 | | -** returns rows in ORDER BY order for complete run of the inner loop. |
| 138350 | +** In the ORDER BY LIMIT optimization, if the inner-most loop is known |
| 138351 | +** to emit rows in increasing order, and if the last row emitted by the |
| 138352 | +** inner-most loop did not fit within the sorter, then we can skip all |
| 138353 | +** subsequent rows for the current iteration of the inner loop (because they |
| 138354 | +** will not fit in the sorter either) and continue with the second inner |
| 138355 | +** loop - the loop immediately outside the inner-most. |
| 138328 | 138356 | ** |
| 138329 | | -** Across multiple iterations of outer loops, the output rows need not be |
| 138330 | | -** sorted. As long as rows are sorted for just the innermost loop, this |
| 138331 | | -** routine can return TRUE. |
| 138357 | +** When a row does not fit in the sorter (because the sorter already |
| 138358 | +** holds LIMIT+OFFSET rows that are smaller), then a jump is made to the |
| 138359 | +** label returned by this function. |
| 138360 | +** |
| 138361 | +** If the ORDER BY LIMIT optimization applies, the jump destination should |
| 138362 | +** be the continuation for the second-inner-most loop. If the ORDER BY |
| 138363 | +** LIMIT optimization does not apply, then the jump destination should |
| 138364 | +** be the continuation for the inner-most loop. |
| 138365 | +** |
| 138366 | +** It is always safe for this routine to return the continuation of the |
| 138367 | +** inner-most loop, in the sense that a correct answer will result. |
| 138368 | +** Returning the continuation the second inner loop is an optimization |
| 138369 | +** that might make the code run a little faster, but should not change |
| 138370 | +** the final answer. |
| 138332 | 138371 | */ |
| 138333 | | -SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo *pWInfo){ |
| 138334 | | - return pWInfo->bOrderedInnerLoop; |
| 138372 | +SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo *pWInfo){ |
| 138373 | + WhereLevel *pInner; |
| 138374 | + if( !pWInfo->bOrderedInnerLoop ){ |
| 138375 | + /* The ORDER BY LIMIT optimization does not apply. Jump to the |
| 138376 | + ** continuation of the inner-most loop. */ |
| 138377 | + return pWInfo->iContinue; |
| 138378 | + } |
| 138379 | + pInner = &pWInfo->a[pWInfo->nLevel-1]; |
| 138380 | + assert( pInner->addrNxt!=0 ); |
| 138381 | + return pInner->addrNxt; |
| 138335 | 138382 | } |
| 138336 | 138383 | |
| 138337 | 138384 | /* |
| 138338 | 138385 | ** Return the VDBE address or label to jump to in order to continue |
| 138339 | 138386 | ** immediately with the next row of a WHERE clause. |
| | @@ -139197,10 +139244,24 @@ |
| 139197 | 139244 | testcase( pTerm->eOperator & WO_IS ); |
| 139198 | 139245 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 139199 | 139246 | testcase( pTerm->eOperator & WO_ALL ); |
| 139200 | 139247 | if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 139201 | 139248 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 139249 | + if( (pSrc->fg.jointype & JT_LEFT)!=0 |
| 139250 | + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 139251 | + && (pTerm->eOperator & (WO_IS|WO_ISNULL)) |
| 139252 | + ){ |
| 139253 | + /* An "IS" term in the WHERE clause where the virtual table is the rhs |
| 139254 | + ** of a LEFT JOIN. Do not pass this term to the virtual table |
| 139255 | + ** implementation, as this can lead to incorrect results from SQL such |
| 139256 | + ** as: |
| 139257 | + ** |
| 139258 | + ** "LEFT JOIN vtab WHERE vtab.col IS NULL" */ |
| 139259 | + testcase( pTerm->eOperator & WO_ISNULL ); |
| 139260 | + testcase( pTerm->eOperator & WO_IS ); |
| 139261 | + continue; |
| 139262 | + } |
| 139202 | 139263 | assert( pTerm->u.leftColumn>=(-1) ); |
| 139203 | 139264 | pIdxCons[j].iColumn = pTerm->u.leftColumn; |
| 139204 | 139265 | pIdxCons[j].iTermOffset = i; |
| 139205 | 139266 | op = pTerm->eOperator & WO_ALL; |
| 139206 | 139267 | if( op==WO_IN ) op = WO_EQ; |
| | @@ -142502,10 +142563,11 @@ |
| 142502 | 142563 | WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], ¬Used); |
| 142503 | 142564 | if( rc==pWInfo->pResultSet->nExpr ){ |
| 142504 | 142565 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 142505 | 142566 | } |
| 142506 | 142567 | } |
| 142568 | + pWInfo->bOrderedInnerLoop = 0; |
| 142507 | 142569 | if( pWInfo->pOrderBy ){ |
| 142508 | 142570 | if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){ |
| 142509 | 142571 | if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){ |
| 142510 | 142572 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 142511 | 142573 | } |
| | @@ -161029,11 +161091,11 @@ |
| 161029 | 161091 | */ |
| 161030 | 161092 | static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){ |
| 161031 | 161093 | int rc = SQLITE_OK; |
| 161032 | 161094 | UNUSED_PARAMETER(iSavepoint); |
| 161033 | 161095 | assert( ((Fts3Table *)pVtab)->inTransaction ); |
| 161034 | | - assert( ((Fts3Table *)pVtab)->mxSavepoint < iSavepoint ); |
| 161096 | + assert( ((Fts3Table *)pVtab)->mxSavepoint <= iSavepoint ); |
| 161035 | 161097 | TESTONLY( ((Fts3Table *)pVtab)->mxSavepoint = iSavepoint ); |
| 161036 | 161098 | if( ((Fts3Table *)pVtab)->bIgnoreSavepoint==0 ){ |
| 161037 | 161099 | rc = fts3SyncMethod(pVtab); |
| 161038 | 161100 | } |
| 161039 | 161101 | return rc; |
| | @@ -214325,11 +214387,11 @@ |
| 214325 | 214387 | int nArg, /* Number of args */ |
| 214326 | 214388 | sqlite3_value **apUnused /* Function arguments */ |
| 214327 | 214389 | ){ |
| 214328 | 214390 | assert( nArg==0 ); |
| 214329 | 214391 | UNUSED_PARAM2(nArg, apUnused); |
| 214330 | | - sqlite3_result_text(pCtx, "fts5: 2018-09-06 18:56:36 91aab32e71fcb924e24c02d5f0901f7a474760fc993a7e7436e667512cf5d3c3", -1, SQLITE_TRANSIENT); |
| 214392 | + sqlite3_result_text(pCtx, "fts5: 2018-09-10 16:38:25 564fa75195c5179d0bc86431aaff06136fc65ec63aa9839cd1114b1fbfac928b", -1, SQLITE_TRANSIENT); |
| 214331 | 214393 | } |
| 214332 | 214394 | |
| 214333 | 214395 | static int fts5Init(sqlite3 *db){ |
| 214334 | 214396 | static const sqlite3_module fts5Mod = { |
| 214335 | 214397 | /* iVersion */ 2, |
| | @@ -219035,12 +219097,12 @@ |
| 219035 | 219097 | } |
| 219036 | 219098 | #endif /* SQLITE_CORE */ |
| 219037 | 219099 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 219038 | 219100 | |
| 219039 | 219101 | /************** End of stmt.c ************************************************/ |
| 219040 | | -#if __LINE__!=219040 |
| 219102 | +#if __LINE__!=219102 |
| 219041 | 219103 | #undef SQLITE_SOURCE_ID |
| 219042 | | -#define SQLITE_SOURCE_ID "2018-09-06 18:56:36 91aab32e71fcb924e24c02d5f0901f7a474760fc993a7e7436e667512cf5alt2" |
| 219104 | +#define SQLITE_SOURCE_ID "2018-09-10 19:34:06 74c381b573817d0212153278b5ee5d2238a27a727dcf7ee769365c47bb9falt2" |
| 219043 | 219105 | #endif |
| 219044 | 219106 | /* Return the source-id for this library */ |
| 219045 | 219107 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 219046 | 219108 | /************************** End of sqlite3.c ******************************/ |
| 219047 | 219109 | |