mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Make auto-vacuum a run-time option (default determined by SQLITE_DEFAULT_AUTOVACUUM macro). (CVS 2067)
FossilOrigin-Name: b9d5f007fc32d4f471e0e11cc4baadb100612878
This commit is contained in:
18
manifest
18
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Auto-vacuum\sbug:\sDon't\sset\smeta(3)\sto\sa\spointer-map\spage\snumber\swhen\sdeleting\sa\stable.\s(CVS\s2066)
|
C Make\sauto-vacuum\sa\srun-time\soption\s(default\sdetermined\sby\sSQLITE_DEFAULT_AUTOVACUUM\smacro).\s(CVS\s2067)
|
||||||
D 2004-11-05T12:58:25
|
D 2004-11-05T15:45:10
|
||||||
F Makefile.in c4d2416860f472a1e3393714d0372074197565df
|
F Makefile.in c4d2416860f472a1e3393714d0372074197565df
|
||||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||||
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
||||||
@@ -29,8 +29,8 @@ 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 6a61345b550be1040b208c5191911676fd9fee72
|
F src/btree.c 9ca965e9fbb28fb567cd76fe2a3cec1a161ad5ba
|
||||||
F src/btree.h 3166388fa58c5594d8064d38b43440d79da38fb6
|
F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
|
||||||
F src/build.c dc8b9ab836f2323d9b313c2d703b00b2e9441382
|
F src/build.c dc8b9ab836f2323d9b313c2d703b00b2e9441382
|
||||||
F src/date.c 34bdb0082db7ec2a83ef00063f7b44e61ee19dad
|
F src/date.c 34bdb0082db7ec2a83ef00063f7b44e61ee19dad
|
||||||
F src/delete.c 6a54fd9f0fa6b93e13e40368a8b7206e3aae760c
|
F src/delete.c 6a54fd9f0fa6b93e13e40368a8b7206e3aae760c
|
||||||
@@ -55,7 +55,7 @@ F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
|
|||||||
F src/pager.c a43e2a392be51966129e9afb18b81551c9f222b8
|
F src/pager.c a43e2a392be51966129e9afb18b81551c9f222b8
|
||||||
F src/pager.h cbe4ba356d9dd3f30260f322b3dc77408164df14
|
F src/pager.h cbe4ba356d9dd3f30260f322b3dc77408164df14
|
||||||
F src/parse.y 97247c0a89ca1667729db5035f1ee60140960984
|
F src/parse.y 97247c0a89ca1667729db5035f1ee60140960984
|
||||||
F src/pragma.c 44e192eb5928157bdb015926f858a7c6e3ef6c98
|
F src/pragma.c 6a0ae7721e614c5a921e918ab5206d5e654f1a6f
|
||||||
F src/printf.c 7a92adc00b758cd5ce087dae80181a8bbdb70ed2
|
F src/printf.c 7a92adc00b758cd5ce087dae80181a8bbdb70ed2
|
||||||
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
||||||
F src/select.c 156990c636102bb6b8de85e7ff3396a62568476b
|
F src/select.c 156990c636102bb6b8de85e7ff3396a62568476b
|
||||||
@@ -87,7 +87,7 @@ F test/attach.test e305dd59a375e37c658c6d401f19f8a95880bf9a
|
|||||||
F test/attach2.test 399128a7b3b209a339a8dbf53ca2ed42eb982d1a
|
F test/attach2.test 399128a7b3b209a339a8dbf53ca2ed42eb982d1a
|
||||||
F test/attach3.test 287af46653e7435b2d1eda10d8115dcc8a6883e2
|
F test/attach3.test 287af46653e7435b2d1eda10d8115dcc8a6883e2
|
||||||
F test/auth.test 1cc252d9e7b3bdc1314199cbf3a0d3c5ed026c21
|
F test/auth.test 1cc252d9e7b3bdc1314199cbf3a0d3c5ed026c21
|
||||||
F test/autovacuum.test 7878efa67268228299ed3759694bb43795b9ffa0
|
F test/autovacuum.test e70d46d598aa4146a3069d830ec8002e384bebbc
|
||||||
F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f
|
F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f
|
||||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||||
F test/bind.test fa74f98417cd313f28272acff832a8a7d04a0916
|
F test/bind.test fa74f98417cd313f28272acff832a8a7d04a0916
|
||||||
@@ -252,7 +252,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
|
|||||||
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
||||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||||
F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c
|
F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c
|
||||||
P 4e2433378e06210f0274c317c6d12b48236211fe
|
P 44a015b3a3bbecc4ec1e02bb371d3274e2b6edf3
|
||||||
R 26dd7f873a531a66e4d8d063a7f19d9e
|
R fba5273e743f06f619fdf4a2b5c9b7df
|
||||||
U danielk1977
|
U danielk1977
|
||||||
Z 498d47c900b187710dd7df26608c1fd2
|
Z 243e31232ec02903a39e127ae0fea404
|
||||||
|
@@ -1 +1 @@
|
|||||||
44a015b3a3bbecc4ec1e02bb371d3274e2b6edf3
|
b9d5f007fc32d4f471e0e11cc4baadb100612878
|
45
src/btree.c
45
src/btree.c
@@ -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.209 2004/11/05 12:58:25 danielk1977 Exp $
|
** $Id: btree.c,v 1.210 2004/11/05 15:45:10 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
|
||||||
@@ -1192,6 +1192,9 @@ int sqlite3BtreeOpen(
|
|||||||
pBt->maxEmbedFrac = 64; /* 25% */
|
pBt->maxEmbedFrac = 64; /* 25% */
|
||||||
pBt->minEmbedFrac = 32; /* 12.5% */
|
pBt->minEmbedFrac = 32; /* 12.5% */
|
||||||
pBt->minLeafFrac = 32; /* 12.5% */
|
pBt->minLeafFrac = 32; /* 12.5% */
|
||||||
|
if( zFilename && strcmp(zFilename,":memory:") ){
|
||||||
|
pBt->autoVacuum = SQLITE_DEFAULT_AUTOVACUUM;
|
||||||
|
}
|
||||||
nReserve = 0;
|
nReserve = 0;
|
||||||
}else{
|
}else{
|
||||||
nReserve = zDbHeader[20];
|
nReserve = zDbHeader[20];
|
||||||
@@ -1199,17 +1202,14 @@ int sqlite3BtreeOpen(
|
|||||||
pBt->minEmbedFrac = zDbHeader[22];
|
pBt->minEmbedFrac = zDbHeader[22];
|
||||||
pBt->minLeafFrac = zDbHeader[23];
|
pBt->minLeafFrac = zDbHeader[23];
|
||||||
pBt->pageSizeFixed = 1;
|
pBt->pageSizeFixed = 1;
|
||||||
|
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||||
|
pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
pBt->usableSize = pBt->pageSize - nReserve;
|
pBt->usableSize = pBt->pageSize - nReserve;
|
||||||
pBt->psAligned = FORCE_ALIGNMENT(pBt->pageSize);
|
pBt->psAligned = FORCE_ALIGNMENT(pBt->pageSize);
|
||||||
sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize);
|
sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize);
|
||||||
*ppBtree = pBt;
|
*ppBtree = pBt;
|
||||||
#ifdef SQLITE_AUTOVACUUM
|
|
||||||
/* Note: This is temporary code for use during development of auto-vacuum. */
|
|
||||||
if( zFilename && 0!=strcmp(zFilename, ":memory:") ){
|
|
||||||
pBt->autoVacuum = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1305,6 +1305,37 @@ int sqlite3BtreeGetReserve(Btree *pBt){
|
|||||||
return pBt->pageSize - pBt->usableSize;
|
return pBt->pageSize - pBt->usableSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
|
||||||
|
** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
|
||||||
|
** is disabled. The default value for the auto-vacuum property is
|
||||||
|
** determined by the SQLITE_DEFAULT_AUTOVACUUM macro.
|
||||||
|
*/
|
||||||
|
int sqlite3BtreeSetAutoVacuum(Btree *pBt, int autoVacuum){
|
||||||
|
#ifdef SQLITE_OMIT_AUTOVACUUM
|
||||||
|
return SQLITE_READONLY
|
||||||
|
#else
|
||||||
|
if( pBt->pageSizeFixed ){
|
||||||
|
return SQLITE_READONLY;
|
||||||
|
}
|
||||||
|
pBt->autoVacuum = (autoVacuum?1:0);
|
||||||
|
return SQLITE_OK;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Return the value of the 'auto-vacuum' property. If auto-vacuum is
|
||||||
|
** enabled 1 is returned. Otherwise 0.
|
||||||
|
*/
|
||||||
|
int sqlite3BtreeGetAutoVacuum(Btree *pBt){
|
||||||
|
#ifdef SQLITE_OMIT_AUTOVACUUM
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return pBt->autoVacuum;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Get a reference to pPage1 of the database file. This will
|
** Get a reference to pPage1 of the database file. This will
|
||||||
** also acquire a readlock on that file.
|
** also acquire a readlock on that file.
|
||||||
|
12
src/btree.h
12
src/btree.h
@@ -13,7 +13,7 @@
|
|||||||
** subsystem. See comments in the source code for a detailed description
|
** subsystem. See comments in the source code for a detailed description
|
||||||
** of what each interface routine does.
|
** of what each interface routine does.
|
||||||
**
|
**
|
||||||
** @(#) $Id: btree.h,v 1.59 2004/11/04 14:30:05 danielk1977 Exp $
|
** @(#) $Id: btree.h,v 1.60 2004/11/05 15:45:10 danielk1977 Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef _BTREE_H_
|
#ifndef _BTREE_H_
|
||||||
#define _BTREE_H_
|
#define _BTREE_H_
|
||||||
@@ -23,6 +23,14 @@
|
|||||||
*/
|
*/
|
||||||
#define SQLITE_N_BTREE_META 10
|
#define SQLITE_N_BTREE_META 10
|
||||||
|
|
||||||
|
/*
|
||||||
|
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
|
||||||
|
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
|
||||||
|
*/
|
||||||
|
#ifndef SQLITE_DEFAULT_AUTOVACUUM
|
||||||
|
#define SQLITE_DEFAULT_AUTOVACUUM 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Forward declarations of structure
|
** Forward declarations of structure
|
||||||
*/
|
*/
|
||||||
@@ -49,6 +57,8 @@ int sqlite3BtreeSetSafetyLevel(Btree*,int);
|
|||||||
int sqlite3BtreeSetPageSize(Btree*,int,int);
|
int sqlite3BtreeSetPageSize(Btree*,int,int);
|
||||||
int sqlite3BtreeGetPageSize(Btree*);
|
int sqlite3BtreeGetPageSize(Btree*);
|
||||||
int sqlite3BtreeGetReserve(Btree*);
|
int sqlite3BtreeGetReserve(Btree*);
|
||||||
|
int sqlite3BtreeSetAutoVacuum(Btree *, int);
|
||||||
|
int sqlite3BtreeGetAutoVacuum(Btree *);
|
||||||
int sqlite3BtreeBeginTrans(Btree*,int);
|
int sqlite3BtreeBeginTrans(Btree*,int);
|
||||||
int sqlite3BtreeCommit(Btree*);
|
int sqlite3BtreeCommit(Btree*);
|
||||||
int sqlite3BtreeRollback(Btree*);
|
int sqlite3BtreeRollback(Btree*);
|
||||||
|
21
src/pragma.c
21
src/pragma.c
@@ -11,7 +11,7 @@
|
|||||||
*************************************************************************
|
*************************************************************************
|
||||||
** This file contains code used to implement the PRAGMA command.
|
** This file contains code used to implement the PRAGMA command.
|
||||||
**
|
**
|
||||||
** $Id: pragma.c,v 1.73 2004/10/31 02:22:49 drh Exp $
|
** $Id: pragma.c,v 1.74 2004/11/05 15:45:11 danielk1977 Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -271,6 +271,25 @@ void sqlite3Pragma(
|
|||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
|
|
||||||
|
/*
|
||||||
|
** PRAGMA [database.]auto_vacuum
|
||||||
|
** PRAGMA [database.]auto_vacuum=N
|
||||||
|
**
|
||||||
|
** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
|
||||||
|
*/
|
||||||
|
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||||
|
if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
|
||||||
|
Btree *pBt = pDb->pBt;
|
||||||
|
if( !zRight ){
|
||||||
|
int auto_vacuum =
|
||||||
|
pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
|
||||||
|
returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
|
||||||
|
}else{
|
||||||
|
sqlite3BtreeSetAutoVacuum(pBt, getBoolean(zRight));
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** PRAGMA [database.]cache_size
|
** PRAGMA [database.]cache_size
|
||||||
** PRAGMA [database.]cache_size=N
|
** PRAGMA [database.]cache_size=N
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
# This file implements regression tests for SQLite library. The
|
# This file implements regression tests for SQLite library. The
|
||||||
# focus of this file is testing the SELECT statement.
|
# focus of this file is testing the SELECT statement.
|
||||||
#
|
#
|
||||||
# $Id: autovacuum.test,v 1.8 2004/11/05 12:58:26 danielk1977 Exp $
|
# $Id: autovacuum.test,v 1.9 2004/11/05 15:45:11 danielk1977 Exp $
|
||||||
|
|
||||||
set testdir [file dirname $argv0]
|
set testdir [file dirname $argv0]
|
||||||
source $testdir/tester.tcl
|
source $testdir/tester.tcl
|
||||||
@@ -28,6 +28,7 @@ proc file_pages {} {
|
|||||||
return [expr [file size test.db] / 1024]
|
return [expr [file size test.db] / 1024]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
# Test cases autovacuum-1.* work as follows:
|
# Test cases autovacuum-1.* work as follows:
|
||||||
#
|
#
|
||||||
# 1. A table with a single indexed field is created.
|
# 1. A table with a single indexed field is created.
|
||||||
@@ -56,6 +57,7 @@ set ENTRY_LEN 3500
|
|||||||
|
|
||||||
do_test autovacuum-1.1 {
|
do_test autovacuum-1.1 {
|
||||||
execsql {
|
execsql {
|
||||||
|
PRAGMA auto_vacuum = 1;
|
||||||
CREATE TABLE av1(a);
|
CREATE TABLE av1(a);
|
||||||
CREATE INDEX av1_idx ON av1(a);
|
CREATE INDEX av1_idx ON av1(a);
|
||||||
}
|
}
|
||||||
@@ -113,6 +115,7 @@ foreach delete_order $delete_orders {
|
|||||||
} {4}
|
} {4}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
# Tests cases autovacuum-2.* test that root pages are allocated
|
# Tests cases autovacuum-2.* test that root pages are allocated
|
||||||
# and deallocated correctly at the start of the file. Operation is roughly as
|
# and deallocated correctly at the start of the file. Operation is roughly as
|
||||||
# follows:
|
# follows:
|
||||||
@@ -290,5 +293,55 @@ do_test autovacuum-2.4.7 {
|
|||||||
file_pages
|
file_pages
|
||||||
} 1
|
} 1
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
# Test cases autovacuum-3.* test the operation of the "PRAGMA auto_vacuum"
|
||||||
|
# command.
|
||||||
|
#
|
||||||
|
do_test autovacuum-3.1 {
|
||||||
|
execsql {
|
||||||
|
PRAGMA auto_vacuum;
|
||||||
|
}
|
||||||
|
} {1}
|
||||||
|
do_test autovacuum-3.2 {
|
||||||
|
db close
|
||||||
|
sqlite3 db test.db
|
||||||
|
execsql {
|
||||||
|
PRAGMA auto_vacuum;
|
||||||
|
}
|
||||||
|
} {1}
|
||||||
|
do_test autovacuum-3.3 {
|
||||||
|
execsql {
|
||||||
|
PRAGMA auto_vacuum = 0;
|
||||||
|
PRAGMA auto_vacuum;
|
||||||
|
}
|
||||||
|
} {1}
|
||||||
|
|
||||||
|
do_test autovacuum-3.4 {
|
||||||
|
db close
|
||||||
|
file delete -force test.db
|
||||||
|
sqlite3 db test.db
|
||||||
|
execsql {
|
||||||
|
PRAGMA auto_vacuum;
|
||||||
|
}
|
||||||
|
} {0}
|
||||||
|
do_test autovacuum-3.5 {
|
||||||
|
execsql {
|
||||||
|
CREATE TABLE av1(x);
|
||||||
|
PRAGMA auto_vacuum;
|
||||||
|
}
|
||||||
|
} {0}
|
||||||
|
do_test autovacuum-3.6 {
|
||||||
|
execsql {
|
||||||
|
PRAGMA auto_vacuum = 1;
|
||||||
|
PRAGMA auto_vacuum;
|
||||||
|
}
|
||||||
|
} {0}
|
||||||
|
do_test autovacuum-3.7 {
|
||||||
|
execsql {
|
||||||
|
DROP TABLE av1;
|
||||||
|
}
|
||||||
|
file_pages
|
||||||
|
} {2}
|
||||||
|
|
||||||
finish_test
|
finish_test
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user