From: drh Date: Wed, 3 Aug 2011 01:07:25 +0000 (+0000) Subject: Adjust the output row estimating logic when using STAT2. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4cd32c4e390024f3ec5f8c1643e1a4e2711f08e2;p=thirdparty%2Fsqlite.git Adjust the output row estimating logic when using STAT2. FossilOrigin-Name: c8ba8855d8e93cd1e7dbbc9398a5f850fed5a382 --- diff --git a/manifest b/manifest index 1ed597e14c..c1ecf5c6a5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Exclude\sthe\s8_3_names.test\sscript\sfrom\sthe\sinmemory_journal\spermutation. -D 2011-08-02T20:14:55.667 +C Adjust\sthe\soutput\srow\sestimating\slogic\swhen\susing\sSTAT2. +D 2011-08-03T01:07:25.236 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1e6988b3c11dee9bd5edc0c804bd4468d74a9cdc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -183,7 +183,7 @@ F src/select.c d219c4b68d603cc734b6f9b1e2780fee12a1fa0d F src/shell.c bbe7818ff5bc8614105ceb81ad67b8bdc0b671dd F src/sqlite.h.in 0b3cab7b2ea51f58396e8871fa5f349cfece5330 F src/sqlite3ext.h 1a1a4f784aa9c3b00edd287940197de52487cd93 -F src/sqliteInt.h ba4a6d6288efb25b84bc0d7d0aaf80f9b42523ba +F src/sqliteInt.h 8a7ca32a1563d25629073c3be8d0e3560d46e2fa F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac64842c86cec2fc1a1d0e5c16d3beb8ad332bf F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -250,7 +250,7 @@ F src/vtab.c 901791a47318c0562cd0c676a2c6ff1bc530e582 F src/wal.c 3154756177d6219e233d84291d5b05f4e06ff5e9 F src/wal.h 66b40bd91bc29a5be1c88ddd1f5ade8f3f48728a F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f -F src/where.c 7d09f4c1512affb60cc1190a4b33d121d4ce039a +F src/where.c e169242225ff4742da34e7d8a20243adbf4664e5 F test/8_3_names.test b93687beebd17f6ebf812405a6833bae5d1f4199 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 @@ -264,9 +264,9 @@ F test/analyze.test c8cb89e8736336f1f0646c8123e6028a14c7b55e F test/analyze2.test 8f2b1534d43f5547ce9a6b736c021d4192c75be3 F test/analyze3.test d61f55d8b472fc6e713160b1e577f7a68e63f38b F test/analyze4.test 757b37875cf9bb528d46f74497bc789c88365045 -F test/analyze5.test 1de8d66b11aae5a1453aa042d62e834a476bac9c +F test/analyze5.test f6c250012b173f9b10ae5d577e9592767b376b1c F test/analyze6.test c125622a813325bba1b4999040ddc213773c2290 -F test/analyze7.test 5508e7828164ea0b518ed219bed7320a481863d4 +F test/analyze7.test ed672a2c09c4b5a5b528ca38951318af463bb17e F test/async.test ad4ba51b77cd118911a3fe1356b0809da9c108c3 F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6 F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e @@ -954,7 +954,10 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings.sh 2ebae31e1eb352696f3c2f7706a34c084b28c262 -P 861a5b62430d0ada07a46d0e394fcf0b0faab1cd -R 0ac986e6982ac12d722abe7bcb3da618 +P 78fc94c8d1229a8bdc9390e98b53c57aeef7fc46 +R 274804d4319047cf711d8a55ade8888e +T *branch * query-planner-tweaks +T *sym-query-planner-tweaks * +T -sym-trunk * U drh -Z 3a732f4c9d85bdfbca1dba2584684292 +Z 278da4b2a2802cf77ca6054afa34f6c4 diff --git a/manifest.uuid b/manifest.uuid index 9e9af6b5d0..e60dc911be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -78fc94c8d1229a8bdc9390e98b53c57aeef7fc46 \ No newline at end of file +c8ba8855d8e93cd1e7dbbc9398a5f850fed5a382 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index bcf6a591af..9d1c07f0a9 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -81,7 +81,9 @@ ** construct a histogram of the table content when running ANALYZE ** and with SQLITE_ENABLE_STAT2 */ -#define SQLITE_INDEX_SAMPLES 10 +#ifndef SQLITE_INDEX_SAMPLES +# define SQLITE_INDEX_SAMPLES 10 +#endif /* ** The following macros are used to cast pointers to integers and diff --git a/src/where.c b/src/where.c index 21fb7f45f4..1f7b709d86 100644 --- a/src/where.c +++ b/src/where.c @@ -2732,7 +2732,7 @@ static int whereEqualScanEst( if( rc ) goto whereEqualScanEst_cancel; WHERETRACE(("equality scan regions: %d..%d\n", iLower, iUpper)); if( iLower>=iUpper ){ - nRowEst = p->aiRowEst[0]/(SQLITE_INDEX_SAMPLES*2); + nRowEst = p->aiRowEst[0]/(SQLITE_INDEX_SAMPLES*3); if( nRowEst<*pnRow ) *pnRow = nRowEst; }else{ nRowEst = (iUpper-iLower)*p->aiRowEst[0]/SQLITE_INDEX_SAMPLES; @@ -2811,7 +2811,7 @@ static int whereInScanEst( nSingle++; } } - nRowEst = (nSpan*2+nSingle)*p->aiRowEst[0]/(2*SQLITE_INDEX_SAMPLES) + nRowEst = (nSpan*3+nSingle)*p->aiRowEst[0]/(3*SQLITE_INDEX_SAMPLES) + nNotFound*p->aiRowEst[1]; if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0]; *pnRow = nRowEst; diff --git a/test/analyze5.test b/test/analyze5.test index a0469da125..e1720341e7 100644 --- a/test/analyze5.test +++ b/test/analyze5.test @@ -128,28 +128,28 @@ foreach {testid where index rows} { 51 {z>=-100 AND z<=2.0} t1z 900 52 {z>=-100 AND z<3.0} t1z 900 - 101 {z=-1} t1z 50 + 101 {z=-1} t1z 33 102 {z=0} t1z 400 103 {z=1} t1z 300 104 {z=2} t1z 200 105 {z=3} t1z 100 - 106 {z=4} t1z 50 - 107 {z=-10.0} t1z 50 + 106 {z=4} t1z 33 + 107 {z=-10.0} t1z 33 108 {z=0.0} t1z 400 109 {z=1.0} t1z 300 110 {z=2.0} t1z 200 111 {z=3.0} t1z 100 - 112 {z=4.0} t1z 50 - 113 {z=1.5} t1z 50 - 114 {z=2.5} t1z 50 + 112 {z=4.0} t1z 33 + 113 {z=1.5} t1z 33 + 114 {z=2.5} t1z 33 - 201 {z IN (-1)} t1z 50 + 201 {z IN (-1)} t1z 33 202 {z IN (0)} t1z 400 203 {z IN (1)} t1z 300 204 {z IN (2)} t1z 200 205 {z IN (3)} t1z 100 - 206 {z IN (4)} t1z 50 - 207 {z IN (0.5)} t1z 50 + 206 {z IN (4)} t1z 33 + 207 {z IN (0.5)} t1z 33 208 {z IN (0,1)} t1z 700 209 {z IN (0,1,2)} t1z 900 210 {z IN (0,1,2,3)} {} 100 @@ -157,12 +157,12 @@ foreach {testid where index rows} { 212 {z IN (1,2)} t1z 500 213 {z IN (2,3)} t1z 300 214 {z=3 OR z=2} t1z 300 - 215 {z IN (-1,3)} t1z 150 - 216 {z=-1 OR z=3} t1z 150 + 215 {z IN (-1,3)} t1z 133 + 216 {z=-1 OR z=3} t1z 133 300 {y=0} {} 100 - 301 {y=1} t1y 50 - 302 {y=0.1} t1y 50 + 301 {y=1} t1y 33 + 302 {y=0.1} t1y 33 400 {x IS NULL} t1x 400 @@ -205,9 +205,9 @@ db eval { # foreach {testid where index rows} { 500 {x IS NULL AND u='charlie'} t1u 20 - 501 {x=1 AND u='charlie'} t1x 5 + 501 {x=1 AND u='charlie'} t1x 3 502 {x IS NULL} {} 100 - 503 {x=1} t1x 50 + 503 {x=1} t1x 33 504 {x IS NOT NULL} t1x 25 505 {+x IS NOT NULL} {} 500 506 {upper(x) IS NOT NULL} {} 500 diff --git a/test/analyze7.test b/test/analyze7.test index 4892a2233a..4fd76285bf 100644 --- a/test/analyze7.test +++ b/test/analyze7.test @@ -99,8 +99,10 @@ do_test analyze7-3.3 { execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND b=123} } {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}} do_test analyze7-3.4 { - execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND b=123} -} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~2 rows)}} + set x [execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND b=123}] + regsub -all {[bcd]+} $x {x} x + set x +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1x (x=?) (~2 rows)}} do_test analyze7-3.5 { execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND c=123} } {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}