Fossil SCM

Update the built-in SQLite to the latest trunk version for testing.

drh 2020-06-08 12:10 trunk
Commit 3ab64c5a4d3deb7860e4b82141f8f386d3d722b9dee063baf133e85f68e68c4f
3 files changed +6 -1 +192 -61 +1 -1
+6 -1
--- src/shell.c
+++ src/shell.c
@@ -9832,10 +9832,11 @@
98329832
#define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
98339833
#define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
98349834
#define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
98359835
#define SHFLG_CountChanges 0x00000020 /* .changes setting */
98369836
#define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
9837
+#define SHFLG_HeaderSet 0x00000080 /* .header has been used */
98379838
98389839
/*
98399840
** Macros for testing and setting shellFlgs
98409841
*/
98419842
#define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -12595,11 +12596,11 @@
1259512596
" If FILE begins with '|' then open as a pipe",
1259612597
" --bom Put a UTF8 byte-order mark at the beginning",
1259712598
" -e Send output to the system text editor",
1259812599
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
1259912600
#ifdef SQLITE_DEBUG
12600
- ".oom [--repeat M] [N] Simulate an OOM error on the N-th allocation",
12601
+ ".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
1260112602
#endif
1260212603
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
1260312604
" Options:",
1260412605
" --append Use appendvfs to append database to the end of FILE",
1260512606
#ifdef SQLITE_ENABLE_DESERIALIZE
@@ -16634,10 +16635,11 @@
1663416635
}else
1663516636
1663616637
if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
1663716638
if( nArg==2 ){
1663816639
p->showHeader = booleanValue(azArg[1]);
16640
+ p->shellFlgs |= SHFLG_HeaderSet;
1663916641
}else{
1664016642
raw_printf(stderr, "Usage: .headers on|off\n");
1664116643
rc = 1;
1664216644
}
1664316645
}else
@@ -17156,10 +17158,13 @@
1715617158
if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
1715717159
p->mode = MODE_Line;
1715817160
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
1715917161
}else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
1716017162
p->mode = MODE_Column;
17163
+ if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){
17164
+ p->showHeader = 1;
17165
+ }
1716117166
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
1716217167
}else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
1716317168
p->mode = MODE_List;
1716417169
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
1716517170
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
1716617171
--- src/shell.c
+++ src/shell.c
@@ -9832,10 +9832,11 @@
9832 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
9833 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
9834 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
9835 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
9836 #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
 
9837
9838 /*
9839 ** Macros for testing and setting shellFlgs
9840 */
9841 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -12595,11 +12596,11 @@
12595 " If FILE begins with '|' then open as a pipe",
12596 " --bom Put a UTF8 byte-order mark at the beginning",
12597 " -e Send output to the system text editor",
12598 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
12599 #ifdef SQLITE_DEBUG
12600 ".oom [--repeat M] [N] Simulate an OOM error on the N-th allocation",
12601 #endif
12602 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
12603 " Options:",
12604 " --append Use appendvfs to append database to the end of FILE",
12605 #ifdef SQLITE_ENABLE_DESERIALIZE
@@ -16634,10 +16635,11 @@
16634 }else
16635
16636 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
16637 if( nArg==2 ){
16638 p->showHeader = booleanValue(azArg[1]);
 
16639 }else{
16640 raw_printf(stderr, "Usage: .headers on|off\n");
16641 rc = 1;
16642 }
16643 }else
@@ -17156,10 +17158,13 @@
17156 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
17157 p->mode = MODE_Line;
17158 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
17159 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
17160 p->mode = MODE_Column;
 
 
 
