From cf4d38aaf0d7d1024e1b308c07b4934006666c3b Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 28 Jul 2010 02:53:36 +0000 Subject: [PATCH 1/7] Do not allow automatic indices for the RHS of IN expressions which are not correlated subqueries. Ticket [8011086c85c6c404014c9] FossilOrigin-Name: 267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/expr.c | 10 ++++++++-- test/autoindex1.test | 30 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 3a65142d27..1bc984af6c 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Update\sthe\smakefiles\sto\sprefer\sTCL\sversion\s8.5\sinstead\sof\s8.4. -D 2010-07-27T16:42:23 +C Do\snot\sallow\sautomatic\sindices\sfor\sthe\sRHS\sof\sIN\sexpressions\swhich\sare\snot\ncorrelated\ssubqueries.\s\sTicket\s[8011086c85c6c404014c9] +D 2010-07-28T02:53:37 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -125,7 +125,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 4f3aadad62c6c9f0d4e5a96718516ac4e3c598df F src/date.c 5dd8448a0bfea8d31fb14cff487d0c06ff8c8b20 F src/delete.c 7ed8a8c8b5f748ece92df173d7e0f7810c899ebd -F src/expr.c 7490fc3b16414d1a45d5acadf559317f9244891f +F src/expr.c a0fd9c5e248229851077de92f2e9346f2c43ed46 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c cacfe3e24b311e4e089a9c470bdb73196af6f729 F src/func.c 75dc1fd91e5692cadb80d257bab68d7343060467 @@ -258,7 +258,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 ffb06a246e2c1f89cfbe3d93eca513c9e78d4063 +F test/autoindex1.test 7df441bf0e7a88644eb80993339dbf1db3a12c68 F test/autovacuum.test bb7c0885e6f8f1d633045de48f2b66082162766d F test/autovacuum_ioerr2.test 598b0663074d3673a9c1bc9a16e80971313bafe6 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 @@ -841,14 +841,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 6df081adbfa581c477bd2c96bb3f7f44be131a8f -R 2e30ee83ed26c6b6d858b65a1a40368a +P 8118de2af33557f75b4f2f1b1194a21d46ccf7fe +R 40c9c305c287d6d5baa795d30f2cf9ee U drh -Z 7c9b71a765785eb5366a775431acbda9 +Z 937ef6a9e9466c178b83c982e778c20e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMTwxyoxKgR168RlERAoWhAKCIJmTkn9tifBBxLWcZZSTjSKv7hQCghz7k -L9/hegUPu/Ry2mCj4VCVOlE= -=kcSH +iD8DBQFMT5u2oxKgR168RlERAsjPAJ4pDaNKroaW8Tnm1cU0jDkzKN0KwACePYGJ +C5ZTN2Lh/obd8jivM7gzwas= +=32EK -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index c1bb427adf..6ff279484e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8118de2af33557f75b4f2f1b1194a21d46ccf7fe \ No newline at end of file +267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index bd28bf9394..153751f7cd 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1512,14 +1512,20 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){ /* Could not found an existing table or index to use as the RHS b-tree. ** We will have to generate an ephemeral table to do the job. */ + double savedNQueryLoop = pParse->nQueryLoop; int rMayHaveNull = 0; eType = IN_INDEX_EPH; if( prNotFound ){ *prNotFound = rMayHaveNull = ++pParse->nMem; - }else if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){ - eType = IN_INDEX_ROWID; + }else{ + testcase( pParse->nQueryLoop>(double)1 ); + pParse->nQueryLoop = (double)1; + if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){ + eType = IN_INDEX_ROWID; + } } sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID); + pParse->nQueryLoop = savedNQueryLoop; }else{ pX->iTable = iTab; } diff --git a/test/autoindex1.test b/test/autoindex1.test index 96b4f1a63a..40e1936cd9 100644 --- a/test/autoindex1.test +++ b/test/autoindex1.test @@ -136,4 +136,34 @@ do_test autoindex1-401 { } } {4087} +# Ticket [8011086c85c6c404014c947fcf3eb9f42b184a0d] from 2010-07-08 +# Make sure automatic indices are not created for the RHS of an IN expression +# that is not a correlated subquery. +# +do_test autoindex1-500 { + db eval { + CREATE TABLE t501(a INTEGER PRIMARY KEY, b); + CREATE TABLE t502(x INTEGER PRIMARY KEY, y); + EXPLAIN QUERY PLAN + SELECT b FROM t501 + WHERE t501.a IN (SELECT x FROM t502 WHERE y=?); + } +} {0 0 {TABLE t501 USING PRIMARY KEY} 0 0 {TABLE t502}} +do_test autoindex1-501 { + db eval { + EXPLAIN QUERY PLAN + SELECT b FROM t501 + WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b); + } +} {0 0 {TABLE t501} 0 0 {TABLE t502 WITH AUTOMATIC INDEX}} +do_test autoindex1-502 { + db eval { + EXPLAIN QUERY PLAN + SELECT b FROM t501 + WHERE t501.a=123 + AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b); + } +} {0 0 {TABLE t501 USING PRIMARY KEY} 0 0 {TABLE t502}} + + finish_test From 154a3192134c86f9b0fd232c0b80e4e9cc2a79d7 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 28 Jul 2010 15:49:02 +0000 Subject: [PATCH 2/7] Add documentation for the SQLITE_STATUS_MALLOC_COUNT parameter to sqlite3_status(). FossilOrigin-Name: dbfbdb60c00b5aeae29c85acec0ae910b82dbdba --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/sqlite.h.in | 3 +++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1bc984af6c..eefc31b6ed 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Do\snot\sallow\sautomatic\sindices\sfor\sthe\sRHS\sof\sIN\sexpressions\swhich\sare\snot\ncorrelated\ssubqueries.\s\sTicket\s[8011086c85c6c404014c9] -D 2010-07-28T02:53:37 +C Add\sdocumentation\sfor\sthe\sSQLITE_STATUS_MALLOC_COUNT\sparameter\sto\nsqlite3_status(). +D 2010-07-28T15:49:02 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714 -F src/sqlite.h.in 5bc6d2d1bc5251b887123b12b67895785ff41a5f +F src/sqlite.h.in 874bf890b70f72d4e444707a2a10b59cd920123a F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 F src/sqliteInt.h a9be6badc6cd6a3c1ae54475a98661cf351ecad5 F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3 @@ -841,14 +841,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 8118de2af33557f75b4f2f1b1194a21d46ccf7fe -R 40c9c305c287d6d5baa795d30f2cf9ee +P 267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3 +R 8575a8caac4126fb5e920b76e9a1802f U drh -Z 937ef6a9e9466c178b83c982e778c20e +Z 4d163993207ade26e450eac3f975081d -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMT5u2oxKgR168RlERAsjPAJ4pDaNKroaW8Tnm1cU0jDkzKN0KwACePYGJ -C5ZTN2Lh/obd8jivM7gzwas= -=32EK +iD8DBQFMUFFxoxKgR168RlERAuu3AJsGZVDMtkyuNWSm7CqMLv7kOY7hmgCfdtQp +ZbImEQ0zq6QE+jWsdQnFVvs= +=OY3A -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 6ff279484e..830363239c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3 \ No newline at end of file +dbfbdb60c00b5aeae29c85acec0ae910b82dbdba \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 0c71848d3d..61cb7ebec0 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5143,6 +5143,9 @@ int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); ** *pHighwater parameter to [sqlite3_status()] is of interest. ** The value written into the *pCurrent parameter is undefined.)^ ** +** ^(
SQLITE_STATUS_MALLOC_COUNT
+**
This parameter records the number of separate memory allocations.
)^ +** ** ^(
SQLITE_STATUS_PAGECACHE_USED
**
This parameter returns the number of pages used out of the ** [pagecache memory allocator] that was configured using From 39539804c666db8b92af0faefec12dddfe168876 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 28 Jul 2010 15:52:09 +0000 Subject: [PATCH 3/7] Lookaside memory is not used to store schemas. Change the SQLITE_DBSATUS_SCHEMA_USED documentation to reflect this fact. FossilOrigin-Name: 07abfd5268564c18afd1074c2069d65c64f4b8eb --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index eefc31b6ed..7e759fc966 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Add\sdocumentation\sfor\sthe\sSQLITE_STATUS_MALLOC_COUNT\sparameter\sto\nsqlite3_status(). -D 2010-07-28T15:49:02 +C Lookaside\smemory\sis\snot\sused\sto\sstore\sschemas.\s\sChange\sthe\nSQLITE_DBSATUS_SCHEMA_USED\sdocumentation\sto\sreflect\sthis\sfact. +D 2010-07-28T15:52:09 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714 -F src/sqlite.h.in 874bf890b70f72d4e444707a2a10b59cd920123a +F src/sqlite.h.in 373dedd8489ecd9dfb33d6d4378ee9f34a3c2386 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 F src/sqliteInt.h a9be6badc6cd6a3c1ae54475a98661cf351ecad5 F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3 @@ -841,14 +841,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3 -R 8575a8caac4126fb5e920b76e9a1802f +P dbfbdb60c00b5aeae29c85acec0ae910b82dbdba +R db99aad6ade6f84bf548bac1cfdabd10 U drh -Z 4d163993207ade26e450eac3f975081d +Z 87e1fd645b598e91788e82cf253f48fb -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMUFFxoxKgR168RlERAuu3AJsGZVDMtkyuNWSm7CqMLv7kOY7hmgCfdtQp -ZbImEQ0zq6QE+jWsdQnFVvs= -=OY3A +iD8DBQFMUFIsoxKgR168RlERAicpAKCHH5v5EXtY/BOEo/lp30OkqVQK0wCgisZZ +js0Ce6xvYCx8PUpn/o0QZSQ= +=7PD/ -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 830363239c..6e05087672 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dbfbdb60c00b5aeae29c85acec0ae910b82dbdba \ No newline at end of file +07abfd5268564c18afd1074c2069d65c64f4b8eb \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 61cb7ebec0..286ff5990f 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5254,7 +5254,7 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); ** ** ^(
SQLITE_DBSTATUS_SCHEMA_USED
**
This parameter returns the approximate number of of bytes of heap -** and lookaside memory used to store the schema for all databases associated +** memory used to store the schema for all databases associated ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ ** ^The full amount of memory used by the schemas is reported, even if the ** schema memory is shared with other database connections due to From 642d8b87fe8844f4a539cafd4e11af203f543eeb Mon Sep 17 00:00:00 2001 From: shaneh Date: Wed, 28 Jul 2010 16:05:34 +0000 Subject: [PATCH 4/7] Modify CLI to optionally display "stats". FossilOrigin-Name: 419ce0ed89d10252492b2926817259899ee74e71 --- manifest | 27 +++------ manifest.uuid | 2 +- src/shell.c | 118 +++++++++++++++++++++++++++++++++++---- tool/shell1.test | 25 ++++++++- tool/shell4.test | 140 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 281 insertions(+), 31 deletions(-) create mode 100644 tool/shell4.test diff --git a/manifest b/manifest index 7e759fc966..91347afecb 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Lookaside\smemory\sis\snot\sused\sto\sstore\sschemas.\s\sChange\sthe\nSQLITE_DBSATUS_SCHEMA_USED\sdocumentation\sto\sreflect\sthis\sfact. -D 2010-07-28T15:52:09 +C Modify\sCLI\sto\soptionally\sdisplay\s"stats". +D 2010-07-28T16:05:35 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -172,7 +169,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c -F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714 +F src/shell.c 74c82a4ecfd833900a5bacc5f32abd18b93079d1 F src/sqlite.h.in 373dedd8489ecd9dfb33d6d4378ee9f34a3c2386 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 F src/sqliteInt.h a9be6badc6cd6a3c1ae54475a98661cf351ecad5 @@ -826,9 +823,10 @@ F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87 F tool/omittest.tcl 27d6f6e3b1e95aeb26a1c140e6eb57771c6d794a F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a -F tool/shell1.test a738c71bc08ea9162baee9a14b3cf9994f181921 +F tool/shell1.test 930444cadb71ce9ce78bc6cd14ec21e6b69776ea F tool/shell2.test 5dc76b8005b465f420fed8241621da7513060ff3 F tool/shell3.test 4fad469e8003938426355afdf34155f08c587836 +F tool/shell4.test 0c82af2b7ce4e8e84565078a8690d1c46ec4e8f6 F tool/showdb.c 01c20e8181941b714fe07f72c64a7560fee17ff9 F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87 F tool/showwal.c f09e5a80a293919290ec85a6a37c85a5ddcf37d9 @@ -841,14 +839,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P dbfbdb60c00b5aeae29c85acec0ae910b82dbdba -R db99aad6ade6f84bf548bac1cfdabd10 -U drh -Z 87e1fd645b598e91788e82cf253f48fb ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFMUFIsoxKgR168RlERAicpAKCHH5v5EXtY/BOEo/lp30OkqVQK0wCgisZZ -js0Ce6xvYCx8PUpn/o0QZSQ= -=7PD/ ------END PGP SIGNATURE----- +P 07abfd5268564c18afd1074c2069d65c64f4b8eb +R 685d62477503a0184c458ad36031979f +U shaneh +Z 72eb3f2af1f8ca9f1cfbf340110562c7 diff --git a/manifest.uuid b/manifest.uuid index 6e05087672..caddf9982a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -07abfd5268564c18afd1074c2069d65c64f4b8eb \ No newline at end of file +419ce0ed89d10252492b2926817259899ee74e71 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 23099b94a4..1212d38caf 100644 --- a/src/shell.c +++ b/src/shell.c @@ -398,6 +398,7 @@ struct previous_mode_data { struct callback_data { sqlite3 *db; /* The database */ int echoOn; /* True to echo input commands */ + int statsOn; /* True to display memory stats before each finalize */ int cnt; /* Number of records displayed so far */ FILE *out; /* Write results here */ int mode; /* An output mode setting */ @@ -961,6 +962,86 @@ static char *save_err_msg( return zErrMsg; } +/* +** Display memory stats. +*/ +static int display_stats( + sqlite3 *db, /* Database to query */ + struct callback_data *pArg, /* Pointer to struct callback_data */ + int bReset /* True to reset the stats */ +){ + int iCur; + int iHiwtr; + + if( pArg && pArg->out ){ + + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Mem Used (Excludes Scratch/Pcache): %d (max %d) bytes\n", iCur, iHiwtr); + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Number of Allocations: %d (max %d)\n", iCur, iHiwtr); +/* +** Not currently used by the CLI. +** iHiwtr = iCur = -1; +** sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset); +** fprintf(pArg->out, "Number of Pcache Pages Used: %d (max %d) pages\n", iCur, iHiwtr); +*/ + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Number of Pcache Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr); +/* +** Not currently used by the CLI. +** iHiwtr = iCur = -1; +** sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset); +** fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n", iCur, iHiwtr); +*/ + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Number of Scratch Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr); + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Largest Allocation: %d bytes\n", iHiwtr); + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n", iHiwtr); + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n", iHiwtr); +#ifdef YYTRACKMAXSTACKDEPTH + iHiwtr = iCur = -1; + sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n", iCur, iHiwtr); +#endif + } + + if( pArg && pArg->out && db ){ + iHiwtr = iCur = -1; + sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr); + iHiwtr = iCur = -1; + sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Pcache Heap Usage: %d bytes\n", iCur); + iHiwtr = iCur = -1; + sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur); + iHiwtr = iCur = -1; + sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset); + fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur); + } + + if( pArg && pArg->out && db && pArg->pStmt ){ + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset); + fprintf(pArg->out, "Fullscan Steps: %d\n", iCur); + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset); + fprintf(pArg->out, "Sort Operations: %d\n", iCur); + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset); + fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur); + } + + return 0; +} + /* ** Execute a statement or set of statements. Print ** any result rows/columns depending on the current mode @@ -1000,10 +1081,16 @@ static int shell_exec( continue; } + /* save off the prepared statment handle and reset row count */ + if( pArg ){ + pArg->pStmt = pStmt; + pArg->cnt = 0; + } + /* echo the sql statement if echo on */ - if( pArg->echoOn ){ + if( pArg && pArg->echoOn ){ const char *zStmtSql = sqlite3_sql(pStmt); - fprintf(pArg->out,"%s\n", zStmtSql ? zStmtSql : zSql); + fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql); } /* perform the first step. this will tell us if we @@ -1029,11 +1116,6 @@ static int shell_exec( for(i=0; ipStmt = pStmt; - pArg->cnt = 0; - } do{ /* extract the data and data types */ for(i=0; ipStmt = NULL; - } } }else{ do{ @@ -1067,6 +1146,11 @@ static int shell_exec( } } + /* print usage stats if stats on */ + if( pArg && pArg->statsOn ){ + display_stats(db, pArg, 0); + } + /* Finalize the statement just executed. If this fails, save a ** copy of the error message. Otherwise, set zSql to point to the ** next statement to execute. */ @@ -1077,6 +1161,11 @@ static int shell_exec( }else if( pzErrMsg ){ *pzErrMsg = save_err_msg(db); } + + /* clear saved stmt handle */ + if( pArg ){ + pArg->pStmt = NULL; + } } } /* end while */ @@ -1256,6 +1345,7 @@ static char zHelp[] = " LIKE pattern TABLE.\n" ".separator STRING Change separator used by output mode and .import\n" ".show Show the current values for various settings\n" + ".stats ON|OFF Turn stats on or off\n" ".tables ?TABLE? List names of tables\n" " If TABLE specified, only list tables matching\n" " LIKE pattern TABLE.\n" @@ -2001,6 +2091,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ fprintf(p->out,"%9.9s: ", "separator"); output_c_string(p->out, p->separator); fprintf(p->out, "\n"); + fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off"); fprintf(p->out,"%9.9s: ","width"); for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) { fprintf(p->out,"%d ",p->colWidth[i]); @@ -2008,6 +2099,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){ fprintf(p->out,"\n"); }else + if( c=='s' && strncmp(azArg[0], "stats", n)==0 && nArg>1 && nArg<3 ){ + p->statsOn = booleanValue(azArg[1]); + }else + if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){ char **azResult; int nRow; @@ -2391,6 +2486,7 @@ static const char zOptions[] = " -line set output mode to 'line'\n" " -list set output mode to 'list'\n" " -separator 'x' set output field separator (|)\n" + " -stats print memory stats before each finalize\n" " -nullvalue 'text' set text string for NULL values\n" " -version show SQLite version\n" ; @@ -2555,6 +2651,8 @@ int main(int argc, char **argv){ data.showHeader = 0; }else if( strcmp(z,"-echo")==0 ){ data.echoOn = 1; + }else if( strcmp(z,"-stats")==0 ){ + data.statsOn = 1; }else if( strcmp(z,"-bail")==0 ){ bail_on_error = 1; }else if( strcmp(z,"-version")==0 ){ diff --git a/tool/shell1.test b/tool/shell1.test index dcdac758a9..f21601a456 100644 --- a/tool/shell1.test +++ b/tool/shell1.test @@ -178,6 +178,11 @@ do_test shell1-1.14.3 { [regexp {Error: missing argument for option: -separator} $res] } {1 1} +# -stats print memory stats before each finalize +do_test shell1-1.14b.1 { + catchcmd "-stats test.db" "" +} {0 {}} + # -nullvalue 'text' set text string for NULL values do_test shell1-1.15.1 { catchcmd "-nullvalue 'x' test.db" "" @@ -195,7 +200,7 @@ do_test shell1-1.15.3 { # -version show SQLite version do_test shell1-1.16.1 { catchcmd "-version test.db" "" -} {0 3.7.0} +} {0 3.7.1} #---------------------------------------------------------------------------- # Test cases shell1-2.*: Basic "dot" command token parsing. @@ -621,13 +626,29 @@ do_test shell1-3.23.1 { [regexp {nullvalue:} $res] \ [regexp {output:} $res] \ [regexp {separator:} $res] \ + [regexp {stats:} $res] \ [regexp {width:} $res] -} {1 1 1 1 1 1 1 1} +} {1 1 1 1 1 1 1 1 1} do_test shell1-3.23.2 { # too many arguments catchcmd "test.db" ".show BAD" } {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for help}} +# .stats ON|OFF Turn stats on or off +do_test shell1-3.23b.1 { + catchcmd "test.db" ".stats" +} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}} +do_test shell1-3.23b.2 { + catchcmd "test.db" ".stats ON" +} {0 {}} +do_test shell1-3.23b.3 { + catchcmd "test.db" ".stats OFF" +} {0 {}} +do_test shell1-3.23b.4 { + # too many arguments + catchcmd "test.db" ".stats OFF BAD" +} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}} + # .tables ?TABLE? List names of tables # If TABLE specified, only list tables matching # LIKE pattern TABLE. diff --git a/tool/shell4.test b/tool/shell4.test new file mode 100644 index 0000000000..e75a4c1ed8 --- /dev/null +++ b/tool/shell4.test @@ -0,0 +1,140 @@ +# 2010 July 28 +# +# 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. +# +#*********************************************************************** +# +# The focus of this file is testing the CLI shell tool. +# +# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ +# + +# Test plan: +# +# shell4-1.*: Basic tests specific to the "stats" command. +# + +package require sqlite3 + +set CLI "./sqlite3" + +proc do_test {name cmd expected} { + puts -nonewline "$name ..." + set res [uplevel $cmd] + if {$res eq $expected} { + puts Ok + } else { + puts Error + puts " Got: $res" + puts " Expected: $expected" + exit + } +} + +proc execsql {sql} { + uplevel [list db eval $sql] +} + +proc catchsql {sql} { + set rc [catch {uplevel [list db eval $sql]} msg] + list $rc $msg +} + +proc catchcmd {db {cmd ""}} { + global CLI + set out [open cmds.txt w] + puts $out $cmd + close $out + set line "exec $CLI $db < cmds.txt" + set rc [catch { eval $line } msg] + list $rc $msg +} + +file delete -force test.db test.db.journal +sqlite3 db test.db + +#---------------------------------------------------------------------------- +# Test cases shell4-1.*: Tests specific to the "stats" command. +# + +# should default to off +do_test shell4-1.1.1 { + set res [catchcmd "test.db" ".show"] + list [regexp {stats: off} $res] +} {1} + +do_test shell4-1.1.2 { + set res [catchcmd "test.db" ".show"] + list [regexp {stats: on} $res] +} {0} + +# -stats should turn it on +do_test shell4-1.2.1 { + set res [catchcmd "-stats test.db" ".show"] + list [regexp {stats: on} $res] +} {1} + +do_test shell4-1.2.2 { + set res [catchcmd "-stats test.db" ".show"] + list [regexp {stats: off} $res] +} {0} + +# .stats ON|OFF Turn stats on or off +do_test shell4-1.3.1 { + catchcmd "test.db" ".stats" +} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}} +do_test shell4-1.3.2 { + catchcmd "test.db" ".stats ON" +} {0 {}} +do_test shell4-1.3.3 { + catchcmd "test.db" ".stats OFF" +} {0 {}} +do_test shell4-1.3.4 { + # too many arguments + catchcmd "test.db" ".stats OFF BAD" +} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}} + +# NB. whitespace is important +do_test shell4-1.4.1 { + set res [catchcmd "test.db" {.show}] + list [regexp {stats: off} $res] +} {1} + +do_test shell4-1.4.2 { + set res [catchcmd "test.db" {.stats ON +.show +}] + list [regexp {stats: on} $res] +} {1} + +do_test shell4-1.4.3 { + set res [catchcmd "test.db" {.stats OFF +.show +}] + list [regexp {stats: off} $res] +} {1} + +# make sure stats not present when off +do_test shell4-1.5.1 { + set res [catchcmd "test.db" {SELECT 1;}] + list [regexp {Mem Used} $res] \ + [regexp {Heap Usage} $res] \ + [regexp {Autoindex Inserts} $res] +} {0 0 0} + +# make sure stats are present when on +do_test shell4-1.5.2 { + set res [catchcmd "test.db" {.stats ON +SELECT 1; +}] + list [regexp {Mem Used} $res] \ + [regexp {Heap Usage} $res] \ + [regexp {Autoindex Inserts} $res] +} {1 1 1} + +puts "CLI tests completed successfully" From 29dfbe3b703639000c4bb6132a64ced49a9e7fb1 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 28 Jul 2010 17:01:24 +0000 Subject: [PATCH 5/7] Record the pcache allocation size statistics even for pcache overflow allocations. Adjust the wording on one of the stat output lines in the shell. FossilOrigin-Name: f9adf66ad575abbb63736caef27bd3c619e516a6 --- manifest | 26 ++++++++++++++++++-------- manifest.uuid | 2 +- src/pcache1.c | 2 +- src/shell.c | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 91347afecb..dff6149e79 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,8 @@ -C Modify\sCLI\sto\soptionally\sdisplay\s"stats". -D 2010-07-28T16:05:35 +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +C Record\sthe\spcache\sallocation\ssize\sstatistics\seven\sfor\spcache\soverflow\nallocations.\s\sAdjust\sthe\swording\son\sone\sof\sthe\sstat\soutput\slines\sin\nthe\sshell. +D 2010-07-28T17:01:24 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -161,7 +164,7 @@ F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07 F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050 -F src/pcache1.c 3a7c28f46a61b43ff0b5c087a7983c154f4b264c +F src/pcache1.c 638844c118163e3a10e1e3265703adf74870312d F src/pragma.c 8b24ce00a93de345b6c3bd1e1e2cfba9f63d2325 F src/prepare.c ce4c35a2b1d5fe916e4a46b70d24a6e997d7c4c6 F src/printf.c 8ae5082dd38a1b5456030c3755ec3a392cd51506 @@ -169,7 +172,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c -F src/shell.c 74c82a4ecfd833900a5bacc5f32abd18b93079d1 +F src/shell.c cc1a4d200a2c67919da363958048b592d9d3b72f F src/sqlite.h.in 373dedd8489ecd9dfb33d6d4378ee9f34a3c2386 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 F src/sqliteInt.h a9be6badc6cd6a3c1ae54475a98661cf351ecad5 @@ -839,7 +842,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 07abfd5268564c18afd1074c2069d65c64f4b8eb -R 685d62477503a0184c458ad36031979f -U shaneh -Z 72eb3f2af1f8ca9f1cfbf340110562c7 +P 419ce0ed89d10252492b2926817259899ee74e71 +R dc9c16c2cc8d28f83225dd05e4b97cc5 +U drh +Z 7a885145d3d413b050104a74c1f92d01 +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.6 (GNU/Linux) + +iD8DBQFMUGJnoxKgR168RlERArUkAJ9o1qOoDHVAVPszZ+b9N0jILvo1HwCfUjk9 +BFlxHahyt1UMfIuBBDlNIKk= +=3jW+ +-----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index caddf9982a..e8736f756c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -419ce0ed89d10252492b2926817259899ee74e71 \ No newline at end of file +f9adf66ad575abbb63736caef27bd3c619e516a6 \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index 9f2b29986b..a9ee63e7cd 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -152,11 +152,11 @@ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ static void *pcache1Alloc(int nByte){ void *p; assert( sqlite3_mutex_held(pcache1.mutex) ); + sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); if( nByte<=pcache1.szSlot && pcache1.pFree ){ assert( pcache1.isInit ); p = (PgHdr1 *)pcache1.pFree; pcache1.pFree = pcache1.pFree->pNext; - sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1); }else{ diff --git a/src/shell.c b/src/shell.c index 1212d38caf..0c6c909f4f 100644 --- a/src/shell.c +++ b/src/shell.c @@ -977,7 +977,7 @@ static int display_stats( iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset); - fprintf(pArg->out, "Mem Used (Excludes Scratch/Pcache): %d (max %d) bytes\n", iCur, iHiwtr); + fprintf(pArg->out, "Memory Used: %d (max %d) bytes\n", iCur, iHiwtr); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Number of Allocations: %d (max %d)\n", iCur, iHiwtr); From abc97a78346c641210f08e35609235fad38061dc Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 28 Jul 2010 17:16:41 +0000 Subject: [PATCH 6/7] Adjust the shell test script "shell4.test" to account for changes in the ".stat on" display format from the previous checkin. FossilOrigin-Name: 2f2fa7dd809ae2a67048643da8c01a4664848ba7 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- tool/shell4.test | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index dff6149e79..90b251dd07 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Record\sthe\spcache\sallocation\ssize\sstatistics\seven\sfor\spcache\soverflow\nallocations.\s\sAdjust\sthe\swording\son\sone\sof\sthe\sstat\soutput\slines\sin\nthe\sshell. -D 2010-07-28T17:01:24 +C Adjust\sthe\sshell\stest\sscript\s"shell4.test"\sto\saccount\sfor\schanges\sin\sthe\n".stat\son"\sdisplay\sformat\sfrom\sthe\sprevious\scheckin. +D 2010-07-28T17:16:41 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -829,7 +829,7 @@ F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/shell1.test 930444cadb71ce9ce78bc6cd14ec21e6b69776ea F tool/shell2.test 5dc76b8005b465f420fed8241621da7513060ff3 F tool/shell3.test 4fad469e8003938426355afdf34155f08c587836 -F tool/shell4.test 0c82af2b7ce4e8e84565078a8690d1c46ec4e8f6 +F tool/shell4.test b8d99dc22399a256f1090f6d755f666f394ba02b F tool/showdb.c 01c20e8181941b714fe07f72c64a7560fee17ff9 F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87 F tool/showwal.c f09e5a80a293919290ec85a6a37c85a5ddcf37d9 @@ -842,14 +842,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 419ce0ed89d10252492b2926817259899ee74e71 -R dc9c16c2cc8d28f83225dd05e4b97cc5 +P f9adf66ad575abbb63736caef27bd3c619e516a6 +R 9558d79cf319dc848ba05a8d52ee237b U drh -Z 7a885145d3d413b050104a74c1f92d01 +Z 2f19f50f273aa39e26644f0a727198db -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMUGJnoxKgR168RlERArUkAJ9o1qOoDHVAVPszZ+b9N0jILvo1HwCfUjk9 -BFlxHahyt1UMfIuBBDlNIKk= -=3jW+ +iD8DBQFMUGX8oxKgR168RlERAtubAJ47D4HEKATV6b/ioA0aSOHcQpGbtACfbXdm +NtY/U+/oQI9Ujb0cG0mLzfE= +=QYCo -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index e8736f756c..3410a6d923 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9adf66ad575abbb63736caef27bd3c619e516a6 \ No newline at end of file +2f2fa7dd809ae2a67048643da8c01a4664848ba7 \ No newline at end of file diff --git a/tool/shell4.test b/tool/shell4.test index e75a4c1ed8..b4bef3afa4 100644 --- a/tool/shell4.test +++ b/tool/shell4.test @@ -122,7 +122,7 @@ do_test shell4-1.4.3 { # make sure stats not present when off do_test shell4-1.5.1 { set res [catchcmd "test.db" {SELECT 1;}] - list [regexp {Mem Used} $res] \ + list [regexp {Memory Used} $res] \ [regexp {Heap Usage} $res] \ [regexp {Autoindex Inserts} $res] } {0 0 0} @@ -132,7 +132,7 @@ do_test shell4-1.5.2 { set res [catchcmd "test.db" {.stats ON SELECT 1; }] - list [regexp {Mem Used} $res] \ + list [regexp {Memory Used} $res] \ [regexp {Heap Usage} $res] \ [regexp {Autoindex Inserts} $res] } {1 1 1} From 233f816b844776d7d2c81c5059357dc52ed01383 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 28 Jul 2010 17:36:11 +0000 Subject: [PATCH 7/7] Improve the accuracy of the Pager heap usage estimate. FossilOrigin-Name: ae89777e7f8bae2cdd3407395ea84c1b39577c4b --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/pager.c | 6 ++++-- src/shell.c | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 90b251dd07..32c52393d6 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Adjust\sthe\sshell\stest\sscript\s"shell4.test"\sto\saccount\sfor\schanges\sin\sthe\n".stat\son"\sdisplay\sformat\sfrom\sthe\sprevious\scheckin. -D 2010-07-28T17:16:41 +C Improve\sthe\saccuracy\sof\sthe\sPager\sheap\susage\sestimate. +D 2010-07-28T17:36:12 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -159,7 +159,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e F src/os_unix.c 3109e0e5a0d5551bab2e8c7322b20a3b8b171248 F src/os_win.c 1f8b0a1a5bcf6289e7754d0d3c16cec16d4c93ab -F src/pager.c 78ca1e1f3315c8227431c403c04d791dccf242fb +F src/pager.c b877df9489b647cb3a9b3590f168bd4ee31bf9e7 F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07 @@ -172,7 +172,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c -F src/shell.c cc1a4d200a2c67919da363958048b592d9d3b72f +F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056 F src/sqlite.h.in 373dedd8489ecd9dfb33d6d4378ee9f34a3c2386 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 F src/sqliteInt.h a9be6badc6cd6a3c1ae54475a98661cf351ecad5 @@ -842,14 +842,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P f9adf66ad575abbb63736caef27bd3c619e516a6 -R 9558d79cf319dc848ba05a8d52ee237b +P 2f2fa7dd809ae2a67048643da8c01a4664848ba7 +R b7bd2ca1374c0179d87c6bae7ca407e6 U drh -Z 2f19f50f273aa39e26644f0a727198db +Z 03585c4f4d1ec104a0103a0a8c108d7f -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMUGX8oxKgR168RlERAtubAJ47D4HEKATV6b/ioA0aSOHcQpGbtACfbXdm -NtY/U+/oQI9Ujb0cG0mLzfE= -=QYCo +iD8DBQFMUGqPoxKgR168RlERAgxrAJ4+w32hgMSWWsLb7m9/xZmvHyOoagCaAmtG +MhNGa6qhE2RISj/kSRw4Vo0= +=wqBl -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 3410a6d923..fba61ba2af 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2f2fa7dd809ae2a67048643da8c01a4664848ba7 \ No newline at end of file +ae89777e7f8bae2cdd3407395ea84c1b39577c4b \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index dfb29e3df7..adab9ff5ee 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5414,9 +5414,11 @@ int sqlite3PagerRefcount(Pager *pPager){ ** used by the pager and its associated cache. */ int sqlite3PagerMemUsed(Pager *pPager){ - int perPageSize = pPager->pageSize + pPager->nExtra + 20; + int perPageSize = pPager->pageSize + pPager->nExtra + sizeof(PgHdr) + + 5*sizeof(void*); return perPageSize*sqlite3PcachePagecount(pPager->pPCache) - + sqlite3MallocSize(pPager); + + sqlite3MallocSize(pPager) + + (pPager->pTmpSpace ? pPager->pageSize : 0); } /* diff --git a/src/shell.c b/src/shell.c index 0c6c909f4f..c5aa40cf29 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1021,7 +1021,7 @@ static int display_stats( fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset); - fprintf(pArg->out, "Pcache Heap Usage: %d bytes\n", iCur); + fprintf(pArg->out, "Pager Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur);