mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Fix a problem with auto-vacuum databases and the VACUUM command. Also add "pages read" and "pages written" statistics to the pager layer. (CVS 2183)
FossilOrigin-Name: fb3bf68d0e83b463c7e2f95b4502ba6f8158c074
This commit is contained in:
18
manifest
18
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Minor\stest\sscript\schanges\sto\sallow\sall.test\sto\srun\swhen\sSQLITE_DEFAULT_AUTOVACUUM=1\sis\sdefined.\s(CVS\s2182)
|
C Fix\sa\sproblem\swith\sauto-vacuum\sdatabases\sand\sthe\sVACUUM\scommand.\sAlso\sadd\s"pages\sread"\sand\s"pages\swritten"\sstatistics\sto\sthe\spager\slayer.\s(CVS\s2183)
|
||||||
D 2005-01-08T02:35:44
|
D 2005-01-08T12:42:39
|
||||||
F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
|
F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
|
||||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||||
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
||||||
@@ -29,7 +29,7 @@ F sqlite3.def dbaeb20c153e1d366e8f421b55a573f5dfc00863
|
|||||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||||
F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
|
F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
|
||||||
F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
|
F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
|
||||||
F src/btree.c 8cab7c66c822ae9c37c59a923ffec81927583ee2
|
F src/btree.c 1f069c10b99cce7ad8942b7b2f584883720a0a60
|
||||||
F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
|
F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
|
||||||
F src/build.c af1296e8a21a406b4f4c4f1e1365e075071219f3
|
F src/build.c af1296e8a21a406b4f4c4f1e1365e075071219f3
|
||||||
F src/cursor.c f883813759742068890b1f699335872bfa8fdf41
|
F src/cursor.c f883813759742068890b1f699335872bfa8fdf41
|
||||||
@@ -53,7 +53,7 @@ F src/os_unix.c f3835451ffa69072ea88f30cfd6f3ed12b728cfa
|
|||||||
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
|
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
|
||||||
F src/os_win.c 39525c414e57ca3f18d860d40d6d38df85689522
|
F src/os_win.c 39525c414e57ca3f18d860d40d6d38df85689522
|
||||||
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
|
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
|
||||||
F src/pager.c 7b4dc9a94228efde924f1d9f4b7751f332da4587
|
F src/pager.c 4a14410a4e67173bb121a919c7f2033b93822186
|
||||||
F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
|
F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
|
||||||
F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1
|
F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1
|
||||||
F src/pragma.c 0394f9361a497b7f74c1e5909bfc95a1f5bf0ce4
|
F src/pragma.c 0394f9361a497b7f74c1e5909bfc95a1f5bf0ce4
|
||||||
@@ -67,7 +67,7 @@ F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
|
|||||||
F src/tclsqlite.c 3a4044ef609565c8cc51e887d8b96933ba9f3b5c
|
F src/tclsqlite.c 3a4044ef609565c8cc51e887d8b96933ba9f3b5c
|
||||||
F src/test1.c b7d94c54e58f95452387a5cabdf98b2be8059f29
|
F src/test1.c b7d94c54e58f95452387a5cabdf98b2be8059f29
|
||||||
F src/test2.c b11fa244fff02190707dd0879987c37c75e61fc8
|
F src/test2.c b11fa244fff02190707dd0879987c37c75e61fc8
|
||||||
F src/test3.c 6f1ec93e13632a004b527049535079eda84c459d
|
F src/test3.c 11082b094eb42b3f9a9d5f4e77b6d98aeb2f00b1
|
||||||
F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df
|
F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df
|
||||||
F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
|
F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
|
||||||
F src/tokenize.c 2ad3d1ae1a0a70746db0b31a0a74f58050a3c39a
|
F src/tokenize.c 2ad3d1ae1a0a70746db0b31a0a74f58050a3c39a
|
||||||
@@ -75,7 +75,7 @@ F src/trigger.c 98f3b07c08ba01b34cff139ef9687883d325ae8e
|
|||||||
F src/update.c 0979397c41ac29c54fe0cc687a356d8629a633af
|
F src/update.c 0979397c41ac29c54fe0cc687a356d8629a633af
|
||||||
F src/utf.c e45ce11be6922408cd381561721f6cca7d3b992a
|
F src/utf.c e45ce11be6922408cd381561721f6cca7d3b992a
|
||||||
F src/util.c 29f43c4a7b9ff29302f7899f793be6836b6cd7f9
|
F src/util.c 29f43c4a7b9ff29302f7899f793be6836b6cd7f9
|
||||||
F src/vacuum.c 705256e1111521fa04f0029de7f1667bc131d015
|
F src/vacuum.c 1a9db113a027461daaf44724c71dd1ebbd064203
|
||||||
F src/vdbe.c 789e3c986ff311ca371adaad24baa65e42e0b029
|
F src/vdbe.c 789e3c986ff311ca371adaad24baa65e42e0b029
|
||||||
F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
|
F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
|
||||||
F src/vdbeInt.h 0f74561e629af86172de7cdf0ecaea014c51696c
|
F src/vdbeInt.h 0f74561e629af86172de7cdf0ecaea014c51696c
|
||||||
@@ -263,7 +263,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
|
|||||||
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
|
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
|
||||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||||
F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
|
F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
|
||||||
P 7373a5d4cf2db921b33132c736ad62ab702d7cde
|
P 5023b1dba2e61bb10d1b488874e3d3eea3973145
|
||||||
R 1374ed5b4e2bf48f719639e9351d8142
|
R 828efbbcb9553b519fed802fb45be0b6
|
||||||
U danielk1977
|
U danielk1977
|
||||||
Z 60af24b70074f0ad63b6e618315bdcee
|
Z 4ff88f42ddcc62731dabe33ae1df2dc7
|
||||||
|
@@ -1 +1 @@
|
|||||||
5023b1dba2e61bb10d1b488874e3d3eea3973145
|
fb3bf68d0e83b463c7e2f95b4502ba6f8158c074
|
@@ -9,7 +9,7 @@
|
|||||||
** May you share freely, never taking more than you give.
|
** May you share freely, never taking more than you give.
|
||||||
**
|
**
|
||||||
*************************************************************************
|
*************************************************************************
|
||||||
** $Id: btree.c,v 1.226 2005/01/07 08:56:44 danielk1977 Exp $
|
** $Id: btree.c,v 1.227 2005/01/08 12:42:39 danielk1977 Exp $
|
||||||
**
|
**
|
||||||
** This file implements a external (disk-based) database using BTrees.
|
** This file implements a external (disk-based) database using BTrees.
|
||||||
** For a detailed discussion of BTrees, refer to
|
** For a detailed discussion of BTrees, refer to
|
||||||
@@ -4487,6 +4487,7 @@ int sqlite3BtreeCreateTable(Btree *pBt, int *piTable, int flags){
|
|||||||
pRoot = pPageMove;
|
pRoot = pPageMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update the pointer-map and meta-data with the new root-page number. */
|
||||||
rc = ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0);
|
rc = ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0);
|
||||||
if( rc ){
|
if( rc ){
|
||||||
releasePage(pRoot);
|
releasePage(pRoot);
|
||||||
@@ -4497,6 +4498,7 @@ int sqlite3BtreeCreateTable(Btree *pBt, int *piTable, int flags){
|
|||||||
releasePage(pRoot);
|
releasePage(pRoot);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0);
|
rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
|
10
src/pager.c
10
src/pager.c
@@ -18,7 +18,7 @@
|
|||||||
** file simultaneously, or one process from reading the database while
|
** file simultaneously, or one process from reading the database while
|
||||||
** another is writing.
|
** another is writing.
|
||||||
**
|
**
|
||||||
** @(#) $Id: pager.c,v 1.179 2004/11/24 01:16:43 drh Exp $
|
** @(#) $Id: pager.c,v 1.180 2005/01/08 12:42:39 danielk1977 Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@@ -244,6 +244,7 @@ struct Pager {
|
|||||||
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
|
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
|
||||||
int mxPage; /* Maximum number of pages to hold in cache */
|
int mxPage; /* Maximum number of pages to hold in cache */
|
||||||
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
|
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
|
||||||
|
int nRead,nWrite; /* Database pages read/written */
|
||||||
void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
|
void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
|
||||||
void *pCodecArg; /* First argument to xCodec() */
|
void *pCodecArg; /* First argument to xCodec() */
|
||||||
u8 journalOpen; /* True if journal file descriptors is valid */
|
u8 journalOpen; /* True if journal file descriptors is valid */
|
||||||
@@ -2067,6 +2068,7 @@ static int pager_write_pagelist(PgHdr *pList){
|
|||||||
TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
|
TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
|
||||||
rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize);
|
rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize);
|
||||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
|
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
|
||||||
|
pPager->nWrite++;
|
||||||
}
|
}
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
else{
|
else{
|
||||||
@@ -2350,6 +2352,8 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
|||||||
}else{
|
}else{
|
||||||
memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
|
memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
pPager->nRead++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -3006,7 +3010,7 @@ int sqlite3pager_isreadonly(Pager *pPager){
|
|||||||
** This routine is used for testing and analysis only.
|
** This routine is used for testing and analysis only.
|
||||||
*/
|
*/
|
||||||
int *sqlite3pager_stats(Pager *pPager){
|
int *sqlite3pager_stats(Pager *pPager){
|
||||||
static int a[9];
|
static int a[11];
|
||||||
a[0] = pPager->nRef;
|
a[0] = pPager->nRef;
|
||||||
a[1] = pPager->nPage;
|
a[1] = pPager->nPage;
|
||||||
a[2] = pPager->mxPage;
|
a[2] = pPager->mxPage;
|
||||||
@@ -3016,6 +3020,8 @@ int *sqlite3pager_stats(Pager *pPager){
|
|||||||
a[6] = pPager->nHit;
|
a[6] = pPager->nHit;
|
||||||
a[7] = pPager->nMiss;
|
a[7] = pPager->nMiss;
|
||||||
a[8] = pPager->nOvfl;
|
a[8] = pPager->nOvfl;
|
||||||
|
a[9] = pPager->nRead;
|
||||||
|
a[10] = pPager->nWrite;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
46
src/test3.c
46
src/test3.c
@@ -13,7 +13,7 @@
|
|||||||
** is not included in the SQLite library. It is used for automated
|
** is not included in the SQLite library. It is used for automated
|
||||||
** testing of the SQLite library.
|
** testing of the SQLite library.
|
||||||
**
|
**
|
||||||
** $Id: test3.c,v 1.57 2004/11/10 11:55:12 danielk1977 Exp $
|
** $Id: test3.c,v 1.58 2005/01/08 12:42:39 danielk1977 Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
@@ -514,10 +514,10 @@ static int btree_pager_stats(
|
|||||||
}
|
}
|
||||||
pBt = sqlite3TextToPtr(argv[1]);
|
pBt = sqlite3TextToPtr(argv[1]);
|
||||||
a = sqlite3pager_stats(sqlite3BtreePager(pBt));
|
a = sqlite3pager_stats(sqlite3BtreePager(pBt));
|
||||||
for(i=0; i<9; i++){
|
for(i=0; i<11; i++){
|
||||||
static char *zName[] = {
|
static char *zName[] = {
|
||||||
"ref", "page", "max", "size", "state", "err",
|
"ref", "page", "max", "size", "state", "err",
|
||||||
"hit", "miss", "ovfl",
|
"hit", "miss", "ovfl", "read", "write"
|
||||||
};
|
};
|
||||||
char zBuf[100];
|
char zBuf[100];
|
||||||
Tcl_AppendElement(interp, zName[i]);
|
Tcl_AppendElement(interp, zName[i]);
|
||||||
@@ -1320,6 +1320,45 @@ static int btree_varint_test(
|
|||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** usage: btree_from_db DB-HANDLE
|
||||||
|
**
|
||||||
|
** This command returns the btree handle for the main database associated
|
||||||
|
** with the database-handle passed as the argument. Example usage:
|
||||||
|
**
|
||||||
|
** sqlite3 db test.db
|
||||||
|
** set bt [btree_from_db db]
|
||||||
|
*/
|
||||||
|
static int btree_from_db(
|
||||||
|
void *NotUsed,
|
||||||
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||||
|
int argc, /* Number of arguments */
|
||||||
|
const char **argv /* Text of each argument */
|
||||||
|
){
|
||||||
|
char zBuf[100];
|
||||||
|
Tcl_CmdInfo info;
|
||||||
|
sqlite3 *db;
|
||||||
|
Btree *pBt;
|
||||||
|
|
||||||
|
if( argc!=2 ){
|
||||||
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||||
|
" DB-HANDLE\"", 0);
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( 1!=Tcl_GetCommandInfo(interp, argv[1], &info) ){
|
||||||
|
Tcl_AppendResult(interp, "No such db-handle: \"", argv[1], "\"", 0);
|
||||||
|
return TCL_ERROR;
|
||||||
|
}
|
||||||
|
db = *((sqlite3 **)info.objClientData);
|
||||||
|
assert( db );
|
||||||
|
|
||||||
|
pBt = db->aDb[0].pBt;
|
||||||
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", pBt);
|
||||||
|
Tcl_SetResult(interp, zBuf, TCL_VOLATILE);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Register commands with the TCL interpreter.
|
** Register commands with the TCL interpreter.
|
||||||
*/
|
*/
|
||||||
@@ -1366,6 +1405,7 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
|
|||||||
{ "btree_begin_statement", (Tcl_CmdProc*)btree_begin_statement },
|
{ "btree_begin_statement", (Tcl_CmdProc*)btree_begin_statement },
|
||||||
{ "btree_commit_statement", (Tcl_CmdProc*)btree_commit_statement },
|
{ "btree_commit_statement", (Tcl_CmdProc*)btree_commit_statement },
|
||||||
{ "btree_rollback_statement", (Tcl_CmdProc*)btree_rollback_statement },
|
{ "btree_rollback_statement", (Tcl_CmdProc*)btree_rollback_statement },
|
||||||
|
{ "btree_from_db", (Tcl_CmdProc*)btree_from_db },
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
** Most of the code in this file may be omitted by defining the
|
** Most of the code in this file may be omitted by defining the
|
||||||
** SQLITE_OMIT_VACUUM macro.
|
** SQLITE_OMIT_VACUUM macro.
|
||||||
**
|
**
|
||||||
** $Id: vacuum.c,v 1.35 2004/11/22 13:35:41 danielk1977 Exp $
|
** $Id: vacuum.c,v 1.36 2005/01/08 12:42:40 danielk1977 Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@@ -166,6 +166,10 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
|||||||
assert( sqlite3BtreeGetPageSize(pTemp)==sqlite3BtreeGetPageSize(pMain) );
|
assert( sqlite3BtreeGetPageSize(pTemp)==sqlite3BtreeGetPageSize(pMain) );
|
||||||
execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
||||||
|
|
||||||
|
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||||
|
sqlite3BtreeSetAutoVacuum(pTemp, sqlite3BtreeGetAutoVacuum(pMain));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Begin a transaction */
|
/* Begin a transaction */
|
||||||
rc = execSql(db, "BEGIN;");
|
rc = execSql(db, "BEGIN;");
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||||
|
Reference in New Issue
Block a user