17161 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
17162 }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
17163 p->mode = MODE_List;
17164 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
17165 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
17166
--- src/shell.c
+++ src/shell.c
@@ -9832,10 +9832,11 @@
9832 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
9833 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
9834 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
9835 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
9836 #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
9837 #define SHFLG_HeaderSet 0x00000080 /* .header has been used */
9838
9839 /*
9840 ** Macros for testing and setting shellFlgs
9841 */
9842 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -12595,11 +12596,11 @@
12596 " If FILE begins with '|' then open as a pipe",
12597 " --bom Put a UTF8 byte-order mark at the beginning",
12598 " -e Send output to the system text editor",
12599 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
12600 #ifdef SQLITE_DEBUG
12601 ".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
12602 #endif
12603 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
12604 " Options:",
12605 " --append Use appendvfs to append database to the end of FILE",
12606 #ifdef SQLITE_ENABLE_DESERIALIZE
@@ -16634,10 +16635,11 @@
16635 }else
16636
16637 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
16638 if( nArg==2 ){
16639 p->showHeader = booleanValue(azArg[1]);
16640 p->shellFlgs |= SHFLG_HeaderSet;
16641 }else{
16642 raw_printf(stderr, "Usage: .headers on|off\n");
16643 rc = 1;
16644 }
16645 }else
@@ -17156,10 +17158,13 @@
17158 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
17159 p->mode = MODE_Line;
17160 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
17161 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
17162 p->mode = MODE_Column;
17163 if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){
17164 p->showHeader = 1;
17165 }
17166 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
17167 }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
17168 p->mode = MODE_List;
17169 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
17170 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
17171
+192 -61
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.33.0"
11661166
#define SQLITE_VERSION_NUMBER 3033000
1167
-#define SQLITE_SOURCE_ID "2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680fb72"
1167
+#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -17861,15 +17861,15 @@
1786117861
int nSortingColumn; /* Number of columns in the sorting index */
1786217862
int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
1786317863
ExprList *pGroupBy; /* The group by clause */
1786417864
struct AggInfo_col { /* For each column used in source tables */
1786517865
Table *pTab; /* Source table */
17866
+ Expr *pExpr; /* The original expression */
1786617867
int iTable; /* Cursor number of the source table */
17867
- int iColumn; /* Column number within the source table */
17868
- int iSorterColumn; /* Column number in the sorting index */
1786917868
int iMem; /* Memory location that acts as accumulator */
17870
- Expr *pExpr; /* The original expression */
17869
+ i16 iColumn; /* Column number within the source table */
17870
+ i16 iSorterColumn; /* Column number in the sorting index */
1787117871
} *aCol;
1787217872
int nColumn; /* Number of used entries in aCol[] */
1787317873
int nAccumulator; /* Number of columns that show through to the output.
1787417874
** Additional columns are used only as parameters to
1787517875
** aggregate functions */
@@ -17878,12 +17878,21 @@
1787817878
FuncDef *pFunc; /* The aggregate function implementation */
1787917879
int iMem; /* Memory location that acts as accumulator */
1788017880
int iDistinct; /* Ephemeral table used to enforce DISTINCT */
1788117881
} *aFunc;
1788217882
int nFunc; /* Number of entries in aFunc[] */
17883
+#ifdef SQLITE_DEBUG
17884
+ int iAggMagic; /* Magic number when valid */
17885
+#endif
17886
+ AggInfo *pNext; /* Next in list of them all */
1788317887
};
1788417888
17889
+/*
17890
+** Value for AggInfo.iAggMagic when the structure is valid
17891
+*/
17892
+#define AggInfoMagic 0x2059e99e
17893
+
1788517894
/*
1788617895
** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
1788717896
** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
1788817897
** than 32767 we have to make it 32-bit. 16-bit is preferred because
1788917898
** it uses less memory in the Expr object, which is a big memory user
@@ -18676,10 +18685,11 @@
1867618685
#endif
1867718686
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
1867818687
Parse *pToplevel; /* Parse structure for main program (or NULL) */
1867918688
Table *pTriggerTab; /* Table triggers are being coded for */
1868018689
Parse *pParentParse; /* Parent parser if this parser is nested */
18690
+ AggInfo *pAggList; /* List of all AggInfo objects */
1868118691
int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
1868218692
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
1868318693
u32 oldmask; /* Mask of old.* columns referenced */
1868418694
u32 newmask; /* Mask of new.* columns referenced */
1868518695
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -19642,10 +19652,11 @@
1964219652
SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
1964319653
SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
1964419654
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
1964519655
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
1964619656
SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
19657
+SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*);
1964719658
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
1964819659
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
1964919660
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
1965019661
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
1965119662
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
@@ -30013,11 +30024,11 @@
3001330024
sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
3001430025
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3001530026
break;
3001630027
}
3001730028
case TK_SELECT: {
30018
- sqlite3TreeViewLine(pView, "SELECT-expr flags=0x%x", pExpr->flags);
30029
+ sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
3001930030
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3002030031
break;
3002130032
}
3002230033
case TK_IN: {
3002330034
sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
@@ -99541,11 +99552,16 @@
9954199552
assert( pExpr!=0 );
9954299553
}
9954399554
op = pExpr->op;
9954499555
if( op==TK_SELECT ){
9954599556
assert( pExpr->flags&EP_xIsSelect );
99546
- return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
99557
+ if( ALWAYS(pExpr->x.pSelect)
99558
+ && pExpr->x.pSelect->pEList
99559
+ && ALWAYS(pExpr->x.pSelect->pEList->a[0].pExpr)
99560
+ ){
99561
+ return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
99562
+ }
9954799563
}
9954899564
if( op==TK_REGISTER ) op = pExpr->op2;
9954999565
#ifndef SQLITE_OMIT_CAST
9955099566
if( op==TK_CAST ){
9955199567
assert( !ExprHasProperty(pExpr, EP_IntValue) );
@@ -105197,10 +105213,68 @@
105197105213
sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
105198105214
}
105199105215
#endif
105200105216
return cnt.nThis>0 || cnt.nOther==0;
105201105217
}
105218
+
105219
+/*
105220
+** This is a Walker expression node callback.
105221
+**
105222
+** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
105223
+** object that is referenced does not refer directly to the Expr. If
105224
+** it does, make a copy. This is done because the pExpr argument is
105225
+** subject to change.
105226
+**
105227
+** The copy is stored on pParse->pConstExpr with a register number of 0.
105228
+** This will cause the expression to be deleted automatically when the
105229
+** Parse object is destroyed, but the zero register number means that it
105230
+** will not generate any code in the preamble.
105231
+*/
105232
+static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
105233
+ if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
105234
+ && pExpr->pAggInfo!=0
105235
+ ){
105236
+ AggInfo *pAggInfo = pExpr->pAggInfo;
105237
+ int iAgg = pExpr->iAgg;
105238
+ Parse *pParse = pWalker->pParse;
105239
+ sqlite3 *db = pParse->db;
105240
+ assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
105241
+ if( pExpr->op==TK_AGG_COLUMN ){
105242
+ assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
105243
+ if( pAggInfo->aCol[iAgg].pExpr==pExpr ){
105244
+ pExpr = sqlite3ExprDup(db, pExpr, 0);
105245
+ if( pExpr ){
105246
+ pAggInfo->aCol[iAgg].pExpr = pExpr;
105247
+ pParse->pConstExpr =
105248
+ sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105249
+ }
105250
+ }
105251
+ }else{
105252
+ assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
105253
+ if( pAggInfo->aFunc[iAgg].pExpr==pExpr ){
105254
+ pExpr = sqlite3ExprDup(db, pExpr, 0);
105255
+ if( pExpr ){
105256
+ pAggInfo->aFunc[iAgg].pExpr = pExpr;
105257
+ pParse->pConstExpr =
105258
+ sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105259
+ }
105260
+ }
105261
+ }
105262
+ }
105263
+ return WRC_Continue;
105264
+}
105265
+
105266
+/*
105267
+** Initialize a Walker object so that will persist AggInfo entries referenced
105268
+** by the tree that is walked.
105269
+*/
105270
+SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker *pWalker, Parse *pParse){
105271
+ memset(pWalker, 0, sizeof(*pWalker));
105272
+ pWalker->pParse = pParse;
105273
+ pWalker->xExprCallback = agginfoPersistExprCb;
105274
+ pWalker->xSelectCallback = sqlite3SelectWalkNoop;
105275
+}
105202105276
105203105277
/*
105204105278
** Add a new element to the pAggInfo->aCol[] array. Return the index of
105205105279
** the new element. Return a negative number if malloc fails.
105206105280
*/
@@ -105228,11 +105302,11 @@
105228105302
sizeof(pInfo->aFunc[0]),
105229105303
&pInfo->nFunc,
105230105304
&i
105231105305
);
105232105306
return i;
105233
-}
105307
+}
105234105308
105235105309
/*
105236105310
** This is the xExprCallback for a tree walker. It is used to
105237105311
** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates
105238105312
** for additional information.
@@ -110283,16 +110357,25 @@
110283110357
110284110358
/* Initialize any AUTOINCREMENT data structures required.
110285110359
*/
110286110360
sqlite3AutoincrementBegin(pParse);
110287110361
110288
- /* Code constant expressions that where factored out of inner loops */
110362
+ /* Code constant expressions that where factored out of inner loops.
110363
+ **
110364
+ ** The pConstExpr list might also contain expressions that we simply
110365
+ ** want to keep around until the Parse object is deleted. Such
110366
+ ** expressions have iConstExprReg==0. Do not generate code for
110367
+ ** those expressions, of course.
110368
+ */
110289110369
if( pParse->pConstExpr ){
110290110370
ExprList *pEL = pParse->pConstExpr;
110291110371
pParse->okConstFactor = 0;
110292110372
for(i=0; i<pEL->nExpr; i++){
110293
- sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
110373
+ int iReg = pEL->a[i].u.iConstExprReg;
110374
+ if( iReg>0 ){
110375
+ sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
110376
+ }
110294110377
}
110295110378
}
110296110379
110297110380
/* Finally, jump back to the beginning of the executable code. */
110298110381
sqlite3VdbeGoto(v, 1);
@@ -128474,16 +128557,31 @@
128474128557
}
128475128558
assert( i>=0 && i<db->nDb );
128476128559
}
128477128560
return i;
128478128561
}
128562
+
128563
+/*
128564
+** Deallocate a single AggInfo object
128565
+*/
128566
+static void agginfoFree(sqlite3 *db, AggInfo *p){
128567
+ sqlite3DbFree(db, p->aCol);
128568
+ sqlite3DbFree(db, p->aFunc);
128569
+ sqlite3DbFree(db, p);
128570
+}
128479128571
128480128572
/*
128481128573
** Free all memory allocations in the pParse object
128482128574
*/
128483128575
SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
128484128576
sqlite3 *db = pParse->db;
128577
+ AggInfo *pThis = pParse->pAggList;
128578
+ while( pThis ){
128579
+ AggInfo *pNext = pThis->pNext;
128580
+ agginfoFree(db, pThis);
128581
+ pThis = pNext;
128582
+ }
128485128583
sqlite3DbFree(db, pParse->aLabel);
128486128584
sqlite3ExprListDelete(db, pParse->pConstExpr);
128487128585
if( db ){
128488128586
assert( db->lookaside.bDisable >= pParse->disableLookaside );
128489128587
db->lookaside.bDisable -= pParse->disableLookaside;
@@ -132668,10 +132766,11 @@
132668132766
int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
132669132767
int i; /* Loop counter */
132670132768
Expr *pWhere; /* The WHERE clause */
132671132769
struct SrcList_item *pSubitem; /* The subquery */
132672132770
sqlite3 *db = pParse->db;
132771
+ Walker w; /* Walker to persist agginfo data */
132673132772
132674132773
/* Check to see if flattening is permitted. Return 0 if not.
132675132774
*/
132676132775
assert( p!=0 );
132677132776
assert( p->pPrior==0 );
@@ -133042,10 +133141,12 @@
133042133141
}
133043133142
133044133143
/* Finially, delete what is left of the subquery and return
133045133144
** success.
133046133145
*/
133146
+ sqlite3AggInfoPersistWalkerInit(&w, pParse);
133147
+ sqlite3WalkSelect(&w,pSub1);
133047133148
sqlite3SelectDelete(db, pSub1);
133048133149
133049133150
#if SELECTTRACE_ENABLED
133050133151
if( sqlite3SelectTrace & 0x100 ){
133051133152
SELECTTRACE(0x100,pParse,p,("After flattening:\n"));
@@ -134626,14 +134727,14 @@
134626134727
ExprList *pEList = 0; /* List of columns to extract. */
134627134728
SrcList *pTabList; /* List of tables to select from */
134628134729
Expr *pWhere; /* The WHERE clause. May be NULL */
134629134730
ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */
134630134731
Expr *pHaving; /* The HAVING clause. May be NULL */
134732
+ AggInfo *pAggInfo = 0; /* Aggregate information */
134631134733
int rc = 1; /* Value to return from this function */
134632134734
DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */
134633134735
SortCtx sSort; /* Info on how to code the ORDER BY clause */
134634
- AggInfo sAggInfo; /* Information used by aggregate queries */
134635134736
int iEnd; /* Address of the end of the query */
134636134737
sqlite3 *db; /* The database connection */
134637134738
ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
134638134739
u8 minMaxFlag; /* Flag for min/max queries */
134639134740
@@ -134641,11 +134742,10 @@
134641134742
v = sqlite3GetVdbe(pParse);
134642134743
if( p==0 || db->mallocFailed || pParse->nErr ){
134643134744
return 1;
134644134745
}
134645134746
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
134646
- memset(&sAggInfo, 0, sizeof(sAggInfo));
134647134747
#if SELECTTRACE_ENABLED
134648134748
SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
134649134749
if( sqlite3SelectTrace & 0x100 ){
134650134750
sqlite3TreeViewSelect(0, p, 0);
134651134751
}
@@ -135231,18 +135331,24 @@
135231135331
135232135332
/* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
135233135333
** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
135234135334
** SELECT statement.
135235135335
*/
135336
+ pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
135337
+ if( pAggInfo==0 ){
135338
+ goto select_end;
135339
+ }
135340
+ pAggInfo->pNext = pParse->pAggList;
135341
+ pParse->pAggList = pAggInfo;
135236135342
memset(&sNC, 0, sizeof(sNC));
135237135343
sNC.pParse = pParse;
135238135344
sNC.pSrcList = pTabList;
135239
- sNC.uNC.pAggInfo = &sAggInfo;
135345
+ sNC.uNC.pAggInfo = pAggInfo;
135240135346
VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
135241
- sAggInfo.mnReg = pParse->nMem+1;
135242
- sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
135243
- sAggInfo.pGroupBy = pGroupBy;
135347
+ pAggInfo->mnReg = pParse->nMem+1;
135348
+ pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
135349
+ pAggInfo->pGroupBy = pGroupBy;
135244135350
sqlite3ExprAnalyzeAggList(&sNC, pEList);
135245135351
sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
135246135352
if( pHaving ){
135247135353
if( pGroupBy ){
135248135354
assert( pWhere==p->pWhere );
@@ -135251,18 +135357,18 @@
135251135357
havingToWhere(pParse, p);
135252135358
pWhere = p->pWhere;
135253135359
}
135254135360
sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135255135361
}
135256
- sAggInfo.nAccumulator = sAggInfo.nColumn;
135257
- if( p->pGroupBy==0 && p->pHaving==0 && sAggInfo.nFunc==1 ){
135258
- minMaxFlag = minMaxQuery(db, sAggInfo.aFunc[0].pExpr, &pMinMaxOrderBy);
135362
+ pAggInfo->nAccumulator = pAggInfo->nColumn;
135363
+ if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
135364
+ minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pExpr, &pMinMaxOrderBy);
135259135365
}else{
135260135366
minMaxFlag = WHERE_ORDERBY_NORMAL;
135261135367
}
135262
- for(i=0; i<sAggInfo.nFunc; i++){
135263
- Expr *pExpr = sAggInfo.aFunc[i].pExpr;
135368
+ for(i=0; i<pAggInfo->nFunc; i++){
135369
+ Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135264135370
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135265135371
sNC.ncFlags |= NC_InAggFunc;
135266135372
sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135267135373
#ifndef SQLITE_OMIT_WINDOWFUNC
135268135374
assert( !IsWindowFunc(pExpr) );
@@ -135270,26 +135376,26 @@
135270135376
sqlite3ExprAnalyzeAggregates(&sNC, pExpr->y.pWin->pFilter);
135271135377
}
135272135378
#endif
135273135379
sNC.ncFlags &= ~NC_InAggFunc;
135274135380
}
135275
- sAggInfo.mxReg = pParse->nMem;
135381
+ pAggInfo->mxReg = pParse->nMem;
135276135382
if( db->mallocFailed ) goto select_end;
135277135383
#if SELECTTRACE_ENABLED
135278135384
if( sqlite3SelectTrace & 0x400 ){
135279135385
int ii;
135280
- SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", &sAggInfo));
135386
+ SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
135281135387
sqlite3TreeViewSelect(0, p, 0);
135282
- for(ii=0; ii<sAggInfo.nColumn; ii++){
135388
+ for(ii=0; ii<pAggInfo->nColumn; ii++){
135283135389
sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135284
- ii, sAggInfo.aCol[ii].iMem);
135285
- sqlite3TreeViewExpr(0, sAggInfo.aCol[ii].pExpr, 0);
135390
+ ii, pAggInfo->aCol[ii].iMem);
135391
+ sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pExpr, 0);
135286135392
}
135287
- for(ii=0; ii<sAggInfo.nFunc; ii++){
135393
+ for(ii=0; ii<pAggInfo->nFunc; ii++){
135288135394
sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135289
- ii, sAggInfo.aFunc[ii].iMem);
135290
- sqlite3TreeViewExpr(0, sAggInfo.aFunc[ii].pExpr, 0);
135395
+ ii, pAggInfo->aFunc[ii].iMem);
135396
+ sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pExpr, 0);
135291135397
}
135292135398
}
135293135399
#endif
135294135400
135295135401
@@ -135310,14 +135416,15 @@
135310135416
/* If there is a GROUP BY clause we might need a sorting index to
135311135417
** implement it. Allocate that sorting index now. If it turns out
135312135418
** that we do not need it after all, the OP_SorterOpen instruction
135313135419
** will be converted into a Noop.
135314135420
*/
135315
- sAggInfo.sortingIdx = pParse->nTab++;
135316
- pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pGroupBy,0,sAggInfo.nColumn);
135421
+ pAggInfo->sortingIdx = pParse->nTab++;
135422
+ pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pGroupBy,
135423
+ 0, pAggInfo->nColumn);
135317135424
addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
135318
- sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
135425
+ pAggInfo->sortingIdx, pAggInfo->nSortingColumn,
135319135426
0, (char*)pKeyInfo, P4_KEYINFO);
135320135427
135321135428
/* Initialize memory locations used by GROUP BY aggregate processing
135322135429
*/
135323135430
iUseFlag = ++pParse->nMem;
@@ -135368,40 +135475,40 @@
135368135475
135369135476
groupBySort = 1;
135370135477
nGroupBy = pGroupBy->nExpr;
135371135478
nCol = nGroupBy;
135372135479
j = nGroupBy;
135373
- for(i=0; i<sAggInfo.nColumn; i++){
135374
- if( sAggInfo.aCol[i].iSorterColumn>=j ){
135480
+ for(i=0; i<pAggInfo->nColumn; i++){
135481
+ if( pAggInfo->aCol[i].iSorterColumn>=j ){
135375135482
nCol++;
135376135483
j++;
135377135484
}
135378135485
}
135379135486
regBase = sqlite3GetTempRange(pParse, nCol);
135380135487
sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
135381135488
j = nGroupBy;
135382
- for(i=0; i<sAggInfo.nColumn; i++){
135383
- struct AggInfo_col *pCol = &sAggInfo.aCol[i];
135489
+ for(i=0; i<pAggInfo->nColumn; i++){
135490
+ struct AggInfo_col *pCol = &pAggInfo->aCol[i];
135384135491
if( pCol->iSorterColumn>=j ){
135385135492
int r1 = j + regBase;
135386135493
sqlite3ExprCodeGetColumnOfTable(v,
135387135494
pCol->pTab, pCol->iTable, pCol->iColumn, r1);
135388135495
j++;
135389135496
}
135390135497
}
135391135498
regRecord = sqlite3GetTempReg(pParse);
135392135499
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
135393
- sqlite3VdbeAddOp2(v, OP_SorterInsert, sAggInfo.sortingIdx, regRecord);
135500
+ sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
135394135501
sqlite3ReleaseTempReg(pParse, regRecord);
135395135502
sqlite3ReleaseTempRange(pParse, regBase, nCol);
135396135503
sqlite3WhereEnd(pWInfo);
135397
- sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
135504
+ pAggInfo->sortingIdxPTab = sortPTab = pParse->nTab++;
135398135505
sortOut = sqlite3GetTempReg(pParse);
135399135506
sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
135400
- sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
135507
+ sqlite3VdbeAddOp2(v, OP_SorterSort, pAggInfo->sortingIdx, addrEnd);
135401135508
VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
135402
- sAggInfo.useSortingIdx = 1;
135509
+ pAggInfo->useSortingIdx = 1;
135403135510
}
135404135511
135405135512
/* If the index or temporary table used by the GROUP BY sort
135406135513
** will naturally deliver rows in the order required by the ORDER BY
135407135514
** clause, cancel the ephemeral table open coded earlier.
@@ -135421,18 +135528,18 @@
135421135528
** Then compare the current GROUP BY terms against the GROUP BY terms
135422135529
** from the previous row currently stored in a0, a1, a2...
135423135530
*/
135424135531
addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
135425135532
if( groupBySort ){
135426
- sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx,
135533
+ sqlite3VdbeAddOp3(v, OP_SorterData, pAggInfo->sortingIdx,
135427135534
sortOut, sortPTab);
135428135535
}
135429135536
for(j=0; j<pGroupBy->nExpr; j++){
135430135537
if( groupBySort ){
135431135538
sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
135432135539
}else{
135433
- sAggInfo.directMode = 1;
135540
+ pAggInfo->directMode = 1;
135434135541
sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
135435135542
}
135436135543
}
135437135544
sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
135438135545
(char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
@@ -135458,18 +135565,18 @@
135458135565
135459135566
/* Update the aggregate accumulators based on the content of
135460135567
** the current row
135461135568
*/
135462135569
sqlite3VdbeJumpHere(v, addr1);
135463
- updateAccumulator(pParse, iUseFlag, &sAggInfo);
135570
+ updateAccumulator(pParse, iUseFlag, pAggInfo);
135464135571
sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
135465135572
VdbeComment((v, "indicate data in accumulator"));
135466135573
135467135574
/* End of the loop
135468135575
*/
135469135576
if( groupBySort ){
135470
- sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
135577
+ sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx, addrTopOfLoop);
135471135578
VdbeCoverage(v);
135472135579
}else{
135473135580
sqlite3WhereEnd(pWInfo);
135474135581
sqlite3VdbeChangeToNoop(v, addrSortingIdx);
135475135582
}
@@ -135498,11 +135605,11 @@
135498135605
addrOutputRow = sqlite3VdbeCurrentAddr(v);
135499135606
sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
135500135607
VdbeCoverage(v);
135501135608
VdbeComment((v, "Groupby result generator entry point"));
135502135609
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
135503
- finalizeAggFunctions(pParse, &sAggInfo);
135610
+ finalizeAggFunctions(pParse, pAggInfo);
135504135611
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
135505135612
selectInnerLoop(pParse, p, -1, &sSort,
135506135613
&sDistinct, pDest,
135507135614
addrOutputRow+1, addrSetAbort);
135508135615
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
@@ -135509,19 +135616,19 @@
135509135616
VdbeComment((v, "end groupby result generator"));
135510135617
135511135618
/* Generate a subroutine that will reset the group-by accumulator
135512135619
*/
135513135620
sqlite3VdbeResolveLabel(v, addrReset);
135514
- resetAccumulator(pParse, &sAggInfo);
135621
+ resetAccumulator(pParse, pAggInfo);
135515135622
sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
135516135623
VdbeComment((v, "indicate accumulator empty"));
135517135624
sqlite3VdbeAddOp1(v, OP_Return, regReset);
135518135625
135519135626
} /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
135520135627
else {
135521135628
Table *pTab;
135522
- if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){
135629
+ if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
135523135630
/* If isSimpleCount() returns a pointer to a Table structure, then
135524135631
** the SQL statement is of the form:
135525135632
**
135526135633
** SELECT count(*) FROM <tbl>
135527135634
**
@@ -135572,11 +135679,11 @@
135572135679
/* Open a read-only cursor, execute the OP_Count, close the cursor. */
135573135680
sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
135574135681
if( pKeyInfo ){
135575135682
sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
135576135683
}
135577
- sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
135684
+ sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
135578135685
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
135579135686
explainSimpleCount(pParse, pTab, pBest);
135580135687
}else{
135581135688
int regAcc = 0; /* "populate accumulators" flag */
135582135689
@@ -135587,16 +135694,20 @@
135587135694
** that the accumulator registers are (a) updated only once if
135588135695
** there are no min() or max functions or (b) always updated for the
135589135696
** first row visited by the aggregate, so that they are updated at
135590135697
** least once even if the FILTER clause means the min() or max()
135591135698
** function visits zero rows. */
135592
- if( sAggInfo.nAccumulator ){
135593
- for(i=0; i<sAggInfo.nFunc; i++){
135594
- if( ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_WinFunc) ) continue;
135595
- if( sAggInfo.aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ) break;
135699
+ if( pAggInfo->nAccumulator ){
135700
+ for(i=0; i<pAggInfo->nFunc; i++){
135701
+ if( ExprHasProperty(pAggInfo->aFunc[i].pExpr, EP_WinFunc) ){
135702
+ continue;
135703
+ }
135704
+ if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
135705
+ break;
135706
+ }
135596135707
}
135597
- if( i==sAggInfo.nFunc ){
135708
+ if( i==pAggInfo->nFunc ){
135598135709
regAcc = ++pParse->nMem;
135599135710
sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
135600135711
}
135601135712
}
135602135713
@@ -135603,11 +135714,11 @@
135603135714
/* This case runs if the aggregate has no GROUP BY clause. The
135604135715
** processing is much simpler since there is only a single row
135605135716
** of output.
135606135717
*/
135607135718
assert( p->pGroupBy==0 );
135608
- resetAccumulator(pParse, &sAggInfo);
135719
+ resetAccumulator(pParse, pAggInfo);
135609135720
135610135721
/* If this query is a candidate for the min/max optimization, then
135611135722
** minMaxFlag will have been previously set to either
135612135723
** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
135613135724
** be an appropriate ORDER BY expression for the optimization.
@@ -135619,19 +135730,19 @@
135619135730
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
135620135731
0, minMaxFlag, 0);
135621135732
if( pWInfo==0 ){
135622135733
goto select_end;
135623135734
}
135624
- updateAccumulator(pParse, regAcc, &sAggInfo);
135735
+ updateAccumulator(pParse, regAcc, pAggInfo);
135625135736
if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
135626135737
if( sqlite3WhereIsOrdered(pWInfo)>0 ){
135627135738
sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
135628135739
VdbeComment((v, "%s() by index",
135629135740
(minMaxFlag==WHERE_ORDERBY_MIN?"min":"max")));
135630135741
}
135631135742
sqlite3WhereEnd(pWInfo);
135632
- finalizeAggFunctions(pParse, &sAggInfo);
135743
+ finalizeAggFunctions(pParse, pAggInfo);
135633135744
}
135634135745
135635135746
sSort.pOrderBy = 0;
135636135747
sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
135637135748
selectInnerLoop(pParse, p, -1, 0, 0,
@@ -135666,12 +135777,29 @@
135666135777
/* Control jumps to here if an error is encountered above, or upon
135667135778
** successful coding of the SELECT.
135668135779
*/
135669135780
select_end:
135670135781
sqlite3ExprListDelete(db, pMinMaxOrderBy);
135671
- sqlite3DbFree(db, sAggInfo.aCol);
135672
- sqlite3DbFree(db, sAggInfo.aFunc);
135782
+#ifdef SQLITE_DEBUG
135783
+ if( pAggInfo ){
135784
+ for(i=0; i<pAggInfo->nColumn; i++){
135785
+ Expr *pExpr = pAggInfo->aCol[i].pExpr;
135786
+ assert( pExpr!=0 || db->mallocFailed );
135787
+ if( pExpr==0 ) continue;
135788
+ assert( pExpr->pAggInfo==pAggInfo );
135789
+ assert( pExpr->iAgg==i );
135790
+ }
135791
+ for(i=0; i<pAggInfo->nFunc; i++){
135792
+ Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135793
+ assert( pExpr!=0 || db->mallocFailed );
135794
+ if( pExpr==0 ) continue;
135795
+ assert( pExpr->pAggInfo==pAggInfo );
135796
+ assert( pExpr->iAgg==i );
135797
+ }
135798
+ }
135799
+#endif
135800
+
135673135801
#if SELECTTRACE_ENABLED
135674135802
SELECTTRACE(0x1,pParse,p,("end processing\n"));
135675135803
if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
135676135804
sqlite3TreeViewSelect(0, p, 0);
135677135805
}
@@ -151361,16 +151489,20 @@
151361151489
151362151490
ExprList *pSublist = 0; /* Expression list for sub-query */
151363151491
Window *pMWin = p->pWin; /* Master window object */
151364151492
Window *pWin; /* Window object iterator */
151365151493
Table *pTab;
151494
+ Walker w;
151495
+
151366151496
u32 selFlags = p->selFlags;
151367151497
151368151498
pTab = sqlite3DbMallocZero(db, sizeof(Table));
151369151499
if( pTab==0 ){
151370151500
return sqlite3ErrorToParser(db, SQLITE_NOMEM);
151371151501
}
151502
+ sqlite3AggInfoPersistWalkerInit(&w, pParse);
151503
+ sqlite3WalkSelect(&w, p);
151372151504
151373151505
p->pSrc = 0;
151374151506
p->pWhere = 0;
151375151507
p->pGroupBy = 0;
151376151508
p->pHaving = 0;
@@ -151447,11 +151579,10 @@
151447151579
pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
151448151580
);
151449151581
p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151450151582
if( p->pSrc ){
151451151583
Table *pTab2;
151452
- Walker w;
151453151584
p->pSrc->a[0].pSelect = pSub;
151454151585
sqlite3SrcListAssignCursors(pParse, p->pSrc);
151455151586
pSub->selFlags |= SF_Expanded;
151456151587
pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
151457151588
pSub->selFlags |= (selFlags & SF_Aggregate);
@@ -224866,11 +224997,11 @@
224866224997
int nArg, /* Number of args */
224867224998
sqlite3_value **apUnused /* Function arguments */
224868224999
){
224869225000
assert( nArg==0 );
224870225001
UNUSED_PARAM2(nArg, apUnused);
224871
- sqlite3_result_text(pCtx, "fts5: 2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680fb72", -1, SQLITE_TRANSIENT);
225002
+ sqlite3_result_text(pCtx, "fts5: 2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb", -1, SQLITE_TRANSIENT);
224872225003
}
224873225004
224874225005
/*
224875225006
** Return true if zName is the extension on one of the shadow tables used
224876225007
** by this module.
@@ -229649,12 +229780,12 @@
229649229780
}
229650229781
#endif /* SQLITE_CORE */
229651229782
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229652229783
229653229784
/************** End of stmt.c ************************************************/
229654
-#if __LINE__!=229654
229785
+#if __LINE__!=229785
229655229786
#undef SQLITE_SOURCE_ID
229656
-#define SQLITE_SOURCE_ID "2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680alt2"
229787
+#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d39500393alt2"
229657229788
#endif
229658229789
/* Return the source-id for this library */
229659229790
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229660229791
/************************** End of sqlite3.c ******************************/
229661229792
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.33.0"
1166 #define SQLITE_VERSION_NUMBER 3033000
1167 #define SQLITE_SOURCE_ID "2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680fb72"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -17861,15 +17861,15 @@
17861 int nSortingColumn; /* Number of columns in the sorting index */
17862 int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
17863 ExprList *pGroupBy; /* The group by clause */
17864 struct AggInfo_col { /* For each column used in source tables */
17865 Table *pTab; /* Source table */
 
17866 int iTable; /* Cursor number of the source table */
17867 int iColumn; /* Column number within the source table */
17868 int iSorterColumn; /* Column number in the sorting index */
17869 int iMem; /* Memory location that acts as accumulator */
17870 Expr *pExpr; /* The original expression */
 
17871 } *aCol;
17872 int nColumn; /* Number of used entries in aCol[] */
17873 int nAccumulator; /* Number of columns that show through to the output.
17874 ** Additional columns are used only as parameters to
17875 ** aggregate functions */
@@ -17878,12 +17878,21 @@
17878 FuncDef *pFunc; /* The aggregate function implementation */
17879 int iMem; /* Memory location that acts as accumulator */
17880 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
17881 } *aFunc;
17882 int nFunc; /* Number of entries in aFunc[] */
 
 
 
 
17883 };
17884
 
 
 
 
 
