]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix some minor issues with logarithmic cost in NGQP.
authordrh <drh@noemail.net>
Mon, 10 Jun 2013 20:46:50 +0000 (20:46 +0000)
committerdrh <drh@noemail.net>
Mon, 10 Jun 2013 20:46:50 +0000 (20:46 +0000)
FossilOrigin-Name: 69cf877283d362915edddf1822fbf7a9f86278b3

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

index 7323ba878c5f05cfa1c7a27f49f8daeb0081ef7a..739f017f0f2b3f846ac012d03b56f026cb9ffdbb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C First\sattempt\sto\sstore\scosts\sand\srow\scounts\sas\sa\slogarithm.
-D 2013-06-10T19:12:39.512
+C Fix\ssome\sminor\sissues\swith\slogarithmic\scost\sin\sNGQP.
+D 2013-06-10T20:46:50.026
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -215,12 +215,12 @@ F src/printf.c bff529ed47657098c55c9910b9c69b1b3b1a1353
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
 F src/resolve.c 89f9003e8316ee3a172795459efc2a0274e1d5a8
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
-F src/select.c 5e8fe15b1c5b2cc592880d3f039c6a6da55bf253
+F src/select.c ddcf0c795f690968de66ab21051e764ca1c13f09
 F src/shell.c ab6eea968c8745be3aa74e45fedb37d057b4cd0d
 F src/sqlite.h.in 5b390ca5d94e09e56e7fee6a51ddde4721b89f8e
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
 F src/sqlite3ext.h d936f797812c28b81b26ed18345baf8db28a21a5
-F src/sqliteInt.h 7b85b09d746cde295c7a0f60711421a28f5c4905
+F src/sqliteInt.h 4284f3a915d6ee86656aa0d47649855e8df8081e
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -289,7 +289,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
 F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
-F src/where.c ae52899cfb8710b5f63c01ac64030b20f284dd5e
+F src/where.c 402d3f74aa8f72bd0d77df6d414cd0ad538411e8
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1094,10 +1094,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 0f8a38ee54208d6a477aa2482cd277b4808450f0
-R 17f9a2533926060b9b736553f681baac
-T *branch * nextgen-query-plan-logcost
-T *sym-nextgen-query-plan-logcost *
-T -sym-nextgen-query-plan-exp *
+P 9e8109673c3a87e379f5a5a97a8b0d5a1afe853d
+R 6b6adbb839b36bd753eb8d10af218a35
 U drh
