]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the sqlite_stat1.stat parsing to allow additional text parameters
authordrh <drh@noemail.net>
Tue, 22 Jul 2014 14:58:12 +0000 (14:58 +0000)
committerdrh <drh@noemail.net>
Tue, 22 Jul 2014 14:58:12 +0000 (14:58 +0000)
at the end.  Unrecognized parameters are silently ignored.

FossilOrigin-Name: ca2a5a2c770fa94cd8db1b1b241ede058a7c58e2

manifest
manifest.uuid
src/analyze.c
src/vdbe.c
test/analyze9.test
test/analyzeC.test [new file with mode: 0644]

index 5a933c39915fa6be7c982ed6a2d058bfe73d78ab..de212466694803ee2b79e34edd606e63bd0ea535 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Expire\sprepared\sstatements\safter\srunning\sANALYZE.
-D 2014-07-22T14:42:16.806
+C Enhance\sthe\ssqlite_stat1.stat\sparsing\sto\sallow\sadditional\stext\sparameters\nat\sthe\send.\s\sUnrecognized\sparameters\sare\ssilently\signored.
+D 2014-07-22T14:58:12.596
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
 F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1
-F src/analyze.c 9f4e473c83a582d696ce57dc8cb7a40ad1314d02
+F src/analyze.c 56799121c72753f40d56f3c17c66c3961af6acb7
 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52
 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
@@ -283,7 +283,7 @@ F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5
 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05
 F src/util.c 049fe1d3c0e2209c1bee107aec2fcff6285f909f
 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
-F src/vdbe.c 514adcc9478e461d01b9b064565d2c99604ed537
+F src/vdbe.c 2f3f0582dfacce292d3d6f22d129fe1abe3ddd00
 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8
 F src/vdbeInt.h 5df5e9afe9b7839cd17256220fc4f7af84b8b1cd
 F src/vdbeapi.c 24e40422382beb774daab11fe9fe9d37e8a04949
@@ -316,9 +316,10 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4
 F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f
 F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f
 F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88
-F test/analyze9.test bd5aaf2a8fd2dd774b08251416897185531a8adf
+F test/analyze9.test 3ef1b471247308e710a794b6e50a6ab536c5604b
 F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944
 F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d
+F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93
 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b
 F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b
 F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7
@@ -1182,7 +1183,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P b22dd165da227a52d88b17a91e80a1701dce61ad
-R 9fe107c1276b2eda80832b2d6848bc6f
+P b083a961f8ac3a6158e822574d73cd63e3103b09
+R 5b14cb35846d5c4a5d2461874ff76990
 U drh
