]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplify the accumulator reset for aggregate query processing so that it
authordrh <drh@noemail.net>
Fri, 20 Dec 2013 13:11:45 +0000 (13:11 +0000)
committerdrh <drh@noemail.net>
Fri, 20 Dec 2013 13:11:45 +0000 (13:11 +0000)
uses a single multi-register OP_Null rather than a separate OP_Null for each
register.

FossilOrigin-Name: 2c7fd9b043f5f3d9d8e22dbefa84a9770ca951d0

manifest
manifest.uuid
src/select.c
src/sqliteInt.h

index 0859d915c2998a998c8cbda637c1af82a0a80f84..5cf3f29245196d462f682a1c50f693e97e3bbec2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Do\snot\sinject\sOOM\sfaults\sinto\sSQLITE_FCNTL_COMMIT_PHASE_TWO\sfile-control\sinvocations.\sIt\scauses\sproblems\sfor\stest\sscripts.
-D 2013-12-19T17:04:58.210
+C Simplify\sthe\saccumulator\sreset\sfor\saggregate\squery\sprocessing\sso\sthat\sit\nuses\sa\ssingle\smulti-register\sOP_Null\srather\sthan\sa\sseparate\sOP_Null\sfor\seach\nregister.
+D 2013-12-20T13:11:45.101
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -219,12 +219,12 @@ F src/printf.c 85d07756e45d7496d19439dcae3e6e9e0090f269
 F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
 F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
-F src/select.c 9d13850293cf19e5ffee59b231fa372e16ce65a9
+F src/select.c 819bb090c9a348d17f69f136cad2bfa9ee9cbb41
 F src/shell.c 18924f6ccfa70da98bf9e388bab512c0fd1e792e
 F src/sqlite.h.in 4ef56464aeaa3785a2c5ca37fb3a0fb229d68b2e
 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
-F src/sqliteInt.h b7e9da87740488671cfe4c70038a8eef3a1d317e
+F src/sqliteInt.h d0815177df125e900056e1e692504435e7610793
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -1147,7 +1147,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P ca3fdfd41961d8d3d1e39d20dc628e8a95dabb2f
-R b2d8ac3bed199d88ddec25ed7c70eec6
-U dan
-Z b85edb7cdda29606f3560dec5a14157c
+P 8eb28d23e353139d24a8af78309d39249ab9eaf0
+R 488c9d6501762ac1c5b904ecc4a5a8a0
+U drh
+Z c5be2c2c1ecdd01c10eef8b3332d3737
index 5b8bd821b1ebedcf464b5665ae70f93822c4f4ea..d0d554d6c8f223bbe8cf79bd57adb2426ec4b9e6 100644 (file)
@@ -1 +1 @@
-8eb28d23e353139d24a8af78309d39249ab9eaf0
\ No newline at end of file
+2c7fd9b043f5f3d9d8e22dbefa84a9770ca951d0
\ No newline at end of file
index 132d54697156324d6458895fc56048ec1b8dd47a..d075116749e0a000a2bef420aabf5aabcef2f8db 100644 (file)
@@ -3822,14 +3822,23 @@ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
   Vdbe *v = pParse->pVdbe;
   int i;
   struct AggInfo_func *pFunc;
-  if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){
-    return;
-  }
+  int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
+  if( nReg==0 ) return;
+#ifdef SQLITE_DEBUG
+  /* Verify that all AggInfo registers are within the range specified by
+  ** AggInfo.mnReg..AggInfo.mxReg */
+  assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
   for(i=0; i<pAggInfo->nColumn; i++){
-    sqlite3VdbeAddOp2(v, OP_Null, 0, pAggInfo->aCol[i].iMem);
+    assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg
+         && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg );
   }
+  for(i=0; i<pAggInfo->nFunc; i++){
+    assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg
+         && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg );
+  }
+#endif
+  sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
   for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
-    sqlite3VdbeAddOp2(v, OP_Null, 0, pFunc->iMem);
     if( pFunc->iDistinct>=0 ){
       Expr *pE = pFunc->pExpr;
       assert( !ExprHasProperty(pE, EP_xIsSelect) );
@@ -4407,6 +4416,7 @@ int sqlite3Select(
     sNC.pParse = pParse;
     sNC.pSrcList = pTabList;
     sNC.pAggInfo = &sAggInfo;
+    sAggInfo.mnReg = pParse->nMem+1;
     sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0;
     sAggInfo.pGroupBy = pGroupBy;
     sqlite3ExprAnalyzeAggList(&sNC, pEList);
@@ -4421,6 +4431,7 @@ int sqlite3Select(
       sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
       sNC.ncFlags &= ~NC_InAggFunc;
     }
+    sAggInfo.mxReg = pParse->nMem;
     if( db->mallocFailed ) goto select_end;
 
     /* Processing for aggregates with GROUP BY is very different and
index af018edf01f75eb18f4cf8dfa731240545078dcd..a33ff4d43b770e75525bbddfa45beec48d587dc1 100644 (file)
@@ -1688,6 +1688,7 @@ struct AggInfo {
   int sortingIdx;         /* Cursor number of the sorting index */
   int sortingIdxPTab;     /* Cursor number of pseudo-table */
   int nSortingColumn;     /* Number of columns in the sorting index */
+  int mnReg, mxReg;       /* Range of registers allocated for aCol and aFunc */
   ExprList *pGroupBy;     /* The group by clause */
   struct AggInfo_col {    /* For each column used in source tables */
     Table *pTab;             /* Source table */