Add the ability to change the autovacuum status of an existing database

by setting the auto_vacuum pragma then running the VACUUM command. (CVS 4592)

FossilOrigin-Name: bdfc19e838b369a8c5d5d23663fad690f55ba3d7
This commit is contained in:
drh 2007-12-05 01:38:23 +00:00
parent 77658e2f0d
commit ddac25c732
7 changed files with 103 additions and 17 deletions

View File

@ -1,5 +1,5 @@
C Make\ssure\sstatement\sjournals\sare\sinitiated\swhen\sdoing\sDROP\soperations\n(since\sthe\sDROP\smight\sfail\safter\ssqlite_master\schanges).\s\sAlso\smake\nsure\sstatement\sjournals\sare\sinitiated\sif\sthere\sare\spending\sSELECT\nstatements.\s\sTicket\s#2820.\s(CVS\s4591)
D 2007-12-04T16:54:53
C Add\sthe\sability\sto\schange\sthe\sautovacuum\sstatus\sof\san\sexisting\sdatabase\nby\ssetting\sthe\sauto_vacuum\spragma\sthen\srunning\sthe\sVACUUM\scommand.\s(CVS\s4592)
D 2007-12-05T01:38:23
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -101,7 +101,7 @@ F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c 124e566563d1c03e68e1396cb44df9870612c6e9
F src/main.c 994a6b6914d91dc6dea5012667ec0a52e74d3bca
F src/main.c 53e71b4d4a0dbc1eb3a73520970973689cabea18
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 6d1a11864963d249c67e72ad5f6533b040333880
@ -127,7 +127,7 @@ F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 65298fee4e815c269fb374d3fe3cd1cf4f05ad94
F src/pager.h f504f7ae84060fee0416a853e368d3d113c3d6fa
F src/parse.y a780b33ef45dd7b3272319cf91e609d6f109a31c
F src/pragma.c cb1486e76dbcad757968afc4083d3472032e62b5
F src/pragma.c 0246032dbe681dded8710ac43eaf654eead1434e
F src/prepare.c f811fdb6fd4a82cca673a6e1d5b041d6caf567f1
F src/printf.c 0d7ad185914c952bfa6235ac8f5f019db5ad37e5
F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
@ -136,7 +136,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c c97be281cfc3dcb14902f45e4b16f20038eb83ff
F src/sqlite.h.in 28e78e9191a655fd2aa728c1f55d35e9f644103a
F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb
F src/sqliteInt.h f5d5b5f0dcfcd2098131c57c08ece6e314e47697
F src/sqliteInt.h a941ccf797b45c27bc0face4e75935b5cc019202
F src/sqliteLimit.h 15ffe2116746c27ace2b428a26a4fcd6dba6fa65
F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
F src/tclsqlite.c 9923abeffc9b3d7dad58e92b319661521f60debf
@ -167,7 +167,7 @@ F src/trigger.c 66695e1375b969ea41a38dec9f40ea28bb0ac767
F src/update.c 2add92a6159fa73128653706574afbcd8fd1dd80
F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624
F src/vacuum.c a5e51c77370c1a6445e86d42abfc43867cdd482d
F src/vacuum.c 25ffbd766f25bca099ead1c1e11f5528c86102b8
F src/vdbe.c a99beac1162fa490c4b75ac36ed97146ab181837
F src/vdbe.h 79e09ff13b85457abe437d9814454534ebbc1fe3
F src/vdbeInt.h 630145b9bfaa19190ab491f52658a7db550f2247
@ -496,7 +496,7 @@ F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
F test/utf16.test 20e2d9ba0d57e952a18b1ac8deab9ad49e082893
F test/utf16align.test 7360e84472095518c56746f76b1f9d4dce99fb4d
F test/vacuum.test cf839fc3ff24d601057319bbb5c700ce9c8e0fb0
F test/vacuum2.test e198d81a1cbc3f3f6b8aeee27cadfffea8995d42
F test/vacuum2.test 5367c04e0968af617b29e51283498dff053d1115
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
F test/view.test 7e15fa1ba3267ddaa9ae96b6daf519f23f95b43e
F test/vtab1.test 3573ad5045c44e8e2d2b6451122bcf2ee2a4f688
@ -597,7 +597,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 7c2cf4542852a81daf29a930ab103c52bb678326
R c111fb18ebb6378f510e950ea7f7ef09
P bf34284ff0c60ae6e735e09bb29cd48b158e8dce
R 268cf574fbaadd8f08b72bad36ab32de
U drh
Z 60a6d3adb97dfb253eaa60aa3a1f2c5c
Z 01b4baedd2f51b7c9bd419e3c44b8fa2

View File

