11/******************************************************************************
22** This file is an amalgamation of many separate C source files from SQLite
3- ** version 3.39.1 . By combining all the individual C code files into this
3+ ** version 3.39.2 . By combining all the individual C code files into this
44** single large file, the entire code can be compiled as a single translation
55** unit. This allows many compilers to do optimizations that would not be
66** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452452** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453** [sqlite_version()] and [sqlite_source_id()].
454454*/
455- #define SQLITE_VERSION "3.39.1 "
456- #define SQLITE_VERSION_NUMBER 3039001
457- #define SQLITE_SOURCE_ID "2022-07-13 19:41:41 7c16541a0efb3985578181171c9f2bb3fdc4bad6a2ec85c6e31ab96f3eff201f "
455+ #define SQLITE_VERSION "3.39.2 "
456+ #define SQLITE_VERSION_NUMBER 3039002
457+ #define SQLITE_SOURCE_ID "2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603 "
458458
459459/*
460460** CAPI3REF: Run-Time Library Version Numbers
@@ -30430,8 +30430,8 @@ SQLITE_API void sqlite3_str_vappendf(
3043030430 case etSQLESCAPE: /* %q: Escape ' characters */
3043130431 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
3043230432 case etSQLESCAPE3: { /* %w: Escape " characters */
30433- int i, j, k, n, isnull ;
30434- int needQuote;
30433+ i64 i, j, k, n;
30434+ int needQuote, isnull ;
3043530435 char ch;
3043630436 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
3043730437 char *escarg;
@@ -31119,8 +31119,8 @@ SQLITE_PRIVATE void sqlite3TreeViewColumnList(
3111931119 sqlite3TreeViewLine(pView, "COLUMNS");
3112031120 for(i=0; i<nCol; i++){
3112131121 u16 flg = aCol[i].colFlags;
31122- int moreToFollow = i<(nCol - 1);
31123- sqlite3TreeViewPush(&pView, moreToFollow );
31122+ int colMoreToFollow = i<(nCol - 1);
31123+ sqlite3TreeViewPush(&pView, colMoreToFollow );
3112431124 sqlite3TreeViewLine(pView, 0);
3112531125 printf(" %s", aCol[i].zCnName);
3112631126 switch( aCol[i].eCType ){
@@ -31251,7 +31251,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
3125131251 Table *pTab = pItem->pTab;
3125231252 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
3125331253 }
31254- assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31254+ assert( (int) pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
3125531255 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
3125631256 }
3125731257 if( pItem->fg.isTabFunc ){
@@ -101540,33 +101540,23 @@ static void resolveAlias(
101540101540 sqlite3ExprDelete(db, pDup);
101541101541 pDup = 0;
101542101542 }else{
101543+ Expr temp;
101543101544 incrAggFunctionDepth(pDup, nSubquery);
101544101545 if( pExpr->op==TK_COLLATE ){
101545101546 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101546101547 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
101547101548 }
101548-
101549- /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
101550- ** prevents ExprDelete() from deleting the Expr structure itself,
101551- ** allowing it to be repopulated by the memcpy() on the following line.
101552- ** The pExpr->u.zToken might point into memory that will be freed by the
101553- ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
101554- ** make a copy of the token before doing the sqlite3DbFree().
101555- */
101556- ExprSetProperty(pExpr, EP_Static);
101557- sqlite3ExprDelete(db, pExpr);
101558- memcpy(pExpr, pDup, sizeof(*pExpr));
101559- if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
101560- assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
101561- pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
101562- pExpr->flags |= EP_MemToken;
101563- }
101549+ memcpy(&temp, pDup, sizeof(Expr));
101550+ memcpy(pDup, pExpr, sizeof(Expr));
101551+ memcpy(pExpr, &temp, sizeof(Expr));
101564101552 if( ExprHasProperty(pExpr, EP_WinFunc) ){
101565101553 if( ALWAYS(pExpr->y.pWin!=0) ){
101566101554 pExpr->y.pWin->pOwner = pExpr;
101567101555 }
101568101556 }
101569- sqlite3DbFree(db, pDup);
101557+ sqlite3ParserAddCleanup(pParse,
101558+ (void(*)(sqlite3*,void*))sqlite3ExprDelete,
101559+ pDup);
101570101560 }
101571101561}
101572101562
@@ -101769,7 +101759,7 @@ static int lookupName(
101769101759 pTab = pItem->pTab;
101770101760 assert( pTab!=0 && pTab->zName!=0 );
101771101761 assert( pTab->nCol>0 || pParse->nErr );
101772- assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101762+ assert( (int) pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101773101763 if( pItem->fg.isNestedFrom ){
101774101764 /* In this case, pItem is a subquery that has been formed from a
101775101765 ** parenthesized subset of the FROM clause terms. Example:
@@ -135859,7 +135849,7 @@ SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
135859135849*/
135860135850SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem *pItem, int iCol){
135861135851 assert( pItem!=0 );
135862- assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135852+ assert( (int) pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135863135853 if( pItem->fg.isNestedFrom ){
135864135854 ExprList *pResults;
135865135855 assert( pItem->pSelect!=0 );
@@ -141446,7 +141436,7 @@ static int selectExpander(Walker *pWalker, Select *p){
141446141436 zTabName = pTab->zName;
141447141437 }
141448141438 if( db->mallocFailed ) break;
141449- assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141439+ assert( (int) pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141450141440 if( pFrom->fg.isNestedFrom ){
141451141441 assert( pFrom->pSelect!=0 );
141452141442 pNestedFrom = pFrom->pSelect->pEList;
@@ -142375,7 +142365,9 @@ SQLITE_PRIVATE int sqlite3Select(
142375142365 ){
142376142366 SELECTTRACE(0x100,pParse,p,
142377142367 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
142378- sqlite3ExprListDelete(db, pSub->pOrderBy);
142368+ sqlite3ParserAddCleanup(pParse,
142369+ (void(*)(sqlite3*,void*))sqlite3ExprListDelete,
142370+ pSub->pOrderBy);
142379142371 pSub->pOrderBy = 0;
142380142372 }
142381142373
@@ -155375,7 +155367,7 @@ static int whereKeyStats(
155375155367#endif
155376155368 assert( pRec!=0 );
155377155369 assert( pIdx->nSample>0 );
155378- assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
155370+ assert( pRec->nField>0 );
155379155371
155380155372 /* Do a binary search to find the first sample greater than or equal
155381155373 ** to pRec. If pRec contains a single field, the set of samples to search
@@ -155421,7 +155413,7 @@ static int whereKeyStats(
155421155413 ** it is extended to two fields. The duplicates that this creates do not
155422155414 ** cause any problems.
155423155415 */
155424- nField = pRec->nField;
155416+ nField = MIN( pRec->nField, pIdx->nSample) ;
155425155417 iCol = 0;
155426155418 iSample = pIdx->nSample * nField;
155427155419 do{
@@ -158110,6 +158102,7 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
158110158102 sqlite3 *db = pWInfo->pParse->db;
158111158103 int rc = SQLITE_OK;
158112158104 int bFirstPastRJ = 0;
158105+ int hasRightJoin = 0;
158113158106 WhereLoop *pNew;
158114158107
158115158108
@@ -158130,15 +158123,16 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
158130158123 ** prevents the right operand of a RIGHT JOIN from being swapped with
158131158124 ** other elements even further to the right.
158132158125 **
158133- ** The JT_LTORJ term prevents any FROM-clause term reordering for terms
158134- ** to the left of a RIGHT JOIN. This is conservative. Relaxing this
158135- ** constraint somewhat to prevent terms from crossing from the right
158136- ** side of a LEFT JOIN over to the left side when they are on the
158137- ** left side of a RIGHT JOIN would be sufficient for all known failure
158138- ** cases. FIX ME: Implement this optimization.
158126+ ** The JT_LTORJ case and the hasRightJoin flag work together to
158127+ ** prevent FROM-clause terms from moving from the right side of
158128+ ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
158129+ ** is itself on the left side of a RIGHT JOIN.
158139158130 */
158131+ if( pItem->fg.jointype & JT_LTORJ ) hasRightJoin = 1;
158140158132 mPrereq |= mPrior;
158141158133 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
158134+ }else if( !hasRightJoin ){
158135+ mPrereq = 0;
158142158136 }
158143158137#ifndef SQLITE_OMIT_VIRTUALTABLE
158144158138 if( IsVirtual(pItem->pTab) ){
@@ -181058,8 +181052,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181058181052 char *aPoslist = 0; /* Position list for deferred tokens */
181059181053 int nPoslist = 0; /* Number of bytes in aPoslist */
181060181054 int iPrev = -1; /* Token number of previous deferred token */
181061-
181062- assert( pPhrase->doclist.bFreeList==0 );
181055+ char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
181063181056
181064181057 for(iToken=0; iToken<pPhrase->nToken; iToken++){
181065181058 Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
@@ -181073,6 +181066,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181073181066
181074181067 if( pList==0 ){
181075181068 sqlite3_free(aPoslist);
181069+ sqlite3_free(aFree);
181076181070 pPhrase->doclist.pList = 0;
181077181071 pPhrase->doclist.nList = 0;
181078181072 return SQLITE_OK;
@@ -181093,6 +181087,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181093181087 nPoslist = (int)(aOut - aPoslist);
181094181088 if( nPoslist==0 ){
181095181089 sqlite3_free(aPoslist);
181090+ sqlite3_free(aFree);
181096181091 pPhrase->doclist.pList = 0;
181097181092 pPhrase->doclist.nList = 0;
181098181093 return SQLITE_OK;
@@ -181145,6 +181140,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181145181140 }
181146181141 }
181147181142
181143+ if( pPhrase->doclist.pList!=aFree ) sqlite3_free(aFree);
181148181144 return SQLITE_OK;
181149181145}
181150181146#endif /* SQLITE_DISABLE_FTS4_DEFERRED */
@@ -182323,7 +182319,6 @@ static int fts3EvalTestExpr(
182323182319 pExpr->iDocid==pCsr->iPrevId && pExpr->pPhrase->doclist.pList
182324182320 ))){
182325182321 Fts3Phrase *pPhrase = pExpr->pPhrase;
182326- assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
182327182322 if( pExpr->bDeferred ){
182328182323 fts3EvalInvalidatePoslist(pPhrase);
182329182324 }
@@ -236641,7 +236636,7 @@ static void fts5SourceIdFunc(
236641236636){
236642236637 assert( nArg==0 );
236643236638 UNUSED_PARAM2(nArg, apUnused);
236644- sqlite3_result_text(pCtx, "fts5: 2022-07-13 19:41:41 7c16541a0efb3985578181171c9f2bb3fdc4bad6a2ec85c6e31ab96f3eff201f ", -1, SQLITE_TRANSIENT);
236639+ sqlite3_result_text(pCtx, "fts5: 2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603 ", -1, SQLITE_TRANSIENT);
236645236640}
236646236641
236647236642/*
0 commit comments