From: drh Date: Wed, 7 Apr 2010 19:31:59 +0000 (+0000) Subject: Add an interface to the SQLITE_STMTSTATUS_AUTOINDEX status information X-Git-Tag: version-3.7.2~489^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c379b010199391634ebc996081f1084b36590eb;p=thirdparty%2Fsqlite.git Add an interface to the SQLITE_STMTSTATUS_AUTOINDEX status information to the TCL bindings. Add some simple automatic index test cases. FossilOrigin-Name: 1f40441204d9a912b1d6b67ff6ff9e17146c7abd --- diff --git a/manifest b/manifest index c4e8fd2cdb..5c5e7a4ae1 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Wrap\sall\sautomatic\sindex\schanges\sinside\sSQLITE_OMIT_AUTOMATIC_INDEX.\s\sAdd\nthe\sautomatic_index\sPRAGMA\sto\sturn\sit\son\sand\soff. -D 2010-04-07T16:54:58 +C Add\san\sinterface\sto\sthe\sSQLITE_STMTSTATUS_AUTOINDEX\sstatus\sinformation\nto\sthe\sTCL\sbindings.\s\sAdd\ssome\ssimple\sautomatic\sindex\stest\scases. +D 2010-04-07T19:32:00 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -175,7 +175,7 @@ F src/sqliteInt.h bd7ff54663bdd5b57e0eb8b49aca5a3a3c60119a F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6 F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e -F src/tclsqlite.c bad6570a005b234ea670b9f7b48256da19a032d3 +F src/tclsqlite.c c00d4ed7b365b61aa80c159e611d5e3fded6ea1c F src/test1.c 8b4c246c41e75c3ff033edb2e8c2cf15820861ae F src/test2.c b6b43413d495addd039a88b87d65c839f86b18cb F src/test3.c 4c21700c73a890a47fc685c1097bfb661346ac94 @@ -249,6 +249,7 @@ F test/auth.test 8f21c160a4562f54f27618e85bac869efcecbcaf F test/auth2.test 270baddc8b9c273682760cffba6739d907bd2882 F test/auth3.test a4755e6a2a2fea547ffe63c874eb569e60a28eb5 F test/autoinc.test 85ef3180a737e6580086a018c09c6f1a52759b46 +F test/autoindex1.test 1ab878fa736b3cf8fa7b99f1d45e09ffa02a6c13 F test/autovacuum.test 25f891bc343a8bf5d9229e2e9ddab9f31a9ab5ec F test/autovacuum_ioerr2.test 598b0663074d3673a9c1bc9a16e80971313bafe6 F test/avtrans.test 1e901d8102706b63534dbd2bdd4d8f16c4082650 @@ -797,14 +798,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 2364313142668b3d0ad144447b4862709be929cd -R 3be9dccae2ed8d28aad0029df3535432 +P a811a47fbe4f757a7ab575ae5a0f65177a3f07c0 +R dbe510a1d9d8d39e89b08673a1789f57 U drh -Z 13e999191d01e0cdb3247533af5674e2 +Z 4e449990f788af388aab3ad158bffbb5 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFLvLjloxKgR168RlERAidKAJ4r8IFGHOGa4sY/vEmjxAhz+N1UcACffePf -Df12WbFRqxuZFQNtbO5BXhs= -=2bnY +iD8DBQFLvN2zoxKgR168RlERAp2oAJwMcL6AMMRbF4hKmnduZZlExp9waACfbPXK +RKD8ALvU6iGgErFuUvakXVo= +=jT+h -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 7a41613e77..f90278ff29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a811a47fbe4f757a7ab575ae5a0f65177a3f07c0 \ No newline at end of file +1f40441204d9a912b1d6b67ff6ff9e17146c7abd \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 7048e4efb0..5ad198fe98 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -132,7 +132,7 @@ struct SqliteDb { int maxStmt; /* The next maximum number of stmtList */ int nStmt; /* Number of statements in stmtList */ IncrblobChannel *pIncrblob;/* Linked list of open incrblob channels */ - int nStep, nSort; /* Statistics for most recent operation */ + int nStep, nSort, nIndex; /* Statistics for most recent operation */ int nTransaction; /* Number of nested [transaction] methods */ }; @@ -1351,6 +1351,7 @@ static int dbEvalStep(DbEvalContext *p){ pDb->nStep = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_FULLSCAN_STEP,1); pDb->nSort = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_SORT,1); + pDb->nIndex = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_AUTOINDEX,1); dbReleaseColumnNames(p); p->pPreStmt = 0; @@ -2528,7 +2529,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ } /* - ** $db status (step|sort) + ** $db status (step|sort|autoindex) ** ** Display SQLITE_STMTSTATUS_FULLSCAN_STEP or ** SQLITE_STMTSTATUS_SORT for the most recent eval. @@ -2545,8 +2546,11 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ v = pDb->nStep; }else if( strcmp(zOp, "sort")==0 ){ v = pDb->nSort; + }else if( strcmp(zOp, "autoindex")==0 ){ + v = pDb->nIndex; }else{ - Tcl_AppendResult(interp, "bad argument: should be step or sort", + Tcl_AppendResult(interp, + "bad argument: should be autoindex, step, or sort", (char*)0); return TCL_ERROR; } diff --git a/test/autoindex1.test b/test/autoindex1.test new file mode 100644 index 0000000000..1f8b9ef87f --- /dev/null +++ b/test/autoindex1.test @@ -0,0 +1,93 @@ +# 2010 April 07 +# +# 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. The +# focus of this script is testing automatic index creation logic. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If the library is not compiled with automatic index support then +# skip all tests in this file. +# +ifcapable {!autoindex} { + finish_test + return +} + +# With automatic index turned off, we do a full scan of the T2 table +do_test autoindex1-100 { + db eval { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,11); + INSERT INTO t1 VALUES(2,22); + INSERT INTO t1 SELECT a+2, b+22 FROM t1; + INSERT INTO t1 SELECT a+4, b+44 FROM t1; + CREATE TABLE t2(c,d); + INSERT INTO t2 SELECT a, 900+b FROM t1; + } + db eval { + PRAGMA automatic_index=OFF; + SELECT b, d FROM t1 JOIN t2 ON a=c ORDER BY b; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-101 { + db status step +} {63} +do_test autoindex1-102 { + db status autoindex +} {0} + +# With autoindex turned on, we build an index once and then use that index +# to find T2 values. +do_test autoindex1-110 { + db eval { + PRAGMA automatic_index=ON; + SELECT b, d FROM t1 JOIN t2 ON a=c ORDER BY b; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-111 { + db status step +} {7} +do_test autoindex1-112 { + db status autoindex +} {7} + +# The same test as above, but this time the T2 query is a subquery rather +# than a join. +do_test autoindex1-200 { + db eval { + PRAGMA automatic_index=OFF; + SELECT b, (SELECT d FROM t2 WHERE c=a) FROM t1; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-201 { + db status step +} {35} +do_test autoindex1-202 { + db status autoindex +} {0} +do_test autoindex1-210 { + db eval { + PRAGMA automatic_index=ON; + SELECT b, (SELECT d FROM t2 WHERE c=a) FROM t1; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-211 { + db status step +} {7} +do_test autoindex1-212 { + db status autoindex +} {7} + + + +finish_test