]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add new WHERETRACE macros for better diagnostics of the query planner.
authordrh <drh@noemail.net>
Thu, 21 Oct 2010 03:13:58 +0000 (03:13 +0000)
committerdrh <drh@noemail.net>
Thu, 21 Oct 2010 03:13:58 +0000 (03:13 +0000)
Added a new test case for the performance regression fixed by the previous
check-in.

FossilOrigin-Name: 1e0db99797be2821716de7138931ebd5cf8fa63b

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

index 1453abb12e38f0ac5a6808ed84246cfe22edbaa9..a608e3fcb8c8e7c43ed512a22cff19a1184cdffb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Fix\sthe\squery\splanner\sso\sthat\sit\suses\sthe\smulti-index\sOR-clause\ssolution\sif\nthat\sis\sthe\slowest\scost\sestimate.\s\sA\sprior\sbug\scause\sthe\smulti-index\ssolution\nto\sbe\signored\sin\ssome\scircumstances.
-D 2010-10-21T02:05:06
+C Add\snew\sWHERETRACE\smacros\sfor\sbetter\sdiagnostics\sof\sthe\squery\splanner.\nAdded\sa\snew\stest\scase\sfor\sthe\sperformance\sregression\sfixed\sby\sthe\sprevious\ncheck-in.
+D 2010-10-21T03:13:59
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in b01fdfcfecf8a0716c29867a67959f6148b79961
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -240,7 +240,7 @@ F src/vtab.c 6c90e3e65b2f026fc54703a8f3c917155f419d87
 F src/wal.c 0dc7eb9e907a2c280cdcde876d313e07ea4ad811
 F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
-F src/where.c 4ca22dea63424d61680021ebdc9248b4f5797666
+F src/where.c d9a31eb3d59466b6c53567c8c9a6c2fe68bbd565
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
 F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce
@@ -836,7 +836,7 @@ F test/where3.test 3a72db38e8804b210e9f72001ea16830fea74b4b
 F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
 F test/where6.test 5da5a98cec820d488e82708301b96cb8c18a258b
-F test/where7.test a0a92b8ce48d9c027fbdd7b764c7de1e1213575a
+F test/where7.test 221fd05b26be4529647c72ef7de5df646482c675
 F test/where8.test a6c740fd286d7883e274e17b6230a9d672a7ab1f
 F test/where8m.test da346596e19d54f0aba35ebade032a7c47d79739
 F test/where9.test be19e1a92f80985c1a121b4678bf7d2123eaa623
@@ -876,14 +876,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P c0ee614fd988f445c4884a37f494479bdd669185
-R 6e8c0a60de16e5bdb6a605bd3f1b39aa
+P 28ba6255282b1419b8b165e8461018d257b1f6c2
+R 356faab25a033ed6868509f3a1892bd9
 U drh
-Z b859e44913d29246f2a51ec2ec0453b6
+Z 6b64c97bbd923b9a49e2113bdc5fc21f
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFMv5/WoxKgR168RlERAgmkAKCN96esWxQzRMXwPF6yb6e9uTWrlQCfYhIV
-wi7V06O0ntyNXUrzsFmI5dw=
-=a2Wv
+iD8DBQFMv6/7oxKgR168RlERArQqAJsHLWslgz2gwl1++DmjsYaRL73uAgCghxuU
+YoUJK40zLY6RYViwah2V2A4=
+=KADs
 -----END PGP SIGNATURE-----
