]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a problem with auto-vacuum databases and the VACUUM command. Also add "pages...
authordanielk1977 <danielk1977@noemail.net>
Sat, 8 Jan 2005 12:42:39 +0000 (12:42 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Sat, 8 Jan 2005 12:42:39 +0000 (12:42 +0000)
FossilOrigin-Name: fb3bf68d0e83b463c7e2f95b4502ba6f8158c074

manifest
manifest.uuid
src/btree.c
src/pager.c
src/test3.c
src/vacuum.c

index 86632c6ab25f4a21db0a679cb1a50e742e3ada5e..35ba70a730220f3cf2ef22e6dd4de38e48cdadda 100644 (file)
--- a/manifest
+++ b/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)
-D 2005-01-08T02:35:44
+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-08T12:42:39
 F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -29,7 +29,7 @@ F sqlite3.def dbaeb20c153e1d366e8f421b55a573f5dfc00863
 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
 F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
 F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
-F src/btree.c 8cab7c66c822ae9c37c59a923ffec81927583ee2
+F src/btree.c 1f069c10b99cce7ad8942b7b2f584883720a0a60
 F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
 F src/build.c af1296e8a21a406b4f4c4f1e1365e075071219f3
 F src/cursor.c f883813759742068890b1f699335872bfa8fdf41
@@ -53,7 +53,7 @@ F src/os_unix.c f3835451ffa69072ea88f30cfd6f3ed12b728cfa
 F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
 F src/os_win.c 39525c414e57ca3f18d860d40d6d38df85689522
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c 7b4dc9a94228efde924f1d9f4b7751f332da4587
+F src/pager.c 4a14410a4e67173bb121a919c7f2033b93822186
 F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
 F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1
 F src/pragma.c 0394f9361a497b7f74c1e5909bfc95a1f5bf0ce4
@@ -67,7 +67,7 @@ F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
 F src/tclsqlite.c 3a4044ef609565c8cc51e887d8b96933ba9f3b5c
 F src/test1.c b7d94c54e58f95452387a5cabdf98b2be8059f29
 F src/test2.c b11fa244fff02190707dd0879987c37c75e61fc8
-F src/test3.c 6f1ec93e13632a004b527049535079eda84c459d
+F src/test3.c 11082b094eb42b3f9a9d5f4e77b6d98aeb2f00b1
 F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df
 F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
 F src/tokenize.c 2ad3d1ae1a0a70746db0b31a0a74f58050a3c39a
@@ -75,7 +75,7 @@ F src/trigger.c 98f3b07c08ba01b34cff139ef9687883d325ae8e
 F src/update.c 0979397c41ac29c54fe0cc687a356d8629a633af
 F src/utf.c e45ce11be6922408cd381561721f6cca7d3b992a
 F src/util.c 29f43c4a7b9ff29302f7899f793be6836b6cd7f9
-F src/vacuum.c 705256e1111521fa04f0029de7f1667bc131d015
+F src/vacuum.c 1a9db113a027461daaf44724c71dd1ebbd064203
 F src/vdbe.c 789e3c986ff311ca371adaad24baa65e42e0b029
 F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
 F src/vdbeInt.h 0f74561e629af86172de7cdf0ecaea014c51696c
@@ -263,7 +263,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
-P 7373a5d4cf2db921b33132c736ad62ab702d7cde
-R 1374ed5b4e2bf48f719639e9351d8142
+P 5023b1dba2e61bb10d1b488874e3d3eea3973145
+R 828efbbcb9553b519fed802fb45be0b6
 U danielk1977
-Z 60af24b70074f0ad63b6e618315bdcee
+Z 4ff88f42ddcc62731dabe33ae1df2dc7
index 03b35d720d2dfd0e415f3b9f419032640a646e4b..a84977b828ad0f5ef2dc50083323267c1a555666 100644 (file)
@@ -1 +1 @@
-5023b1dba2e61bb10d1b488874e3d3eea3973145
\ No newline at end of file
+fb3bf68d0e83b463c7e2f95b4502ba6f8158c074
\ No newline at end of file
index 71185701d8cb07338126cb46ccc09a910539a51a..30db93f0b9907c3d1868834b1a73d6a9250d0423 100644 (file)
@@ -9,7 +9,7 @@
 **    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.
 ** For a detailed discussion of BTrees, refer to