17885 /*
17886 ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
17887 ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
17888 ** than 32767 we have to make it 32-bit. 16-bit is preferred because
17889 ** it uses less memory in the Expr object, which is a big memory user
@@ -18676,10 +18685,11 @@
18676 #endif
18677 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
18678 Parse *pToplevel; /* Parse structure for main program (or NULL) */
18679 Table *pTriggerTab; /* Table triggers are being coded for */
18680 Parse *pParentParse; /* Parent parser if this parser is nested */
 
18681 int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
18682 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
18683 u32 oldmask; /* Mask of old.* columns referenced */
18684 u32 newmask; /* Mask of new.* columns referenced */
18685 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -19642,10 +19652,11 @@
19642 SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
19643 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
19644 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
19645 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
19646 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
 
19647 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
19648 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
19649 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
19650 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
19651 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
@@ -30013,11 +30024,11 @@
30013 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
30014 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30015 break;
30016 }
30017 case TK_SELECT: {
30018 sqlite3TreeViewLine(pView, "SELECT-expr flags=0x%x", pExpr->flags);
30019 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30020 break;
30021 }
30022 case TK_IN: {
30023 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
@@ -99541,11 +99552,16 @@
99541 assert( pExpr!=0 );
99542 }
99543 op = pExpr->op;
99544 if( op==TK_SELECT ){
99545 assert( pExpr->flags&EP_xIsSelect );
99546 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
 
 
 
 
 
99547 }
99548 if( op==TK_REGISTER ) op = pExpr->op2;
99549 #ifndef SQLITE_OMIT_CAST
99550 if( op==TK_CAST ){
99551 assert( !ExprHasProperty(pExpr, EP_IntValue) );
@@ -105197,10 +105213,68 @@
105197 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
105198 }
105199 #endif
105200 return cnt.nThis>0 || cnt.nOther==0;
105201 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105202
105203 /*
105204 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
105205 ** the new element. Return a negative number if malloc fails.
105206 */
@@ -105228,11 +105302,11 @@
105228 sizeof(pInfo->aFunc[0]),
105229 &pInfo->nFunc,
105230 &i
105231 );
105232 return i;
105233 }
105234
105235 /*
105236 ** This is the xExprCallback for a tree walker. It is used to
105237 ** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates
105238 ** for additional information.
@@ -110283,16 +110357,25 @@
110283
110284 /* Initialize any AUTOINCREMENT data structures required.
110285 */
110286 sqlite3AutoincrementBegin(pParse);
110287
110288 /* Code constant expressions that where factored out of inner loops */
 
 
 
 
 
 
110289 if( pParse->pConstExpr ){
110290 ExprList *pEL = pParse->pConstExpr;
110291 pParse->okConstFactor = 0;
110292 for(i=0; i<pEL->nExpr; i++){
110293 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
 
 
 
110294 }
110295 }
110296
110297 /* Finally, jump back to the beginning of the executable code. */
110298 sqlite3VdbeGoto(v, 1);
@@ -128474,16 +128557,31 @@
128474 }
128475 assert( i>=0 && i<db->nDb );
128476 }
128477 return i;
128478 }
 
 
 
 
 
 
 
 
 
