-C Import\sfurther\scorner-case\sfixes\sfor\sthe\sin-scan-vs-index\sor\sOP_SeekScan\noptimization\sfrom\strunk.
-D 2020-10-02T13:57:13.021
+C (no\scomment)
+D 2020-10-22T18:58:33.187
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
F src/alter.c d8f927946f25d6a39a344e18db52d1ca492ce561e9b8c4b985fc580bc050bb93
-F src/analyze.c 58db66344a5c58dcabb57f26696f6f2993956c830446da40b444051d2fdaf644
+F src/analyze.c eb5fae655948660f84c270ca4fd553fa482f9e51af8d45ab4653be69819f0fea
F src/attach.c 78e986baee90cb7b83fb9eafa79c22581a8ada14030fd633b0683c95cf11213c
F src/auth.c 0fac71038875693a937e506bceb492c5f136dd7b1249fbd4ae70b4e8da14f9df
F src/backup.c 78d3cecfbe28230a3a9a1793e2ead609f469be43e8f486ca996006be551857ab
F src/sqlite.h.in 59f5e145b8d7a915ca29c6bf4a1f00e3112c1605c9ac5c627c45060110332ba2
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5
-F src/sqliteInt.h 34fb4aa27d7f172805a8be51a826bafe05138ea604329bb91886516c4ca6e6b7
+F src/sqliteInt.h e19d89d6a1c24cded45b39f4bd9249c0222ded77681576675f91f035aca769c6
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
F src/wal.c 9eccc7ebb532a7b0fd3cabc16cff576b9afa763472272db67d84fb8cec96f5c0
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
F src/walker.c 7607f1a68130c028255d8d56094ea602fc402c79e1e35a46e6282849d90d5fe4
-F src/where.c 9030f0f4d674d9099932ed7913eb1f8ddd58acc6cfea893deec7efa76fc44d13
+F src/where.c d0feda2eb597cba0a1de3fd2a69e4c46fb641257b076602fbd3b289700854efd
F src/whereInt.h bcbba483d0cd72c17ab9af97061dce3c00eb3695cd17a5d41cdfec2cb5a6e8ce
F src/wherecode.c 5e0b6dec8591e13f1f0af828d350e4a5dd2e3518b63d328f21bb38e2456dfeb7
F src/whereexpr.c 90859652920f153d2c03f075488744be2926625ebd36911bcbcb17d0d29c891c
F test/skipscan1.test b1fef3046d555836712d4a3a7c8ae8193356c6a15bee59cb3976e4ee98596c97
F test/skipscan2.test 3eb703ce794f139e7b83567911046298bcde29606116727f9b700ce34f559d2d
F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5
-F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2
+F test/skipscan5.test 980875ad45d8aacfe7bdec7c288343520cd1d14e84befdcfe50c785f9e6c8709
F test/skipscan6.test 0b4cd1b4ac9f84d91454df513c99a4932fa07e8f27b8049bea605068b3e34ac7
F test/snapshot.test a504f2e7009f512ef66c719f0ea1c55a556bdaf1e1312c80a04d46fc1a3e9632
F test/snapshot2.test 8d6ff5dd9cc503f6e12d408a30409c3f9c653507b24408d9cd7195931c89bc54
F test/whereD.test 711d4df58d6d4fb9b3f5ce040b818564198be002
F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f
F test/whereF.test 3d9412b1199d3e2bed34fcb76b4c48d0bf4df95d27e3f8dd27b6f8b4716d0d89
-F test/whereG.test 0158783235a6dd82fc0e37652b8522b186b9510594ac0a4bff0c4101b4396a52
+F test/whereG.test 3ceb63370bf96d0ebc8b5589b5efbaab6506bea86ad7b481a2ecf241378ed9a1
F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2
F test/whereI.test a2874062140ed4aba9ffae76e6190a3df6fc73d1373fdfa8fd632945082a5364
F test/whereJ.test 88287550f6ee604422403b053455b1ad894eeaa5c35d348532dfa1439286cb9a
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P ec37744c6ea61f94bb850875f9ac86e80ac0c111bc5a2c2eb2050897ec1e63cd
-Q +ad5ab24ebd557e7af1d92ab3fbcb3747c04da5ad4ed779fb6391dc94042687dd
-Q +c0400f8c0bcb85ba39004feff753eae2f8e82065539e52b5788febd7644c417b
-R ed40b319cb8ff5e5e2a58c08d4ee2c80
+P c144d6404ff122d6a92d59fed09fab9a0a592e4dab771ef41b0db3535359f1d6
+Q +0e7e113d9f2c929c1f8a85e2cfad8e2e60f0e8770212b5e5320fb2a2c42911f8
+R 4ca1a3da910bf98bc6e4950d0ce095f1
U drh
-Z 61ad1955920a3fa1588d272c2f0c8015
+Z 0bf840746e1be7de2c0bb7a051dce63e
-c144d6404ff122d6a92d59fed09fab9a0a592e4dab771ef41b0db3535359f1d6
\ No newline at end of file
+263293f1e6db26039d94c9ed7efa2cdea25df5e5f42673a116ce2d03b9fadff4
\ No newline at end of file
}
pSpace = (tRowcnt*)&pIdx->aSample[nSample];
pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
+ pIdx->pTable->tabFlags |= TF_HasStat4;
for(i=0; i<nSample; i++){
pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
pIdx->aSample[i].anLt = pSpace; pSpace += nIdxCol;
** Index.aiRowLogEst[] values */
#define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */
#define TF_Shadow 0x0400 /* True for a shadow table */
+#define TF_HasStat4 0x2000 /* STAT4 info available for this table */
/*
** Test to see whether or not a table is a virtual table. This is
/* Full table scan */
pNew->iSortIdx = b ? iSortIdx : 0;
- /* TUNING: Cost of full table scan is (N*3.0). */
+ /* TUNING: Cost of full table scan is 3.0*N. The 3.0 factor is an
+ ** extra cost designed to discourage the use of full table scans,
+ ** since index lookups have better worst-case performance if our
+ ** stat guesses are wrong. Reduce the 3.0 penalty slightly
+ ** (to 2.75) if we have valid STAT4 information for the table.
+ ** At 2.75, a full table scan is preferred over using an index on
+ ** a column with just two distinct values where each value has about
+ ** an equal number of appearances. Without STAT4 data, we still want
+ ** to use an index in that case, since the constraint might be for
+ ** the scarcer of the two values, and in that case an index lookup is
+ ** better.
+ */
+#ifdef SQLITE_ENABLE_STAT4
+ pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
+#else
pNew->rRun = rSize + 16;
+#endif
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
whereLoopOutputAdjust(pWC, pNew, rSize);
rc = whereLoopInsert(pBuilder, pNew);
expr srand(4)
do_test 1.2 {
- for {set i 0} {$i < 100} {incr i} {
+ for {set i 0} {$i < 1000} {incr i} {
set a [expr int(rand()*4.0) + 1]
set b [expr int(rand()*20.0) + 1]
execsql { INSERT INTO t1 VALUES($a, $b, NULL) }
2 "b > 12 AND b < 16" {/*ANY(a) AND b>? AND b<?*/}
3 "b > 2 AND b < 16" {/*SCAN TABLE t1*/}
4 "b > 18 AND b < 25" {/*ANY(a) AND b>? AND b<?*/}
- 5 "b > 15" {/*ANY(a) AND b>?*/}
+ 5 "b > 16" {/*ANY(a) AND b>?*/}
6 "b > 5" {/*SCAN TABLE t1*/}
7 "b < 15" {/*SCAN TABLE t1*/}
8 "b < 5" {/*ANY(a) AND b<?*/}
11 "b > '12' AND b < '16'" {/*ANY(a) AND b>? AND b<?*/}
12 "b > '2' AND b < '16'" {/*SCAN TABLE t1*/}
13 "b > '18' AND b < '25'" {/*ANY(a) AND b>? AND b<?*/}
- 14 "b > '15'" {/*ANY(a) AND b>?*/}
+ 14 "b > '16'" {/*ANY(a) AND b>?*/}
15 "b > '5'" {/*SCAN TABLE t1*/}
16 "b < '15'" {/*SCAN TABLE t1*/}
17 "b < '5'" {/*ANY(a) AND b<?*/}
3 { c > 'q' } {/*ANY(a) AND ANY(b) AND c>?*/}
4 { c > 'e' } {/*SCAN TABLE t2*/}
5 { c < 'q' } {/*SCAN TABLE t2*/}
- 6 { c < 'c' } {/*ANY(a) AND ANY(b) AND c<?*/}
+ 6 { c < 'b' } {/*ANY(a) AND ANY(b) AND c<?*/}
} {
set sql "EXPLAIN QUERY PLAN SELECT * FROM t2 WHERE $q"
do_execsql_test 2.$tn.$tn2 $sql $res
SELECT * FROM t1 WHERE likely(b>?)
} {SCAN TABLE t1}
-do_eqp_test 5.3.1 {
- SELECT * FROM t1 WHERE a=?
-} {SEARCH TABLE t1 USING INDEX i1 (a=?)}
+ifcapable stat4 {
+ do_eqp_test 5.3.1.stat4 {
+ SELECT * FROM t1 WHERE a=?
+ } {SCAN TABLE t1}
+} else {
+ do_eqp_test 5.3.1 {
+ SELECT * FROM t1 WHERE a=?
+ } {SEARCH TABLE t1 USING INDEX i1}
+}
do_eqp_test 5.3.2 {
SELECT * FROM t1 WHERE likelihood(a=?, 0.9)
} {SCAN TABLE t1}