diff options
author | drh <drh@noemail.net> | 2013-06-10 20:46:50 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2013-06-10 20:46:50 +0000 |
commit | c63367ef6848896d8fc602c7aba12977089c72e0 (patch) | |
tree | 9d7af29734b87006f80c3fff2fb7b2b454430397 | |
parent | b8a8e8a5d2f45c74ab624f57a333afa96fe252a1 (diff) | |
download | sqlite-c63367ef6848896d8fc602c7aba12977089c72e0.tar.gz sqlite-c63367ef6848896d8fc602c7aba12977089c72e0.zip |
Fix some minor issues with logarithmic cost in NGQP.
FossilOrigin-Name: 69cf877283d362915edddf1822fbf7a9f86278b3
-rw-r--r-- | manifest | 19 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/select.c | 12 | ||||
-rw-r--r-- | src/sqliteInt.h | 6 | ||||
-rw-r--r-- | src/where.c | 30 |
5 files changed, 44 insertions, 25 deletions
@@ -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 diff --git a/manifest.uuid b/manifest.uuid index 78304d046..98fac7263 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e8109673c3a87e379f5a5a97a8b0d5a1afe853d
\ No newline at end of file +69cf877283d362915edddf1822fbf7a9f86278b3
\ No newline at end of file diff --git a/src/select.c b/src/select.c index d160513bd..ee994a8c2 100644 --- a/src/select.c +++ b/src/select.c @@ -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; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 76835385f..aa1ea5101 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -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*); diff --git a/src/where.c b/src/where.c index 7d2f1f73b..4ddb37012 100644 --- a/src/where.c +++ b/src/where.c @@ -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{ |