]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the OR-clause optimizer takes the cost of sorting into account.
authordrh <drh@noemail.net>
Wed, 14 Jan 2009 00:55:09 +0000 (00:55 +0000)
committerdrh <drh@noemail.net>
Wed, 14 Jan 2009 00:55:09 +0000 (00:55 +0000)
Reset the rowid cache on the OP_Rewind and OP_Last opcodes.  Bump the
version number so that we can do an emergency release.  Ticket #3581. (CVS 6173)

FossilOrigin-Name: d28b58209bf5eb575d0cad8dc71ac043395c6471

VERSION
manifest
manifest.uuid
src/vdbe.c
src/where.c
test/where7.test

diff --git a/VERSION b/VERSION
index 424e1794de6cdada03ccf70036a2c2646669f291..cff2619cfb9409b0f202973810ccc91fc1c25fc5 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.6.8
+3.6.9
index 03aff07c68d0894edc4981e299455f81ac90a755..e9fbda48dbdefe8be48ef5572d0478038c111dca 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,11 +1,11 @@
-C Updates\sto\scomments\sas\ssuggested\sby\stickets\s#3578\sand\s#3579.\s(CVS\s6172)
-D 2009-01-13T20:14:16
+C Make\ssure\sthe\sOR-clause\soptimizer\stakes\sthe\scost\sof\ssorting\sinto\saccount.\nReset\sthe\srowid\scache\son\sthe\sOP_Rewind\sand\sOP_Last\sopcodes.\s\sBump\sthe\nversion\snumber\sso\sthat\swe\scan\sdo\san\semergency\srelease.\s\sTicket\s#3581.\s(CVS\s6173)
+D 2009-01-14T00:55:10
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 05461a9b5803d5ad10c79f989801e9fd2cc3e592
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
 F Makefile.vxwSH4 d53b4be86491060d498b22148951b6d765884cab
 F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
-F VERSION 6a08811e265335dd6353db7fc3e65ccec7e54eb1
+F VERSION 081a767ef589d53640175c43d6d42b26a3a5a3f8
 F aclocal.m4 7d02b11fed45174e11156144227278deb6236eea
 F addopcodes.awk 215333be9d99c260e076c3080a81dba3ae928c45
 F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
@@ -198,7 +198,7 @@ F src/update.c 8c4925f9ca664effc8a1faaad67449d2074567b1
 F src/utf.c 1da9c832dba0fa8f865b5b902d93f420a1ee4245
 F src/util.c 7b1e3987e1ae6b3aa773b0eb1b7391b1f72569d2
 F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9
-F src/vdbe.c 4e9b83e758a43882a29fe5cde479acb1db04f7dd
+F src/vdbe.c b917020da4c14c3ea6032cc288462f4ba525ade7
 F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6
 F src/vdbeInt.h 5530e45fc64c1572f123aca384096e1b84cf834b
 F src/vdbeapi.c 85c33cfbfa56249cbe627831610afafba754477d
@@ -207,7 +207,7 @@ F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
 F src/vdbemem.c 19f94b504d3da44b31aef200fa6c8e07862de2e8
 F src/vtab.c e39e011d7443a8d574b1b9cde207a35522e6df43
 F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
-F src/where.c bd4fef1701c0b032a273c230400873a7db341338
+F src/where.c e9a37defa7c0cf413a096991d6ff4ea3fc25381a
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
@@ -662,7 +662,7 @@ F test/where3.test 97d3936e6a443b968f1a61cdcc0f673252000e94
 F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
 F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf
-F test/where7.test 88eb7c53bdbd900cfd130e8f40bb3036bfab031d
+F test/where7.test 2487cda68faabf5edeb524289913f00f8d64e223
 F test/where8.test 1b9152a086408ee789166d0a954abc597372f868
 F test/where8m.test c1010d61826412ff66abd29bfb32e5d6b37d965c
 F test/where9.test a46d394037a40b56e7855d29cce951f91108c353
@@ -696,7 +696,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 36fe9a7a51b5279f1a3964139aa636e81f9c8b06
-R b541b7fe0404ff776b91c0f6aaf1ae26
+P b5927213b6171e57018f1f265940c9bcc7a0ba04
+R 5756dc3cd885a7776d15af4f4a23753a
 U drh
