From: dan Date: Wed, 30 Apr 2014 15:00:16 +0000 (+0000) Subject: Add text to the header comment of whereLoopAddBtree() describing how the costs of... X-Git-Tag: version-3.8.5~65^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fexperimental-costs;p=thirdparty%2Fsqlite.git Add text to the header comment of whereLoopAddBtree() describing how the costs of various b-tree loops are estimated. FossilOrigin-Name: 05e6e16cb28c9ffb4596bd2ef81f687c5403ecbb --- diff --git a/manifest b/manifest index 9f27ec6f9b..35f78b46c2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sa\scouple\sof\stest\scases\sto\saccount\sfor\sthe\sfact\sthat\sthis\sbranch\sprefers\san\sindex\sscan\sand\spartial\ssort\sover\sa\sfull-table\sscan\sand\sfull\sexternal\ssort. -D 2014-04-30T14:53:21.345 +C Add\stext\sto\sthe\sheader\scomment\sof\swhereLoopAddBtree()\sdescribing\show\sthe\scosts\sof\svarious\sb-tree\sloops\sare\sestimated. +D 2014-04-30T15:00:16.197 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -292,7 +292,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c e91b92908c973b2b6b03145dcd131a8ca8b1bf64 +F src/where.c 4aeb1caa0a16c76e0c0566af4c64ba003836a0aa F src/whereInt.h 6804c2e5010378568c2bb1350477537755296a46 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1166,7 +1166,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P eefeda32d54efbbdf7d20b719299eda48b891fae -R 50e654a1c0b26308b8a927bcd26c6421 +P 9b975bf33cd8fc28c64183a9642bf9fb436a4746 +R 20e49e26218874ddfe5fb9438df8f580 U dan -Z f4d62e136a5d6e05753f5050c6fb0c4a +Z c1e32968c738a6da213a45755f91539c diff --git a/manifest.uuid b/manifest.uuid index 00e612df5f..6ee1deefef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9b975bf33cd8fc28c64183a9642bf9fb436a4746 \ No newline at end of file +05e6e16cb28c9ffb4596bd2ef81f687c5403ecbb \ No newline at end of file diff --git a/src/where.c b/src/where.c index ec7a908b1a..7d01db61ee 100644 --- a/src/where.c +++ b/src/where.c @@ -4349,6 +4349,29 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){ ** Add all WhereLoop objects for a single table of the join where the table ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be ** a b-tree table, not a virtual table. +** +** The costs (WhereLoop.rRun) of the b-tree loops added by this function +** are calculated as follows: +** +** For a full scan, assuming the table (or index) contains nRow rows: +** +** cost = nRow * 3.0 // full-table scan +** cost = nRow * K // scan of covering index +** cost = nRow * (K+3.0) // scan of non-covering index +** +** where K is a value between 1.1 and 3.0 set based on the relative +** estimated average size of the index and table records. +** +** For an index scan, where nVisit is the number of index rows visited +** by the scan, and nSeek is the number of seek operations required on +** the index b-tree: +** +** cost = nSeek * (log(nRow) + K * nVisit) // covering index +** cost = nSeek * (log(nRow) + (K+3.0) * nVisit) // non-covering index +** +** Normally, nSeek is 1. nSeek values greater than 1 come about if the +** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when +** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans. */ static int whereLoopAddBtree( WhereLoopBuilder *pBuilder, /* WHERE clause information */