Upgrade SQLite bundled sources to 3.23.3

This commit is contained in:
gwenn 2020-08-09 08:35:23 +02:00
parent e909b80bed
commit 18f49164ea
4 changed files with 257 additions and 86 deletions

View File

@ -1,9 +1,9 @@
/* automatically generated by rust-bindgen */ /* automatically generated by rust-bindgen 0.54.1 */
pub const SQLITE_VERSION: &'static [u8; 7usize] = b"3.32.2\0"; pub const SQLITE_VERSION: &'static [u8; 7usize] = b"3.32.3\0";
pub const SQLITE_VERSION_NUMBER: i32 = 3032002; pub const SQLITE_VERSION_NUMBER: i32 = 3032003;
pub const SQLITE_SOURCE_ID: &'static [u8; 85usize] = pub const SQLITE_SOURCE_ID: &'static [u8; 85usize] =
b"2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c\0"; b"2020-06-18 14:00:33 7ebdfa80be8e8e73324b8d66b3460222eb74c7e9dfd655b48d6ca7e1933cc8fd\0";
pub const SQLITE_OK: i32 = 0; pub const SQLITE_OK: i32 = 0;
pub const SQLITE_ERROR: i32 = 1; pub const SQLITE_ERROR: i32 = 1;
pub const SQLITE_INTERNAL: i32 = 2; pub const SQLITE_INTERNAL: i32 = 2;

View File