-Z 09eabc86e977812e7a4384766d6d56c9
+Z 63ab172d3002b8551771471f762541d8
index bd02260cd79728a0432b3bc2dc38ec2d79d94849..256227f4e693f69506caf26081b8b122873b2179 100644 (file)
@@ -1 +1 @@
-b5927213b6171e57018f1f265940c9bcc7a0ba04
\ No newline at end of file
+d28b58209bf5eb575d0cad8dc71ac043395c6471
\ No newline at end of file
index 18f40b13a097821e43cf67879ecca438671a230b..60ce2d094551ff9ce35629f332f52e81498b7b96 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.810 2009/01/05 22:30:39 drh Exp $
+** $Id: vdbe.c,v 1.811 2009/01/14 00:55:10 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -3908,6 +3908,7 @@ case OP_Last: {        /* jump */
   rc = sqlite3BtreeLast(pCrsr, &res);
   pC->nullRow = (u8)res;
   pC->deferredMoveto = 0;
+  pC->rowidIsValid = 0;
   pC->cacheStatus = CACHE_STALE;
   if( res && pOp->p2>0 ){
     pc = pOp->p2 - 1;
@@ -3958,6 +3959,7 @@ case OP_Rewind: {        /* jump */
     pC->atFirst = res==0 ?1:0;
     pC->deferredMoveto = 0;
     pC->cacheStatus = CACHE_STALE;
+    pC->rowidIsValid = 0;
   }else{
     res = 1;
   }
index 85978d2d994cab175087034ec7764b1446127381..9f96de28134ae67a9726db2d1a1fe303863d25b6 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.363 2009/01/10 15:34:12 drh Exp $
+** $Id: where.c,v 1.364 2009/01/14 00:55:10 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1846,6 +1846,7 @@ static void bestIndex(
       WhereClause *pOrWC = &pTerm->u.pOrInfo->wc;
       WhereTerm *pOrTerm;
       int j;
+      int sortable = 0;
       double rTotal = 0;
       nRow = 0;
       for(j=0, pOrTerm=pOrWC->a; j<pOrWC->nTerm; j++, pOrTerm++){
@@ -1865,6 +1866,14 @@ static void bestIndex(
         nRow += sTermCost.nRow;
         if( rTotal>=pCost->rCost ) break;
       }
+      if( pOrderBy!=0 ){
+        if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) && !rev ){
+          sortable = 1;
+        }else{
+          rTotal += nRow*estLog(nRow);
+          WHERETRACE(("... sorting increases OR cost to %.9g\n", rTotal));
+        }
+      }
       WHERETRACE(("... multi-index OR cost=%.9g nrow=%.9g\n",
                   rTotal, nRow));
       if( rTotal<pCost->rCost ){
@@ -1872,10 +1881,7 @@ static void bestIndex(
         pCost->nRow = nRow;
         pCost->plan.wsFlags = WHERE_MULTI_OR;
         pCost->plan.u.pTerm = pTerm;
-        if( pOrderBy!=0
-         && sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)
-         && !rev
-        ){
+        if( sortable ){
           pCost->plan.wsFlags = WHERE_ORDERBY|WHERE_MULTI_OR;
         }
       }
index 8690322fd5ba5396d785104ea1eee6decb1710c8..2a1dd2fa18ea4ec334436fe982bcac6741df38c5 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the multi-index OR clause optimizer.
 #
-# $Id: where7.test,v 1.6 2008/12/30 17:55:00 drh Exp $
+# $Id: where7.test,v 1.7 2009/01/14 00:55:10 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -99,11 +99,17 @@ do_test where7-1.12 {
     SELECT a FROM t1 WHERE (b BETWEEN 2 AND 4) OR c=100 ORDER BY a
   }
 } {1 2 3 5 scan 0 sort 0}
-do_test where7-1.13 {
+do_test where7-1.13.1 {
   count_steps {
     SELECT a FROM t1 WHERE (b BETWEEN 0 AND 2) OR (c BETWEEN 9 AND 999)
     ORDER BY a DESC
   }
+} {5 4 1 scan 4 sort 0}
+do_test where7-1.13.2 {
+  count_steps {
+    SELECT a FROM t1 WHERE (b BETWEEN 0 AND 2) OR (c BETWEEN 9 AND 999)
+    ORDER BY +a DESC
+  }
 } {5 4 1 scan 0 sort 1}
 
 do_test where7-1.14 {