Fossil SCM
Update the built-in SQLite to the first 3.35.0 beta, for testing of SQLite.
Commit
722073a15719cb21dcd65fd6e45db7ded029b3adf0fcede55cfc4509e36aac18
Parent
6fc730e0c76d4bd…
2 files changed
+182
-63
+1
-1
+182
-63
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1186,11 +1186,11 @@ | ||
| 1186 | 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | 1188 | */ |
| 1189 | 1189 | #define SQLITE_VERSION "3.35.0" |
| 1190 | 1190 | #define SQLITE_VERSION_NUMBER 3035000 |
| 1191 | -#define SQLITE_SOURCE_ID "2021-02-22 16:42:09 b5a0778cc5a98a864bea72670f83262da940aceb91fa4cdf46ec097337a3alt1" | |
| 1191 | +#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092" | |
| 1192 | 1192 | |
| 1193 | 1193 | /* |
| 1194 | 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | 1196 | ** |
| @@ -18665,10 +18665,11 @@ | ||
| 18665 | 18665 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 18666 | 18666 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 18667 | 18667 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 18668 | 18668 | #define SF_UpdateFrom 0x0800000 /* Statement is an UPDATE...FROM */ |
| 18669 | 18669 | #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ |
| 18670 | +#define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ | |
| 18670 | 18671 | |
| 18671 | 18672 | /* |
| 18672 | 18673 | ** The results of a SELECT can be distributed in several ways, as defined |
| 18673 | 18674 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 18674 | 18675 | ** Type". |
| @@ -50636,10 +50637,11 @@ | ||
| 50636 | 50637 | #endif |
| 50637 | 50638 | p->page.pBuf = pPg; |
| 50638 | 50639 | p->page.pExtra = &p[1]; |
| 50639 | 50640 | p->isBulkLocal = 0; |
| 50640 | 50641 | p->isAnchor = 0; |
| 50642 | + p->pLruPrev = 0; /* Initializing this saves a valgrind error */ | |
| 50641 | 50643 | } |
| 50642 | 50644 | (*pCache->pnPurgeable)++; |
| 50643 | 50645 | return p; |
| 50644 | 50646 | } |
| 50645 | 50647 | |
| @@ -52554,10 +52556,11 @@ | ||
| 52554 | 52556 | i64 iOffset; /* Starting offset in main journal */ |
| 52555 | 52557 | i64 iHdrOffset; /* See above */ |
| 52556 | 52558 | Bitvec *pInSavepoint; /* Set of pages in this savepoint */ |
| 52557 | 52559 | Pgno nOrig; /* Original number of pages in file */ |
| 52558 | 52560 | Pgno iSubRec; /* Index of first record in sub-journal */ |
| 52561 | + int bTruncateOnRelease; /* If stmt journal may be truncated on RELEASE */ | |
| 52559 | 52562 | #ifndef SQLITE_OMIT_WAL |
| 52560 | 52563 | u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */ |
| 52561 | 52564 | #endif |
| 52562 | 52565 | }; |
| 52563 | 52566 | |
| @@ -53189,10 +53192,13 @@ | ||
| 53189 | 53192 | Pgno pgno = pPg->pgno; |
| 53190 | 53193 | int i; |
| 53191 | 53194 | for(i=0; i<pPager->nSavepoint; i++){ |
| 53192 | 53195 | p = &pPager->aSavepoint[i]; |
| 53193 | 53196 | if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){ |
| 53197 | + for(i=i+1; i<pPager->nSavepoint; i++){ | |
| 53198 | + pPager->aSavepoint[i].bTruncateOnRelease = 0; | |
| 53199 | + } | |
| 53194 | 53200 | return 1; |
| 53195 | 53201 | } |
| 53196 | 53202 | } |
| 53197 | 53203 | return 0; |
| 53198 | 53204 | } |
| @@ -58967,10 +58973,11 @@ | ||
| 58967 | 58973 | }else{ |
| 58968 | 58974 | aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager); |
| 58969 | 58975 | } |
| 58970 | 58976 | aNew[ii].iSubRec = pPager->nSubRec; |
| 58971 | 58977 | aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize); |
| 58978 | + aNew[ii].bTruncateOnRelease = 1; | |
| 58972 | 58979 | if( !aNew[ii].pInSavepoint ){ |
| 58973 | 58980 | return SQLITE_NOMEM_BKPT; |
| 58974 | 58981 | } |
| 58975 | 58982 | if( pagerUseWal(pPager) ){ |
| 58976 | 58983 | sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData); |
| @@ -59048,17 +59055,19 @@ | ||
| 59048 | 59055 | pPager->nSavepoint = nNew; |
| 59049 | 59056 | |
| 59050 | 59057 | /* If this is a release of the outermost savepoint, truncate |
| 59051 | 59058 | ** the sub-journal to zero bytes in size. */ |
| 59052 | 59059 | if( op==SAVEPOINT_RELEASE ){ |
| 59053 | - if( nNew==0 && isOpen(pPager->sjfd) ){ | |
| 59060 | + PagerSavepoint *pRel = &pPager->aSavepoint[nNew]; | |
| 59061 | + if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){ | |
| 59054 | 59062 | /* Only truncate if it is an in-memory sub-journal. */ |
| 59055 | 59063 | if( sqlite3JournalIsInMemory(pPager->sjfd) ){ |
| 59056 | - rc = sqlite3OsTruncate(pPager->sjfd, 0); | |
| 59064 | + i64 sz = (pPager->pageSize+4)*pRel->iSubRec; | |
| 59065 | + rc = sqlite3OsTruncate(pPager->sjfd, sz); | |
| 59057 | 59066 | assert( rc==SQLITE_OK ); |
| 59058 | 59067 | } |
| 59059 | - pPager->nSubRec = 0; | |
| 59068 | + pPager->nSubRec = pRel->iSubRec; | |
| 59060 | 59069 | } |
| 59061 | 59070 | } |
| 59062 | 59071 | /* Else this is a rollback operation, playback the specified savepoint. |
| 59063 | 59072 | ** If this is a temp-file, it is possible that the journal file has |
| 59064 | 59073 | ** not yet been opened. In this case there have been no changes to |
| @@ -72558,11 +72567,13 @@ | ||
| 72558 | 72567 | }else{ |
| 72559 | 72568 | pRight = findCell(pParent, i+nxDiv-pParent->nOverflow); |
| 72560 | 72569 | } |
| 72561 | 72570 | pgno = get4byte(pRight); |
| 72562 | 72571 | while( 1 ){ |
| 72563 | - rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0); | |
| 72572 | + if( rc==SQLITE_OK ){ | |
| 72573 | + rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0); | |
| 72574 | + } | |
| 72564 | 72575 | if( rc ){ |
| 72565 | 72576 | memset(apOld, 0, (i+1)*sizeof(MemPage*)); |
| 72566 | 72577 | goto balance_cleanup; |
| 72567 | 72578 | } |
| 72568 | 72579 | if( apOld[i]->nFree<0 ){ |
| @@ -72597,16 +72608,14 @@ | ||
| 72597 | 72608 | ** buffer. It will be copied out again as soon as the aSpace[] buffer |
| 72598 | 72609 | ** is allocated. */ |
| 72599 | 72610 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| 72600 | 72611 | int iOff; |
| 72601 | 72612 | |
| 72613 | + /* If the following if() condition is not true, the db is corrupted. | |
| 72614 | + ** The call to dropCell() below will detect this. */ | |
| 72602 | 72615 | iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData); |
| 72603 | - if( (iOff+szNew[i])>(int)pBt->usableSize ){ | |
| 72604 | - rc = SQLITE_CORRUPT_BKPT; | |
| 72605 | - memset(apOld, 0, (i+1)*sizeof(MemPage*)); | |
| 72606 | - goto balance_cleanup; | |
| 72607 | - }else{ | |
| 72616 | + if( (iOff+szNew[i])<=(int)pBt->usableSize ){ | |
| 72608 | 72617 | memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]); |
| 72609 | 72618 | apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData]; |
| 72610 | 72619 | } |
| 72611 | 72620 | } |
| 72612 | 72621 | dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc); |
| @@ -97963,11 +97972,10 @@ | ||
| 97963 | 97972 | struct MemJournal { |
| 97964 | 97973 | const sqlite3_io_methods *pMethod; /* Parent class. MUST BE FIRST */ |
| 97965 | 97974 | int nChunkSize; /* In-memory chunk-size */ |
| 97966 | 97975 | |
| 97967 | 97976 | int nSpill; /* Bytes of data before flushing */ |
| 97968 | - int nSize; /* Bytes of data currently in memory */ | |
| 97969 | 97977 | FileChunk *pFirst; /* Head of in-memory chunk-list */ |
| 97970 | 97978 | FilePoint endpoint; /* Pointer to the end of the file */ |
| 97971 | 97979 | FilePoint readpoint; /* Pointer to the end of the last xRead() */ |
| 97972 | 97980 | |
| 97973 | 97981 | int flags; /* xOpen flags */ |
| @@ -98024,18 +98032,17 @@ | ||
| 98024 | 98032 | } |
| 98025 | 98033 | |
| 98026 | 98034 | /* |
| 98027 | 98035 | ** Free the list of FileChunk structures headed at MemJournal.pFirst. |
| 98028 | 98036 | */ |
| 98029 | -static void memjrnlFreeChunks(MemJournal *p){ | |
| 98037 | +static void memjrnlFreeChunks(FileChunk *pFirst){ | |
| 98030 | 98038 | FileChunk *pIter; |
| 98031 | 98039 | FileChunk *pNext; |
| 98032 | - for(pIter=p->pFirst; pIter; pIter=pNext){ | |
| 98040 | + for(pIter=pFirst; pIter; pIter=pNext){ | |
| 98033 | 98041 | pNext = pIter->pNext; |
| 98034 | 98042 | sqlite3_free(pIter); |
| 98035 | 98043 | } |
| 98036 | - p->pFirst = 0; | |
| 98037 | 98044 | } |
| 98038 | 98045 | |
| 98039 | 98046 | /* |
| 98040 | 98047 | ** Flush the contents of memory to a real file on disk. |
| 98041 | 98048 | */ |
| @@ -98058,11 +98065,11 @@ | ||
| 98058 | 98065 | if( rc ) break; |
| 98059 | 98066 | iOff += nChunk; |
| 98060 | 98067 | } |
| 98061 | 98068 | if( rc==SQLITE_OK ){ |
| 98062 | 98069 | /* No error has occurred. Free the in-memory buffers. */ |
| 98063 | - memjrnlFreeChunks(©); | |
| 98070 | + memjrnlFreeChunks(copy.pFirst); | |
| 98064 | 98071 | } |
| 98065 | 98072 | } |
| 98066 | 98073 | if( rc!=SQLITE_OK ){ |
| 98067 | 98074 | /* If an error occurred while creating or writing to the file, restore |
| 98068 | 98075 | ** the original before returning. This way, SQLite uses the in-memory |
| @@ -98141,43 +98148,50 @@ | ||
| 98141 | 98148 | memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace); |
| 98142 | 98149 | zWrite += iSpace; |
| 98143 | 98150 | nWrite -= iSpace; |
| 98144 | 98151 | p->endpoint.iOffset += iSpace; |
| 98145 | 98152 | } |
| 98146 | - p->nSize = iAmt + iOfst; | |
| 98147 | 98153 | } |
| 98148 | 98154 | } |
| 98149 | 98155 | |
| 98150 | 98156 | return SQLITE_OK; |
| 98151 | 98157 | } |
| 98152 | 98158 | |
| 98153 | 98159 | /* |
| 98154 | -** Truncate the file. | |
| 98155 | -** | |
| 98156 | -** If the journal file is already on disk, truncate it there. Or, if it | |
| 98157 | -** is still in main memory but is being truncated to zero bytes in size, | |
| 98158 | -** ignore | |
| 98160 | +** Truncate the in-memory file. | |
| 98159 | 98161 | */ |
| 98160 | 98162 | static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ |
| 98161 | 98163 | MemJournal *p = (MemJournal *)pJfd; |
| 98162 | - if( ALWAYS(size==0) ){ | |
| 98163 | - memjrnlFreeChunks(p); | |
| 98164 | - p->nSize = 0; | |
| 98165 | - p->endpoint.pChunk = 0; | |
| 98166 | - p->endpoint.iOffset = 0; | |
| 98167 | - p->readpoint.pChunk = 0; | |
| 98168 | - p->readpoint.iOffset = 0; | |
| 98169 | - } | |
| 98164 | + FileChunk *pIter = 0; | |
| 98165 | + | |
| 98166 | + if( size==0 ){ | |
| 98167 | + memjrnlFreeChunks(p->pFirst); | |
| 98168 | + p->pFirst = 0; | |
| 98169 | + }else{ | |
| 98170 | + i64 iOff = p->nChunkSize; | |
| 98171 | + for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){ | |
| 98172 | + iOff += p->nChunkSize; | |
| 98173 | + } | |
| 98174 | + if( pIter ){ | |
| 98175 | + memjrnlFreeChunks(pIter->pNext); | |
| 98176 | + pIter->pNext = 0; | |
| 98177 | + } | |
| 98178 | + } | |
| 98179 | + | |
| 98180 | + p->endpoint.pChunk = pIter; | |
| 98181 | + p->endpoint.iOffset = size; | |
| 98182 | + p->readpoint.pChunk = 0; | |
| 98183 | + p->readpoint.iOffset = 0; | |
| 98170 | 98184 | return SQLITE_OK; |
| 98171 | 98185 | } |
| 98172 | 98186 | |
| 98173 | 98187 | /* |
| 98174 | 98188 | ** Close the file. |
| 98175 | 98189 | */ |
| 98176 | 98190 | static int memjrnlClose(sqlite3_file *pJfd){ |
| 98177 | 98191 | MemJournal *p = (MemJournal *)pJfd; |
| 98178 | - memjrnlFreeChunks(p); | |
| 98192 | + memjrnlFreeChunks(p->pFirst); | |
| 98179 | 98193 | return SQLITE_OK; |
| 98180 | 98194 | } |
| 98181 | 98195 | |
| 98182 | 98196 | /* |
| 98183 | 98197 | ** Sync the file. |
| @@ -99359,10 +99373,48 @@ | ||
| 99359 | 99373 | pExpr->iTable = pItem->iCursor; |
| 99360 | 99374 | pExpr->iColumn--; |
| 99361 | 99375 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 99362 | 99376 | break; |
| 99363 | 99377 | } |
| 99378 | + | |
| 99379 | + /* An "<expr> IS NOT NULL" or "<expr> IS NULL". After resolving the | |
| 99380 | + ** LHS, check if there is a NOT NULL constraint in the schema that | |
| 99381 | + ** means the value of the expression can be determined immediately. | |
| 99382 | + ** If that is the case, replace the current expression node with | |
| 99383 | + ** a TK_TRUEFALSE node. | |
| 99384 | + ** | |
| 99385 | + ** If the node is replaced with a TK_TRUEFALSE node, then also restore | |
| 99386 | + ** the NameContext ref-counts to the state they where in before the | |
| 99387 | + ** LHS expression was resolved. This prevents the current select | |
| 99388 | + ** from being erroneously marked as correlated in some cases. | |
| 99389 | + */ | |
| 99390 | + case TK_NOTNULL: | |
| 99391 | + case TK_ISNULL: { | |
| 99392 | + int anRef[8]; | |
| 99393 | + NameContext *p; | |
| 99394 | + int i; | |
| 99395 | + for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ | |
| 99396 | + anRef[i] = p->nRef; | |
| 99397 | + } | |
| 99398 | + sqlite3WalkExpr(pWalker, pExpr->pLeft); | |
| 99399 | + if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) ){ | |
| 99400 | + if( pExpr->op==TK_NOTNULL ){ | |
| 99401 | + pExpr->u.zToken = "true"; | |
| 99402 | + ExprSetProperty(pExpr, EP_IsTrue); | |
| 99403 | + }else{ | |
| 99404 | + pExpr->u.zToken = "false"; | |
| 99405 | + ExprSetProperty(pExpr, EP_IsFalse); | |
| 99406 | + } | |
| 99407 | + pExpr->op = TK_TRUEFALSE; | |
| 99408 | + for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ | |
| 99409 | + p->nRef = anRef[i]; | |
| 99410 | + } | |
| 99411 | + sqlite3ExprDelete(pParse->db, pExpr->pLeft); | |
| 99412 | + pExpr->pLeft = 0; | |
| 99413 | + } | |
| 99414 | + return WRC_Prune; | |
| 99415 | + } | |
| 99364 | 99416 | |
| 99365 | 99417 | /* A column name: ID |
| 99366 | 99418 | ** Or table name and column name: ID.ID |
| 99367 | 99419 | ** Or a database, table and column: ID.ID.ID |
| 99368 | 99420 | ** |
| @@ -100164,29 +100216,28 @@ | ||
| 100164 | 100216 | /* Recursively resolve names in all subqueries |
| 100165 | 100217 | */ |
| 100166 | 100218 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 100167 | 100219 | SrcItem *pItem = &p->pSrc->a[i]; |
| 100168 | 100220 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){ |
| 100169 | - NameContext *pNC; /* Used to iterate name contexts */ | |
| 100170 | - int nRef = 0; /* Refcount for pOuterNC and outer contexts */ | |
| 100221 | + int nRef = pOuterNC ? pOuterNC->nRef : 0; | |
| 100171 | 100222 | const char *zSavedContext = pParse->zAuthContext; |
| 100172 | 100223 | |
| 100173 | - /* Count the total number of references to pOuterNC and all of its | |
| 100174 | - ** parent contexts. After resolving references to expressions in | |
| 100175 | - ** pItem->pSelect, check if this value has changed. If so, then | |
| 100176 | - ** SELECT statement pItem->pSelect must be correlated. Set the | |
| 100177 | - ** pItem->fg.isCorrelated flag if this is the case. */ | |
| 100178 | - for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef; | |
| 100179 | - | |
| 100180 | 100224 | if( pItem->zName ) pParse->zAuthContext = pItem->zName; |
| 100181 | 100225 | sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC); |
| 100182 | 100226 | pParse->zAuthContext = zSavedContext; |
| 100183 | 100227 | if( pParse->nErr || db->mallocFailed ) return WRC_Abort; |
| 100184 | 100228 | |
| 100185 | - for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef; | |
| 100186 | - assert( pItem->fg.isCorrelated==0 && nRef<=0 ); | |
| 100187 | - pItem->fg.isCorrelated = (nRef!=0); | |
| 100229 | + /* If the number of references to the outer context changed when | |
| 100230 | + ** expressions in the sub-select were resolved, the sub-select | |
| 100231 | + ** is correlated. It is not required to check the refcount on any | |
| 100232 | + ** but the innermost outer context object, as lookupName() increments | |
| 100233 | + ** the refcount on all contexts between the current one and the | |
| 100234 | + ** context containing the column when it resolves a name. */ | |
| 100235 | + if( pOuterNC ){ | |
| 100236 | + assert( pItem->fg.isCorrelated==0 && pOuterNC->nRef>=nRef ); | |
| 100237 | + pItem->fg.isCorrelated = (pOuterNC->nRef>nRef); | |
| 100238 | + } | |
| 100188 | 100239 | } |
| 100189 | 100240 | } |
| 100190 | 100241 | |
| 100191 | 100242 | /* Set up the local name-context to pass to sqlite3ResolveExprNames() to |
| 100192 | 100243 | ** resolve the result-set expression list. |
| @@ -114298,10 +114349,11 @@ | ||
| 114298 | 114349 | ** the column names from the SELECT statement that defines the view. |
| 114299 | 114350 | */ |
| 114300 | 114351 | assert( pTable->aCol==0 ); |
| 114301 | 114352 | pTable->nCol = pSelTab->nCol; |
| 114302 | 114353 | pTable->aCol = pSelTab->aCol; |
| 114354 | + pTable->tabFlags |= (pSelTab->tabFlags & COLFLAG_NOINSERT); | |
| 114303 | 114355 | pSelTab->nCol = 0; |
| 114304 | 114356 | pSelTab->aCol = 0; |
| 114305 | 114357 | assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); |
| 114306 | 114358 | } |
| 114307 | 114359 | pTable->nNVCol = pTable->nCol; |
| @@ -117505,14 +117557,16 @@ | ||
| 117505 | 117557 | } |
| 117506 | 117558 | |
| 117507 | 117559 | /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree |
| 117508 | 117560 | ** and the SELECT subtree. */ |
| 117509 | 117561 | pSrc->a[0].pTab = 0; |
| 117510 | - pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0); | |
| 117562 | + pSelectSrc = sqlite3SrcListDup(db, pSrc, 0); | |
| 117511 | 117563 | pSrc->a[0].pTab = pTab; |
| 117512 | 117564 | if( pSrc->a[0].fg.isIndexedBy ){ |
| 117513 | 117565 | pSrc->a[0].u2.pIBIndex = 0; |
| 117566 | + pSrc->a[0].fg.isIndexedBy = 0; | |
| 117567 | + sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy); | |
| 117514 | 117568 | }else if( pSrc->a[0].fg.isCte ){ |
| 117515 | 117569 | pSrc->a[0].u2.pCteUse->nUse++; |
| 117516 | 117570 | } |
| 117517 | 117571 | |
| 117518 | 117572 | /* generate the SELECT expression tree. */ |
| @@ -131396,10 +131450,13 @@ | ||
| 131396 | 131450 | static void unsetJoinExpr(Expr *p, int iTable){ |
| 131397 | 131451 | while( p ){ |
| 131398 | 131452 | if( ExprHasProperty(p, EP_FromJoin) |
| 131399 | 131453 | && (iTable<0 || p->iRightJoinTable==iTable) ){ |
| 131400 | 131454 | ExprClearProperty(p, EP_FromJoin); |
| 131455 | + } | |
| 131456 | + if( p->op==TK_COLUMN && p->iTable==iTable ){ | |
| 131457 | + ExprClearProperty(p, EP_CanBeNull); | |
| 131401 | 131458 | } |
| 131402 | 131459 | if( p->op==TK_FUNCTION && p->x.pList ){ |
| 131403 | 131460 | int i; |
| 131404 | 131461 | for(i=0; i<p->x.pList->nExpr; i++){ |
| 131405 | 131462 | unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| @@ -135479,10 +135536,39 @@ | ||
| 135479 | 135536 | } |
| 135480 | 135537 | }while( x.nChng ); |
| 135481 | 135538 | return nChng; |
| 135482 | 135539 | } |
| 135483 | 135540 | |
| 135541 | +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) | |
| 135542 | +# if !defined(SQLITE_OMIT_WINDOWFUNC) | |
| 135543 | +/* | |
| 135544 | +** This function is called to determine whether or not it is safe to | |
| 135545 | +** push WHERE clause expression pExpr down to FROM clause sub-query | |
| 135546 | +** pSubq, which contains at least one window function. Return 1 | |
| 135547 | +** if it is safe and the expression should be pushed down, or 0 | |
| 135548 | +** otherwise. | |
| 135549 | +** | |
| 135550 | +** It is only safe to push the expression down if it consists only | |
| 135551 | +** of constants and copies of expressions that appear in the PARTITION | |
| 135552 | +** BY clause of all window function used by the sub-query. It is safe | |
| 135553 | +** to filter out entire partitions, but not rows within partitions, as | |
| 135554 | +** this may change the results of the window functions. | |
| 135555 | +** | |
| 135556 | +** At the time this function is called it is guaranteed that | |
| 135557 | +** | |
| 135558 | +** * the sub-query uses only one distinct window frame, and | |
| 135559 | +** * that the window frame has a PARTITION BY clase. | |
| 135560 | +*/ | |
| 135561 | +static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ | |
| 135562 | + assert( pSubq->pWin->pPartition ); | |
| 135563 | + assert( (pSubq->selFlags & SF_MultiPart)==0 ); | |
| 135564 | + assert( pSubq->pPrior==0 ); | |
| 135565 | + return sqlite3ExprIsConstantOrGroupBy(pParse, pExpr, pSubq->pWin->pPartition); | |
| 135566 | +} | |
| 135567 | +# endif /* SQLITE_OMIT_WINDOWFUNC */ | |
| 135568 | +#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ | |
| 135569 | + | |
| 135484 | 135570 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 135485 | 135571 | /* |
| 135486 | 135572 | ** Make copies of relevant WHERE clause terms of the outer query into |
| 135487 | 135573 | ** the WHERE clause of subquery. Example: |
| 135488 | 135574 | ** |
| @@ -135526,13 +135612,24 @@ | ||
| 135526 | 135612 | ** |
| 135527 | 135613 | ** The correct answer is three rows: (1,1,NULL),(2,2,8),(2,2,9). |
| 135528 | 135614 | ** But if the (b2=2) term were to be pushed down into the bb subquery, |
| 135529 | 135615 | ** then the (1,1,NULL) row would be suppressed. |
| 135530 | 135616 | ** |
| 135531 | -** (6) The inner query features one or more window-functions (since | |
| 135532 | -** changes to the WHERE clause of the inner query could change the | |
| 135533 | -** window over which window functions are calculated). | |
| 135617 | +** (6) Window functions make things tricky as changes to the WHERE clause | |
| 135618 | +** of the inner query could change the window over which window | |
| 135619 | +** functions are calculated. Therefore, do not attempt the optimization | |
| 135620 | +** if: | |
| 135621 | +** | |
| 135622 | +** (6a) The inner query uses multiple incompatible window partitions. | |
| 135623 | +** | |
| 135624 | +** (6b) The inner query is a compound and uses window-functions. | |
| 135625 | +** | |
| 135626 | +** (6c) The WHERE clause does not consist entirely of constants and | |
| 135627 | +** copies of expressions found in the PARTITION BY clause of | |
| 135628 | +** all window-functions used by the sub-query. It is safe to | |
| 135629 | +** filter out entire partitions, as this does not change the | |
| 135630 | +** window over which any window-function is calculated. | |
| 135534 | 135631 | ** |
| 135535 | 135632 | ** (7) The inner query is a Common Table Expression (CTE) that should |
| 135536 | 135633 | ** be materialized. (This restriction is implemented in the calling |
| 135537 | 135634 | ** routine.) |
| 135538 | 135635 | ** |
| @@ -135546,17 +135643,21 @@ | ||
| 135546 | 135643 | int iCursor, /* Cursor number of the subquery */ |
| 135547 | 135644 | int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ |
| 135548 | 135645 | ){ |
| 135549 | 135646 | Expr *pNew; |
| 135550 | 135647 | int nChng = 0; |
| 135551 | - Select *pSel; | |
| 135552 | 135648 | if( pWhere==0 ) return 0; |
| 135553 | - if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ | |
| 135649 | + if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0; | |
| 135554 | 135650 | |
| 135555 | 135651 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 135556 | - for(pSel=pSubq; pSel; pSel=pSel->pPrior){ | |
| 135557 | - if( pSel->pWin ) return 0; /* restriction (6) */ | |
| 135652 | + if( pSubq->pPrior ){ | |
| 135653 | + Select *pSel; | |
| 135654 | + for(pSel=pSubq; pSel; pSel=pSel->pPrior){ | |
| 135655 | + if( pSel->pWin ) return 0; /* restriction (6b) */ | |
| 135656 | + } | |
| 135657 | + }else{ | |
| 135658 | + if( pSubq->pWin && pSubq->pWin->pPartition==0 ) return 0; | |
| 135558 | 135659 | } |
| 135559 | 135660 | #endif |
| 135560 | 135661 | |
| 135561 | 135662 | #ifdef SQLITE_DEBUG |
| 135562 | 135663 | /* Only the first term of a compound can have a WITH clause. But make |
| @@ -135599,10 +135700,18 @@ | ||
| 135599 | 135700 | x.iTable = iCursor; |
| 135600 | 135701 | x.iNewTable = iCursor; |
| 135601 | 135702 | x.isLeftJoin = 0; |
| 135602 | 135703 | x.pEList = pSubq->pEList; |
| 135603 | 135704 | pNew = substExpr(&x, pNew); |
| 135705 | +#ifndef SQLITE_OMIT_WINDOWFUNC | |
| 135706 | + if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){ | |
| 135707 | + /* Restriction 6c has prevented push-down in this case */ | |
| 135708 | + sqlite3ExprDelete(pParse->db, pNew); | |
| 135709 | + nChng--; | |
| 135710 | + break; | |
| 135711 | + } | |
| 135712 | +#endif | |
| 135604 | 135713 | if( pSubq->selFlags & SF_Aggregate ){ |
| 135605 | 135714 | pSubq->pHaving = sqlite3ExprAnd(pParse, pSubq->pHaving, pNew); |
| 135606 | 135715 | }else{ |
| 135607 | 135716 | pSubq->pWhere = sqlite3ExprAnd(pParse, pSubq->pWhere, pNew); |
| 135608 | 135717 | } |
| @@ -147542,10 +147651,16 @@ | ||
| 147542 | 147651 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 147543 | 147652 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 147544 | 147653 | pNew->prereqRight = prereqLeft | extraRight; |
| 147545 | 147654 | pNew->prereqAll = prereqAll; |
| 147546 | 147655 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| 147656 | + }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){ | |
| 147657 | + pExpr->op = TK_TRUEFALSE; | |
| 147658 | + pExpr->u.zToken = "false"; | |
| 147659 | + ExprSetProperty(pExpr, EP_IsFalse); | |
| 147660 | + pTerm->prereqAll = 0; | |
| 147661 | + pTerm->eOperator = 0; | |
| 147547 | 147662 | } |
| 147548 | 147663 | } |
| 147549 | 147664 | |
| 147550 | 147665 | #ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 147551 | 147666 | /* If a term is the BETWEEN operator, create two new virtual terms |
| @@ -153019,11 +153134,11 @@ | ||
| 153019 | 153134 | } |
| 153020 | 153135 | } |
| 153021 | 153136 | if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ |
| 153022 | 153137 | pWInfo->revMask = ALLBITS; |
| 153023 | 153138 | } |
| 153024 | - if( pParse->nErr || NEVER(db->mallocFailed) ){ | |
| 153139 | + if( pParse->nErr || db->mallocFailed ){ | |
| 153025 | 153140 | goto whereBeginError; |
| 153026 | 153141 | } |
| 153027 | 153142 | #ifdef WHERETRACE_ENABLED |
| 153028 | 153143 | if( sqlite3WhereTrace ){ |
| 153029 | 153144 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| @@ -154961,19 +155076,23 @@ | ||
| 154961 | 155076 | ** to be processed as part of SELECT statement pSel). The window is linked |
| 154962 | 155077 | ** in if either (a) there are no other windows already linked to this |
| 154963 | 155078 | ** SELECT, or (b) the windows already linked use a compatible window frame. |
| 154964 | 155079 | */ |
| 154965 | 155080 | SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin){ |
| 154966 | - if( pSel!=0 | |
| 154967 | - && (0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0)) | |
| 154968 | - ){ | |
| 154969 | - pWin->pNextWin = pSel->pWin; | |
| 154970 | - if( pSel->pWin ){ | |
| 154971 | - pSel->pWin->ppThis = &pWin->pNextWin; | |
| 154972 | - } | |
| 154973 | - pSel->pWin = pWin; | |
| 154974 | - pWin->ppThis = &pSel->pWin; | |
| 155081 | + if( pSel ){ | |
| 155082 | + if( 0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0) ){ | |
| 155083 | + pWin->pNextWin = pSel->pWin; | |
| 155084 | + if( pSel->pWin ){ | |
| 155085 | + pSel->pWin->ppThis = &pWin->pNextWin; | |
| 155086 | + } | |
| 155087 | + pSel->pWin = pWin; | |
| 155088 | + pWin->ppThis = &pSel->pWin; | |
| 155089 | + }else{ | |
| 155090 | + if( sqlite3ExprListCompare(pWin->pPartition, pSel->pWin->pPartition,-1) ){ | |
| 155091 | + pSel->selFlags |= SF_MultiPart; | |
| 155092 | + } | |
| 155093 | + } | |
| 154975 | 155094 | } |
| 154976 | 155095 | } |
| 154977 | 155096 | |
| 154978 | 155097 | /* |
| 154979 | 155098 | ** Return 0 if the two window objects are identical, 1 if they are |
| @@ -228990,11 +229109,11 @@ | ||
| 228990 | 229109 | int nArg, /* Number of args */ |
| 228991 | 229110 | sqlite3_value **apUnused /* Function arguments */ |
| 228992 | 229111 | ){ |
| 228993 | 229112 | assert( nArg==0 ); |
| 228994 | 229113 | UNUSED_PARAM2(nArg, apUnused); |
| 228995 | - sqlite3_result_text(pCtx, "fts5: 2021-02-22 11:07:25 b66a49570852cf118a372a6ac44be3070cf9b4254696f16315b7c79a614e6c35", -1, SQLITE_TRANSIENT); | |
| 229114 | + sqlite3_result_text(pCtx, "fts5: 2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092", -1, SQLITE_TRANSIENT); | |
| 228996 | 229115 | } |
| 228997 | 229116 | |
| 228998 | 229117 | /* |
| 228999 | 229118 | ** Return true if zName is the extension on one of the shadow tables used |
| 229000 | 229119 | ** by this module. |
| @@ -233916,12 +234035,12 @@ | ||
| 233916 | 234035 | } |
| 233917 | 234036 | #endif /* SQLITE_CORE */ |
| 233918 | 234037 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 233919 | 234038 | |
| 233920 | 234039 | /************** End of stmt.c ************************************************/ |
| 233921 | -#if __LINE__!=233921 | |
| 234040 | +#if __LINE__!=234040 | |
| 233922 | 234041 | #undef SQLITE_SOURCE_ID |
| 233923 | -#define SQLITE_SOURCE_ID "2021-02-22 16:42:09 b5a0778cc5a98a864bea72670f83262da940aceb91fa4cdf46ec097337a3alt2" | |
| 234042 | +#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9alt2" | |
| 233924 | 234043 | #endif |
| 233925 | 234044 | /* Return the source-id for this library */ |
| 233926 | 234045 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 233927 | 234046 | /************************** End of sqlite3.c ******************************/ |
| 233928 | 234047 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1186,11 +1186,11 @@ | |
| 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | */ |
| 1189 | #define SQLITE_VERSION "3.35.0" |
| 1190 | #define SQLITE_VERSION_NUMBER 3035000 |
| 1191 | #define SQLITE_SOURCE_ID "2021-02-22 16:42:09 b5a0778cc5a98a864bea72670f83262da940aceb91fa4cdf46ec097337a3alt1" |
| 1192 | |
| 1193 | /* |
| 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | ** |
| @@ -18665,10 +18665,11 @@ | |
| 18665 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 18666 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 18667 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 18668 | #define SF_UpdateFrom 0x0800000 /* Statement is an UPDATE...FROM */ |
| 18669 | #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ |
| 18670 | |
| 18671 | /* |
| 18672 | ** The results of a SELECT can be distributed in several ways, as defined |
| 18673 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 18674 | ** Type". |
| @@ -50636,10 +50637,11 @@ | |
| 50636 | #endif |
| 50637 | p->page.pBuf = pPg; |
| 50638 | p->page.pExtra = &p[1]; |
| 50639 | p->isBulkLocal = 0; |
| 50640 | p->isAnchor = 0; |
| 50641 | } |
| 50642 | (*pCache->pnPurgeable)++; |
| 50643 | return p; |
| 50644 | } |
| 50645 | |
| @@ -52554,10 +52556,11 @@ | |
| 52554 | i64 iOffset; /* Starting offset in main journal */ |
| 52555 | i64 iHdrOffset; /* See above */ |
| 52556 | Bitvec *pInSavepoint; /* Set of pages in this savepoint */ |
| 52557 | Pgno nOrig; /* Original number of pages in file */ |
| 52558 | Pgno iSubRec; /* Index of first record in sub-journal */ |
| 52559 | #ifndef SQLITE_OMIT_WAL |
| 52560 | u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */ |
| 52561 | #endif |
| 52562 | }; |
| 52563 | |
| @@ -53189,10 +53192,13 @@ | |
| 53189 | Pgno pgno = pPg->pgno; |
| 53190 | int i; |
| 53191 | for(i=0; i<pPager->nSavepoint; i++){ |
| 53192 | p = &pPager->aSavepoint[i]; |
| 53193 | if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){ |
| 53194 | return 1; |
| 53195 | } |
| 53196 | } |
| 53197 | return 0; |
| 53198 | } |
| @@ -58967,10 +58973,11 @@ | |
| 58967 | }else{ |
| 58968 | aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager); |
| 58969 | } |
| 58970 | aNew[ii].iSubRec = pPager->nSubRec; |
| 58971 | aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize); |
| 58972 | if( !aNew[ii].pInSavepoint ){ |
| 58973 | return SQLITE_NOMEM_BKPT; |
| 58974 | } |
| 58975 | if( pagerUseWal(pPager) ){ |
| 58976 | sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData); |
| @@ -59048,17 +59055,19 @@ | |
| 59048 | pPager->nSavepoint = nNew; |
| 59049 | |
| 59050 | /* If this is a release of the outermost savepoint, truncate |
| 59051 | ** the sub-journal to zero bytes in size. */ |
| 59052 | if( op==SAVEPOINT_RELEASE ){ |
| 59053 | if( nNew==0 && isOpen(pPager->sjfd) ){ |
| 59054 | /* Only truncate if it is an in-memory sub-journal. */ |
| 59055 | if( sqlite3JournalIsInMemory(pPager->sjfd) ){ |
| 59056 | rc = sqlite3OsTruncate(pPager->sjfd, 0); |
| 59057 | assert( rc==SQLITE_OK ); |
| 59058 | } |
| 59059 | pPager->nSubRec = 0; |
| 59060 | } |
| 59061 | } |
| 59062 | /* Else this is a rollback operation, playback the specified savepoint. |
| 59063 | ** If this is a temp-file, it is possible that the journal file has |
| 59064 | ** not yet been opened. In this case there have been no changes to |
| @@ -72558,11 +72567,13 @@ | |
| 72558 | }else{ |
| 72559 | pRight = findCell(pParent, i+nxDiv-pParent->nOverflow); |
| 72560 | } |
| 72561 | pgno = get4byte(pRight); |
| 72562 | while( 1 ){ |
| 72563 | rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0); |
| 72564 | if( rc ){ |
| 72565 | memset(apOld, 0, (i+1)*sizeof(MemPage*)); |
| 72566 | goto balance_cleanup; |
| 72567 | } |
| 72568 | if( apOld[i]->nFree<0 ){ |
| @@ -72597,16 +72608,14 @@ | |
| 72597 | ** buffer. It will be copied out again as soon as the aSpace[] buffer |
| 72598 | ** is allocated. */ |
| 72599 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| 72600 | int iOff; |
| 72601 | |
| 72602 | iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData); |
| 72603 | if( (iOff+szNew[i])>(int)pBt->usableSize ){ |
| 72604 | rc = SQLITE_CORRUPT_BKPT; |
| 72605 | memset(apOld, 0, (i+1)*sizeof(MemPage*)); |
| 72606 | goto balance_cleanup; |
| 72607 | }else{ |
| 72608 | memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]); |
| 72609 | apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData]; |
| 72610 | } |
| 72611 | } |
| 72612 | dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc); |
| @@ -97963,11 +97972,10 @@ | |
| 97963 | struct MemJournal { |
| 97964 | const sqlite3_io_methods *pMethod; /* Parent class. MUST BE FIRST */ |
| 97965 | int nChunkSize; /* In-memory chunk-size */ |
| 97966 | |
| 97967 | int nSpill; /* Bytes of data before flushing */ |
| 97968 | int nSize; /* Bytes of data currently in memory */ |
| 97969 | FileChunk *pFirst; /* Head of in-memory chunk-list */ |
| 97970 | FilePoint endpoint; /* Pointer to the end of the file */ |
| 97971 | FilePoint readpoint; /* Pointer to the end of the last xRead() */ |
| 97972 | |
| 97973 | int flags; /* xOpen flags */ |
| @@ -98024,18 +98032,17 @@ | |
| 98024 | } |
| 98025 | |
| 98026 | /* |
| 98027 | ** Free the list of FileChunk structures headed at MemJournal.pFirst. |
| 98028 | */ |
| 98029 | static void memjrnlFreeChunks(MemJournal *p){ |
| 98030 | FileChunk *pIter; |
| 98031 | FileChunk *pNext; |
| 98032 | for(pIter=p->pFirst; pIter; pIter=pNext){ |
| 98033 | pNext = pIter->pNext; |
| 98034 | sqlite3_free(pIter); |
| 98035 | } |
| 98036 | p->pFirst = 0; |
| 98037 | } |
| 98038 | |
| 98039 | /* |
| 98040 | ** Flush the contents of memory to a real file on disk. |
| 98041 | */ |
| @@ -98058,11 +98065,11 @@ | |
| 98058 | if( rc ) break; |
| 98059 | iOff += nChunk; |
| 98060 | } |
| 98061 | if( rc==SQLITE_OK ){ |
| 98062 | /* No error has occurred. Free the in-memory buffers. */ |
| 98063 | memjrnlFreeChunks(©); |
| 98064 | } |
| 98065 | } |
| 98066 | if( rc!=SQLITE_OK ){ |
| 98067 | /* If an error occurred while creating or writing to the file, restore |
| 98068 | ** the original before returning. This way, SQLite uses the in-memory |
| @@ -98141,43 +98148,50 @@ | |
| 98141 | memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace); |
| 98142 | zWrite += iSpace; |
| 98143 | nWrite -= iSpace; |
| 98144 | p->endpoint.iOffset += iSpace; |
| 98145 | } |
| 98146 | p->nSize = iAmt + iOfst; |
| 98147 | } |
| 98148 | } |
| 98149 | |
| 98150 | return SQLITE_OK; |
| 98151 | } |
| 98152 | |
| 98153 | /* |
| 98154 | ** Truncate the file. |
| 98155 | ** |
| 98156 | ** If the journal file is already on disk, truncate it there. Or, if it |
| 98157 | ** is still in main memory but is being truncated to zero bytes in size, |
| 98158 | ** ignore |
| 98159 | */ |
| 98160 | static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ |
| 98161 | MemJournal *p = (MemJournal *)pJfd; |
| 98162 | if( ALWAYS(size==0) ){ |
| 98163 | memjrnlFreeChunks(p); |
| 98164 | p->nSize = 0; |
| 98165 | p->endpoint.pChunk = 0; |
| 98166 | p->endpoint.iOffset = 0; |
| 98167 | p->readpoint.pChunk = 0; |
| 98168 | p->readpoint.iOffset = 0; |
| 98169 | } |
| 98170 | return SQLITE_OK; |
| 98171 | } |
| 98172 | |
| 98173 | /* |
| 98174 | ** Close the file. |
| 98175 | */ |
| 98176 | static int memjrnlClose(sqlite3_file *pJfd){ |
| 98177 | MemJournal *p = (MemJournal *)pJfd; |
| 98178 | memjrnlFreeChunks(p); |
| 98179 | return SQLITE_OK; |
| 98180 | } |
| 98181 | |
| 98182 | /* |
| 98183 | ** Sync the file. |
| @@ -99359,10 +99373,48 @@ | |
| 99359 | pExpr->iTable = pItem->iCursor; |
| 99360 | pExpr->iColumn--; |
| 99361 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 99362 | break; |
| 99363 | } |
| 99364 | |
| 99365 | /* A column name: ID |
| 99366 | ** Or table name and column name: ID.ID |
| 99367 | ** Or a database, table and column: ID.ID.ID |
| 99368 | ** |
| @@ -100164,29 +100216,28 @@ | |
| 100164 | /* Recursively resolve names in all subqueries |
| 100165 | */ |
| 100166 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 100167 | SrcItem *pItem = &p->pSrc->a[i]; |
| 100168 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){ |
| 100169 | NameContext *pNC; /* Used to iterate name contexts */ |
| 100170 | int nRef = 0; /* Refcount for pOuterNC and outer contexts */ |
| 100171 | const char *zSavedContext = pParse->zAuthContext; |
| 100172 | |
| 100173 | /* Count the total number of references to pOuterNC and all of its |
| 100174 | ** parent contexts. After resolving references to expressions in |
| 100175 | ** pItem->pSelect, check if this value has changed. If so, then |
| 100176 | ** SELECT statement pItem->pSelect must be correlated. Set the |
| 100177 | ** pItem->fg.isCorrelated flag if this is the case. */ |
| 100178 | for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef; |
| 100179 | |
| 100180 | if( pItem->zName ) pParse->zAuthContext = pItem->zName; |
| 100181 | sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC); |
| 100182 | pParse->zAuthContext = zSavedContext; |
| 100183 | if( pParse->nErr || db->mallocFailed ) return WRC_Abort; |
| 100184 | |
| 100185 | for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef; |
| 100186 | assert( pItem->fg.isCorrelated==0 && nRef<=0 ); |
| 100187 | pItem->fg.isCorrelated = (nRef!=0); |
| 100188 | } |
| 100189 | } |
| 100190 | |
| 100191 | /* Set up the local name-context to pass to sqlite3ResolveExprNames() to |
| 100192 | ** resolve the result-set expression list. |
| @@ -114298,10 +114349,11 @@ | |
| 114298 | ** the column names from the SELECT statement that defines the view. |
| 114299 | */ |
| 114300 | assert( pTable->aCol==0 ); |
| 114301 | pTable->nCol = pSelTab->nCol; |
| 114302 | pTable->aCol = pSelTab->aCol; |
| 114303 | pSelTab->nCol = 0; |
| 114304 | pSelTab->aCol = 0; |
| 114305 | assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); |
| 114306 | } |
| 114307 | pTable->nNVCol = pTable->nCol; |
| @@ -117505,14 +117557,16 @@ | |
| 117505 | } |
| 117506 | |
| 117507 | /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree |
| 117508 | ** and the SELECT subtree. */ |
| 117509 | pSrc->a[0].pTab = 0; |
| 117510 | pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0); |
| 117511 | pSrc->a[0].pTab = pTab; |
| 117512 | if( pSrc->a[0].fg.isIndexedBy ){ |
| 117513 | pSrc->a[0].u2.pIBIndex = 0; |
| 117514 | }else if( pSrc->a[0].fg.isCte ){ |
| 117515 | pSrc->a[0].u2.pCteUse->nUse++; |
| 117516 | } |
| 117517 | |
| 117518 | /* generate the SELECT expression tree. */ |
| @@ -131396,10 +131450,13 @@ | |
| 131396 | static void unsetJoinExpr(Expr *p, int iTable){ |
| 131397 | while( p ){ |
| 131398 | if( ExprHasProperty(p, EP_FromJoin) |
| 131399 | && (iTable<0 || p->iRightJoinTable==iTable) ){ |
| 131400 | ExprClearProperty(p, EP_FromJoin); |
| 131401 | } |
| 131402 | if( p->op==TK_FUNCTION && p->x.pList ){ |
| 131403 | int i; |
| 131404 | for(i=0; i<p->x.pList->nExpr; i++){ |
| 131405 | unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| @@ -135479,10 +135536,39 @@ | |
| 135479 | } |
| 135480 | }while( x.nChng ); |
| 135481 | return nChng; |
| 135482 | } |
| 135483 | |
| 135484 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 135485 | /* |
| 135486 | ** Make copies of relevant WHERE clause terms of the outer query into |
| 135487 | ** the WHERE clause of subquery. Example: |
| 135488 | ** |
| @@ -135526,13 +135612,24 @@ | |
| 135526 | ** |
| 135527 | ** The correct answer is three rows: (1,1,NULL),(2,2,8),(2,2,9). |
| 135528 | ** But if the (b2=2) term were to be pushed down into the bb subquery, |
| 135529 | ** then the (1,1,NULL) row would be suppressed. |
| 135530 | ** |
| 135531 | ** (6) The inner query features one or more window-functions (since |
| 135532 | ** changes to the WHERE clause of the inner query could change the |
| 135533 | ** window over which window functions are calculated). |
| 135534 | ** |
| 135535 | ** (7) The inner query is a Common Table Expression (CTE) that should |
| 135536 | ** be materialized. (This restriction is implemented in the calling |
| 135537 | ** routine.) |
| 135538 | ** |
| @@ -135546,17 +135643,21 @@ | |
| 135546 | int iCursor, /* Cursor number of the subquery */ |
| 135547 | int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ |
| 135548 | ){ |
| 135549 | Expr *pNew; |
| 135550 | int nChng = 0; |
| 135551 | Select *pSel; |
| 135552 | if( pWhere==0 ) return 0; |
| 135553 | if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ |
| 135554 | |
| 135555 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 135556 | for(pSel=pSubq; pSel; pSel=pSel->pPrior){ |
| 135557 | if( pSel->pWin ) return 0; /* restriction (6) */ |
| 135558 | } |
| 135559 | #endif |
| 135560 | |
| 135561 | #ifdef SQLITE_DEBUG |
| 135562 | /* Only the first term of a compound can have a WITH clause. But make |
| @@ -135599,10 +135700,18 @@ | |
| 135599 | x.iTable = iCursor; |
| 135600 | x.iNewTable = iCursor; |
| 135601 | x.isLeftJoin = 0; |
| 135602 | x.pEList = pSubq->pEList; |
| 135603 | pNew = substExpr(&x, pNew); |
| 135604 | if( pSubq->selFlags & SF_Aggregate ){ |
| 135605 | pSubq->pHaving = sqlite3ExprAnd(pParse, pSubq->pHaving, pNew); |
| 135606 | }else{ |
| 135607 | pSubq->pWhere = sqlite3ExprAnd(pParse, pSubq->pWhere, pNew); |
| 135608 | } |
| @@ -147542,10 +147651,16 @@ | |
| 147542 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 147543 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 147544 | pNew->prereqRight = prereqLeft | extraRight; |
| 147545 | pNew->prereqAll = prereqAll; |
| 147546 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| 147547 | } |
| 147548 | } |
| 147549 | |
| 147550 | #ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 147551 | /* If a term is the BETWEEN operator, create two new virtual terms |
| @@ -153019,11 +153134,11 @@ | |
| 153019 | } |
| 153020 | } |
| 153021 | if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ |
| 153022 | pWInfo->revMask = ALLBITS; |
| 153023 | } |
| 153024 | if( pParse->nErr || NEVER(db->mallocFailed) ){ |
| 153025 | goto whereBeginError; |
| 153026 | } |
| 153027 | #ifdef WHERETRACE_ENABLED |
| 153028 | if( sqlite3WhereTrace ){ |
| 153029 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| @@ -154961,19 +155076,23 @@ | |
| 154961 | ** to be processed as part of SELECT statement pSel). The window is linked |
| 154962 | ** in if either (a) there are no other windows already linked to this |
| 154963 | ** SELECT, or (b) the windows already linked use a compatible window frame. |
| 154964 | */ |
| 154965 | SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin){ |
| 154966 | if( pSel!=0 |
| 154967 | && (0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0)) |
| 154968 | ){ |
| 154969 | pWin->pNextWin = pSel->pWin; |
| 154970 | if( pSel->pWin ){ |
| 154971 | pSel->pWin->ppThis = &pWin->pNextWin; |
| 154972 | } |
| 154973 | pSel->pWin = pWin; |
| 154974 | pWin->ppThis = &pSel->pWin; |
| 154975 | } |
| 154976 | } |
| 154977 | |
| 154978 | /* |
| 154979 | ** Return 0 if the two window objects are identical, 1 if they are |
| @@ -228990,11 +229109,11 @@ | |
| 228990 | int nArg, /* Number of args */ |
| 228991 | sqlite3_value **apUnused /* Function arguments */ |
| 228992 | ){ |
| 228993 | assert( nArg==0 ); |
| 228994 | UNUSED_PARAM2(nArg, apUnused); |
| 228995 | sqlite3_result_text(pCtx, "fts5: 2021-02-22 11:07:25 b66a49570852cf118a372a6ac44be3070cf9b4254696f16315b7c79a614e6c35", -1, SQLITE_TRANSIENT); |
| 228996 | } |
| 228997 | |
| 228998 | /* |
| 228999 | ** Return true if zName is the extension on one of the shadow tables used |
| 229000 | ** by this module. |
| @@ -233916,12 +234035,12 @@ | |
| 233916 | } |
| 233917 | #endif /* SQLITE_CORE */ |
| 233918 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 233919 | |
| 233920 | /************** End of stmt.c ************************************************/ |
| 233921 | #if __LINE__!=233921 |
| 233922 | #undef SQLITE_SOURCE_ID |
| 233923 | #define SQLITE_SOURCE_ID "2021-02-22 16:42:09 b5a0778cc5a98a864bea72670f83262da940aceb91fa4cdf46ec097337a3alt2" |
| 233924 | #endif |
| 233925 | /* Return the source-id for this library */ |
| 233926 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 233927 | /************************** End of sqlite3.c ******************************/ |
| 233928 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1186,11 +1186,11 @@ | |
| 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | */ |
| 1189 | #define SQLITE_VERSION "3.35.0" |
| 1190 | #define SQLITE_VERSION_NUMBER 3035000 |
| 1191 | #define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092" |
| 1192 | |
| 1193 | /* |
| 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | ** |
| @@ -18665,10 +18665,11 @@ | |
| 18665 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 18666 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 18667 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 18668 | #define SF_UpdateFrom 0x0800000 /* Statement is an UPDATE...FROM */ |
| 18669 | #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ |
| 18670 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 18671 | |
| 18672 | /* |
| 18673 | ** The results of a SELECT can be distributed in several ways, as defined |
| 18674 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 18675 | ** Type". |
| @@ -50636,10 +50637,11 @@ | |
| 50637 | #endif |
| 50638 | p->page.pBuf = pPg; |
| 50639 | p->page.pExtra = &p[1]; |
| 50640 | p->isBulkLocal = 0; |
| 50641 | p->isAnchor = 0; |
| 50642 | p->pLruPrev = 0; /* Initializing this saves a valgrind error */ |
| 50643 | } |
| 50644 | (*pCache->pnPurgeable)++; |
| 50645 | return p; |
| 50646 | } |
| 50647 | |
| @@ -52554,10 +52556,11 @@ | |
| 52556 | i64 iOffset; /* Starting offset in main journal */ |
| 52557 | i64 iHdrOffset; /* See above */ |
| 52558 | Bitvec *pInSavepoint; /* Set of pages in this savepoint */ |
| 52559 | Pgno nOrig; /* Original number of pages in file */ |
| 52560 | Pgno iSubRec; /* Index of first record in sub-journal */ |
| 52561 | int bTruncateOnRelease; /* If stmt journal may be truncated on RELEASE */ |
| 52562 | #ifndef SQLITE_OMIT_WAL |
| 52563 | u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */ |
| 52564 | #endif |
| 52565 | }; |
| 52566 | |
| @@ -53189,10 +53192,13 @@ | |
| 53192 | Pgno pgno = pPg->pgno; |
| 53193 | int i; |
| 53194 | for(i=0; i<pPager->nSavepoint; i++){ |
| 53195 | p = &pPager->aSavepoint[i]; |
| 53196 | if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){ |
| 53197 | for(i=i+1; i<pPager->nSavepoint; i++){ |
| 53198 | pPager->aSavepoint[i].bTruncateOnRelease = 0; |
| 53199 | } |
| 53200 | return 1; |
| 53201 | } |
| 53202 | } |
| 53203 | return 0; |
| 53204 | } |
| @@ -58967,10 +58973,11 @@ | |
| 58973 | }else{ |
| 58974 | aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager); |
| 58975 | } |
| 58976 | aNew[ii].iSubRec = pPager->nSubRec; |
| 58977 | aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize); |
| 58978 | aNew[ii].bTruncateOnRelease = 1; |
| 58979 | if( !aNew[ii].pInSavepoint ){ |
| 58980 | return SQLITE_NOMEM_BKPT; |
| 58981 | } |
| 58982 | if( pagerUseWal(pPager) ){ |
| 58983 | sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData); |
| @@ -59048,17 +59055,19 @@ | |
| 59055 | pPager->nSavepoint = nNew; |
| 59056 | |
| 59057 | /* If this is a release of the outermost savepoint, truncate |
| 59058 | ** the sub-journal to zero bytes in size. */ |
| 59059 | if( op==SAVEPOINT_RELEASE ){ |
| 59060 | PagerSavepoint *pRel = &pPager->aSavepoint[nNew]; |
| 59061 | if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){ |
| 59062 | /* Only truncate if it is an in-memory sub-journal. */ |
| 59063 | if( sqlite3JournalIsInMemory(pPager->sjfd) ){ |
| 59064 | i64 sz = (pPager->pageSize+4)*pRel->iSubRec; |
| 59065 | rc = sqlite3OsTruncate(pPager->sjfd, sz); |
| 59066 | assert( rc==SQLITE_OK ); |
| 59067 | } |
| 59068 | pPager->nSubRec = pRel->iSubRec; |
| 59069 | } |
| 59070 | } |
| 59071 | /* Else this is a rollback operation, playback the specified savepoint. |
| 59072 | ** If this is a temp-file, it is possible that the journal file has |
| 59073 | ** not yet been opened. In this case there have been no changes to |
| @@ -72558,11 +72567,13 @@ | |
| 72567 | }else{ |
| 72568 | pRight = findCell(pParent, i+nxDiv-pParent->nOverflow); |
| 72569 | } |
| 72570 | pgno = get4byte(pRight); |
| 72571 | while( 1 ){ |
| 72572 | if( rc==SQLITE_OK ){ |
| 72573 | rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0); |
| 72574 | } |
| 72575 | if( rc ){ |
| 72576 | memset(apOld, 0, (i+1)*sizeof(MemPage*)); |
| 72577 | goto balance_cleanup; |
| 72578 | } |
| 72579 | if( apOld[i]->nFree<0 ){ |
| @@ -72597,16 +72608,14 @@ | |
| 72608 | ** buffer. It will be copied out again as soon as the aSpace[] buffer |
| 72609 | ** is allocated. */ |
| 72610 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| 72611 | int iOff; |
| 72612 | |
| 72613 | /* If the following if() condition is not true, the db is corrupted. |
| 72614 | ** The call to dropCell() below will detect this. */ |
| 72615 | iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData); |
| 72616 | if( (iOff+szNew[i])<=(int)pBt->usableSize ){ |
| 72617 | memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]); |
| 72618 | apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData]; |
| 72619 | } |
| 72620 | } |
| 72621 | dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc); |
| @@ -97963,11 +97972,10 @@ | |
| 97972 | struct MemJournal { |
| 97973 | const sqlite3_io_methods *pMethod; /* Parent class. MUST BE FIRST */ |
| 97974 | int nChunkSize; /* In-memory chunk-size */ |
| 97975 | |
| 97976 | int nSpill; /* Bytes of data before flushing */ |
| 97977 | FileChunk *pFirst; /* Head of in-memory chunk-list */ |
| 97978 | FilePoint endpoint; /* Pointer to the end of the file */ |
| 97979 | FilePoint readpoint; /* Pointer to the end of the last xRead() */ |
| 97980 | |
| 97981 | int flags; /* xOpen flags */ |
| @@ -98024,18 +98032,17 @@ | |
| 98032 | } |
| 98033 | |
| 98034 | /* |
| 98035 | ** Free the list of FileChunk structures headed at MemJournal.pFirst. |
| 98036 | */ |
| 98037 | static void memjrnlFreeChunks(FileChunk *pFirst){ |
| 98038 | FileChunk *pIter; |
| 98039 | FileChunk *pNext; |
| 98040 | for(pIter=pFirst; pIter; pIter=pNext){ |
| 98041 | pNext = pIter->pNext; |
| 98042 | sqlite3_free(pIter); |
| 98043 | } |
| 98044 | } |
| 98045 | |
| 98046 | /* |
| 98047 | ** Flush the contents of memory to a real file on disk. |
| 98048 | */ |
| @@ -98058,11 +98065,11 @@ | |
| 98065 | if( rc ) break; |
| 98066 | iOff += nChunk; |
| 98067 | } |
| 98068 | if( rc==SQLITE_OK ){ |
| 98069 | /* No error has occurred. Free the in-memory buffers. */ |
| 98070 | memjrnlFreeChunks(copy.pFirst); |
| 98071 | } |
| 98072 | } |
| 98073 | if( rc!=SQLITE_OK ){ |
| 98074 | /* If an error occurred while creating or writing to the file, restore |
| 98075 | ** the original before returning. This way, SQLite uses the in-memory |
| @@ -98141,43 +98148,50 @@ | |
| 98148 | memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace); |
| 98149 | zWrite += iSpace; |
| 98150 | nWrite -= iSpace; |
| 98151 | p->endpoint.iOffset += iSpace; |
| 98152 | } |
| 98153 | } |
| 98154 | } |
| 98155 | |
| 98156 | return SQLITE_OK; |
| 98157 | } |
| 98158 | |
| 98159 | /* |
| 98160 | ** Truncate the in-memory file. |
| 98161 | */ |
| 98162 | static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ |
| 98163 | MemJournal *p = (MemJournal *)pJfd; |
| 98164 | FileChunk *pIter = 0; |
| 98165 | |
| 98166 | if( size==0 ){ |
| 98167 | memjrnlFreeChunks(p->pFirst); |
| 98168 | p->pFirst = 0; |
| 98169 | }else{ |
| 98170 | i64 iOff = p->nChunkSize; |
| 98171 | for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){ |
| 98172 | iOff += p->nChunkSize; |
| 98173 | } |
| 98174 | if( pIter ){ |
| 98175 | memjrnlFreeChunks(pIter->pNext); |
| 98176 | pIter->pNext = 0; |
| 98177 | } |
| 98178 | } |
| 98179 | |
| 98180 | p->endpoint.pChunk = pIter; |
| 98181 | p->endpoint.iOffset = size; |
| 98182 | p->readpoint.pChunk = 0; |
| 98183 | p->readpoint.iOffset = 0; |
| 98184 | return SQLITE_OK; |
| 98185 | } |
| 98186 | |
| 98187 | /* |
| 98188 | ** Close the file. |
| 98189 | */ |
| 98190 | static int memjrnlClose(sqlite3_file *pJfd){ |
| 98191 | MemJournal *p = (MemJournal *)pJfd; |
| 98192 | memjrnlFreeChunks(p->pFirst); |
| 98193 | return SQLITE_OK; |
| 98194 | } |
| 98195 | |
| 98196 | /* |
| 98197 | ** Sync the file. |
| @@ -99359,10 +99373,48 @@ | |
| 99373 | pExpr->iTable = pItem->iCursor; |
| 99374 | pExpr->iColumn--; |
| 99375 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 99376 | break; |
| 99377 | } |
| 99378 | |
| 99379 | /* An "<expr> IS NOT NULL" or "<expr> IS NULL". After resolving the |
| 99380 | ** LHS, check if there is a NOT NULL constraint in the schema that |
| 99381 | ** means the value of the expression can be determined immediately. |
| 99382 | ** If that is the case, replace the current expression node with |
| 99383 | ** a TK_TRUEFALSE node. |
| 99384 | ** |
| 99385 | ** If the node is replaced with a TK_TRUEFALSE node, then also restore |
| 99386 | ** the NameContext ref-counts to the state they where in before the |
| 99387 | ** LHS expression was resolved. This prevents the current select |
| 99388 | ** from being erroneously marked as correlated in some cases. |
| 99389 | */ |
| 99390 | case TK_NOTNULL: |
| 99391 | case TK_ISNULL: { |
| 99392 | int anRef[8]; |
| 99393 | NameContext *p; |
| 99394 | int i; |
| 99395 | for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ |
| 99396 | anRef[i] = p->nRef; |
| 99397 | } |
| 99398 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 99399 | if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) ){ |
| 99400 | if( pExpr->op==TK_NOTNULL ){ |
| 99401 | pExpr->u.zToken = "true"; |
| 99402 | ExprSetProperty(pExpr, EP_IsTrue); |
| 99403 | }else{ |
| 99404 | pExpr->u.zToken = "false"; |
| 99405 | ExprSetProperty(pExpr, EP_IsFalse); |
| 99406 | } |
| 99407 | pExpr->op = TK_TRUEFALSE; |
| 99408 | for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ |
| 99409 | p->nRef = anRef[i]; |
| 99410 | } |
| 99411 | sqlite3ExprDelete(pParse->db, pExpr->pLeft); |
| 99412 | pExpr->pLeft = 0; |
| 99413 | } |
| 99414 | return WRC_Prune; |
| 99415 | } |
| 99416 | |
| 99417 | /* A column name: ID |
| 99418 | ** Or table name and column name: ID.ID |
| 99419 | ** Or a database, table and column: ID.ID.ID |
| 99420 | ** |
| @@ -100164,29 +100216,28 @@ | |
| 100216 | /* Recursively resolve names in all subqueries |
| 100217 | */ |
| 100218 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 100219 | SrcItem *pItem = &p->pSrc->a[i]; |
| 100220 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){ |
| 100221 | int nRef = pOuterNC ? pOuterNC->nRef : 0; |
| 100222 | const char *zSavedContext = pParse->zAuthContext; |
| 100223 | |
| 100224 | if( pItem->zName ) pParse->zAuthContext = pItem->zName; |
| 100225 | sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC); |
| 100226 | pParse->zAuthContext = zSavedContext; |
| 100227 | if( pParse->nErr || db->mallocFailed ) return WRC_Abort; |
| 100228 | |
| 100229 | /* If the number of references to the outer context changed when |
| 100230 | ** expressions in the sub-select were resolved, the sub-select |
| 100231 | ** is correlated. It is not required to check the refcount on any |
| 100232 | ** but the innermost outer context object, as lookupName() increments |
| 100233 | ** the refcount on all contexts between the current one and the |
| 100234 | ** context containing the column when it resolves a name. */ |
| 100235 | if( pOuterNC ){ |
| 100236 | assert( pItem->fg.isCorrelated==0 && pOuterNC->nRef>=nRef ); |
| 100237 | pItem->fg.isCorrelated = (pOuterNC->nRef>nRef); |
| 100238 | } |
| 100239 | } |
| 100240 | } |
| 100241 | |
| 100242 | /* Set up the local name-context to pass to sqlite3ResolveExprNames() to |
| 100243 | ** resolve the result-set expression list. |
| @@ -114298,10 +114349,11 @@ | |
| 114349 | ** the column names from the SELECT statement that defines the view. |
| 114350 | */ |
| 114351 | assert( pTable->aCol==0 ); |
| 114352 | pTable->nCol = pSelTab->nCol; |
| 114353 | pTable->aCol = pSelTab->aCol; |
| 114354 | pTable->tabFlags |= (pSelTab->tabFlags & COLFLAG_NOINSERT); |
| 114355 | pSelTab->nCol = 0; |
| 114356 | pSelTab->aCol = 0; |
| 114357 | assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); |
| 114358 | } |
| 114359 | pTable->nNVCol = pTable->nCol; |
| @@ -117505,14 +117557,16 @@ | |
| 117557 | } |
| 117558 | |
| 117559 | /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree |
| 117560 | ** and the SELECT subtree. */ |
| 117561 | pSrc->a[0].pTab = 0; |
| 117562 | pSelectSrc = sqlite3SrcListDup(db, pSrc, 0); |
| 117563 | pSrc->a[0].pTab = pTab; |
| 117564 | if( pSrc->a[0].fg.isIndexedBy ){ |
| 117565 | pSrc->a[0].u2.pIBIndex = 0; |
| 117566 | pSrc->a[0].fg.isIndexedBy = 0; |
| 117567 | sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy); |
| 117568 | }else if( pSrc->a[0].fg.isCte ){ |
| 117569 | pSrc->a[0].u2.pCteUse->nUse++; |
| 117570 | } |
| 117571 | |
| 117572 | /* generate the SELECT expression tree. */ |
| @@ -131396,10 +131450,13 @@ | |
| 131450 | static void unsetJoinExpr(Expr *p, int iTable){ |
| 131451 | while( p ){ |
| 131452 | if( ExprHasProperty(p, EP_FromJoin) |
| 131453 | && (iTable<0 || p->iRightJoinTable==iTable) ){ |
| 131454 | ExprClearProperty(p, EP_FromJoin); |
| 131455 | } |
| 131456 | if( p->op==TK_COLUMN && p->iTable==iTable ){ |
| 131457 | ExprClearProperty(p, EP_CanBeNull); |
| 131458 | } |
| 131459 | if( p->op==TK_FUNCTION && p->x.pList ){ |
| 131460 | int i; |
| 131461 | for(i=0; i<p->x.pList->nExpr; i++){ |
| 131462 | unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| @@ -135479,10 +135536,39 @@ | |
| 135536 | } |
| 135537 | }while( x.nChng ); |
| 135538 | return nChng; |
| 135539 | } |
| 135540 | |
| 135541 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 135542 | # if !defined(SQLITE_OMIT_WINDOWFUNC) |
| 135543 | /* |
| 135544 | ** This function is called to determine whether or not it is safe to |
| 135545 | ** push WHERE clause expression pExpr down to FROM clause sub-query |
| 135546 | ** pSubq, which contains at least one window function. Return 1 |
| 135547 | ** if it is safe and the expression should be pushed down, or 0 |
| 135548 | ** otherwise. |
| 135549 | ** |
| 135550 | ** It is only safe to push the expression down if it consists only |
| 135551 | ** of constants and copies of expressions that appear in the PARTITION |
| 135552 | ** BY clause of all window function used by the sub-query. It is safe |
| 135553 | ** to filter out entire partitions, but not rows within partitions, as |
| 135554 | ** this may change the results of the window functions. |
| 135555 | ** |
| 135556 | ** At the time this function is called it is guaranteed that |
| 135557 | ** |
| 135558 | ** * the sub-query uses only one distinct window frame, and |
| 135559 | ** * that the window frame has a PARTITION BY clase. |
| 135560 | */ |
| 135561 | static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ |
| 135562 | assert( pSubq->pWin->pPartition ); |
| 135563 | assert( (pSubq->selFlags & SF_MultiPart)==0 ); |
| 135564 | assert( pSubq->pPrior==0 ); |
| 135565 | return sqlite3ExprIsConstantOrGroupBy(pParse, pExpr, pSubq->pWin->pPartition); |
| 135566 | } |
| 135567 | # endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 135568 | #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ |
| 135569 | |
| 135570 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 135571 | /* |
| 135572 | ** Make copies of relevant WHERE clause terms of the outer query into |
| 135573 | ** the WHERE clause of subquery. Example: |
| 135574 | ** |
| @@ -135526,13 +135612,24 @@ | |
| 135612 | ** |
| 135613 | ** The correct answer is three rows: (1,1,NULL),(2,2,8),(2,2,9). |
| 135614 | ** But if the (b2=2) term were to be pushed down into the bb subquery, |
| 135615 | ** then the (1,1,NULL) row would be suppressed. |
| 135616 | ** |
| 135617 | ** (6) Window functions make things tricky as changes to the WHERE clause |
| 135618 | ** of the inner query could change the window over which window |
| 135619 | ** functions are calculated. Therefore, do not attempt the optimization |
| 135620 | ** if: |
| 135621 | ** |
| 135622 | ** (6a) The inner query uses multiple incompatible window partitions. |
| 135623 | ** |
| 135624 | ** (6b) The inner query is a compound and uses window-functions. |
| 135625 | ** |
| 135626 | ** (6c) The WHERE clause does not consist entirely of constants and |
| 135627 | ** copies of expressions found in the PARTITION BY clause of |
| 135628 | ** all window-functions used by the sub-query. It is safe to |
| 135629 | ** filter out entire partitions, as this does not change the |
| 135630 | ** window over which any window-function is calculated. |
| 135631 | ** |
| 135632 | ** (7) The inner query is a Common Table Expression (CTE) that should |
| 135633 | ** be materialized. (This restriction is implemented in the calling |
| 135634 | ** routine.) |
| 135635 | ** |
| @@ -135546,17 +135643,21 @@ | |
| 135643 | int iCursor, /* Cursor number of the subquery */ |
| 135644 | int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ |
| 135645 | ){ |
| 135646 | Expr *pNew; |
| 135647 | int nChng = 0; |
| 135648 | if( pWhere==0 ) return 0; |
| 135649 | if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0; |
| 135650 | |
| 135651 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 135652 | if( pSubq->pPrior ){ |
| 135653 | Select *pSel; |
| 135654 | for(pSel=pSubq; pSel; pSel=pSel->pPrior){ |
| 135655 | if( pSel->pWin ) return 0; /* restriction (6b) */ |
| 135656 | } |
| 135657 | }else{ |
| 135658 | if( pSubq->pWin && pSubq->pWin->pPartition==0 ) return 0; |
| 135659 | } |
| 135660 | #endif |
| 135661 | |
| 135662 | #ifdef SQLITE_DEBUG |
| 135663 | /* Only the first term of a compound can have a WITH clause. But make |
| @@ -135599,10 +135700,18 @@ | |
| 135700 | x.iTable = iCursor; |
| 135701 | x.iNewTable = iCursor; |
| 135702 | x.isLeftJoin = 0; |
| 135703 | x.pEList = pSubq->pEList; |
| 135704 | pNew = substExpr(&x, pNew); |
| 135705 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 135706 | if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){ |
| 135707 | /* Restriction 6c has prevented push-down in this case */ |
| 135708 | sqlite3ExprDelete(pParse->db, pNew); |
| 135709 | nChng--; |
| 135710 | break; |
| 135711 | } |
| 135712 | #endif |
| 135713 | if( pSubq->selFlags & SF_Aggregate ){ |
| 135714 | pSubq->pHaving = sqlite3ExprAnd(pParse, pSubq->pHaving, pNew); |
| 135715 | }else{ |
| 135716 | pSubq->pWhere = sqlite3ExprAnd(pParse, pSubq->pWhere, pNew); |
| 135717 | } |
| @@ -147542,10 +147651,16 @@ | |
| 147651 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 147652 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 147653 | pNew->prereqRight = prereqLeft | extraRight; |
| 147654 | pNew->prereqAll = prereqAll; |
| 147655 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| 147656 | }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){ |
| 147657 | pExpr->op = TK_TRUEFALSE; |
| 147658 | pExpr->u.zToken = "false"; |
| 147659 | ExprSetProperty(pExpr, EP_IsFalse); |
| 147660 | pTerm->prereqAll = 0; |
| 147661 | pTerm->eOperator = 0; |
| 147662 | } |
| 147663 | } |
| 147664 | |
| 147665 | #ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 147666 | /* If a term is the BETWEEN operator, create two new virtual terms |
| @@ -153019,11 +153134,11 @@ | |
| 153134 | } |
| 153135 | } |
| 153136 | if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ |
| 153137 | pWInfo->revMask = ALLBITS; |
| 153138 | } |
| 153139 | if( pParse->nErr || db->mallocFailed ){ |
| 153140 | goto whereBeginError; |
| 153141 | } |
| 153142 | #ifdef WHERETRACE_ENABLED |
| 153143 | if( sqlite3WhereTrace ){ |
| 153144 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| @@ -154961,19 +155076,23 @@ | |
| 155076 | ** to be processed as part of SELECT statement pSel). The window is linked |
| 155077 | ** in if either (a) there are no other windows already linked to this |
| 155078 | ** SELECT, or (b) the windows already linked use a compatible window frame. |
| 155079 | */ |
| 155080 | SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin){ |
| 155081 | if( pSel ){ |
| 155082 | if( 0==pSel->pWin || 0==sqlite3WindowCompare(0, pSel->pWin, pWin, 0) ){ |
| 155083 | pWin->pNextWin = pSel->pWin; |
| 155084 | if( pSel->pWin ){ |
| 155085 | pSel->pWin->ppThis = &pWin->pNextWin; |
| 155086 | } |
| 155087 | pSel->pWin = pWin; |
| 155088 | pWin->ppThis = &pSel->pWin; |
| 155089 | }else{ |
| 155090 | if( sqlite3ExprListCompare(pWin->pPartition, pSel->pWin->pPartition,-1) ){ |
| 155091 | pSel->selFlags |= SF_MultiPart; |
| 155092 | } |
| 155093 | } |
| 155094 | } |
| 155095 | } |
| 155096 | |
| 155097 | /* |
| 155098 | ** Return 0 if the two window objects are identical, 1 if they are |
| @@ -228990,11 +229109,11 @@ | |
| 229109 | int nArg, /* Number of args */ |
| 229110 | sqlite3_value **apUnused /* Function arguments */ |
| 229111 | ){ |
| 229112 | assert( nArg==0 ); |
| 229113 | UNUSED_PARAM2(nArg, apUnused); |
| 229114 | sqlite3_result_text(pCtx, "fts5: 2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092", -1, SQLITE_TRANSIENT); |
| 229115 | } |
| 229116 | |
| 229117 | /* |
| 229118 | ** Return true if zName is the extension on one of the shadow tables used |
| 229119 | ** by this module. |
| @@ -233916,12 +234035,12 @@ | |
| 234035 | } |
| 234036 | #endif /* SQLITE_CORE */ |
| 234037 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 234038 | |
| 234039 | /************** End of stmt.c ************************************************/ |
| 234040 | #if __LINE__!=234040 |
| 234041 | #undef SQLITE_SOURCE_ID |
| 234042 | #define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9alt2" |
| 234043 | #endif |
| 234044 | /* Return the source-id for this library */ |
| 234045 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 234046 | /************************** End of sqlite3.c ******************************/ |
| 234047 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -123,11 +123,11 @@ | ||
| 123 | 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | 125 | */ |
| 126 | 126 | #define SQLITE_VERSION "3.35.0" |
| 127 | 127 | #define SQLITE_VERSION_NUMBER 3035000 |
| 128 | -#define SQLITE_SOURCE_ID "2021-02-22 16:42:09 b5a0778cc5a98a864bea72670f83262da940aceb91fa4cdf46ec097337a3alt1" | |
| 128 | +#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092" | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | 133 | ** |
| 134 | 134 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.35.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3035000 |
| 128 | #define SQLITE_SOURCE_ID "2021-02-22 16:42:09 b5a0778cc5a98a864bea72670f83262da940aceb91fa4cdf46ec097337a3alt1" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| 134 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.35.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3035000 |
| 128 | #define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| 134 |