index c178568b65be923c2a1b3485717d3a59e490ab1e..baf776c133348df34ab89f3ce6c4fd88a2455e4f 100644 (file)
@@ -1 +1 @@
-28ba6255282b1419b8b165e8461018d257b1f6c2
\ No newline at end of file
+1e0db99797be2821716de7138931ebd5cf8fa63b
\ No newline at end of file
index 7b3cfce43d1500418c99078055028b489fc2cfd1..eb0e8ead763855122e3f368e00fecc48fc161dd7 100644 (file)
@@ -4067,6 +4067,7 @@ WhereInfo *sqlite3WhereBegin(
 
     memset(&bestPlan, 0, sizeof(bestPlan));
     bestPlan.rCost = SQLITE_BIG_DBL;
+    WHERETRACE(("*** Begin search for loop %d ***\n", i));
 
     /* Loop through the remaining entries in the FROM clause to find the
     ** next nested loop. The loop tests all FROM clause entries
@@ -4131,6 +4132,8 @@ WhereInfo *sqlite3WhereBegin(
         pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
         if( pTabItem->pIndex==0 ) nUnconstrained++;
   
+        WHERETRACE(("=== trying table %d with isOptimal=%d ===\n",
+                    j, isOptimal));
         assert( pTabItem->pTab );
 #ifndef SQLITE_OMIT_VIRTUALTABLE
         if( IsVirtual(pTabItem->pTab) ){
@@ -4183,8 +4186,9 @@ WhereInfo *sqlite3WhereBegin(
             && (bestJ<0 || sCost.rCost<bestPlan.rCost      /* (4) */
                 || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
         ){
-          WHERETRACE(("... best so far with cost=%g and nRow=%g\n",
-                      sCost.rCost, sCost.nRow));
+          WHERETRACE(("=== table %d is best so far"
+                      " with cost=%g and nRow=%g\n",
+                      j, sCost.rCost, sCost.nRow));
           bestPlan = sCost;
           bestJ = j;
         }
@@ -4193,8 +4197,9 @@ WhereInfo *sqlite3WhereBegin(
     }
     assert( bestJ>=0 );
     assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
-    WHERETRACE(("*** Optimizer selects table %d for loop %d\n", bestJ,
-           pLevel-pWInfo->a));
+    WHERETRACE(("*** Optimizer selects table %d for loop %d"
+                " with cost=%g and nRow=%g\n",
+                bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.nRow));
     if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
       *ppOrderBy = 0;
     }
index dbb9bc6b686f5a64d709e7025cef5955200b1478..07aba9e60d03a9581518730640243f3e3d7f24d9 100644 (file)
@@ -23299,6 +23299,49 @@ do_test where7-2.1001.2 {
          OR a=91
   }
 } {2 22 23 28 54 80 91 scan 0 sort 0}
-finish_test
+
+# test case for the performance regression fixed by
+# check-in 28ba6255282b on 2010-10-21 02:05:06
+#
+# The test case that follows is code from an actual
+# application with identifiers change and unused columns
+# remove.
+#
+do_test where7-3.1 {
+  db eval {
+    CREATE TABLE t301 (
+        c8 INTEGER PRIMARY KEY,
+        c6 INTEGER,
+        c4 INTEGER,
+        c7 INTEGER,
+        FOREIGN KEY (c4) REFERENCES series(c4)
+    );
+    CREATE INDEX t301_c6 on t301(c6);
+    CREATE INDEX t301_c4 on t301(c4);
+    CREATE INDEX t301_c7 on t301(c7);
+    
+    CREATE TABLE t302 (
+        c1 INTEGER PRIMARY KEY,
+        c8 INTEGER,
+        c5 INTEGER,
+        c3 INTEGER,
+        c2 INTEGER,
+        c4 INTEGER,
+        FOREIGN KEY (c8) REFERENCES t301(c8)
+    );
+    CREATE INDEX t302_c3 on t302(c3);
+    CREATE INDEX t302_c8_c3 on t302(c8, c3);
+    CREATE INDEX t302_c5 on t302(c5);
+    
+    EXPLAIN QUERY PLAN
+    SELECT t302.c1 
+      FROM t302 JOIN t301 ON t302.c8 = t301.c8
+      WHERE t302.c2 = 19571
+        AND t302.c3 > 1287603136
+        AND (t301.c4 = 1407449685622784
+             OR t301.c8 = 1407424651264000)
+     ORDER BY t302.c5 LIMIT 200;
+  }
+} {0 1 {TABLE t301 VIA MULTI-INDEX UNION} 1 0 {TABLE t302 WITH INDEX t302_c8_c3} 0 0 {TABLE t301 WITH INDEX t301_c4} 0 0 {TABLE t301 USING PRIMARY KEY}}
 
 finish_test