@ -1,6 +1,6 @@
/****************************************************************************** /******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite ** This file is an amalgamation of many separate C source files from SQLite
** version 3.32.2. By combining all the individual C code files into this ** version 3.32.3. By combining all the individual C code files into this
** single large file, the entire code can be compiled as a single translation ** single large file, the entire code can be compiled as a single translation
** unit. This allows many compilers to do optimizations that would not be ** unit. This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately. Performance improvements ** possible if the files were compiled separately. Performance improvements
@ -1162,9 +1162,9 @@ extern "C" {
** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()]. ** [sqlite_version()] and [sqlite_source_id()].
*/ */
#define SQLITE_VERSION "3.32.2" #define SQLITE_VERSION "3.32.3"
#define SQLITE_VERSION_NUMBER 3032002 #define SQLITE_VERSION_NUMBER 3032003
#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c" #define SQLITE_SOURCE_ID "2020-06-18 14:00:33 7ebdfa80be8e8e73324b8d66b3460222eb74c7e9dfd655b48d6ca7e1933cc8fd"
/* /*
** CAPI3REF: Run-Time Library Version Numbers ** CAPI3REF: Run-Time Library Version Numbers
@ -17863,11 +17863,11 @@ struct AggInfo {
ExprList *pGroupBy; /* The group by clause */ ExprList *pGroupBy; /* The group by clause */
struct AggInfo_col { /* For each column used in source tables */ struct AggInfo_col { /* For each column used in source tables */
Table *pTab; /* Source table */ Table *pTab; /* Source table */
int iTable; /* Cursor number of the source table */
int iColumn; /* Column number within the source table */
int iSorterColumn; /* Column number in the sorting index */
int iMem; /* Memory location that acts as accumulator */
Expr *pExpr; /* The original expression */ Expr *pExpr; /* The original expression */
int iTable; /* Cursor number of the source table */
int iMem; /* Memory location that acts as accumulator */
i16 iColumn; /* Column number within the source table */
i16 iSorterColumn; /* Column number in the sorting index */
} *aCol; } *aCol;
int nColumn; /* Number of used entries in aCol[] */ int nColumn; /* Number of used entries in aCol[] */
int nAccumulator; /* Number of columns that show through to the output. int nAccumulator; /* Number of columns that show through to the output.
@ -17880,8 +17880,17 @@ struct AggInfo {
int iDistinct; /* Ephemeral table used to enforce DISTINCT */ int iDistinct; /* Ephemeral table used to enforce DISTINCT */
} *aFunc; } *aFunc;
int nFunc; /* Number of entries in aFunc[] */ int nFunc; /* Number of entries in aFunc[] */
#ifdef SQLITE_DEBUG
int iAggMagic; /* Magic number when valid */
#endif
AggInfo *pNext; /* Next in list of them all */
}; };
/*
** Value for AggInfo.iAggMagic when the structure is valid
*/
#define AggInfoMagic 0x2059e99e
/* /*
** The datatype ynVar is a signed integer, either 16-bit or 32-bit. ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
@ -18462,6 +18471,7 @@ struct Select {
#define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
#define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
#define SF_View 0x0200000 /* SELECT statement is a view */ #define SF_View 0x0200000 /* SELECT statement is a view */
#define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */
/* /*
** The results of a SELECT can be distributed in several ways, as defined ** The results of a SELECT can be distributed in several ways, as defined
@ -18678,6 +18688,7 @@ struct Parse {
Parse *pToplevel; /* Parse structure for main program (or NULL) */ Parse *pToplevel; /* Parse structure for main program (or NULL) */
Table *pTriggerTab; /* Table triggers are being coded for */ Table *pTriggerTab; /* Table triggers are being coded for */
Parse *pParentParse; /* Parent parser if this parser is nested */ Parse *pParentParse; /* Parent parser if this parser is nested */
AggInfo *pAggList; /* List of all AggInfo objects */
int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */ int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
u32 oldmask; /* Mask of old.* columns referenced */ u32 oldmask; /* Mask of old.* columns referenced */
@ -19644,6 +19655,7 @@ SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int); SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int); SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*);
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
@ -64526,16 +64538,18 @@ static int hasSharedCacheTableLock(
** table. */ ** table. */
if( isIndex ){ if( isIndex ){
HashElem *p; HashElem *p;
int bSeen = 0;
for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){ for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
Index *pIdx = (Index *)sqliteHashData(p); Index *pIdx = (Index *)sqliteHashData(p);
if( pIdx->tnum==(int)iRoot ){ if( pIdx->tnum==(int)iRoot ){
if( iTab ){ if( bSeen ){
/* Two or more indexes share the same root page. There must /* Two or more indexes share the same root page. There must
** be imposter tables. So just return true. The assert is not ** be imposter tables. So just return true. The assert is not
** useful in that case. */ ** useful in that case. */
return 1; return 1;
} }
iTab = pIdx->pTable->tnum; iTab = pIdx->pTable->tnum;
bSeen = 1;
} }
} }
}else{ }else{
@ -66077,7 +66091,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
nFrag = iFreeBlk - iEnd; nFrag = iFreeBlk - iEnd;
if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage); if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
if( NEVER(iEnd > pPage->pBt->usableSize) ){ if( iEnd > pPage->pBt->usableSize ){
return SQLITE_CORRUPT_PAGE(pPage); return SQLITE_CORRUPT_PAGE(pPage);
} }
iSize = iEnd - iStart; iSize = iEnd - iStart;
@ -87194,7 +87208,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
if( (flags1 | flags3)&MEM_Str ){ if( (flags1 | flags3)&MEM_Str ){
if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
applyNumericAffinity(pIn1,0); applyNumericAffinity(pIn1,0);
assert( flags3==pIn3->flags ); testcase( flags3==pIn3->flags );
flags3 = pIn3->flags; flags3 = pIn3->flags;
} }
if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){ if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
@ -99536,8 +99550,13 @@ SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
op = pExpr->op; op = pExpr->op;
if( op==TK_SELECT ){ if( op==TK_SELECT ){
assert( pExpr->flags&EP_xIsSelect ); assert( pExpr->flags&EP_xIsSelect );
if( ALWAYS(pExpr->x.pSelect)
&& pExpr->x.pSelect->pEList
&& ALWAYS(pExpr->x.pSelect->pEList->a[0].pExpr)
){
return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
} }
}
if( op==TK_REGISTER ) op = pExpr->op2; if( op==TK_REGISTER ) op = pExpr->op2;
#ifndef SQLITE_OMIT_CAST #ifndef SQLITE_OMIT_CAST
if( op==TK_CAST ){ if( op==TK_CAST ){
@ -101527,8 +101546,10 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
/* Fall through */ /* Fall through */
case TK_IF_NULL_ROW: case TK_IF_NULL_ROW:
case TK_REGISTER: case TK_REGISTER:
case TK_DOT:
testcase( pExpr->op==TK_REGISTER ); testcase( pExpr->op==TK_REGISTER );
testcase( pExpr->op==TK_IF_NULL_ROW ); testcase( pExpr->op==TK_IF_NULL_ROW );
testcase( pExpr->op==TK_DOT );
pWalker->eCode = 0; pWalker->eCode = 0;
return WRC_Abort; return WRC_Abort;
case TK_VARIABLE: case TK_VARIABLE:
@ -105134,10 +105155,25 @@ SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(
*/ */
struct SrcCount { struct SrcCount {
SrcList *pSrc; /* One particular FROM clause in a nested query */ SrcList *pSrc; /* One particular FROM clause in a nested query */
int iSrcInner; /* Smallest cursor number in this context */
int nThis; /* Number of references to columns in pSrcList */ int nThis; /* Number of references to columns in pSrcList */
int nOther; /* Number of references to columns in other FROM clauses */ int nOther; /* Number of references to columns in other FROM clauses */
}; };
/*
** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first
** SELECT with a FROM clause encountered during this iteration, set
** SrcCount.iSrcInner to the cursor number of the leftmost object in
** the FROM cause.
*/
static int selectSrcCount(Walker *pWalker, Select *pSel){
struct SrcCount *p = pWalker->u.pSrcCount;
if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){
pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor;
}
return WRC_Continue;
}
/* /*
** Count the number of references to columns. ** Count the number of references to columns.
*/ */
@ -105158,7 +105194,7 @@ static int exprSrcCount(Walker *pWalker, Expr *pExpr){
} }
if( i<nSrc ){ if( i<nSrc ){
p->nThis++; p->nThis++;
}else if( nSrc==0 || pExpr->iTable<pSrc->a[0].iCursor ){ }else if( pExpr->iTable<p->iSrcInner ){
/* In a well-formed parse tree (no name resolution errors), /* In a well-formed parse tree (no name resolution errors),
** TK_COLUMN nodes with smaller Expr.iTable values are in an ** TK_COLUMN nodes with smaller Expr.iTable values are in an
** outer context. Those are the only ones to count as "other" */ ** outer context. Those are the only ones to count as "other" */
@ -105180,9 +105216,10 @@ SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){
assert( pExpr->op==TK_AGG_FUNCTION ); assert( pExpr->op==TK_AGG_FUNCTION );
memset(&w, 0, sizeof(w)); memset(&w, 0, sizeof(w));
w.xExprCallback = exprSrcCount; w.xExprCallback = exprSrcCount;
w.xSelectCallback = sqlite3SelectWalkNoop; w.xSelectCallback = selectSrcCount;
w.u.pSrcCount = &cnt; w.u.pSrcCount = &cnt;
cnt.pSrc = pSrcList; cnt.pSrc = pSrcList;
cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
cnt.nThis = 0; cnt.nThis = 0;
cnt.nOther = 0; cnt.nOther = 0;
sqlite3WalkExprList(&w, pExpr->x.pList); sqlite3WalkExprList(&w, pExpr->x.pList);
@ -105194,6 +105231,64 @@ SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){
return cnt.nThis>0 || cnt.nOther==0; return cnt.nThis>0 || cnt.nOther==0;
} }
/*
** This is a Walker expression node callback.
**
** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
** object that is referenced does not refer directly to the Expr. If
** it does, make a copy. This is done because the pExpr argument is
** subject to change.
**
** The copy is stored on pParse->pConstExpr with a register number of 0.
** This will cause the expression to be deleted automatically when the
** Parse object is destroyed, but the zero register number means that it
** will not generate any code in the preamble.
*/
static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
&& pExpr->pAggInfo!=0
){
AggInfo *pAggInfo = pExpr->pAggInfo;
int iAgg = pExpr->iAgg;
Parse *pParse = pWalker->pParse;
sqlite3 *db = pParse->db;
assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
if( pExpr->op==TK_AGG_COLUMN ){
assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
if( pAggInfo->aCol[iAgg].pExpr==pExpr ){
pExpr = sqlite3ExprDup(db, pExpr, 0);
if( pExpr ){
pAggInfo->aCol[iAgg].pExpr = pExpr;
pParse->pConstExpr =
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
}
}
}else{
assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
if( pAggInfo->aFunc[iAgg].pExpr==pExpr ){
pExpr = sqlite3ExprDup(db, pExpr, 0);
if( pExpr ){
pAggInfo->aFunc[iAgg].pExpr = pExpr;
pParse->pConstExpr =
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
}
}
}
}
return WRC_Continue;
}
/*
** Initialize a Walker object so that will persist AggInfo entries referenced
** by the tree that is walked.
*/
SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker *pWalker, Parse *pParse){
memset(pWalker, 0, sizeof(*pWalker));
pWalker->pParse = pParse;
pWalker->xExprCallback = agginfoPersistExprCb;
pWalker->xSelectCallback = sqlite3SelectWalkNoop;
}
/* /*
** Add a new element to the pAggInfo->aCol[] array. Return the index of ** Add a new element to the pAggInfo->aCol[] array. Return the index of
** the new element. Return a negative number if malloc fails. ** the new element. Return a negative number if malloc fails.
@ -110255,12 +110350,21 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
*/ */
sqlite3AutoincrementBegin(pParse); sqlite3AutoincrementBegin(pParse);
/* Code constant expressions that where factored out of inner loops */ /* Code constant expressions that where factored out of inner loops.
**
** The pConstExpr list might also contain expressions that we simply
** want to keep around until the Parse object is deleted. Such
** expressions have iConstExprReg==0. Do not generate code for
** those expressions, of course.
*/
if( pParse->pConstExpr ){ if( pParse->pConstExpr ){
ExprList *pEL = pParse->pConstExpr; ExprList *pEL = pParse->pConstExpr;
pParse->okConstFactor = 0; pParse->okConstFactor = 0;
for(i=0; i<pEL->nExpr; i++){ for(i=0; i<pEL->nExpr; i++){
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg); int iReg = pEL->a[i].u.iConstExprReg;
if( iReg>0 ){
sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
}
} }
} }
@ -128434,11 +128538,26 @@ SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
return i; return i;
} }
/*
** Deallocate a single AggInfo object
*/
static void agginfoFree(sqlite3 *db, AggInfo *p){
sqlite3DbFree(db, p->aCol);
sqlite3DbFree(db, p->aFunc);
sqlite3DbFree(db, p);
}
/* /*
** Free all memory allocations in the pParse object ** Free all memory allocations in the pParse object
*/ */
SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
sqlite3 *db = pParse->db; sqlite3 *db = pParse->db;
AggInfo *pThis = pParse->pAggList;
while( pThis ){
AggInfo *pNext = pThis->pNext;
agginfoFree(db, pThis);
pThis = pNext;
}
sqlite3DbFree(db, pParse->aLabel); sqlite3DbFree(db, pParse->aLabel);
sqlite3ExprListDelete(db, pParse->pConstExpr); sqlite3ExprListDelete(db, pParse->pConstExpr);
if( db ){ if( db ){
@ -131553,9 +131672,7 @@ static int multiSelect(
selectOpName(p->op))); selectOpName(p->op)));
rc = sqlite3Select(pParse, p, &uniondest); rc = sqlite3Select(pParse, p, &uniondest);
testcase( rc!=SQLITE_OK ); testcase( rc!=SQLITE_OK );
/* Query flattening in sqlite3Select() might refill p->pOrderBy. assert( p->pOrderBy==0 );
** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */
sqlite3ExprListDelete(db, p->pOrderBy);
pDelete = p->pPrior; pDelete = p->pPrior;
p->pPrior = pPrior; p->pPrior = pPrior;
p->pOrderBy = 0; p->pOrderBy = 0;
@ -132628,6 +132745,7 @@ static int flattenSubquery(
Expr *pWhere; /* The WHERE clause */ Expr *pWhere; /* The WHERE clause */
struct SrcList_item *pSubitem; /* The subquery */ struct SrcList_item *pSubitem; /* The subquery */
sqlite3 *db = pParse->db; sqlite3 *db = pParse->db;
Walker w; /* Walker to persist agginfo data */
/* Check to see if flattening is permitted. Return 0 if not. /* Check to see if flattening is permitted. Return 0 if not.
*/ */
@ -132941,7 +133059,7 @@ static int flattenSubquery(
** We look at every expression in the outer query and every place we see ** We look at every expression in the outer query and every place we see
** "a" we substitute "x*3" and every place we see "b" we substitute "y+10". ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
*/ */
if( pSub->pOrderBy ){ if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
/* At this point, any non-zero iOrderByCol values indicate that the /* At this point, any non-zero iOrderByCol values indicate that the
** ORDER BY column expression is identical to the iOrderByCol'th ** ORDER BY column expression is identical to the iOrderByCol'th
** expression returned by SELECT statement pSub. Since these values ** expression returned by SELECT statement pSub. Since these values
@ -132965,7 +133083,13 @@ static int flattenSubquery(
if( isLeftJoin>0 ){ if( isLeftJoin>0 ){
sqlite3SetJoinExpr(pWhere, iNewParent); sqlite3SetJoinExpr(pWhere, iNewParent);
} }
pParent->pWhere = sqlite3ExprAnd(pParse, pWhere, pParent->pWhere); if( pWhere ){
if( pParent->pWhere ){
pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
}else{
pParent->pWhere = pWhere;
}
}
if( db->mallocFailed==0 ){ if( db->mallocFailed==0 ){
SubstContext x; SubstContext x;
x.pParse = pParse; x.pParse = pParse;
@ -133002,6 +133126,8 @@ static int flattenSubquery(
/* Finially, delete what is left of the subquery and return /* Finially, delete what is left of the subquery and return
** success. ** success.
*/ */
sqlite3AggInfoPersistWalkerInit(&w, pParse);
sqlite3WalkSelect(&w,pSub1);
sqlite3SelectDelete(db, pSub1); sqlite3SelectDelete(db, pSub1);
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
@ -133262,11 +133388,14 @@ static int pushDownWhereTerms(
){ ){
Expr *pNew; Expr *pNew;
int nChng = 0; int nChng = 0;
Select *pSel;
if( pWhere==0 ) return 0; if( pWhere==0 ) return 0;
if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */
#ifndef SQLITE_OMIT_WINDOWFUNC #ifndef SQLITE_OMIT_WINDOWFUNC
if( pSubq->pWin ) return 0; /* restriction (6) */ for(pSel=pSubq; pSel; pSel=pSel->pPrior){
if( pSel->pWin ) return 0; /* restriction (6) */
}
#endif #endif
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
@ -133466,6 +133595,14 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){} for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
if( pX==0 ) return WRC_Continue; if( pX==0 ) return WRC_Continue;
a = p->pOrderBy->a; a = p->pOrderBy->a;
#ifndef SQLITE_OMIT_WINDOWFUNC
/* If iOrderByCol is already non-zero, then it has already been matched
** to a result column of the SELECT statement. This occurs when the
** SELECT is rewritten for window-functions processing and then passed
** to sqlite3SelectPrep() and similar a second time. The rewriting done
** by this function is not required in this case. */
if( a[0].u.x.iOrderByCol ) return WRC_Continue;
#endif
for(i=p->pOrderBy->nExpr-1; i>=0; i--){ for(i=p->pOrderBy->nExpr-1; i>=0; i--){
if( a[i].pExpr->flags & EP_Collate ) break; if( a[i].pExpr->flags & EP_Collate ) break;
} }
@ -134586,10 +134723,10 @@ SQLITE_PRIVATE int sqlite3Select(
Expr *pWhere; /* The WHERE clause. May be NULL */ Expr *pWhere; /* The WHERE clause. May be NULL */
ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */ ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */
Expr *pHaving; /* The HAVING clause. May be NULL */ Expr *pHaving; /* The HAVING clause. May be NULL */
AggInfo *pAggInfo = 0; /* Aggregate information */
int rc = 1; /* Value to return from this function */ int rc = 1; /* Value to return from this function */
DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */ DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */
SortCtx sSort; /* Info on how to code the ORDER BY clause */ SortCtx sSort; /* Info on how to code the ORDER BY clause */
AggInfo sAggInfo; /* Information used by aggregate queries */
int iEnd; /* Address of the end of the query */ int iEnd; /* Address of the end of the query */
sqlite3 *db; /* The database connection */ sqlite3 *db; /* The database connection */
ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */ ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
@ -134601,7 +134738,6 @@ SQLITE_PRIVATE int sqlite3Select(
return 1; return 1;
} }
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
memset(&sAggInfo, 0, sizeof(sAggInfo));
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain)); SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
if( sqlite3SelectTrace & 0x100 ){ if( sqlite3SelectTrace & 0x100 ){
@ -134623,6 +134759,7 @@ SQLITE_PRIVATE int sqlite3Select(
sqlite3ExprListDelete(db, p->pOrderBy); sqlite3ExprListDelete(db, p->pOrderBy);
p->pOrderBy = 0; p->pOrderBy = 0;
p->selFlags &= ~SF_Distinct; p->selFlags &= ~SF_Distinct;
p->selFlags |= SF_NoopOrderBy;
} }
sqlite3SelectPrep(pParse, p, 0); sqlite3SelectPrep(pParse, p, 0);
if( pParse->nErr || db->mallocFailed ){ if( pParse->nErr || db->mallocFailed ){
@ -135191,14 +135328,20 @@ SQLITE_PRIVATE int sqlite3Select(
** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
** SELECT statement. ** SELECT statement.
*/ */
pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
if( pAggInfo==0 ){
goto select_end;
}
pAggInfo->pNext = pParse->pAggList;
pParse->pAggList = pAggInfo;
memset(&sNC, 0, sizeof(sNC)); memset(&sNC, 0, sizeof(sNC));
sNC.pParse = pParse; sNC.pParse = pParse;
sNC.pSrcList = pTabList; sNC.pSrcList = pTabList;
sNC.uNC.pAggInfo = &sAggInfo; sNC.uNC.pAggInfo = pAggInfo;
VVA_ONLY( sNC.ncFlags = NC_UAggInfo; ) VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
sAggInfo.mnReg = pParse->nMem+1; pAggInfo->mnReg = pParse->nMem+1;
sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0; pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
sAggInfo.pGroupBy = pGroupBy; pAggInfo->pGroupBy = pGroupBy;
sqlite3ExprAnalyzeAggList(&sNC, pEList); sqlite3ExprAnalyzeAggList(&sNC, pEList);
sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy); sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
if( pHaving ){ if( pHaving ){
@ -135211,14 +135354,14 @@ SQLITE_PRIVATE int sqlite3Select(
} }
sqlite3ExprAnalyzeAggregates(&sNC, pHaving); sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
} }
sAggInfo.nAccumulator = sAggInfo.nColumn; pAggInfo->nAccumulator = pAggInfo->nColumn;
if( p->pGroupBy==0 && p->pHaving==0 && sAggInfo.nFunc==1 ){ if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
minMaxFlag = minMaxQuery(db, sAggInfo.aFunc[0].pExpr, &pMinMaxOrderBy); minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pExpr, &pMinMaxOrderBy);
}else{ }else{
minMaxFlag = WHERE_ORDERBY_NORMAL; minMaxFlag = WHERE_ORDERBY_NORMAL;
} }
for(i=0; i<sAggInfo.nFunc; i++){ for(i=0; i<pAggInfo->nFunc; i++){
Expr *pExpr = sAggInfo.aFunc[i].pExpr; Expr *pExpr = pAggInfo->aFunc[i].pExpr;
assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
sNC.ncFlags |= NC_InAggFunc; sNC.ncFlags |= NC_InAggFunc;
sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList); sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
@ -135230,22 +135373,22 @@ SQLITE_PRIVATE int sqlite3Select(
#endif #endif
sNC.ncFlags &= ~NC_InAggFunc; sNC.ncFlags &= ~NC_InAggFunc;
} }
sAggInfo.mxReg = pParse->nMem; pAggInfo->mxReg = pParse->nMem;
if( db->mallocFailed ) goto select_end; if( db->mallocFailed ) goto select_end;
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
if( sqlite3SelectTrace & 0x400 ){ if( sqlite3SelectTrace & 0x400 ){
int ii; int ii;
SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", &sAggInfo)); SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
sqlite3TreeViewSelect(0, p, 0); sqlite3TreeViewSelect(0, p, 0);
for(ii=0; ii<sAggInfo.nColumn; ii++){ for(ii=0; ii<pAggInfo->nColumn; ii++){
sqlite3DebugPrintf("agg-column[%d] iMem=%d\n", sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
ii, sAggInfo.aCol[ii].iMem); ii, pAggInfo->aCol[ii].iMem);
sqlite3TreeViewExpr(0, sAggInfo.aCol[ii].pExpr, 0); sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pExpr, 0);
} }
for(ii=0; ii<sAggInfo.nFunc; ii++){ for(ii=0; ii<pAggInfo->nFunc; ii++){
sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n", sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
ii, sAggInfo.aFunc[ii].iMem); ii, pAggInfo->aFunc[ii].iMem);
sqlite3TreeViewExpr(0, sAggInfo.aFunc[ii].pExpr, 0); sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pExpr, 0);
} }
} }
#endif #endif
@ -135270,10 +135413,11 @@ SQLITE_PRIVATE int sqlite3Select(
** that we do not need it after all, the OP_SorterOpen instruction ** that we do not need it after all, the OP_SorterOpen instruction
** will be converted into a Noop. ** will be converted into a Noop.
*/ */
sAggInfo.sortingIdx = pParse->nTab++; pAggInfo->sortingIdx = pParse->nTab++;
pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pGroupBy,0,sAggInfo.nColumn); pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pGroupBy,
0, pAggInfo->nColumn);
addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen, addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
sAggInfo.sortingIdx, sAggInfo.nSortingColumn, pAggInfo->sortingIdx, pAggInfo->nSortingColumn,
0, (char*)pKeyInfo, P4_KEYINFO); 0, (char*)pKeyInfo, P4_KEYINFO);
/* Initialize memory locations used by GROUP BY aggregate processing /* Initialize memory locations used by GROUP BY aggregate processing
@ -135328,8 +135472,8 @@ SQLITE_PRIVATE int sqlite3Select(
nGroupBy = pGroupBy->nExpr; nGroupBy = pGroupBy->nExpr;
nCol = nGroupBy; nCol = nGroupBy;
j = nGroupBy; j = nGroupBy;
for(i=0; i<sAggInfo.nColumn; i++){ for(i=0; i<pAggInfo->nColumn; i++){
if( sAggInfo.aCol[i].iSorterColumn>=j ){ if( pAggInfo->aCol[i].iSorterColumn>=j ){
nCol++; nCol++;
j++; j++;
} }
@ -135337,8 +135481,8 @@ SQLITE_PRIVATE int sqlite3Select(
regBase = sqlite3GetTempRange(pParse, nCol); regBase = sqlite3GetTempRange(pParse, nCol);
sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0); sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
j = nGroupBy; j = nGroupBy;
for(i=0; i<sAggInfo.nColumn; i++){ for(i=0; i<pAggInfo->nColumn; i++){
struct AggInfo_col *pCol = &sAggInfo.aCol[i]; struct AggInfo_col *pCol = &pAggInfo->aCol[i];
if( pCol->iSorterColumn>=j ){ if( pCol->iSorterColumn>=j ){
int r1 = j + regBase; int r1 = j + regBase;
sqlite3ExprCodeGetColumnOfTable(v, sqlite3ExprCodeGetColumnOfTable(v,
@ -135348,16 +135492,16 @@ SQLITE_PRIVATE int sqlite3Select(
} }
regRecord = sqlite3GetTempReg(pParse); regRecord = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord); sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
sqlite3VdbeAddOp2(v, OP_SorterInsert, sAggInfo.sortingIdx, regRecord); sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
sqlite3ReleaseTempReg(pParse, regRecord); sqlite3ReleaseTempReg(pParse, regRecord);
sqlite3ReleaseTempRange(pParse, regBase, nCol); sqlite3ReleaseTempRange(pParse, regBase, nCol);
sqlite3WhereEnd(pWInfo); sqlite3WhereEnd(pWInfo);
sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++; pAggInfo->sortingIdxPTab = sortPTab = pParse->nTab++;
sortOut = sqlite3GetTempReg(pParse); sortOut = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol); sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd); sqlite3VdbeAddOp2(v, OP_SorterSort, pAggInfo->sortingIdx, addrEnd);
VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v); VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
sAggInfo.useSortingIdx = 1; pAggInfo->useSortingIdx = 1;
} }
/* If the index or temporary table used by the GROUP BY sort /* If the index or temporary table used by the GROUP BY sort
@ -135381,14 +135525,14 @@ SQLITE_PRIVATE int sqlite3Select(
*/ */
addrTopOfLoop = sqlite3VdbeCurrentAddr(v); addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
if( groupBySort ){ if( groupBySort ){
sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx, sqlite3VdbeAddOp3(v, OP_SorterData, pAggInfo->sortingIdx,
sortOut, sortPTab); sortOut, sortPTab);
} }
for(j=0; j<pGroupBy->nExpr; j++){ for(j=0; j<pGroupBy->nExpr; j++){
if( groupBySort ){ if( groupBySort ){
sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j); sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
}else{ }else{
sAggInfo.directMode = 1; pAggInfo->directMode = 1;
sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j); sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
} }
} }
@ -135418,14 +135562,14 @@ SQLITE_PRIVATE int sqlite3Select(
** the current row ** the current row
*/ */
sqlite3VdbeJumpHere(v, addr1); sqlite3VdbeJumpHere(v, addr1);
updateAccumulator(pParse, iUseFlag, &sAggInfo); updateAccumulator(pParse, iUseFlag, pAggInfo);
sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag); sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
VdbeComment((v, "indicate data in accumulator")); VdbeComment((v, "indicate data in accumulator"));
/* End of the loop /* End of the loop
*/ */
if( groupBySort ){ if( groupBySort ){
sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop); sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx, addrTopOfLoop);
VdbeCoverage(v); VdbeCoverage(v);
}else{ }else{
sqlite3WhereEnd(pWInfo); sqlite3WhereEnd(pWInfo);
@ -135458,7 +135602,7 @@ SQLITE_PRIVATE int sqlite3Select(
VdbeCoverage(v); VdbeCoverage(v);
VdbeComment((v, "Groupby result generator entry point")); VdbeComment((v, "Groupby result generator entry point"));
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
finalizeAggFunctions(pParse, &sAggInfo); finalizeAggFunctions(pParse, pAggInfo);
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL); sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
selectInnerLoop(pParse, p, -1, &sSort, selectInnerLoop(pParse, p, -1, &sSort,
&sDistinct, pDest, &sDistinct, pDest,
@ -135469,7 +135613,7 @@ SQLITE_PRIVATE int sqlite3Select(
/* Generate a subroutine that will reset the group-by accumulator /* Generate a subroutine that will reset the group-by accumulator
*/ */
sqlite3VdbeResolveLabel(v, addrReset); sqlite3VdbeResolveLabel(v, addrReset);
resetAccumulator(pParse, &sAggInfo); resetAccumulator(pParse, pAggInfo);
sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag); sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
VdbeComment((v, "indicate accumulator empty")); VdbeComment((v, "indicate accumulator empty"));
sqlite3VdbeAddOp1(v, OP_Return, regReset); sqlite3VdbeAddOp1(v, OP_Return, regReset);
@ -135477,7 +135621,7 @@ SQLITE_PRIVATE int sqlite3Select(
} /* endif pGroupBy. Begin aggregate queries without GROUP BY: */ } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
else { else {
Table *pTab; Table *pTab;
if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){ if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
/* If isSimpleCount() returns a pointer to a Table structure, then /* If isSimpleCount() returns a pointer to a Table structure, then
** the SQL statement is of the form: ** the SQL statement is of the form:
** **
@ -135532,7 +135676,7 @@ SQLITE_PRIVATE int sqlite3Select(
if( pKeyInfo ){ if( pKeyInfo ){
sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO); sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
} }
sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem); sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
sqlite3VdbeAddOp1(v, OP_Close, iCsr); sqlite3VdbeAddOp1(v, OP_Close, iCsr);
explainSimpleCount(pParse, pTab, pBest); explainSimpleCount(pParse, pTab, pBest);
}else{ }else{
@ -135547,12 +135691,16 @@ SQLITE_PRIVATE int sqlite3Select(
** first row visited by the aggregate, so that they are updated at ** first row visited by the aggregate, so that they are updated at
** least once even if the FILTER clause means the min() or max() ** least once even if the FILTER clause means the min() or max()
** function visits zero rows. */ ** function visits zero rows. */
if( sAggInfo.nAccumulator ){ if( pAggInfo->nAccumulator ){
for(i=0; i<sAggInfo.nFunc; i++){ for(i=0; i<pAggInfo->nFunc; i++){
if( ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_WinFunc) ) continue; if( ExprHasProperty(pAggInfo->aFunc[i].pExpr, EP_WinFunc) ){
if( sAggInfo.aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ) break; continue;
} }
if( i==sAggInfo.nFunc ){ if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
break;
}
}
if( i==pAggInfo->nFunc ){
regAcc = ++pParse->nMem; regAcc = ++pParse->nMem;
sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc); sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
} }
@ -135563,7 +135711,7 @@ SQLITE_PRIVATE int sqlite3Select(
** of output. ** of output.
*/ */
assert( p->pGroupBy==0 ); assert( p->pGroupBy==0 );
resetAccumulator(pParse, &sAggInfo); resetAccumulator(pParse, pAggInfo);
/* If this query is a candidate for the min/max optimization, then /* If this query is a candidate for the min/max optimization, then
** minMaxFlag will have been previously set to either ** minMaxFlag will have been previously set to either
@ -135579,7 +135727,7 @@ SQLITE_PRIVATE int sqlite3Select(
if( pWInfo==0 ){ if( pWInfo==0 ){
goto select_end; goto select_end;
} }
updateAccumulator(pParse, regAcc, &sAggInfo); updateAccumulator(pParse, regAcc, pAggInfo);
if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc); if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
if( sqlite3WhereIsOrdered(pWInfo)>0 ){ if( sqlite3WhereIsOrdered(pWInfo)>0 ){
sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo)); sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
@ -135587,7 +135735,7 @@ SQLITE_PRIVATE int sqlite3Select(
(minMaxFlag==WHERE_ORDERBY_MIN?"min":"max"))); (minMaxFlag==WHERE_ORDERBY_MIN?"min":"max")));
} }
sqlite3WhereEnd(pWInfo); sqlite3WhereEnd(pWInfo);
finalizeAggFunctions(pParse, &sAggInfo); finalizeAggFunctions(pParse, pAggInfo);
} }
sSort.pOrderBy = 0; sSort.pOrderBy = 0;
@ -135626,8 +135774,25 @@ SQLITE_PRIVATE int sqlite3Select(
*/ */
select_end: select_end:
sqlite3ExprListDelete(db, pMinMaxOrderBy); sqlite3ExprListDelete(db, pMinMaxOrderBy);
sqlite3DbFree(db, sAggInfo.aCol); #ifdef SQLITE_DEBUG
sqlite3DbFree(db, sAggInfo.aFunc); if( pAggInfo && !db->mallocFailed ){
for(i=0; i<pAggInfo->nColumn; i++){
Expr *pExpr = pAggInfo->aCol[i].pExpr;
assert( pExpr!=0 || db->mallocFailed );
if( pExpr==0 ) continue;
assert( pExpr->pAggInfo==pAggInfo );
assert( pExpr->iAgg==i );
}
for(i=0; i<pAggInfo->nFunc; i++){
Expr *pExpr = pAggInfo->aFunc[i].pExpr;
assert( pExpr!=0 || db->mallocFailed );
if( pExpr==0 ) continue;
assert( pExpr->pAggInfo==pAggInfo );
assert( pExpr->iAgg==i );
}
}
#endif
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
SELECTTRACE(0x1,pParse,p,("end processing\n")); SELECTTRACE(0x1,pParse,p,("end processing\n"));
if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){ if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
@ -151319,12 +151484,16 @@ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
Window *pMWin = p->pWin; /* Master window object */ Window *pMWin = p->pWin; /* Master window object */
Window *pWin; /* Window object iterator */ Window *pWin; /* Window object iterator */
Table *pTab; Table *pTab;
Walker w;
u32 selFlags = p->selFlags; u32 selFlags = p->selFlags;
pTab = sqlite3DbMallocZero(db, sizeof(Table)); pTab = sqlite3DbMallocZero(db, sizeof(Table));
if( pTab==0 ){ if( pTab==0 ){
return sqlite3ErrorToParser(db, SQLITE_NOMEM); return sqlite3ErrorToParser(db, SQLITE_NOMEM);
} }
sqlite3AggInfoPersistWalkerInit(&w, pParse);
sqlite3WalkSelect(&w, p);
p->pSrc = 0; p->pSrc = 0;
p->pWhere = 0; p->pWhere = 0;
@ -151405,7 +151574,6 @@ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0); p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
if( p->pSrc ){ if( p->pSrc ){
Table *pTab2; Table *pTab2;
Walker w;
p->pSrc->a[0].pSelect = pSub; p->pSrc->a[0].pSelect = pSub;
sqlite3SrcListAssignCursors(pParse, p->pSrc); sqlite3SrcListAssignCursors(pParse, p->pSrc);
pSub->selFlags |= SF_Expanded; pSub->selFlags |= SF_Expanded;
@ -168302,6 +168470,9 @@ static int fts3PoslistMerge(
*/ */
fts3GetDeltaVarint(&p1, &i1); fts3GetDeltaVarint(&p1, &i1);
fts3GetDeltaVarint(&p2, &i2); fts3GetDeltaVarint(&p2, &i2);
if( i1<2 || i2<2 ){
break;
}
do { do {
fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2); fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
iPrev -= 2; iPrev -= 2;
@ -168370,7 +168541,7 @@ static int fts3PoslistPhraseMerge(
/* Never set both isSaveLeft and isExact for the same invocation. */ /* Never set both isSaveLeft and isExact for the same invocation. */
assert( isSaveLeft==0 || isExact==0 ); assert( isSaveLeft==0 || isExact==0 );
assert( p!=0 && *p1!=0 && *p2!=0 ); assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
if( *p1==POS_COLUMN ){ if( *p1==POS_COLUMN ){
p1++; p1++;
p1 += fts3GetVarint32(p1, &iCol1); p1 += fts3GetVarint32(p1, &iCol1);
@ -170555,7 +170726,7 @@ SQLITE_PRIVATE void sqlite3Fts3DoclistNext(
assert( nDoclist>0 ); assert( nDoclist>0 );
assert( *pbEof==0 ); assert( *pbEof==0 );
assert( p || *piDocid==0 ); assert_fts3_nc( p || *piDocid==0 );
assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) ); assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) );
if( p==0 ){ if( p==0 ){
@ -171205,7 +171376,7 @@ static void fts3EvalInvalidatePoslist(Fts3Phrase *pPhrase){
** **
** Parameter nNear is passed the NEAR distance of the expression (5 in ** Parameter nNear is passed the NEAR distance of the expression (5 in
** the example above). When this function is called, *paPoslist points to ** the example above). When this function is called, *paPoslist points to
** the position list, and *pnToken is the number of phrase tokens in, the ** the position list, and *pnToken is the number of phrase tokens in the
** phrase on the other side of the NEAR operator to pPhrase. For example, ** phrase on the other side of the NEAR operator to pPhrase. For example,
** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to ** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to
** the position list associated with phrase "abc". ** the position list associated with phrase "abc".
@ -224824,7 +224995,7 @@ static void fts5SourceIdFunc(
){ ){
assert( nArg==0 ); assert( nArg==0 );
UNUSED_PARAM2(nArg, apUnused); UNUSED_PARAM2(nArg, apUnused);
sqlite3_result_text(pCtx, "fts5: 2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c", -1, SQLITE_TRANSIENT); sqlite3_result_text(pCtx, "fts5: 2020-06-18 14:00:33 7ebdfa80be8e8e73324b8d66b3460222eb74c7e9dfd655b48d6ca7e1933cc8fd", -1, SQLITE_TRANSIENT);
} }
/* /*
@ -229607,9 +229778,9 @@ SQLITE_API int sqlite3_stmt_init(
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
/************** End of stmt.c ************************************************/ /************** End of stmt.c ************************************************/
#if __LINE__!=229610 #if __LINE__!=229781
#undef SQLITE_SOURCE_ID #undef SQLITE_SOURCE_ID
#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e8686alt2" #define SQLITE_SOURCE_ID "2020-06-18 14:00:33 7ebdfa80be8e8e73324b8d66b3460222eb74c7e9dfd655b48d6ca7e1933calt2"
#endif #endif
/* Return the source-id for this library */ /* Return the source-id for this library */
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }

View File

@ -123,9 +123,9 @@ extern "C" {
** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()]. ** [sqlite_version()] and [sqlite_source_id()].
*/ */
#define SQLITE_VERSION "3.32.2" #define SQLITE_VERSION "3.32.3"
#define SQLITE_VERSION_NUMBER 3032002 #define SQLITE_VERSION_NUMBER 3032003
#define SQLITE_SOURCE_ID "2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c" #define SQLITE_SOURCE_ID "2020-06-18 14:00:33 7ebdfa80be8e8e73324b8d66b3460222eb74c7e9dfd655b48d6ca7e1933cc8fd"
/* /*
** CAPI3REF: Run-Time Library Version Numbers ** CAPI3REF: Run-Time Library Version Numbers

View File

@ -6,7 +6,7 @@ cd "$SCRIPT_DIR" || { echo "fatal error"; exit 1; }
export SQLITE3_LIB_DIR=$SCRIPT_DIR/sqlite3 export SQLITE3_LIB_DIR=$SCRIPT_DIR/sqlite3
# Download and extract amalgamation # Download and extract amalgamation
SQLITE=sqlite-amalgamation-3320200 SQLITE=sqlite-amalgamation-3320300
curl -O https://sqlite.org/2020/$SQLITE.zip curl -O https://sqlite.org/2020/$SQLITE.zip
unzip -p "$SQLITE.zip" "$SQLITE/sqlite3.c" > "$SQLITE3_LIB_DIR/sqlite3.c" unzip -p "$SQLITE.zip" "$SQLITE/sqlite3.c" > "$SQLITE3_LIB_DIR/sqlite3.c"
unzip -p "$SQLITE.zip" "$SQLITE/sqlite3.h" > "$SQLITE3_LIB_DIR/sqlite3.h" unzip -p "$SQLITE.zip" "$SQLITE/sqlite3.h" > "$SQLITE3_LIB_DIR/sqlite3.h"