From: drh Date: Fri, 1 Apr 2011 14:04:36 +0000 (+0000) Subject: Test cases for ANALYZE-index. X-Git-Tag: version-3.7.6~67^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=be28a9b07233e5a0ad259fb279ec0dbb46a45545;p=thirdparty%2Fsqlite.git Test cases for ANALYZE-index. FossilOrigin-Name: 365896cb0868fa476e3b4f5a965a1344a2914cc2 --- diff --git a/manifest b/manifest index 9223615437..814dad6c8b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sANALYZE\scommand\sso\sthat\sit\swill\saccept\san\sindex\sname\sas\sits\nargument\sand\sonly\sreanalyze\sthat\sone\sindex.\s\sA\squick\ssmoke-test\sworks.\nNeed\sto\sstudy\sthe\simplications\sto\sthe\squery\splanner\sand\stest\scorner\scases. -D 2011-03-31T02:03:28.435 +C Test\scases\sfor\sANALYZE-index. +D 2011-04-01T14:04:36.013 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -259,6 +259,7 @@ F test/analyze3.test d61f55d8b472fc6e713160b1e577f7a68e63f38b F test/analyze4.test 757b37875cf9bb528d46f74497bc789c88365045 F test/analyze5.test adc89b92fc9fee5ca1cb0bc8512f3206ad0fe5aa F test/analyze6.test c125622a813325bba1b4999040ddc213773c2290 +F test/analyze7.test 06405dd3d2a3101de14270da508016a59254873b F test/async.test ad4ba51b77cd118911a3fe1356b0809da9c108c3 F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6 F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e @@ -920,11 +921,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P a84f7711949ea3885b0e36e48118d2c76a8a5b82 -R 2733d2c2848c13b668e60a30cb1bc35d -T *bgcolor * #ab8eb2 -T *branch * analyze-idx -T *sym-analyze-idx * -T -sym-trunk * +P c8f9edd962442cbdd848c48f1a134557ab8c6ef5 +R 1095a96b12af8399e13f3de1ef24664d U drh -Z 6f592daac956cab070466c419bbb51de +Z a7b9c4ff9eb44077c37bf72bf0e8f05e diff --git a/manifest.uuid b/manifest.uuid index 0b6dd511e9..e7c4683363 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c8f9edd962442cbdd848c48f1a134557ab8c6ef5 \ No newline at end of file +365896cb0868fa476e3b4f5a965a1344a2914cc2 \ No newline at end of file diff --git a/test/analyze7.test b/test/analyze7.test new file mode 100644 index 0000000000..4c2fd53e85 --- /dev/null +++ b/test/analyze7.test @@ -0,0 +1,106 @@ +# 2011 April 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# This file implements tests for the ANALYZE command when an idnex +# name is given as the argument. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There is nothing to test if ANALYZE is disable for this build. +# +ifcapable {!analyze} { + finish_test + return +} + +# Generate some test data +# +do_test analyze7-1.0 { + execsql { + CREATE TABLE sequence(x INTEGER PRIMARY KEY); + INSERT INTO sequence VALUES(1); + INSERT INTO sequence VALUES(2); + INSERT INTO sequence SELECT x+2 FROM sequence; + INSERT INTO sequence SELECT x+4 FROM sequence; + INSERT INTO sequence SELECT x+8 FROM sequence; + INSERT INTO sequence SELECT x+16 FROM sequence; + INSERT INTO sequence SELECT x+32 FROM sequence; + INSERT INTO sequence SELECT x+64 FROM sequence; + INSERT INTO sequence SELECT x+128 FROM sequence; + INSERT INTO sequence SELECT x+256 FROM sequence; + CREATE TABLE t1(a,b,c,d); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + CREATE INDEX t1cd ON t1(c,d); + INSERT INTO t1 SELECT x, x, x/100, x FROM sequence; + EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123; + } +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~10 rows)}} +do_test analyze7-1.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~10 rows)}} +do_test analyze7-1.2 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~10 rows)}} + +# Run an analyze on one of the three indices. Verify that this +# effects the row-count estimate on the one query that uses that +# one index. +# +do_test analyze7-2.0 { + execsql {ANALYZE t1a;} + db cache flush + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}} +do_test analyze7-2.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~10 rows)}} +do_test analyze7-2.2 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~10 rows)}} + +# Verify that since the query planner now things that t1a is more +# selective than t1b, it prefers to use t1a. +# +do_test analyze7-2.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)}} + +# Run an analysis on another of the three indices. Verify that this +# new analysis works and does not disrupt the previous analysis. +# +do_test analyze7-3.0 { + execsql {ANALYZE t1cd;} + db cache flush; + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}} +do_test analyze7-3.1 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~10 rows)}} +do_test analyze7-3.2 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~102 rows)}} +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)}} +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)}} +do_test analyze7-3.6 { + execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND d=123 AND b=123} +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=? AND d=?) (~1 rows)}} + +finish_test