]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Increase the estimated cost of using a virtual table as the outer loop of a join...
authordan <dan@noemail.net>
Sat, 27 Mar 2010 09:44:42 +0000 (09:44 +0000)
committerdan <dan@noemail.net>
Sat, 27 Mar 2010 09:44:42 +0000 (09:44 +0000)
FossilOrigin-Name: 9e075e70f0e2a1ad302d17150cd58f91669a97a6

manifest
manifest.uuid
src/where.c
test/fts3query.test

index d55c804f68624bfa98dcadacb97233d4491a0002..233eb87ec31b43f029f524d7396f1f5686335517 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sOOM\serror\son\sANALYZE\swith\sSTAT2\senabled\swith\szero-length\sdata.\sTicket\s[cbd054fa6b].
-D 2010-03-26T01:54:33
+C Increase\sthe\sestimated\scost\sof\susing\sa\svirtual\stable\sas\sthe\souter\sloop\sof\sa\sjoin\swhen\sthere\sexists\san\sORDER\sBY\sclause\sthat\sis\snot\ssatisfied\sby\sthe\svirtual\stable.\sFix\sfor\s[775b39dd3c].
+D 2010-03-27T09:44:42
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -221,7 +221,7 @@ F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c 606adf51cd6d4ba51a8c6dccede06a6f7b0dd72d
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
-F src/where.c 399ea4c090284c9d16f76d685b9b44e8b9b4442b
+F src/where.c 71ef4e89715740f7af49e6f15a3fd987e040800a
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
 F test/all.test 14165b3e32715b700b5f0cbf8f6e3833dda0be45
@@ -408,7 +408,7 @@ F test/fts3expr.test 5e745b2b6348499d9ef8d59015de3182072c564c
 F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a
 F test/fts3malloc.test 059592c4f37ccd30138bbf8e3e5b7982cb5c8f2e
 F test/fts3near.test 2e318ee434d32babd27c167142e2b94ddbab4844
-F test/fts3query.test 154fe4b015fd61af523ee083570a134f508f5be7
+F test/fts3query.test 1acb21b58d6aa7504e990f0f589be85e9a133969
 F test/fts3rnd.test 2f5761db9dd92f6fe09d08976ac658ef521846ed
 F test/fts3snippet.test 9f9a4a7e396c5d8ce2898be65ebabc429555430f
 F test/fts4aa.test eadf85621c0a113d4c7ad3ccbf8441130e007b8f
@@ -794,7 +794,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P d37034f7fc46b83be681247fde97823736c994cc
-R f632179d00144c3248d5550420baa55a
-U shaneh
-Z 000ac439cfaa4b57f906b494905bfe51
+P c33b38b59f733494ca0bce3f59a669fe7ed76b9f
+R 1048b4f005b8cf985bff319e6cd284fa
+U dan
+Z 25a9f1889e9ba9dd674533c69390c60b
index 6a94a709b400b09cb360c3f0418efdd1da1bff48..cefdd79cc524fb8f1fc4d871878125a95dace220 100644 (file)
@@ -1 +1 @@
-c33b38b59f733494ca0bce3f59a669fe7ed76b9f
\ No newline at end of file
+9e075e70f0e2a1ad302d17150cd58f91669a97a6
\ No newline at end of file
index 5f81ce07686754dbdc4e90bb16576342f51cdd9e..3ed7d3d8e055a583c6888e66bb70df2b08e45573 100644 (file)
@@ -1819,6 +1819,7 @@ static void bestVirtualIndex(
   WhereTerm *pTerm;
   int i, j;
   int nOrderBy;
+  double rCost;
 
   /* Make sure wsFlags is initialized to some sane value. Otherwise, if the 
   ** malloc in allocateIndexInfo() fails and this function returns leaving
@@ -1905,6 +1906,15 @@ static void bestVirtualIndex(
     }
   }
 
+  /* If there is an ORDER BY clause, and the selected virtual table index
+  ** does not satisfy it, increase the cost of the scan accordingly. This
+  ** matches the processing for non-virtual tables in bestBtreeIndex().
+  */
+  rCost = pIdxInfo->estimatedCost;
+  if( pOrderBy && pIdxInfo->orderByConsumed==0 ){
+    rCost += estLog(rCost)*rCost;
+  }
+
   /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
   ** inital value of lowestCost in this loop. If it is, then the
   ** (cost<lowestCost) test below will never be true.
@@ -1912,10 +1922,10 @@ static void bestVirtualIndex(
   ** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT 
   ** is defined.
   */
-  if( (SQLITE_BIG_DBL/((double)2))<pIdxInfo->estimatedCost ){
+  if( (SQLITE_BIG_DBL/((double)2))<rCost ){
     pCost->rCost = (SQLITE_BIG_DBL/((double)2));
   }else{
-    pCost->rCost = pIdxInfo->estimatedCost;
+    pCost->rCost = rCost;
   }
   pCost->plan.u.pVtabIdx = pIdxInfo;
   if( pIdxInfo->orderByConsumed ){
index b5af50a7ab108610a5c2083be36caa2ca7635ebc..3a94ee9e792312323ca65000d9289a5c75026d6d 100644 (file)
@@ -101,5 +101,33 @@ do_test fts3query-3.3 {
   execsql { SELECT mit(matchinfo(foobar)) FROM foobar WHERE foobar MATCH 'the' }
 } {{1 1 3 3 1}}
 
+# The following tests check that ticket 775b39dd3c has been fixed.
+#
+proc eqp {sql} {
+  uplevel [list execsql "EXPLAIN QUERY PLAN $sql"]
+}
+do_test fts3query-4.1 {
+  execsql {
+    DROP TABLE IF EXISTS t1;
+    CREATE TABLE t1(number INTEGER PRIMARY KEY, date);
+    CREATE INDEX i1 ON t1(date);
+    CREATE VIRTUAL TABLE ft USING fts3(title);
+    CREATE TABLE bt(title);
+  }
+} {}
+do_test fts3query-4.2 {
+  eqp "SELECT t1.number FROM t1, ft WHERE t1.number=ft.rowid ORDER BY t1.date"
+} {0 0 {TABLE t1 WITH INDEX i1 ORDER BY} 1 1 {TABLE ft VIRTUAL TABLE INDEX 1:}}
+do_test fts3query-4.3 {
+  eqp "SELECT t1.number FROM ft, t1 WHERE t1.number=ft.rowid ORDER BY t1.date"
+} {0 1 {TABLE t1 WITH INDEX i1 ORDER BY} 1 0 {TABLE ft VIRTUAL TABLE INDEX 1:}}
+do_test fts3query-4.4 {
+  eqp "SELECT t1.number FROM t1, bt WHERE t1.number=bt.rowid ORDER BY t1.date"
+} {0 0 {TABLE t1 WITH INDEX i1 ORDER BY} 1 1 {TABLE bt USING PRIMARY KEY}}
+do_test fts3query-4.5 {
+  eqp "SELECT t1.number FROM bt, t1 WHERE t1.number=bt.rowid ORDER BY t1.date"
+} {0 1 {TABLE t1 WITH INDEX i1 ORDER BY} 1 0 {TABLE bt USING PRIMARY KEY}}
+
+
 finish_test