aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2014-03-10 20:12:31 +0000
committerdrh <drh@noemail.net>2014-03-10 20:12:31 +0000
commit89212fb9f9f0c35bb4725bfc8b85eb96ad751939 (patch)
treea5925c1286c5bb97a6bb40c5ee9716ce8067dce2
parentb06a4ec1f01f6140206374a58a240abdefc9a356 (diff)
downloadsqlite-89212fb9f9f0c35bb4725bfc8b85eb96ad751939.tar.gz
sqlite-89212fb9f9f0c35bb4725bfc8b85eb96ad751939.zip
Adjustments to the cost computation for the skip-scan query plan, to take
into account the fact that a seek has to occur on each skip. FossilOrigin-Name: 0769eebd028ce31375cf93509a1d3687f7b117eb
-rw-r--r--manifest14
-rw-r--r--manifest.uuid2
-rw-r--r--src/where.c3
-rw-r--r--test/skipscan1.test38
4 files changed, 49 insertions, 8 deletions
diff --git a/manifest b/manifest
index f54d726bd..37e199a7c 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Attempt\sto\swork\saround\sMSVC's\streatment\sof\s__LINE__\sas\sa\snon-constant\svalue\nin\s"Edit\sand\sContinue"\smode\sby\savoiding\sthe\suse\sof\s__LINE__\swhen\nSQLITE_VDBE_COVERAGE\sis\snot\sdefined.
-D 2014-03-10T18:03:09.341
+C Adjustments\sto\sthe\scost\scomputation\sfor\sthe\sskip-scan\squery\splan,\sto\stake\ninto\saccount\sthe\sfact\sthat\sa\sseek\shas\sto\soccur\son\seach\sskip.
+D 2014-03-10T20:12:31.746
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -290,7 +290,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 95d30485879122acc5284d4523e01399b23b6148
+F src/where.c bb50b5aed4f9b2284eb92c944253e60df2fb8259
F src/whereInt.h 921f935af8b684ffb49705610bda7284db1db138
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -810,7 +810,7 @@ F test/shell5.test bb755ea9144b8078a752fc56223582627070b5f1
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868
F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329
-F test/skipscan1.test 8c777ffd9dad6ee6d2568160cb2158f0b5cd9dd2
+F test/skipscan1.test bed8cbe9d554c8c27afb6c88500f704c86a9196f
F test/skipscan2.test 5a4db0799c338ddbacb154aaa5589c0254b36a8d
F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24
@@ -1155,7 +1155,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 530a1ee7dc2435f80960ce4710a3c2d2bfaaccc5
-R 760c031eed969eb2e4721ef1a6cbabbc
+P 0a5318bc272b844e937cb1df3a07224034bc3450
+R e70fe0ad6a94758a25d6a041a31ecb69
U drh
-Z a6c38cee4adc797ddcb5e254b94d119b
+Z 344f247bc956540503c85d9ccd8fecb9
diff --git a/manifest.uuid b/manifest.uuid
index b4216cd10..ed97f1ebb 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-0a5318bc272b844e937cb1df3a07224034bc3450 \ No newline at end of file
+0769eebd028ce31375cf93509a1d3687f7b117eb \ No newline at end of file
diff --git a/src/where.c b/src/where.c
index 963878d00..6cd9c167a 100644
--- a/src/where.c
+++ b/src/where.c
@@ -3974,7 +3974,10 @@ static int whereLoopAddBtreeIndex(
pNew->aLTerm[pNew->nLTerm++] = 0;
pNew->wsFlags |= WHERE_SKIPSCAN;
nIter = sqlite3LogEst(pProbe->aiRowEst[0]/pProbe->aiRowEst[saved_nEq+1]);
+ pNew->rRun = rLogSize + nIter;
+ pNew->nOut += nIter;
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter);
+ pNew->nOut = saved_nOut;
}
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
int nIn = 0;
diff --git a/test/skipscan1.test b/test/skipscan1.test
index b9eaf2729..81cbc1dbc 100644
--- a/test/skipscan1.test
+++ b/test/skipscan1.test
@@ -209,4 +209,42 @@ do_execsql_test skipscan1-4.1 {
SELECT i FROM t4 WHERE h=8;
} {9 9 9 9 9 9 9 9}
+# Make sure skip-scan cost computation in the query planner takes into
+# account the fact that the seek must occur multiple times.
+#
+# Prior to 2014-03-10, the costs were computed incorrectly which would
+# cause index t5i2 to be used instead of t5i1 on the skipscan1-5.3.
+#
+do_execsql_test skipscan1-5.1 {
+ CREATE TABLE t5(
+ id INTEGER PRIMARY KEY,
+ loc TEXT,
+ lang INTEGER,
+ utype INTEGER,
+ xa INTEGER,
+ xd INTEGER,
+ xh INTEGER
+ );
+ CREATE INDEX t5i1 on t5(loc, xh, xa, utype, lang);
+ CREATE INDEX t5i2 ON t5(xd,loc,utype,lang);
+ EXPLAIN QUERY PLAN
+ SELECT xh, loc FROM t5 WHERE loc >= 'M' AND loc < 'N';
+} {/.*COVERING INDEX t5i1 .*/}
+do_execsql_test skipscan1-5.2 {
+ ANALYZE;
+ DELETE FROM sqlite_stat1;
+ DROP TABLE IF EXISTS sqlite_stat4;
+ DROP TABLE IF EXISTS sqlite_stat3;
+ INSERT INTO sqlite_stat1 VALUES('t5','t5i1','2702931 3 2 2 2 2');
+ INSERT INTO sqlite_stat1 VALUES('t5','t5i2','2702931 686 2 2 2');
+ ANALYZE sqlite_master;
+} {}
+db cache flush
+do_execsql_test skipscan1-5.3 {
+ EXPLAIN QUERY PLAN
+ SELECT xh, loc FROM t5 WHERE loc >= 'M' AND loc < 'N';
+} {/.*COVERING INDEX t5i1 .*/}
+
+
+
finish_test