@@ -4487,6 +4487,7 @@ int sqlite3BtreeCreateTable(Btree *pBt, int *piTable, int flags){
       pRoot = pPageMove;
     } 
 
+    /* Update the pointer-map and meta-data with the new root-page number. */
     rc = ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0);
     if( rc ){
       releasePage(pRoot);
@@ -4497,6 +4498,7 @@ int sqlite3BtreeCreateTable(Btree *pBt, int *piTable, int flags){
       releasePage(pRoot);
       return rc;
     }
+
   }else{
     rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0);
     if( rc ) return rc;
index 22e3ec39c95f5bdc5a8665d1270293806000b3ed..c59e3a8de3921d6ba23e57a960c602a84da49eea 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** 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 "os.h"
@@ -244,6 +244,7 @@ struct Pager {
   int nRef;                   /* Number of in-memory pages with PgHdr.nRef>0 */
   int mxPage;                 /* Maximum number of pages to hold in cache */
   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 *pCodecArg;            /* First argument to xCodec() */
   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);
       rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize);
       CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
+      pPager->nWrite++;
     }
 #ifndef NDEBUG
     else{
@@ -2350,6 +2352,8 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
         }else{
           memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
         }
+      }else{
+        pPager->nRead++;
       }
     }
   }else{
@@ -3006,7 +3010,7 @@ int sqlite3pager_isreadonly(Pager *pPager){
 ** This routine is used for testing and analysis only.
 */
 int *sqlite3pager_stats(Pager *pPager){
-  static int a[9];
+  static int a[11];
   a[0] = pPager->nRef;
   a[1] = pPager->nPage;
   a[2] = pPager->mxPage;
@@ -3016,6 +3020,8 @@ int *sqlite3pager_stats(Pager *pPager){
   a[6] = pPager->nHit;
   a[7] = pPager->nMiss;
   a[8] = pPager->nOvfl;
+  a[9] = pPager->nRead;
+  a[10] = pPager->nWrite;
   return a;
 }
 
index 0ffcf93262fbe0a29490f0cf256a3d266e056c90..2e9b7fe95a5fa06c17c0cc7b57426625df0f599b 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** 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 "pager.h"
@@ -514,10 +514,10 @@ static int btree_pager_stats(
   }
   pBt = sqlite3TextToPtr(argv[1]);
   a = sqlite3pager_stats(sqlite3BtreePager(pBt));
-  for(i=0; i<9; i++){
+  for(i=0; i<11; i++){
     static char *zName[] = {
       "ref", "page", "max", "size", "state", "err",
-      "hit", "miss", "ovfl",
+      "hit", "miss", "ovfl", "read", "write"
     };
     char zBuf[100];
     Tcl_AppendElement(interp, zName[i]);
@@ -1320,6 +1320,45 @@ static int btree_varint_test(
   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.
 */
@@ -1366,6 +1405,7 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
      { "btree_begin_statement",    (Tcl_CmdProc*)btree_begin_statement    },
      { "btree_commit_statement",   (Tcl_CmdProc*)btree_commit_statement   },
      { "btree_rollback_statement", (Tcl_CmdProc*)btree_rollback_statement },
+     { "btree_from_db",            (Tcl_CmdProc*)btree_from_db            },
   };
   int i;
 
index 62fabfb4b5a6710fd085579ca48a9af328b1378f..9531fc72c43720d86ca1bdf179ccf82fbf28597f 100644 (file)
@@ -14,7 +14,7 @@
 ** Most of the code in this file may be omitted by defining the
 ** 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 "os.h"
@@ -166,6 +166,10 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   assert( sqlite3BtreeGetPageSize(pTemp)==sqlite3BtreeGetPageSize(pMain) );
   execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
 
+#ifndef SQLITE_OMIT_AUTOVACUUM
+  sqlite3BtreeSetAutoVacuum(pTemp, sqlite3BtreeGetAutoVacuum(pMain));
+#endif
+
   /* Begin a transaction */
   rc = execSql(db, "BEGIN;");
   if( rc!=SQLITE_OK ) goto end_of_vacuum;