-Z 54d8743399e09513763a4a3a09f86610
+Z 267c7ac0e4de2238ef8d9515f94ccafd
index 300e0983ce0f57b1fcbcb2d39be0d8be8001bb93..cc3037dca8a6d0716f7bf6ac6265a6871dcd80f0 100644 (file)
@@ -1 +1 @@
-b083a961f8ac3a6158e822574d73cd63e3103b09
\ No newline at end of file
+ca2a5a2c770fa94cd8db1b1b241ede058a7c58e2
\ No newline at end of file
index 7d2bed8c7faced88e189d07300509efd79937c03..97305f0dc1462f406ebc41b7fbfbb5bc3da3ed04 100644 (file)
@@ -1428,14 +1428,16 @@ static void decodeIntArray(
 #else
   if( pIndex )
 #endif
-  {
-    if( strcmp(z, "unordered")==0 ){
+  while( z[0] ){
+    if( sqlite3_strglob("unordered*", z)==0 ){
       pIndex->bUnordered = 1;
     }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
       int v32 = 0;
       sqlite3GetInt32(z+3, &v32);
       pIndex->szIdxRow = sqlite3LogEst(v32);
     }
+    while( z[0]!=0 && z[0]!=' ' ) z++;
+    while( z[0]==' ' ) z++;
   }
 }
 
@@ -1476,6 +1478,7 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
   z = argv[2];
 
   if( pIndex ){
+    pIndex->bUnordered = 0;
     decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
     if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
   }else{
index ecea3782d436bba9941fbf90ee9ae71ad72f66c9..86cf8b048490a3271cfa88f88c70939bd2a13889 100644 (file)
@@ -5794,12 +5794,13 @@ case OP_IncrVacuum: {        /* jump */
 
 /* Opcode: Expire P1 * * * *
 **
-** Cause precompiled statements to become expired. An expired statement
-** fails with an error code of SQLITE_SCHEMA if it is ever executed 
-** (via sqlite3_step()).
+** Cause precompiled statements to expire.  When an expired statement
+** is executed using sqlite3_step() it will either automatically
+** reprepare itself (if it was originally created using sqlite3_prepare_v2())
+** or it will fail with SQLITE_SCHEMA.
 ** 
 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
-** then only the currently executing statement is affected. 
+** then only the currently executing statement is expired.
 */
 case OP_Expire: {
   if( !pOp->p1 ){
index fc5a13f43f879aaf4f84eb848854baf2bd9495f4..0d72658df6a00ddd4f9baa8599d66c920cb13552 100644 (file)
@@ -1089,5 +1089,3 @@ foreach {tn where eqp} {
 }
 
 finish_test
-
-
diff --git a/test/analyzeC.test b/test/analyzeC.test
new file mode 100644 (file)
index 0000000..02faa9c
--- /dev/null
@@ -0,0 +1,167 @@
+# 2014-07-22
+#
+# 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 contains automated tests used to verify that the text terms
+# at the end of sqlite_stat1.stat are processed correctly.
+#
+#  (1) "unordered" means that the index cannot be used for ORDER BY
+#      or for range queries
+#
+#  (2) "sz=NNN" sets the relative size of the index entries
+#
+#  (3) All other fields are silently ignored
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix analyzeC
+
+# Baseline case.  Range queries work OK.  Indexes can be used for
+# ORDER BY.
+#
+do_execsql_test 1.0 {
+  CREATE TABLE t1(a,b,c);
+  INSERT INTO t1(a,b,c)
+    VALUES(1,2,3),(7,8,9),(4,5,6),(10,11,12),(4,8,12),(1,11,111);
+  CREATE INDEX t1a ON t1(a);
+  CREATE INDEX t1b ON t1(b);
+  ANALYZE;
+  DELETE FROM sqlite_stat1;
+  INSERT INTO sqlite_stat1(tbl,idx,stat)
+    VALUES('t1','t1a','12345 2'),('t1','t1b','12345 4');
+  ANALYZE sqlite_master;
+  SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c;
+} {4 5 6 # 7 8 9 # 4 8 12 #}
+do_execsql_test 1.1 {
+  EXPLAIN QUERY PLAN
+  SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c;
+} {/.* USING INDEX t1a .a>. AND a<...*/}
+do_execsql_test 1.2 {
+  SELECT c FROM t1 ORDER BY a;
+} {3 111 6 12 9 12}
+do_execsql_test 1.3 {
+  EXPLAIN QUERY PLAN
+  SELECT c FROM t1 ORDER BY a;
+} {/.*SCAN TABLE t1 USING INDEX t1a.*/}
+do_execsql_test 1.3x {
+  EXPLAIN QUERY PLAN
+  SELECT c FROM t1 ORDER BY a;
+} {~/.*B-TREE FOR ORDER BY.*/}
+
+# Now mark the t1a index as "unordered".  Range queries and ORDER BY no
+# longer use the index, but equality queries do.
+#
+do_execsql_test 2.0 {
+  UPDATE sqlite_stat1 SET stat='12345 2 unordered' WHERE idx='t1a';
+  ANALYZE sqlite_master;
+  SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c;
+} {4 5 6 # 7 8 9 # 4 8 12 #}
+do_execsql_test 2.1 {
+  EXPLAIN QUERY PLAN
+  SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c;
+} {~/.*USING INDEX.*/}
+do_execsql_test 2.2 {
+  SELECT c FROM t1 ORDER BY a;
+} {3 111 6 12 9 12}
+do_execsql_test 2.3 {
+  EXPLAIN QUERY PLAN
+  SELECT c FROM t1 ORDER BY a;
+} {~/.*USING INDEX.*/}
+do_execsql_test 2.3x {
+  EXPLAIN QUERY PLAN
+  SELECT c FROM t1 ORDER BY a;
+} {/.*B-TREE FOR ORDER BY.*/}
+
+# Ignore extraneous text parameters in the sqlite_stat1.stat field.
+#
+do_execsql_test 3.0 {
+  UPDATE sqlite_stat1 SET stat='12345 2 whatever=5 unordered xyzzy=11'
+   WHERE idx='t1a';
+  ANALYZE sqlite_master;
+  SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c;
+} {4 5 6 # 7 8 9 # 4 8 12 #}
+do_execsql_test 3.1 {
+  EXPLAIN QUERY PLAN
+  SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c;
+} {~/.*USING INDEX.*/}
+do_execsql_test 3.2 {
+  SELECT c FROM t1 ORDER BY a;
+} {3 111 6 12 9 12}
+do_execsql_test 3.3 {
+  EXPLAIN QUERY PLAN
+  SELECT c FROM t1 ORDER BY a;
+} {~/.*USING INDEX.*/}
+do_execsql_test 3.3x {
+  EXPLAIN QUERY PLAN
+  SELECT c FROM t1 ORDER BY a;
+} {/.*B-TREE FOR ORDER BY.*/}
+
+# The sz=NNN parameter determines which index to scan
+#
+do_execsql_test 4.0 {
+  DROP INDEX t1a;
+  CREATE INDEX t1ab ON t1(a,b);
+  CREATE INDEX t1ca ON t1(c,a);
+  DELETE FROM sqlite_stat1;
+  INSERT INTO sqlite_stat1(tbl,idx,stat)
+    VALUES('t1','t1ab','12345 3 2 sz=10'),('t1','t1ca','12345 3 2 sz=20');
+  ANALYZE sqlite_master;
+  SELECT count(a) FROM t1;
+} {6}
+do_execsql_test 4.1 {
+  EXPLAIN QUERY PLAN
+  SELECT count(a) FROM t1;
+} {/.*INDEX t1ab.*/}
+do_execsql_test 4.2 {
+  DELETE FROM sqlite_stat1;
+  INSERT INTO sqlite_stat1(tbl,idx,stat)
+    VALUES('t1','t1ab','12345 3 2 sz=20'),('t1','t1ca','12345 3 2 sz=10');
+  ANALYZE sqlite_master;
+  SELECT count(a) FROM t1;
+} {6}
+do_execsql_test 4.3 {
+  EXPLAIN QUERY PLAN
+  SELECT count(a) FROM t1;
+} {/.*INDEX t1ca.*/}
+
+
+# The sz=NNN parameter works even if there is other extraneous text
+# in the sqlite_stat1.stat column.
+#
+do_execsql_test 5.0 {
+  DELETE FROM sqlite_stat1;
+  INSERT INTO sqlite_stat1(tbl,idx,stat)
+    VALUES('t1','t1ab','12345 3 2 x=5 sz=10 y=10'),
+          ('t1','t1ca','12345 3 2 whatever sz=20 junk');
+  ANALYZE sqlite_master;
+  SELECT count(a) FROM t1;
+} {6}
+do_execsql_test 5.1 {
+  EXPLAIN QUERY PLAN
+  SELECT count(a) FROM t1;
+} {/.*INDEX t1ab.*/}
+do_execsql_test 5.2 {
+  DELETE FROM sqlite_stat1;
+  INSERT INTO sqlite_stat1(tbl,idx,stat)
+    VALUES('t1','t1ca','12345 3 2 x=5 sz=10 y=10'),
+          ('t1','t1ab','12345 3 2 whatever sz=20 junk');
+  ANALYZE sqlite_master;
+  SELECT count(a) FROM t1;
+} {6}
+do_execsql_test 5.3 {
+  EXPLAIN QUERY PLAN
+  SELECT count(a) FROM t1;
+} {/.*INDEX t1ca.*/}
+
+
+
+
+finish_test