@ -1 +1 @@
bf34284ff0c60ae6e735e09bb29cd48b158e8dce
bdfc19e838b369a8c5d5d23663fad690f55ba3d7

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.407 2007/10/12 19:35:49 drh Exp $
** $Id: main.c,v 1.408 2007/12/05 01:38:23 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -965,6 +965,7 @@ static int openDatabase(
db->magic = SQLITE_MAGIC_BUSY;
db->aDb = db->aDbStatic;
db->autoCommit = 1;
db->nextAutovac = -1;
db->flags |= SQLITE_ShortColNames
#if SQLITE_DEFAULT_FILE_FORMAT<4
| SQLITE_LegacyFileFmt

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.150 2007/11/13 10:30:25 danielk1977 Exp $
** $Id: pragma.c,v 1.151 2007/12/05 01:38:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -440,6 +440,7 @@ void sqlite3Pragma(
returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
}else{
int eAuto = getAutoVacuum(zRight);
db->nextAutovac = eAuto;
if( eAuto>=0 ){
/* Call SetAutoVacuum() to set initialize the internal auto and
** incr-vacuum flags. This is required in case this connection

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.622 2007/11/29 17:05:18 danielk1977 Exp $
** @(#) $Id: sqliteInt.h,v 1.623 2007/12/05 01:38:24 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@ -481,6 +481,7 @@ struct sqlite3 {
u8 autoCommit; /* The auto-commit flag. */
u8 temp_store; /* 1: file 2: memory 0: default */
u8 mallocFailed; /* True if we have seen a malloc failure */
char nextAutovac; /* Autovac setting after VACUUM if >=0 */
int nTable; /* Number of tables in the database */
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
i64 lastRowid; /* ROWID of most recent insert (see above) */

View 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.74 2007/10/20 20:58:57 drh Exp $
** $Id: vacuum.c,v 1.75 2007/12/05 01:38:24 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@ -125,7 +125,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
}
#ifndef SQLITE_OMIT_AUTOVACUUM
sqlite3BtreeSetAutoVacuum(pTemp, sqlite3BtreeGetAutoVacuum(pMain));
sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
sqlite3BtreeGetAutoVacuum(pMain));
#endif
/* Begin a transaction */

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the VACUUM statement.
#
# $Id: vacuum2.test,v 1.3 2007/07/19 16:35:17 drh Exp $
# $Id: vacuum2.test,v 1.4 2007/12/05 01:38:24 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -57,4 +57,86 @@ do_test vacuum2-2.1 {
hexio_get_int [hexio_read test.db 24 4]
} [expr {[hexio_get_int [hexio_read test.db 24 4]]+1}]
############################################################################
# Verify that we can use the auto_vacuum pragma to request a new
# autovacuum setting, do a VACUUM, and the new setting takes effect.
# Make sure this happens correctly even if there are multiple open
# connections to the same database file.
#
sqlite3 db2 test.db
set pageSize [db eval {pragma page_size}]
# Compute a checksum on the content of a database
#
proc cksum {{db db}} {
set sql "SELECT name, type, sql FROM sqlite_master ORDER BY name, type"
set txt [$db eval $sql]\n
set sql "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
foreach tbl [$db eval $sql] {
append txt [$db eval "SELECT * FROM $tbl"]\n
}
foreach prag {default_cache_size} {
append txt $prag-[$db eval "PRAGMA $prag"]\n
}
set cksum [string length $txt]-[md5 $txt]
return $cksum
}
# We are currently not autovacuuming so the database should be 3 pages
# in size. 1 page for each of sqlite_master, t1, and t2.
#
do_test vacuum2-3.1 {
execsql {
INSERT INTO t1 VALUES('hello');
INSERT INTO t2 VALUES('out there');
}
expr {[file size test.db]/$pageSize}
} {3}
set cksum [cksum]
do_test vacuum2-3.2 {
cksum db2
} $cksum
# Convert the database to an autovacuumed database.
do_test vacuum2-3.3 {
execsql {
PRAGMA auto_vacuum=FULL;
VACUUM;
}
expr {[file size test.db]/$pageSize}
} {4}
do_test vacuum2-3.4 {
cksum db2
} $cksum
do_test vacuum2-3.5 {
cksum
} $cksum
do_test vacuum2-3.6 {
execsql {PRAGMA integrity_check} db2
} {ok}
do_test vacuum2-3.7 {
execsql {PRAGMA integrity_check} db
} {ok}
# Convert the database back to a non-autovacuumed database.
do_test vacuum2-3.13 {
execsql {
PRAGMA auto_vacuum=NONE;
VACUUM;
}
expr {[file size test.db]/$pageSize}
} {3}
do_test vacuum2-3.14 {
cksum db2
} $cksum
do_test vacuum2-3.15 {
cksum
} $cksum
do_test vacuum2-3.16 {
execsql {PRAGMA integrity_check} db2
} {ok}
do_test vacuum2-3.17 {
execsql {PRAGMA integrity_check} db
} {ok}
finish_test