128479
128480 /*
128481 ** Free all memory allocations in the pParse object
128482 */
128483 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
128484 sqlite3 *db = pParse->db;
 
 
 
 
 
 
128485 sqlite3DbFree(db, pParse->aLabel);
128486 sqlite3ExprListDelete(db, pParse->pConstExpr);
128487 if( db ){
128488 assert( db->lookaside.bDisable >= pParse->disableLookaside );
128489 db->lookaside.bDisable -= pParse->disableLookaside;
@@ -132668,10 +132766,11 @@
132668 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
132669 int i; /* Loop counter */
132670 Expr *pWhere; /* The WHERE clause */
132671 struct SrcList_item *pSubitem; /* The subquery */
132672 sqlite3 *db = pParse->db;
 
132673
132674 /* Check to see if flattening is permitted. Return 0 if not.
132675 */
132676 assert( p!=0 );
132677 assert( p->pPrior==0 );
@@ -133042,10 +133141,12 @@
133042 }
133043
133044 /* Finially, delete what is left of the subquery and return
133045 ** success.
133046 */
 
 
133047 sqlite3SelectDelete(db, pSub1);
133048
133049 #if SELECTTRACE_ENABLED
133050 if( sqlite3SelectTrace & 0x100 ){
133051 SELECTTRACE(0x100,pParse,p,("After flattening:\n"));
@@ -134626,14 +134727,14 @@
134626 ExprList *pEList = 0; /* List of columns to extract. */
134627 SrcList *pTabList; /* List of tables to select from */
134628 Expr *pWhere; /* The WHERE clause. May be NULL */
134629 ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */
134630 Expr *pHaving; /* The HAVING clause. May be NULL */
 
134631 int rc = 1; /* Value to return from this function */
134632 DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */
134633 SortCtx sSort; /* Info on how to code the ORDER BY clause */
134634 AggInfo sAggInfo; /* Information used by aggregate queries */
134635 int iEnd; /* Address of the end of the query */
134636 sqlite3 *db; /* The database connection */
134637 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
134638 u8 minMaxFlag; /* Flag for min/max queries */
134639
@@ -134641,11 +134742,10 @@
134641 v = sqlite3GetVdbe(pParse);
134642 if( p==0 || db->mallocFailed || pParse->nErr ){
134643 return 1;
134644 }
134645 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
134646 memset(&sAggInfo, 0, sizeof(sAggInfo));
134647 #if SELECTTRACE_ENABLED
134648 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
134649 if( sqlite3SelectTrace & 0x100 ){
134650 sqlite3TreeViewSelect(0, p, 0);
134651 }
@@ -135231,18 +135331,24 @@
135231
135232 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
135233 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
135234 ** SELECT statement.
135235 */
 
 
 
 
 
 
135236 memset(&sNC, 0, sizeof(sNC));
135237 sNC.pParse = pParse;
135238 sNC.pSrcList = pTabList;
135239 sNC.uNC.pAggInfo = &sAggInfo;
135240 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
135241 sAggInfo.mnReg = pParse->nMem+1;
135242 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
135243 sAggInfo.pGroupBy = pGroupBy;
135244 sqlite3ExprAnalyzeAggList(&sNC, pEList);
135245 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
135246 if( pHaving ){
135247 if( pGroupBy ){
135248 assert( pWhere==p->pWhere );
@@ -135251,18 +135357,18 @@
135251 havingToWhere(pParse, p);
135252 pWhere = p->pWhere;
135253 }
135254 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135255 }
135256 sAggInfo.nAccumulator = sAggInfo.nColumn;
135257 if( p->pGroupBy==0 && p->pHaving==0 && sAggInfo.nFunc==1 ){
135258 minMaxFlag = minMaxQuery(db, sAggInfo.aFunc[0].pExpr, &pMinMaxOrderBy);
135259 }else{
135260 minMaxFlag = WHERE_ORDERBY_NORMAL;
135261 }
135262 for(i=0; i<sAggInfo.nFunc; i++){
135263 Expr *pExpr = sAggInfo.aFunc[i].pExpr;
135264 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135265 sNC.ncFlags |= NC_InAggFunc;
135266 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135267 #ifndef SQLITE_OMIT_WINDOWFUNC
135268 assert( !IsWindowFunc(pExpr) );
@@ -135270,26 +135376,26 @@
135270 sqlite3ExprAnalyzeAggregates(&sNC, pExpr->y.pWin->pFilter);
135271 }
135272 #endif
135273 sNC.ncFlags &= ~NC_InAggFunc;
135274 }
135275 sAggInfo.mxReg = pParse->nMem;
135276 if( db->mallocFailed ) goto select_end;
135277 #if SELECTTRACE_ENABLED
135278 if( sqlite3SelectTrace & 0x400 ){
135279 int ii;
135280 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", &sAggInfo));
135281 sqlite3TreeViewSelect(0, p, 0);
135282 for(ii=0; ii<sAggInfo.nColumn; ii++){
135283 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135284 ii, sAggInfo.aCol[ii].iMem);
135285 sqlite3TreeViewExpr(0, sAggInfo.aCol[ii].pExpr, 0);
135286 }
135287 for(ii=0; ii<sAggInfo.nFunc; ii++){
135288 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135289 ii, sAggInfo.aFunc[ii].iMem);
135290 sqlite3TreeViewExpr(0, sAggInfo.aFunc[ii].pExpr, 0);
135291 }
135292 }
135293 #endif
135294
135295
@@ -135310,14 +135416,15 @@
135310 /* If there is a GROUP BY clause we might need a sorting index to
135311 ** implement it. Allocate that sorting index now. If it turns out
135312 ** that we do not need it after all, the OP_SorterOpen instruction
135313 ** will be converted into a Noop.
135314 */
135315 sAggInfo.sortingIdx = pParse->nTab++;
135316 pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pGroupBy,0,sAggInfo.nColumn);
 
