]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Refactoring of DISTINCT code. Change the name of the local variable
authordrh <drh@noemail.net>
Thu, 20 Sep 2012 14:26:22 +0000 (14:26 +0000)
committerdrh <drh@noemail.net>
Thu, 20 Sep 2012 14:26:22 +0000 (14:26 +0000)
"distinct" to "distinctTab".  Generate cleaner code w/o unnecessary P4
and P5 values on the OP_Null for WHERE_DISTINCT_ORDERED.

FossilOrigin-Name: 0cda241a2bcb3c6f2ae6c48f522780bc4eddfc02

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

index 4afd96e7ed49971a41f065fdb23196b26b0ef1cc..8c9cfcf868e299e94dc9e4dacb2ef282e65f239e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Tighter\sVDBE\scode\sfor\sthe\sWHERE_DISTINCT_ORDERED\scase\sof\sDISTINCT\skeyword\nhandling.
-D 2012-09-19T21:15:46.053
+C Refactoring\sof\sDISTINCT\scode.\s\sChange\sthe\sname\sof\sthe\slocal\svariable\n"distinct"\sto\s"distinctTab".\s\sGenerate\scleaner\scode\sw/o\sunnecessary\sP4\nand\sP5\svalues\son\sthe\sOP_Null\sfor\sWHERE_DISTINCT_ORDERED.
+D 2012-09-20T14:26:22.088
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -174,12 +174,12 @@ F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
 F src/resolve.c 9e28280ec98035f31900fdd1db01f86f68ca6c32
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
-F src/select.c 63206bbfd19e0f85e609307041db9276ddf9f2c2
+F src/select.c 7878dd564f5ec107e9b58af5f3eeb27ac640770b
 F src/shell.c 87953c5d9c73d9494db97d1607e2e2280418f261
 F src/sqlite.h.in c76c38f9635590ff5844684a7976843878327137
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
-F src/sqliteInt.h 7fa267db5593970061523081b29d8da7f5399a2c
+F src/sqliteInt.h bcfaf463a0fecda2d10efd68a52fea11f1cff388
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -1016,7 +1016,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9
-P 82320501904f65030622a67836ba30f412169056
-R 9541e63a94fc58e6e6ac938d40479670
+P 94b48064db3cbb43e911fdf7183218b08146ec10
+R 5e2afb7573559eb5eba9ed47e068d0d2
 U drh