-Z a107d2813c152067f49ec61599513e6e
+Z 0c1be235257af3633fe6569a03c10208
index 78304d046a2a0b3931ca3aeb08938c1ba931f426..98fac7263e888f6eed52ab086b582fd0cc47340e 100644 (file)
@@ -1 +1 @@
-9e8109673c3a87e379f5a5a97a8b0d5a1afe853d
\ No newline at end of file
+69cf877283d362915edddf1822fbf7a9f86278b3
\ No newline at end of file
index d160513bd367b8cfa28c33294b78eabe40b7e012..ee994a8c20e071783a2a8e0925c942810480e2dd 100644 (file)
@@ -1539,7 +1539,7 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
       if( n==0 ){
         sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
       }else{
-        if( p->nSelectRow > (double)n ) p->nSelectRow = (double)n;
+        if( p->nSelectRow > n ) p->nSelectRow = n;
       }
     }else{
       sqlite3ExprCode(pParse, p->pLimit, iLimit);
@@ -1733,9 +1733,9 @@ static int multiSelect(
       p->nSelectRow += pPrior->nSelectRow;
       if( pPrior->pLimit
        && sqlite3ExprIsInteger(pPrior->pLimit, &nLimit)
-       && p->nSelectRow > (double)nLimit 
+       && p->nSelectRow > nLimit 
       ){
-        p->nSelectRow = (double)nLimit;
+        p->nSelectRow = nLimit;
       }
       if( addr ){
         sqlite3VdbeJumpHere(v, addr);
@@ -4239,7 +4239,7 @@ int sqlite3Select(
   /* Set the limiter.
   */
   iEnd = sqlite3VdbeMakeLabel(v);
-  p->nSelectRow = (double)LARGEST_INT64;
+  p->nSelectRow = LARGEST_INT64;
   computeLimitRegisters(pParse, p, iEnd);
   if( p->iLimit==0 && addrSortIndex>=0 ){
     sqlite3VdbeGetOp(v, addrSortIndex)->opcode = OP_SorterOpen;
@@ -4320,9 +4320,9 @@ int sqlite3Select(
       for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
         pItem->iAlias = 0;
       }
-      if( p->nSelectRow>(double)100 ) p->nSelectRow = (double)100;
+      if( p->nSelectRow>100 ) p->nSelectRow = 100;
     }else{
-      p->nSelectRow = (double)1;
+      p->nSelectRow = 1;
     }
 
  
index 76835385fb9910eb005514647ebd04da182443f6..aa1ea510111b6286e19d97c265c42dbd757def51 100644 (file)
@@ -2042,7 +2042,7 @@ struct Select {
   u16 selFlags;          /* Various SF_* values */
   int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
   int addrOpenEphm[3];   /* OP_OpenEphem opcodes related to this select */
-  double nSelectRow;     /* Estimated number of result rows */
+  u64 nSelectRow;        /* Estimated number of result rows */
   SrcList *pSrc;         /* The FROM clause */
   Expr *pWhere;          /* The WHERE clause */
   ExprList *pGroupBy;    /* The GROUP BY clause */
@@ -2226,7 +2226,7 @@ struct Parse {
   /* Information used while coding trigger programs. */
   Parse *pToplevel;    /* Parse structure for main program (or NULL) */
   Table *pTriggerTab;  /* Table triggers are being coded for */
-  double nQueryLoop;   /* Estimated number of iterations of a query */
+  u32 nQueryLoop;      /* Estimated number of iterations of a query */
   u32 oldmask;         /* Mask of old.* columns referenced */
   u32 newmask;         /* Mask of new.* columns referenced */
   u8 eTriggerOp;       /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -2796,7 +2796,7 @@ void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
 void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
 WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
 void sqlite3WhereEnd(WhereInfo*);
-double sqlite3WhereOutputRowCount(WhereInfo*);
+u64 sqlite3WhereOutputRowCount(WhereInfo*);
 int sqlite3WhereIsDistinct(WhereInfo*);
 int sqlite3WhereIsOrdered(WhereInfo*);
 int sqlite3WhereContinueLabel(WhereInfo*);
index 7d2f1f73bbfa8075d6f35fe654c1d31e75a7944d..4ddb370124cc431827063cb449d2560231a925d9 100644 (file)
@@ -45,7 +45,13 @@ typedef struct WherePath WherePath;
 typedef struct WhereTerm WhereTerm;
 typedef struct WhereLoopBuilder WhereLoopBuilder;
 typedef struct WhereScan WhereScan;
-typedef unsigned short int WhereCost;  /* 10 times log2() of run-time */
+
+/*
+** Cost X is tracked as 10*log2(X) stored in a 16-bit integer.  The
+** maximum cost is 64*(2**63) which becomes 6900.  So all costs can be
+** be stored in a 16-bit unsigned integer without risk of overflow.
+*/
+typedef unsigned short int WhereCost;
 
 /*
 ** For each nested loop in a WHERE clause implementation, the WhereInfo
@@ -401,11 +407,25 @@ struct WhereInfo {
 #define WHERE_TEMP_INDEX   0x00004000  /* Uses an ephemeral index */
 #define WHERE_COVER_SCAN   0x00008000  /* Full scan of a covering index */
 
+
+/* Convert a WhereCost value (10 times log2(X)) into its integer value X.
+*/
+static u64 whereCostToInt(WhereCost x){
+  u64 n;
+  if( x<=10 ) return 1;
+  n = x%10;
+  x /= 10;
+  if( n>=5 ) n -= 2;
+  else if( n>=1 ) n -= 1;
+  if( x>=3 ) return (n+8)<<(x-3);
+  return (n+8)>>(3-x);
+}
+
 /*
 ** Return the estimated number of output rows from a WHERE clause
 */
-double sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
-  return (double)pWInfo->nRowOut;
+u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
+  return whereCostToInt(pWInfo->nRowOut);
 }
 
 /*
@@ -4716,6 +4736,7 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
   sqlite3 *db = pWInfo->pParse->db;
   int nTabList = pWInfo->nLevel;
   int rc = SQLITE_OK;
+  u8 priorJoinType = 0;
   WhereLoop *pNew;
 
   /* Loop over the tables in the join, from left to right */
@@ -4724,9 +4745,10 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
   for(iTab=0, pItem=pTabList->a; iTab<nTabList; iTab++, pItem++){
     pNew->iTab = iTab;
     pNew->maskSelf = getMask(&pWInfo->sMaskSet, pItem->iCursor);
-    if( (pItem->jointype & (JT_LEFT|JT_CROSS))!=0 ){
+    if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
       mExtra = mPrior;
     }
+    priorJoinType = pItem->jointype;
     if( IsVirtual(pItem->pTab) ){
       rc = whereLoopAddVirtual(pBuilder, mExtra);
     }else{