]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Only use the skip-ahead-distinct optimization if the index has been analyzed
authordrh <drh@noemail.net>
Thu, 13 Apr 2017 13:01:59 +0000 (13:01 +0000)
committerdrh <drh@noemail.net>
Thu, 13 Apr 2017 13:01:59 +0000 (13:01 +0000)
and we know that a skip-head is likely to skip over at least 11 rows.  The
magic number 11 was determined by experimentation.

FossilOrigin-Name: 0cf16decd534bf2d66620c293f8c8987f356305f2d97f8fd12d260bda1571385

manifest
manifest.uuid
src/where.c

index 9c2c74dfef0800af931a1ceea312dc7a6e1a746d..c04086b54cf4ca4acc7aa3bf2fc9b7f899eddf6d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Forward\sport\sthe\sskip-ahead-distinct\sbranch\swhich\swas\sabandoned\sfor\ssome\sreason\nthat\sI\sdo\snot\srecall.\s\sThis\sport\sshould\shave\sbeen\sachived\sby\sa\smerge\sof\strunk\ninto\sthe\sprevious\shead\sof\sskip-ahead-distinct,\sbut\sthat\sdid\snot\swork.\s\sSo\sI\shad\nto\smanually\s"rebase"\sthe\schanges.
-D 2017-04-13T01:19:30.439
+C Only\suse\sthe\sskip-ahead-distinct\soptimization\sif\sthe\sindex\shas\sbeen\sanalyzed\nand\swe\sknow\sthat\sa\sskip-head\sis\slikely\sto\sskip\sover\sat\sleast\s11\srows.\s\sThe\nmagic\snumber\s11\swas\sdetermined\sby\sexperimentation.
+D 2017-04-13T13:01:59.793
 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc a4c0613a18663bda56d8cf76079ab6590a7c3602e54befb4bbdef76bcaa38b6a
@@ -482,7 +482,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 40c543f0a2195d1b0dc88ef12142bea690009344
 F src/wal.h 06b2a0b599cc0f53ea97f497cf8c6b758c999f71
 F src/walker.c b71a992b413b3a022572eccf29ef4b4890223791
-F src/where.c 33fd1fcda81dcbfe5e7622247a2e0196f97f8188cbcd6b9a0e0aa5cdb82d9545
+F src/where.c 56111492a24dac936a4e5af7da18bdec6a8e0650a69bf0a8654a2a1b3241b247
 F src/whereInt.h 7a21ef633e26acbf46df04add2eba6e0a2100c78dc5879049e93f981fc3344df
 F src/wherecode.c 943e32e9dccd0af802e0683ae11071c8bd808364e5908a5fb66758bd404c8681
 F src/whereexpr.c e913aaa7b73ffcce66abcea5f197e2c538d48b5df78d0b7bba8ff4d73cc2e745
@@ -1572,10 +1572,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8e7b611863247a3bf46a96ec4b47d24c0ae0d60c9cee968a1cfd1da157e7c9bb
-R de2bc0d85efdd08063075633dcadd275
-T *branch * skip-ahead-distinct
-T *sym-skip-ahead-distinct *
-T -sym-trunk *
+P 132339a1fb0b9664df4d3eefbed6e77ef100ba95a91dcc622da7bd3fcdfcd6af
+R 5c1ba5f3c1c29d44b68025e1a39bfee8
 U drh
-Z 4afe54ae8fd900ea4ea328fe1c4fe900
+Z 06d9008ebfc7601c93a90ebae38b456d
index 411dd2c3a59744219f75a7e608dbd76f465f2ddf..1154c43c92ed1ae36d18a97e5403a4eeca96e0c0 100644 (file)
@@ -1 +1 @@
-132339a1fb0b9664df4d3eefbed6e77ef100ba95a91dcc622da7bd3fcdfcd6af
\ No newline at end of file
+0cf16decd534bf2d66620c293f8c8987f356305f2d97f8fd12d260bda1571385
\ No newline at end of file
index e79e88c3c525ca1e68b2d2eb94425b017c515158..52cf1363320b75d2cc800cf7967a16453d907cf5 100644 (file)
@@ -4853,16 +4853,17 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
       int n = -1;
       int j, k, op;
       int r1 = pParse->nMem+1;
+      Index *pIdx;
       if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
        && (pLoop->wsFlags & WHERE_INDEXED)!=0
        && OptimizationEnabled(db, SQLITE_SkipAhead)
+       && (pIdx = pLoop->u.btree.pIndex)->hasStat1
       ){
         /* This is the Skip-ahead optimization.  When doing a DISTINCT query
         ** that has WHERE_DISTINCT_ORDERED, use OP_SkipGT/OP_SkipLT to skip
         ** over all duplicate entries, rather than visiting all duplicates
         ** using OP_Next/OP_Prev. */
         ExprList *pX = pWInfo->pResultSet;
-        Index *pIdx = pLoop->u.btree.pIndex;
         for(j=0; j<pX->nExpr; j++){
           Expr *pE = sqlite3ExprSkipCollate(pX->a[j].pExpr);
           if( pE->op==TK_COLUMN ){
@@ -4880,7 +4881,11 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
           }
         }
       }
-      if( n>0 ){
+      /* TUNING: Only try to skip ahead using OP_Seek if we expect to
+      ** skip over 11 or more rows.  Otherwise, OP_Next is just as fast.
+      */
+      assert( 36==sqlite3LogEst(12) );
+      if( n>0 && pIdx->aiRowLogEst[n]>=36 ){
         for(j=0; j<n; j++){
           sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
         }