135317 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
135318 sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
135319 0, (char*)pKeyInfo, P4_KEYINFO);
135320
135321 /* Initialize memory locations used by GROUP BY aggregate processing
135322 */
135323 iUseFlag = ++pParse->nMem;
@@ -135368,40 +135475,40 @@
135368
135369 groupBySort = 1;
135370 nGroupBy = pGroupBy->nExpr;
135371 nCol = nGroupBy;
135372 j = nGroupBy;
135373 for(i=0; i<sAggInfo.nColumn; i++){
135374 if( sAggInfo.aCol[i].iSorterColumn>=j ){
135375 nCol++;
135376 j++;
135377 }
135378 }
135379 regBase = sqlite3GetTempRange(pParse, nCol);
135380 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
135381 j = nGroupBy;
135382 for(i=0; i<sAggInfo.nColumn; i++){
135383 struct AggInfo_col *pCol = &sAggInfo.aCol[i];
135384 if( pCol->iSorterColumn>=j ){
135385 int r1 = j + regBase;
135386 sqlite3ExprCodeGetColumnOfTable(v,
135387 pCol->pTab, pCol->iTable, pCol->iColumn, r1);
135388 j++;
135389 }
135390 }
135391 regRecord = sqlite3GetTempReg(pParse);
135392 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
135393 sqlite3VdbeAddOp2(v, OP_SorterInsert, sAggInfo.sortingIdx, regRecord);
135394 sqlite3ReleaseTempReg(pParse, regRecord);
135395 sqlite3ReleaseTempRange(pParse, regBase, nCol);
135396 sqlite3WhereEnd(pWInfo);
135397 sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
135398 sortOut = sqlite3GetTempReg(pParse);
135399 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
135400 sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
135401 VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
135402 sAggInfo.useSortingIdx = 1;
135403 }
135404
135405 /* If the index or temporary table used by the GROUP BY sort
135406 ** will naturally deliver rows in the order required by the ORDER BY
135407 ** clause, cancel the ephemeral table open coded earlier.
@@ -135421,18 +135528,18 @@
135421 ** Then compare the current GROUP BY terms against the GROUP BY terms
135422 ** from the previous row currently stored in a0, a1, a2...
135423 */
135424 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
135425 if( groupBySort ){
135426 sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx,
135427 sortOut, sortPTab);
135428 }
135429 for(j=0; j<pGroupBy->nExpr; j++){
135430 if( groupBySort ){
135431 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
135432 }else{
135433 sAggInfo.directMode = 1;
135434 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
135435 }
135436 }
135437 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
135438 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
@@ -135458,18 +135565,18 @@
135458
135459 /* Update the aggregate accumulators based on the content of
135460 ** the current row
135461 */
135462 sqlite3VdbeJumpHere(v, addr1);
135463 updateAccumulator(pParse, iUseFlag, &sAggInfo);
135464 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
135465 VdbeComment((v, "indicate data in accumulator"));
135466
135467 /* End of the loop
135468 */
135469 if( groupBySort ){
135470 sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
135471 VdbeCoverage(v);
135472 }else{
135473 sqlite3WhereEnd(pWInfo);
135474 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
135475 }
@@ -135498,11 +135605,11 @@
135498 addrOutputRow = sqlite3VdbeCurrentAddr(v);
135499 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
135500 VdbeCoverage(v);
135501 VdbeComment((v, "Groupby result generator entry point"));
135502 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
135503 finalizeAggFunctions(pParse, &sAggInfo);
135504 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
135505 selectInnerLoop(pParse, p, -1, &sSort,
135506 &sDistinct, pDest,
135507 addrOutputRow+1, addrSetAbort);
135508 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
@@ -135509,19 +135616,19 @@
135509 VdbeComment((v, "end groupby result generator"));
135510
135511 /* Generate a subroutine that will reset the group-by accumulator
135512 */
135513 sqlite3VdbeResolveLabel(v, addrReset);
135514 resetAccumulator(pParse, &sAggInfo);
135515 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
135516 VdbeComment((v, "indicate accumulator empty"));
135517 sqlite3VdbeAddOp1(v, OP_Return, regReset);
135518
135519 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
135520 else {
135521 Table *pTab;
135522 if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){
135523 /* If isSimpleCount() returns a pointer to a Table structure, then
135524 ** the SQL statement is of the form:
135525 **
135526 ** SELECT count(*) FROM <tbl>
135527 **
@@ -135572,11 +135679,11 @@
135572 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
135573 sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
135574 if( pKeyInfo ){
135575 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
135576 }
135577 sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
135578 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
135579 explainSimpleCount(pParse, pTab, pBest);
135580 }else{
135581 int regAcc = 0; /* "populate accumulators" flag */
135582
@@ -135587,16 +135694,20 @@
135587 ** that the accumulator registers are (a) updated only once if
135588 ** there are no min() or max functions or (b) always updated for the
135589 ** first row visited by the aggregate, so that they are updated at
135590 ** least once even if the FILTER clause means the min() or max()
135591 ** function visits zero rows. */
135592 if( sAggInfo.nAccumulator ){
135593 for(i=0; i<sAggInfo.nFunc; i++){
135594 if( ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_WinFunc) ) continue;
135595 if( sAggInfo.aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ) break;
 
 
 
 
135596 }
135597 if( i==sAggInfo.nFunc ){
135598 regAcc = ++pParse->nMem;
135599 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
135600 }
135601 }
135602
@@ -135603,11 +135714,11 @@
135603 /* This case runs if the aggregate has no GROUP BY clause. The
135604 ** processing is much simpler since there is only a single row
135605 ** of output.
135606 */
135607 assert( p->pGroupBy==0 );
135608 resetAccumulator(pParse, &sAggInfo);
135609
135610 /* If this query is a candidate for the min/max optimization, then
135611 ** minMaxFlag will have been previously set to either
135612 ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
135613 ** be an appropriate ORDER BY expression for the optimization.
@@ -135619,19 +135730,19 @@
135619 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
135620 0, minMaxFlag, 0);
135621 if( pWInfo==0 ){
135622 goto select_end;
135623 }
135624 updateAccumulator(pParse, regAcc, &sAggInfo);
135625 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
135626 if( sqlite3WhereIsOrdered(pWInfo)>0 ){
135627 sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
135628 VdbeComment((v, "%s() by index",
135629 (minMaxFlag==WHERE_ORDERBY_MIN?"min":"max")));
135630 }
135631 sqlite3WhereEnd(pWInfo);
135632 finalizeAggFunctions(pParse, &sAggInfo);
135633 }
135634
135635 sSort.pOrderBy = 0;
135636 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
135637 selectInnerLoop(pParse, p, -1, 0, 0,
@@ -135666,12 +135777,29 @@
135666 /* Control jumps to here if an error is encountered above, or upon
135667 ** successful coding of the SELECT.
135668 */
135669 select_end:
135670 sqlite3ExprListDelete(db, pMinMaxOrderBy);
135671 sqlite3DbFree(db, sAggInfo.aCol);
135672 sqlite3DbFree(db, sAggInfo.aFunc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135673 #if SELECTTRACE_ENABLED
135674 SELECTTRACE(0x1,pParse,p,("end processing\n"));
135675 if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
135676 sqlite3TreeViewSelect(0, p, 0);
135677 }
@@ -151361,16 +151489,20 @@
151361
151362 ExprList *pSublist = 0; /* Expression list for sub-query */
151363 Window *pMWin = p->pWin; /* Master window object */
151364 Window *pWin; /* Window object iterator */
151365 Table *pTab;
 
 
151366 u32 selFlags = p->selFlags;
151367
151368 pTab = sqlite3DbMallocZero(db, sizeof(Table));
151369 if( pTab==0 ){
151370 return sqlite3ErrorToParser(db, SQLITE_NOMEM);
151371 }
 
 
151372
151373 p->pSrc = 0;
151374 p->pWhere = 0;
151375 p->pGroupBy = 0;
151376 p->pHaving = 0;
@@ -151447,11 +151579,10 @@
151447 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
151448 );
151449 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151450 if( p->pSrc ){
151451 Table *pTab2;
151452 Walker w;
151453 p->pSrc->a[0].pSelect = pSub;
151454 sqlite3SrcListAssignCursors(pParse, p->pSrc);
151455 pSub->selFlags |= SF_Expanded;
151456 pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
151457 pSub->selFlags |= (selFlags & SF_Aggregate);
@@ -224866,11 +224997,11 @@
224866 int nArg, /* Number of args */
224867 sqlite3_value **apUnused /* Function arguments */
224868 ){
224869 assert( nArg==0 );
224870 UNUSED_PARAM2(nArg, apUnused);
224871 sqlite3_result_text(pCtx, "fts5: 2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680fb72", -1, SQLITE_TRANSIENT);
224872 }
224873
224874 /*
224875 ** Return true if zName is the extension on one of the shadow tables used
224876 ** by this module.
@@ -229649,12 +229780,12 @@
229649 }
229650 #endif /* SQLITE_CORE */
229651 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229652
229653 /************** End of stmt.c ************************************************/
229654 #if __LINE__!=229654
229655 #undef SQLITE_SOURCE_ID
229656 #define SQLITE_SOURCE_ID "2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680alt2"
229657 #endif
229658 /* Return the source-id for this library */
229659 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229660 /************************** End of sqlite3.c ******************************/
229661
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.33.0"
1166 #define SQLITE_VERSION_NUMBER 3033000
1167 #define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -17861,15 +17861,15 @@
17861 int nSortingColumn; /* Number of columns in the sorting index */
17862 int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
17863 ExprList *pGroupBy; /* The group by clause */
17864 struct AggInfo_col { /* For each column used in source tables */
17865 Table *pTab; /* Source table */
17866 Expr *pExpr; /* The original expression */
17867 int iTable; /* Cursor number of the source table */
 
 
17868 int iMem; /* Memory location that acts as accumulator */
17869 i16 iColumn; /* Column number within the source table */
17870 i16 iSorterColumn; /* Column number in the sorting index */
17871 } *aCol;
17872 int nColumn; /* Number of used entries in aCol[] */
17873 int nAccumulator; /* Number of columns that show through to the output.
17874 ** Additional columns are used only as parameters to
17875 ** aggregate functions */
@@ -17878,12 +17878,21 @@
17878 FuncDef *pFunc; /* The aggregate function implementation */
17879 int iMem; /* Memory location that acts as accumulator */
17880 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
17881 } *aFunc;
17882 int nFunc; /* Number of entries in aFunc[] */
17883 #ifdef SQLITE_DEBUG
17884 int iAggMagic; /* Magic number when valid */
17885 #endif
17886 AggInfo *pNext; /* Next in list of them all */
17887 };
17888
17889 /*
17890 ** Value for AggInfo.iAggMagic when the structure is valid
17891 */
17892 #define AggInfoMagic 0x2059e99e
17893
17894 /*
17895 ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
17896 ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
17897 ** than 32767 we have to make it 32-bit. 16-bit is preferred because
17898 ** it uses less memory in the Expr object, which is a big memory user
@@ -18676,10 +18685,11 @@
18685 #endif
18686 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
18687 Parse *pToplevel; /* Parse structure for main program (or NULL) */
18688 Table *pTriggerTab; /* Table triggers are being coded for */
18689 Parse *pParentParse; /* Parent parser if this parser is nested */
18690 AggInfo *pAggList; /* List of all AggInfo objects */
18691 int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
18692 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
18693 u32 oldmask; /* Mask of old.* columns referenced */
18694 u32 newmask; /* Mask of new.* columns referenced */
18695 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -19642,10 +19652,11 @@
19652 SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
19653 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
19654 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
19655 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
19656 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
19657 SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*);
19658 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
19659 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
19660 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
19661 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
19662 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
@@ -30013,11 +30024,11 @@
30024 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
30025 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30026 break;
30027 }
30028 case TK_SELECT: {
30029 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
30030 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30031 break;
30032 }
30033 case TK_IN: {
30034 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
@@ -99541,11 +99552,16 @@
99552 assert( pExpr!=0 );
99553 }
99554 op = pExpr->op;
99555 if( op==TK_SELECT ){
99556 assert( pExpr->flags&EP_xIsSelect );
99557 if( ALWAYS(pExpr->x.pSelect)
99558 && pExpr->x.pSelect->pEList
99559 && ALWAYS(pExpr->x.pSelect->pEList->a[0].pExpr)
99560 ){
99561 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
99562 }
99563 }
99564 if( op==TK_REGISTER ) op = pExpr->op2;
99565 #ifndef SQLITE_OMIT_CAST
99566 if( op==TK_CAST ){
99567 assert( !ExprHasProperty(pExpr, EP_IntValue) );
@@ -105197,10 +105213,68 @@
105213 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
105214 }
105215 #endif
105216 return cnt.nThis>0 || cnt.nOther==0;
105217 }
105218
105219 /*
105220 ** This is a Walker expression node callback.
105221 **
105222 ** For Expr nodes that contain pAggInfo pointers, make sure the AggInfo
105223 ** object that is referenced does not refer directly to the Expr. If
105224 ** it does, make a copy. This is done because the pExpr argument is
105225 ** subject to change.
105226 **
105227 ** The copy is stored on pParse->pConstExpr with a register number of 0.
105228 ** This will cause the expression to be deleted automatically when the
105229 ** Parse object is destroyed, but the zero register number means that it
105230 ** will not generate any code in the preamble.
105231 */
105232 static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
105233 if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
105234 && pExpr->pAggInfo!=0
105235 ){
105236 AggInfo *pAggInfo = pExpr->pAggInfo;
105237 int iAgg = pExpr->iAgg;
105238 Parse *pParse = pWalker->pParse;
105239 sqlite3 *db = pParse->db;
105240 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
105241 if( pExpr->op==TK_AGG_COLUMN ){
105242 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
105243 if( pAggInfo->aCol[iAgg].pExpr==pExpr ){
105244 pExpr = sqlite3ExprDup(db, pExpr, 0);
105245 if( pExpr ){
105246 pAggInfo->aCol[iAgg].pExpr = pExpr;
105247 pParse->pConstExpr =
105248 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105249 }
105250 }
105251 }else{
105252 assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
105253 if( pAggInfo->aFunc[iAgg].pExpr==pExpr ){
105254 pExpr = sqlite3ExprDup(db, pExpr, 0);
105255 if( pExpr ){
105256 pAggInfo->aFunc[iAgg].pExpr = pExpr;
105257 pParse->pConstExpr =
105258 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105259 }
105260 }
105261 }
105262 }
105263 return WRC_Continue;
105264 }
105265
105266 /*
105267 ** Initialize a Walker object so that will persist AggInfo entries referenced
105268 ** by the tree that is walked.
105269 */
105270 SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker *pWalker, Parse *pParse){
105271 memset(pWalker, 0, sizeof(*pWalker));
105272 pWalker->pParse = pParse;
105273 pWalker->xExprCallback = agginfoPersistExprCb;
105274 pWalker->xSelectCallback = sqlite3SelectWalkNoop;
105275 }
105276
105277 /*
105278 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
105279 ** the new element. Return a negative number if malloc fails.
105280 */
@@ -105228,11 +105302,11 @@
105302 sizeof(pInfo->aFunc[0]),
105303 &pInfo->nFunc,
105304 &i
105305 );
105306 return i;
105307 }
105308
105309 /*
105310 ** This is the xExprCallback for a tree walker. It is used to
105311 ** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates
105312 ** for additional information.
@@ -110283,16 +110357,25 @@
110357
110358 /* Initialize any AUTOINCREMENT data structures required.
110359 */
110360 sqlite3AutoincrementBegin(pParse);
110361
110362 /* Code constant expressions that where factored out of inner loops.
110363 **
110364 ** The pConstExpr list might also contain expressions that we simply
110365 ** want to keep around until the Parse object is deleted. Such
110366 ** expressions have iConstExprReg==0. Do not generate code for
110367 ** those expressions, of course.
110368 */
110369 if( pParse->pConstExpr ){
110370 ExprList *pEL = pParse->pConstExpr;
110371 pParse->okConstFactor = 0;
110372 for(i=0; i<pEL->nExpr; i++){
110373 int iReg = pEL->a[i].u.iConstExprReg;
110374 if( iReg>0 ){
110375 sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
110376 }
110377 }
110378 }
110379
110380 /* Finally, jump back to the beginning of the executable code. */
110381 sqlite3VdbeGoto(v, 1);
@@ -128474,16 +128557,31 @@
128557 }
128558 assert( i>=0 && i<db->nDb );
128559 }
128560 return i;
128561 }
128562
128563 /*
128564 ** Deallocate a single AggInfo object
128565 */
128566 static void agginfoFree(sqlite3 *db, AggInfo *p){
128567 sqlite3DbFree(db, p->aCol);
128568 sqlite3DbFree(db, p->aFunc);
128569 sqlite3DbFree(db, p);
128570 }
128571
128572 /*
128573 ** Free all memory allocations in the pParse object
128574 */
128575 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
128576 sqlite3 *db = pParse->db;
128577 AggInfo *pThis = pParse->pAggList;
128578 while( pThis ){
128579 AggInfo *pNext = pThis->pNext;
128580 agginfoFree(db, pThis);
128581 pThis = pNext;
128582 }
128583 sqlite3DbFree(db, pParse->aLabel);
128584 sqlite3ExprListDelete(db, pParse->pConstExpr);
128585 if( db ){
128586 assert( db->lookaside.bDisable >= pParse->disableLookaside );
128587 db->lookaside.bDisable -= pParse->disableLookaside;
@@ -132668,10 +132766,11 @@
132766 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
132767 int i; /* Loop counter */
132768 Expr *pWhere; /* The WHERE clause */
132769 struct SrcList_item *pSubitem; /* The subquery */
132770 sqlite3 *db = pParse->db;
132771 Walker w; /* Walker to persist agginfo data */
132772
132773 /* Check to see if flattening is permitted. Return 0 if not.
132774 */
132775 assert( p!=0 );
132776 assert( p->pPrior==0 );
@@ -133042,10 +133141,12 @@
133141 }
133142
133143 /* Finially, delete what is left of the subquery and return
133144 ** success.
133145 */
133146 sqlite3AggInfoPersistWalkerInit(&w, pParse);
133147 sqlite3WalkSelect(&w,pSub1);
133148 sqlite3SelectDelete(db, pSub1);
133149
133150 #if SELECTTRACE_ENABLED
133151 if( sqlite3SelectTrace & 0x100 ){
133152 SELECTTRACE(0x100,pParse,p,("After flattening:\n"));
@@ -134626,14 +134727,14 @@
134727 ExprList *pEList = 0; /* List of columns to extract. */
134728 SrcList *pTabList; /* List of tables to select from */
134729 Expr *pWhere; /* The WHERE clause. May be NULL */
134730 ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */
134731 Expr *pHaving; /* The HAVING clause. May be NULL */
134732 AggInfo *pAggInfo = 0; /* Aggregate information */
134733 int rc = 1; /* Value to return from this function */
134734 DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */
134735 SortCtx sSort; /* Info on how to code the ORDER BY clause */
 
134736 int iEnd; /* Address of the end of the query */
134737 sqlite3 *db; /* The database connection */
134738 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
134739 u8 minMaxFlag; /* Flag for min/max queries */
134740
@@ -134641,11 +134742,10 @@
134742 v = sqlite3GetVdbe(pParse);
134743 if( p==0 || db->mallocFailed || pParse->nErr ){
134744 return 1;
134745 }
134746 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
 
134747 #if SELECTTRACE_ENABLED
134748 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
134749 if( sqlite3SelectTrace & 0x100 ){
134750 sqlite3TreeViewSelect(0, p, 0);
134751 }
@@ -135231,18 +135331,24 @@
135331
135332 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
135333 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
135334 ** SELECT statement.
135335 */
135336 pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
135337 if( pAggInfo==0 ){
135338 goto select_end;
135339 }
135340 pAggInfo->pNext = pParse->pAggList;
135341 pParse->pAggList = pAggInfo;
135342 memset(&sNC, 0, sizeof(sNC));
135343 sNC.pParse = pParse;
135344 sNC.pSrcList = pTabList;
135345 sNC.uNC.pAggInfo = pAggInfo;
135346 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
135347 pAggInfo->mnReg = pParse->nMem+1;
135348 pAggInfo->nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
135349 pAggInfo->pGroupBy = pGroupBy;
135350 sqlite3ExprAnalyzeAggList(&sNC, pEList);
135351 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
135352 if( pHaving ){
135353 if( pGroupBy ){
135354 assert( pWhere==p->pWhere );
@@ -135251,18 +135357,18 @@
135357 havingToWhere(pParse, p);
135358 pWhere = p->pWhere;
135359 }
135360 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135361 }
135362 pAggInfo->nAccumulator = pAggInfo->nColumn;
135363 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
135364 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pExpr, &pMinMaxOrderBy);
135365 }else{
135366 minMaxFlag = WHERE_ORDERBY_NORMAL;
135367 }
135368 for(i=0; i<pAggInfo->nFunc; i++){
135369 Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135370 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135371 sNC.ncFlags |= NC_InAggFunc;
135372 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135373 #ifndef SQLITE_OMIT_WINDOWFUNC
135374 assert( !IsWindowFunc(pExpr) );
@@ -135270,26 +135376,26 @@
135376 sqlite3ExprAnalyzeAggregates(&sNC, pExpr->y.pWin->pFilter);
135377 }
135378 #endif
135379 sNC.ncFlags &= ~NC_InAggFunc;
135380 }
135381 pAggInfo->mxReg = pParse->nMem;
135382 if( db->mallocFailed ) goto select_end;
135383 #if SELECTTRACE_ENABLED
135384 if( sqlite3SelectTrace & 0x400 ){
135385 int ii;
135386 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
135387 sqlite3TreeViewSelect(0, p, 0);
135388 for(ii=0; ii<pAggInfo->nColumn; ii++){
135389 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135390 ii, pAggInfo->aCol[ii].iMem);
135391 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pExpr, 0);
135392 }
135393 for(ii=0; ii<pAggInfo->nFunc; ii++){
135394 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135395 ii, pAggInfo->aFunc[ii].iMem);
135396 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pExpr, 0);
135397 }
135398 }
135399 #endif
135400
135401
@@ -135310,14 +135416,15 @@
135416 /* If there is a GROUP BY clause we might need a sorting index to
135417 ** implement it. Allocate that sorting index now. If it turns out
135418 ** that we do not need it after all, the OP_SorterOpen instruction
135419 ** will be converted into a Noop.
135420 */
135421 pAggInfo->sortingIdx = pParse->nTab++;
135422 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pGroupBy,
135423 0, pAggInfo->nColumn);
135424 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
135425 pAggInfo->sortingIdx, pAggInfo->nSortingColumn,
135426 0, (char*)pKeyInfo, P4_KEYINFO);
135427
135428 /* Initialize memory locations used by GROUP BY aggregate processing
135429 */
135430 iUseFlag = ++pParse->nMem;
@@ -135368,40 +135475,40 @@
135475
135476 groupBySort = 1;
135477 nGroupBy = pGroupBy->nExpr;
135478 nCol = nGroupBy;
135479 j = nGroupBy;
135480 for(i=0; i<pAggInfo->nColumn; i++){
135481 if( pAggInfo->aCol[i].iSorterColumn>=j ){
135482 nCol++;
135483 j++;
135484 }
135485 }
135486 regBase = sqlite3GetTempRange(pParse, nCol);
135487 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
135488 j = nGroupBy;
135489 for(i=0; i<pAggInfo->nColumn; i++){
135490 struct AggInfo_col *pCol = &pAggInfo->aCol[i];
135491 if( pCol->iSorterColumn>=j ){
135492 int r1 = j + regBase;
135493 sqlite3ExprCodeGetColumnOfTable(v,
135494 pCol->pTab, pCol->iTable, pCol->iColumn, r1);
135495 j++;
135496 }
135497 }
135498 regRecord = sqlite3GetTempReg(pParse);
135499 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
135500 sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
135501 sqlite3ReleaseTempReg(pParse, regRecord);
135502 sqlite3ReleaseTempRange(pParse, regBase, nCol);
135503 sqlite3WhereEnd(pWInfo);
135504 pAggInfo->sortingIdxPTab = sortPTab = pParse->nTab++;
135505 sortOut = sqlite3GetTempReg(pParse);
135506 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
135507 sqlite3VdbeAddOp2(v, OP_SorterSort, pAggInfo->sortingIdx, addrEnd);
135508 VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
135509 pAggInfo->useSortingIdx = 1;
135510 }
135511
135512 /* If the index or temporary table used by the GROUP BY sort
135513 ** will naturally deliver rows in the order required by the ORDER BY
135514 ** clause, cancel the ephemeral table open coded earlier.
@@ -135421,18 +135528,18 @@
135528 ** Then compare the current GROUP BY terms against the GROUP BY terms
135529 ** from the previous row currently stored in a0, a1, a2...
135530 */
135531 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
135532 if( groupBySort ){
135533 sqlite3VdbeAddOp3(v, OP_SorterData, pAggInfo->sortingIdx,
135534 sortOut, sortPTab);
135535 }
135536 for(j=0; j<pGroupBy->nExpr; j++){
135537 if( groupBySort ){
135538 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
135539 }else{
135540 pAggInfo->directMode = 1;
135541 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
135542 }
135543 }
135544 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
135545 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
@@ -135458,18 +135565,18 @@
135565
135566 /* Update the aggregate accumulators based on the content of
135567 ** the current row
135568 */
135569 sqlite3VdbeJumpHere(v, addr1);
135570 updateAccumulator(pParse, iUseFlag, pAggInfo);
135571 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
135572 VdbeComment((v, "indicate data in accumulator"));
135573
135574 /* End of the loop
135575 */
135576 if( groupBySort ){
135577 sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx, addrTopOfLoop);
135578 VdbeCoverage(v);
135579 }else{
135580 sqlite3WhereEnd(pWInfo);
135581 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
135582 }
@@ -135498,11 +135605,11 @@
135605 addrOutputRow = sqlite3VdbeCurrentAddr(v);
135606 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
135607 VdbeCoverage(v);
135608 VdbeComment((v, "Groupby result generator entry point"));
135609 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
135610 finalizeAggFunctions(pParse, pAggInfo);
135611 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
135612 selectInnerLoop(pParse, p, -1, &sSort,
135613 &sDistinct, pDest,
135614 addrOutputRow+1, addrSetAbort);
135615 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
@@ -135509,19 +135616,19 @@
135616 VdbeComment((v, "end groupby result generator"));
135617
135618 /* Generate a subroutine that will reset the group-by accumulator
135619 */
135620 sqlite3VdbeResolveLabel(v, addrReset);
135621 resetAccumulator(pParse, pAggInfo);
135622 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
135623 VdbeComment((v, "indicate accumulator empty"));
135624 sqlite3VdbeAddOp1(v, OP_Return, regReset);
135625
135626 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
135627 else {
135628 Table *pTab;
135629 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
135630 /* If isSimpleCount() returns a pointer to a Table structure, then
135631 ** the SQL statement is of the form:
135632 **
135633 ** SELECT count(*) FROM <tbl>
135634 **
@@ -135572,11 +135679,11 @@
135679 /* Open a read-only cursor, execute the OP_Count, close the cursor. */
135680 sqlite3VdbeAddOp4Int(v, OP_OpenRead, iCsr, iRoot, iDb, 1);
135681 if( pKeyInfo ){
135682 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO);
135683 }
135684 sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
135685 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
135686 explainSimpleCount(pParse, pTab, pBest);
135687 }else{
135688 int regAcc = 0; /* "populate accumulators" flag */
135689
@@ -135587,16 +135694,20 @@
135694 ** that the accumulator registers are (a) updated only once if
135695 ** there are no min() or max functions or (b) always updated for the
135696 ** first row visited by the aggregate, so that they are updated at
135697 ** least once even if the FILTER clause means the min() or max()
135698 ** function visits zero rows. */
135699 if( pAggInfo->nAccumulator ){
135700 for(i=0; i<pAggInfo->nFunc; i++){
135701 if( ExprHasProperty(pAggInfo->aFunc[i].pExpr, EP_WinFunc) ){
135702 continue;
135703 }
135704 if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
135705 break;
135706 }
135707 }
135708 if( i==pAggInfo->nFunc ){
135709 regAcc = ++pParse->nMem;
135710 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
135711 }
135712 }
135713
@@ -135603,11 +135714,11 @@
135714 /* This case runs if the aggregate has no GROUP BY clause. The
135715 ** processing is much simpler since there is only a single row
135716 ** of output.
135717 */
135718 assert( p->pGroupBy==0 );
135719 resetAccumulator(pParse, pAggInfo);
135720
135721 /* If this query is a candidate for the min/max optimization, then
135722 ** minMaxFlag will have been previously set to either
135723 ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
135724 ** be an appropriate ORDER BY expression for the optimization.
@@ -135619,19 +135730,19 @@
135730 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
135731 0, minMaxFlag, 0);
135732 if( pWInfo==0 ){
135733 goto select_end;
135734 }
135735 updateAccumulator(pParse, regAcc, pAggInfo);
135736 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
135737 if( sqlite3WhereIsOrdered(pWInfo)>0 ){
135738 sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
135739 VdbeComment((v, "%s() by index",
135740 (minMaxFlag==WHERE_ORDERBY_MIN?"min":"max")));
135741 }
135742 sqlite3WhereEnd(pWInfo);
135743 finalizeAggFunctions(pParse, pAggInfo);
135744 }
135745
135746 sSort.pOrderBy = 0;
135747 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
135748 selectInnerLoop(pParse, p, -1, 0, 0,
@@ -135666,12 +135777,29 @@
135777 /* Control jumps to here if an error is encountered above, or upon
135778 ** successful coding of the SELECT.
135779 */
135780 select_end:
135781 sqlite3ExprListDelete(db, pMinMaxOrderBy);
135782 #ifdef SQLITE_DEBUG
135783 if( pAggInfo ){
135784 for(i=0; i<pAggInfo->nColumn; i++){
135785 Expr *pExpr = pAggInfo->aCol[i].pExpr;
135786 assert( pExpr!=0 || db->mallocFailed );
135787 if( pExpr==0 ) continue;
135788 assert( pExpr->pAggInfo==pAggInfo );
135789 assert( pExpr->iAgg==i );
135790 }
135791 for(i=0; i<pAggInfo->nFunc; i++){
135792 Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135793 assert( pExpr!=0 || db->mallocFailed );
135794 if( pExpr==0 ) continue;
135795 assert( pExpr->pAggInfo==pAggInfo );
135796 assert( pExpr->iAgg==i );
135797 }
135798 }
135799 #endif
135800
135801 #if SELECTTRACE_ENABLED
135802 SELECTTRACE(0x1,pParse,p,("end processing\n"));
135803 if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
135804 sqlite3TreeViewSelect(0, p, 0);
135805 }
@@ -151361,16 +151489,20 @@
151489
151490 ExprList *pSublist = 0; /* Expression list for sub-query */
151491 Window *pMWin = p->pWin; /* Master window object */
151492 Window *pWin; /* Window object iterator */
151493 Table *pTab;
151494 Walker w;
151495
151496 u32 selFlags = p->selFlags;
151497
151498 pTab = sqlite3DbMallocZero(db, sizeof(Table));
151499 if( pTab==0 ){
151500 return sqlite3ErrorToParser(db, SQLITE_NOMEM);
151501 }
151502 sqlite3AggInfoPersistWalkerInit(&w, pParse);
151503 sqlite3WalkSelect(&w, p);
151504
151505 p->pSrc = 0;
151506 p->pWhere = 0;
151507 p->pGroupBy = 0;
151508 p->pHaving = 0;
@@ -151447,11 +151579,10 @@
151579 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
151580 );
151581 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151582 if( p->pSrc ){
151583 Table *pTab2;
 
151584 p->pSrc->a[0].pSelect = pSub;
151585 sqlite3SrcListAssignCursors(pParse, p->pSrc);
151586 pSub->selFlags |= SF_Expanded;
151587 pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
151588 pSub->selFlags |= (selFlags & SF_Aggregate);
@@ -224866,11 +224997,11 @@
224997 int nArg, /* Number of args */
224998 sqlite3_value **apUnused /* Function arguments */
224999 ){
225000 assert( nArg==0 );
225001 UNUSED_PARAM2(nArg, apUnused);
225002 sqlite3_result_text(pCtx, "fts5: 2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb", -1, SQLITE_TRANSIENT);
225003 }
225004
225005 /*
225006 ** Return true if zName is the extension on one of the shadow tables used
225007 ** by this module.
@@ -229649,12 +229780,12 @@
229780 }
229781 #endif /* SQLITE_CORE */
229782 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229783
229784 /************** End of stmt.c ************************************************/
229785 #if __LINE__!=229785
229786 #undef SQLITE_SOURCE_ID
229787 #define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d39500393alt2"
229788 #endif
229789 /* Return the source-id for this library */
229790 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229791 /************************** End of sqlite3.c ******************************/
229792
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.33.0"
127127
#define SQLITE_VERSION_NUMBER 3033000
128
-#define SQLITE_SOURCE_ID "2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680fb72"
128
+#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- 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.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-06-04 18:05:39 6da784c9e174744d6deeb76c553b515b96c1fcb80c55a281e476959ec680fb72"
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.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button