-Z 981d7e657532e16949d872fc02730646
+Z 5042a680f6b5da609676733ff0c80d03
index 1ae05cab56c845082fbd219b6e339b886068f13d..6c9b3f4ffeabea2b8df19ca3060797373570a31c 100644 (file)
@@ -1 +1 @@
-94b48064db3cbb43e911fdf7183218b08146ec10
\ No newline at end of file
+0cda241a2bcb3c6f2ae6c48f522780bc4eddfc02
\ No newline at end of file
index fdd9931e31540d35b926dbcde66efd767cd21eeb..d9266e2f3302539129cff6904216c53bf5bc6d03 100644 (file)
@@ -541,7 +541,7 @@ static void selectInnerLoop(
   int srcTab,             /* Pull data from this table */
   int nColumn,            /* Number of columns in the source table */
   ExprList *pOrderBy,     /* If not NULL, sort results using this key */
-  int distinct,           /* If >=0, make sure results are distinct */
+  int distinctTab,        /* If >=0, make sure results are distinct */
   SelectDest *pDest,      /* How to dispose of the results */
   int iContinue,          /* Jump here to continue with next row */
   int iBreak              /* Jump here to break out of the inner loop */
@@ -557,7 +557,7 @@ static void selectInnerLoop(
   assert( v );
   if( NEVER(v==0) ) return;
   assert( pEList!=0 );
-  hasDistinct = distinct>=0;
+  hasDistinct = distinctTab>=0;
   if( pOrderBy==0 && !hasDistinct ){
     codeOffset(v, p, iContinue);
   }
@@ -597,7 +597,7 @@ static void selectInnerLoop(
   if( hasDistinct ){
     assert( pEList!=0 );
     assert( pEList->nExpr==nColumn );
-    codeDistinct(pParse, distinct, iContinue, nColumn, regResult);
+    codeDistinct(pParse, distinctTab, iContinue, nColumn, regResult);
     if( pOrderBy==0 ){
       codeOffset(v, p, iContinue);
     }
@@ -3787,7 +3787,7 @@ int sqlite3Select(
   ExprList *pGroupBy;    /* The GROUP BY clause.  May be NULL */
   Expr *pHaving;         /* The HAVING clause.  May be NULL */
   int isDistinct;        /* True if the DISTINCT keyword is present */
-  int distinct;          /* Table to use for the distinct set */
+  int distinctTab;       /* Table to use for the distinct set */
   int rc = 1;            /* Value to return from this function */
   int addrSortIndex;     /* Address of an OP_OpenEphemeral instruction */
   int addrDistinctIndex; /* Address of an OP_OpenEphemeral instruction */
@@ -4018,13 +4018,13 @@ int sqlite3Select(
   */
   if( p->selFlags & SF_Distinct ){
     KeyInfo *pKeyInfo;
-    distinct = pParse->nTab++;
+    distinctTab = pParse->nTab++;
     pKeyInfo = keyInfoFromExprList(pParse, p->pEList);
-    addrDistinctIndex = sqlite3VdbeAddOp4(v, OP_OpenEphemeral, distinct, 0, 0,
-        (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
+    addrDistinctIndex = sqlite3VdbeAddOp4(v, OP_OpenEphemeral, distinctTab,
+                                   0, 0, (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
     sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
   }else{
-    distinct = addrDistinctIndex = -1;
+    distinctTab = addrDistinctIndex = -1;
   }
 
   /* Aggregate and non-aggregate queries are handled differently */
@@ -4049,13 +4049,14 @@ int sqlite3Select(
       VdbeOp *pOp;                /* No longer required OpenEphemeral instr. */
      
       assert( addrDistinctIndex>=0 );
+      sqlite3VdbeChangeToNoop(v, addrDistinctIndex);
       pOp = sqlite3VdbeGetOp(v, addrDistinctIndex);
 
       assert( isDistinct );
       assert( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED 
            || pWInfo->eDistinct==WHERE_DISTINCT_UNIQUE 
       );
-      distinct = -1;
+      distinctTab = -1;
       if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED ){
         int iJump;
         int iExpr;
@@ -4073,7 +4074,6 @@ int sqlite3Select(
         pOp->opcode = OP_Null;
         pOp->p1 = 1;
         pOp->p2 = iBase2;
-        pOp->p3 = iBase2 + nExpr - 1;
 
         sqlite3ExprCodeExprList(pParse, pEList, iBase, 1);
         iJump = sqlite3VdbeCurrentAddr(v) + pEList->nExpr;
@@ -4090,13 +4090,11 @@ int sqlite3Select(
         }
         assert( sqlite3VdbeCurrentAddr(v)==iJump );
         sqlite3VdbeAddOp3(v, OP_Move, iBase, iBase2, pEList->nExpr);
-      }else{
-        pOp->opcode = OP_Noop;
       }
     }
 
     /* Use the standard inner loop. */
-    selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, pDest,
+    selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinctTab, pDest,
                     pWInfo->iContinue, pWInfo->iBreak);
 
     /* End the database scan loop.
@@ -4364,7 +4362,7 @@ int sqlite3Select(
       finalizeAggFunctions(pParse, &sAggInfo);
       sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
       selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy,
-                      distinct, pDest,
+                      distinctTab, pDest,
                       addrOutputRow+1, addrSetAbort);
       sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
       VdbeComment((v, "end groupby result generator"));
@@ -4505,7 +4503,7 @@ int sqlite3Select(
     
   } /* endif aggregate query */
 
-  if( distinct>=0 ){
+  if( distinctTab>=0 ){
     explainTempTable(pParse, "DISTINCT");
   }
 
index 9d8d742eab8d666a442ee228549e46b06c8eca65..00aa480cafb60b9260940fa60457bb920532ce53 100644 (file)
@@ -2059,7 +2059,7 @@ struct NameContext {
 ** as the OP_OpenEphm instruction is coded because not
 ** enough information about the compound query is known at that point.
 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
-** for the result set.  The KeyInfo for addrOpenTran[2] contains collating
+** for the result set.  The KeyInfo for addrOpenEphm[2] contains collating
 ** sequences for the ORDER BY clause.
 */
 struct Select {