mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
The VACUUM command now does a database sanity check. (CVS 364)
FossilOrigin-Name: 95d1f8389dd5e168bdf0290169662296b6a0f6d9
This commit is contained in:
22
manifest
22
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Five-algorithm\sconflict\sresolution\sappears\sto\sbe\sworking.\s(CVS\s363)
|
C The\sVACUUM\scommand\snow\sdoes\sa\sdatabase\ssanity\scheck.\s(CVS\s364)
|
||||||
D 2002-02-03T00:56:10
|
D 2002-02-03T03:34:08
|
||||||
F Makefile.in 9fa4277413bf1d9cf91365f07d4108d7d87ed2af
|
F Makefile.in 9fa4277413bf1d9cf91365f07d4108d7d87ed2af
|
||||||
F Makefile.template 3372d45f8853afdb70bd30cc6fb50a3cd9069834
|
F Makefile.template 3372d45f8853afdb70bd30cc6fb50a3cd9069834
|
||||||
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
|
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
|
||||||
@@ -19,13 +19,13 @@ F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
|
|||||||
F publish.sh 5b59f4aff037aafa0e4a3b6fa599495dbd73f360
|
F publish.sh 5b59f4aff037aafa0e4a3b6fa599495dbd73f360
|
||||||
F sqlite.1 2e2bb0529ef468ade9e4322bd609d0695fb9ded9
|
F sqlite.1 2e2bb0529ef468ade9e4322bd609d0695fb9ded9
|
||||||
F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
|
F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
|
||||||
F src/btree.c ba5712cf620f80055948cc41157e14eab6ceee86
|
F src/btree.c ced7d25e7ed33df5ef177e839db3e137d3c6a361
|
||||||
F src/btree.h a94bef69f5174461331b6b9ae45a2d84f05af6db
|
F src/btree.h a94bef69f5174461331b6b9ae45a2d84f05af6db
|
||||||
F src/build.c 0c7346d0522e59be67a4bb841020540d8ba5d136
|
F src/build.c a8851852bd67821a06dc1a816291ca0edaf15a18
|
||||||
F src/delete.c f8ad71be53cf18656b6573de65395852fe817f0c
|
F src/delete.c f8ad71be53cf18656b6573de65395852fe817f0c
|
||||||
F src/expr.c a2a87dbd411a508ff89dffa90505ad42dac2f920
|
F src/expr.c a2a87dbd411a508ff89dffa90505ad42dac2f920
|
||||||
F src/hash.c 8f7c740ef2eaaa8decfa8751f2be30680b123e46
|
F src/hash.c 8f7c740ef2eaaa8decfa8751f2be30680b123e46
|
||||||
F src/hash.h a5f5b3ce2d086a172c5879b0b06a27a82eac9fac
|
F src/hash.h d1ce47900c7325af5e41c4feb4855c4bf2b841e7
|
||||||
F src/insert.c 173da7b06fe9282e0f529ff1e599460304ceeb23
|
F src/insert.c 173da7b06fe9282e0f529ff1e599460304ceeb23
|
||||||
F src/main.c 300320ba68d3e5b22c2c5b2c07fa884878202181
|
F src/main.c 300320ba68d3e5b22c2c5b2c07fa884878202181
|
||||||
F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
|
F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
|
||||||
@@ -49,15 +49,15 @@ F src/test3.c d6775f95fd91f5b3cf0e2382a28e5aaeb68f745b
|
|||||||
F src/tokenize.c 01a09db6adf933e941db1b781789a0c175be6504
|
F src/tokenize.c 01a09db6adf933e941db1b781789a0c175be6504
|
||||||
F src/update.c 95459f94a061860bf8e5716b3426a5ba85c79103
|
F src/update.c 95459f94a061860bf8e5716b3426a5ba85c79103
|
||||||
F src/util.c 8f8973dd55a6ec63be9632fc5de86965c99d6327
|
F src/util.c 8f8973dd55a6ec63be9632fc5de86965c99d6327
|
||||||
F src/vdbe.c df1c920e74b2cd76d763833a655fbabb67f17237
|
F src/vdbe.c 6e9851f14edaa98fd244103ff899082063a0e519
|
||||||
F src/vdbe.h 3791edabb212038ae5fbcfa72580204596be01a7
|
F src/vdbe.h 3d49d22ba9ad14ea0e380bc582ff57347eaddb59
|
||||||
F src/where.c 2dda39367f193194e4c7d2e0dcab31527d9d8aba
|
F src/where.c 2dda39367f193194e4c7d2e0dcab31527d9d8aba
|
||||||
F test/all.test 2a51e5395ac7c2c539689b123b9782a05e3837fe
|
F test/all.test 2a51e5395ac7c2c539689b123b9782a05e3837fe
|
||||||
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
|
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
|
||||||
F test/btree.test 6ab4dc5f595905a276ef588fad3c9236dc07a47b
|
F test/btree.test 6ab4dc5f595905a276ef588fad3c9236dc07a47b
|
||||||
F test/btree2.test 08e9485619265cbaf5d11bd71f357cdc26bb87e0
|
F test/btree2.test 08e9485619265cbaf5d11bd71f357cdc26bb87e0
|
||||||
F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
|
F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
|
||||||
F test/conflict.test dd1b380595bb48b90289d761f4d11a46d7c60178
|
F test/conflict.test 5515d5dcbb6be9c715d1b83b2796b8a9cb7a32d4
|
||||||
F test/copy.test 9ff0063c0b95b3d51b8d0c7fe0ff51dabaa66549
|
F test/copy.test 9ff0063c0b95b3d51b8d0c7fe0ff51dabaa66549
|
||||||
F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
|
F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
|
||||||
F test/expr.test c8a495050dcec3f9e68538c3ef466726933302c1
|
F test/expr.test c8a495050dcec3f9e68538c3ef466726933302c1
|
||||||
@@ -122,7 +122,7 @@ F www/speed.tcl 83457b2bf6bb430900bd48ca3dd98264d9a916a5
|
|||||||
F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
|
F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
|
||||||
F www/tclsqlite.tcl 829b393d1ab187fd7a5e978631b3429318885c49
|
F www/tclsqlite.tcl 829b393d1ab187fd7a5e978631b3429318885c49
|
||||||
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
||||||
P 9be4d4c6f12056782966396dca0b8e2d384d0cf2
|
P 0115518f8e4591123582e3d2bb67282111ebcf60
|
||||||
R 60fe69f0169f5844176ca5b7853e2e65
|
R 3b844437150a914d910bcb945e186cae
|
||||||
U drh
|
U drh
|
||||||
Z fa5a72d3a4d7961b510d6a8d5ba99c2c
|
Z 41bd35da914d3e147a09ab98b479c192
|
||||||
|
@@ -1 +1 @@
|
|||||||
0115518f8e4591123582e3d2bb67282111ebcf60
|
95d1f8389dd5e168bdf0290169662296b6a0f6d9
|
@@ -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.48 2002/02/03 00:56:10 drh Exp $
|
** $Id: btree.c,v 1.49 2002/02/03 03:34:08 drh 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
|
||||||
@@ -2737,7 +2737,7 @@ static int checkTreePage(
|
|||||||
cur.idx = i;
|
cur.idx = i;
|
||||||
zKey2 = sqliteMalloc( NKEY(pCell->h)+1 );
|
zKey2 = sqliteMalloc( NKEY(pCell->h)+1 );
|
||||||
getPayload(&cur, 0, NKEY(pCell->h), zKey2);
|
getPayload(&cur, 0, NKEY(pCell->h), zKey2);
|
||||||
if( zKey1 && strcmp(zKey1,zKey2)>=0 ){
|
if( zKey1 && strcmp(zKey1,zKey2)>0 ){
|
||||||
checkAppendMsg(pCheck, zContext, "Key is out of order");
|
checkAppendMsg(pCheck, zContext, "Key is out of order");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
61
src/build.c
61
src/build.c
@@ -25,7 +25,7 @@
|
|||||||
** ROLLBACK
|
** ROLLBACK
|
||||||
** PRAGMA
|
** PRAGMA
|
||||||
**
|
**
|
||||||
** $Id: build.c,v 1.72 2002/02/03 00:56:10 drh Exp $
|
** $Id: build.c,v 1.73 2002/02/03 03:34:08 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -1397,49 +1397,34 @@ copy_cleanup:
|
|||||||
** The non-standard VACUUM command is used to clean up the database,
|
** The non-standard VACUUM command is used to clean up the database,
|
||||||
** collapse free space, etc. It is modelled after the VACUUM command
|
** collapse free space, etc. It is modelled after the VACUUM command
|
||||||
** in PostgreSQL.
|
** in PostgreSQL.
|
||||||
|
**
|
||||||
|
** In this implementation, no cleanup occurs. Instead, the B-tree that
|
||||||
|
** forms the database is checked for integrity. This is a no-op unless
|
||||||
|
** SQLite is compiled with the SQLITE_TEST macro.
|
||||||
*/
|
*/
|
||||||
void sqliteVacuum(Parse *pParse, Token *pTableName){
|
void sqliteVacuum(Parse *pParse, Token *pTableName){
|
||||||
char *zName;
|
#if 1
|
||||||
|
static VdbeOp checkDb[] = {
|
||||||
|
{ OP_SetInsert, 0, 0, "2"},
|
||||||
|
{ OP_Open, 0, 2, 0},
|
||||||
|
{ OP_Rewind, 0, 6, 0},
|
||||||
|
{ OP_Column, 0, 3, 0},
|
||||||
|
{ OP_SetInsert, 0, 0, 0},
|
||||||
|
{ OP_Next, 0, 3, 0},
|
||||||
|
{ OP_SanityCheck, 0, 0, 0},
|
||||||
|
{ OP_ColumnCount, 1, 0, 0},
|
||||||
|
{ OP_ColumnName, 0, 0, "sanity_check"},
|
||||||
|
{ OP_Callback, 1, 0, 0},
|
||||||
|
};
|
||||||
|
static
|
||||||
Vdbe *v;
|
Vdbe *v;
|
||||||
sqlite *db = pParse->db;
|
|
||||||
|
|
||||||
if( pParse->nErr || sqlite_malloc_failed ) return;
|
|
||||||
if( pTableName ){
|
|
||||||
zName = sqliteTableNameFromToken(pTableName);
|
|
||||||
}else{
|
|
||||||
zName = 0;
|
|
||||||
}
|
|
||||||
if( zName && sqliteFindIndex(db, zName)==0
|
|
||||||
&& sqliteFindTable(db, zName)==0 ){
|
|
||||||
sqliteSetString(&pParse->zErrMsg, "no such table or index: ", zName, 0);
|
|
||||||
pParse->nErr++;
|
|
||||||
goto vacuum_cleanup;
|
|
||||||
}
|
|
||||||
v = sqliteGetVdbe(pParse);
|
v = sqliteGetVdbe(pParse);
|
||||||
if( v==0 ) goto vacuum_cleanup;
|
if( v==0 ) return;
|
||||||
sqliteBeginWriteOperation(pParse);
|
sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
|
||||||
if( zName ){
|
|
||||||
sqliteVdbeAddOp(v, OP_Reorganize, 0, 0);
|
|
||||||
sqliteVdbeChangeP3(v, -1, zName, strlen(zName));
|
|
||||||
}else{
|
|
||||||
Table *pTab;
|
|
||||||
Index *pIdx;
|
|
||||||
HashElem *pE;
|
|
||||||
for(pE=sqliteHashFirst(&db->tblHash); pE; pE=sqliteHashNext(pE)){
|
|
||||||
pTab = sqliteHashData(pE);
|
|
||||||
sqliteVdbeAddOp(v, OP_Reorganize, 0, 0);
|
|
||||||
sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
|
||||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
|
||||||
sqliteVdbeAddOp(v, OP_Reorganize, 0, 0);
|
|
||||||
sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sqliteEndWriteOperation(pParse);
|
|
||||||
|
|
||||||
vacuum_cleanup:
|
|
||||||
sqliteFree(zName);
|
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
** This is the header file for the generic hash-table implemenation
|
** This is the header file for the generic hash-table implemenation
|
||||||
** used in SQLite.
|
** used in SQLite.
|
||||||
**
|
**
|
||||||
** $Id: hash.h,v 1.2 2001/10/09 04:19:47 drh Exp $
|
** $Id: hash.h,v 1.3 2002/02/03 03:34:09 drh Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef _SQLITE_HASH_H_
|
#ifndef _SQLITE_HASH_H_
|
||||||
#define _SQLITE_HASH_H_
|
#define _SQLITE_HASH_H_
|
||||||
@@ -98,5 +98,11 @@ void sqliteHashClear(Hash*);
|
|||||||
#define sqliteHashFirst(H) ((H)->first)
|
#define sqliteHashFirst(H) ((H)->first)
|
||||||
#define sqliteHashNext(E) ((E)->next)
|
#define sqliteHashNext(E) ((E)->next)
|
||||||
#define sqliteHashData(E) ((E)->data)
|
#define sqliteHashData(E) ((E)->data)
|
||||||
|
#define sqliteHashKey(E) ((E)->pKey)
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Number of entries in a hash table
|
||||||
|
*/
|
||||||
|
#define sqliteHashCount(H) ((H)->count)
|
||||||
|
|
||||||
#endif /* _SQLITE_HASH_H_ */
|
#endif /* _SQLITE_HASH_H_ */
|
||||||
|
52
src/vdbe.c
52
src/vdbe.c
@@ -30,7 +30,7 @@
|
|||||||
** But other routines are also provided to help in building up
|
** But other routines are also provided to help in building up
|
||||||
** a program instruction by instruction.
|
** a program instruction by instruction.
|
||||||
**
|
**
|
||||||
** $Id: vdbe.c,v 1.115 2002/02/03 00:56:10 drh Exp $
|
** $Id: vdbe.c,v 1.116 2002/02/03 03:34:09 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -868,7 +868,7 @@ static char *zOpName[] = { 0,
|
|||||||
"IsUnique", "NotExists", "Delete", "Column",
|
"IsUnique", "NotExists", "Delete", "Column",
|
||||||
"KeyAsData", "Recno", "FullKey", "Rewind",
|
"KeyAsData", "Recno", "FullKey", "Rewind",
|
||||||
"Next", "Destroy", "Clear", "CreateIndex",
|
"Next", "Destroy", "Clear", "CreateIndex",
|
||||||
"CreateTable", "Reorganize", "IdxPut", "IdxDelete",
|
"CreateTable", "SanityCheck", "IdxPut", "IdxDelete",
|
||||||
"IdxRecno", "IdxGT", "IdxGE", "MemLoad",
|
"IdxRecno", "IdxGT", "IdxGE", "MemLoad",
|
||||||
"MemStore", "ListWrite", "ListRewind", "ListRead",
|
"MemStore", "ListWrite", "ListRewind", "ListRead",
|
||||||
"ListReset", "SortPut", "SortMakeRec", "SortMakeKey",
|
"ListReset", "SortPut", "SortMakeRec", "SortMakeKey",
|
||||||
@@ -3481,15 +3481,51 @@ case OP_CreateTable: {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Opcode: Reorganize P1 * *
|
/* Opcode: SanityCheck P1 * *
|
||||||
**
|
**
|
||||||
** Compress, optimize, and tidy up table or index whose root page in the
|
** Do an analysis of the currently open database. Push onto the
|
||||||
** database file is P1.
|
** stack the text of an error message describing any problems.
|
||||||
|
** If there are no errors, push a "ok" onto the stack.
|
||||||
**
|
**
|
||||||
** In the current implementation, this is a no-op.
|
** P1 is the index of a set that contains the root page numbers
|
||||||
|
** for all tables and indices in this database.
|
||||||
|
**
|
||||||
|
** This opcode is used for testing purposes only.
|
||||||
*/
|
*/
|
||||||
case OP_Reorganize: {
|
case OP_SanityCheck: {
|
||||||
/* This is currently a no-op */
|
#if 1 /* This opcode used for testing only */
|
||||||
|
int nRoot;
|
||||||
|
int *aRoot;
|
||||||
|
int tos = ++p->tos;
|
||||||
|
int iSet = pOp->p1;
|
||||||
|
Set *pSet;
|
||||||
|
int j;
|
||||||
|
HashElem *i;
|
||||||
|
char *z;
|
||||||
|
|
||||||
|
if( iSet<0 || iSet>=p->nSet ){
|
||||||
|
goto bad_instruction;
|
||||||
|
}
|
||||||
|
VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
|
||||||
|
pSet = &p->aSet[iSet];
|
||||||
|
nRoot = sqliteHashCount(&pSet->hash);
|
||||||
|
aRoot = sqliteMalloc( sizeof(int)*(nRoot+1) );
|
||||||
|
for(j=0, i=sqliteHashFirst(&pSet->hash); i; i=sqliteHashNext(i), j++){
|
||||||
|
aRoot[j] = atoi((char*)sqliteHashKey(i));
|
||||||
|
}
|
||||||
|
aRoot[j] = 0;
|
||||||
|
z = sqliteBtreeSanityCheck(pBt, aRoot, nRoot);
|
||||||
|
if( z==0 || z[0]==0 ){
|
||||||
|
zStack[tos] = "ok";
|
||||||
|
aStack[tos].n = 3;
|
||||||
|
aStack[tos].flags = STK_Str | STK_Static;
|
||||||
|
if( z ) sqliteFree(z);
|
||||||
|
}else{
|
||||||
|
zStack[tos] = z;
|
||||||
|
aStack[tos].n = strlen(z) + 1;
|
||||||
|
aStack[tos].flags = STK_Str | STK_Dyn;
|
||||||
|
}
|
||||||
|
#endif /* SQLITE_TEST */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
** or VDBE. The VDBE implements an abstract machine that runs a
|
** or VDBE. The VDBE implements an abstract machine that runs a
|
||||||
** simple program to access and modify the underlying database.
|
** simple program to access and modify the underlying database.
|
||||||
**
|
**
|
||||||
** $Id: vdbe.h,v 1.40 2002/02/02 18:49:21 drh Exp $
|
** $Id: vdbe.h,v 1.41 2002/02/03 03:34:09 drh Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef _SQLITE_VDBE_H_
|
#ifndef _SQLITE_VDBE_H_
|
||||||
#define _SQLITE_VDBE_H_
|
#define _SQLITE_VDBE_H_
|
||||||
@@ -104,7 +104,7 @@ typedef struct VdbeOp VdbeOp;
|
|||||||
#define OP_Clear 31
|
#define OP_Clear 31
|
||||||
#define OP_CreateIndex 32
|
#define OP_CreateIndex 32
|
||||||
#define OP_CreateTable 33
|
#define OP_CreateTable 33
|
||||||
#define OP_Reorganize 34
|
#define OP_SanityCheck 34
|
||||||
|
|
||||||
#define OP_IdxPut 35
|
#define OP_IdxPut 35
|
||||||
#define OP_IdxDelete 36
|
#define OP_IdxDelete 36
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
# This file implements tests for the conflict resolution extension
|
# This file implements tests for the conflict resolution extension
|
||||||
# to SQLite.
|
# to SQLite.
|
||||||
#
|
#
|
||||||
# $Id: conflict.test,v 1.5 2002/02/03 00:56:11 drh Exp $
|
# $Id: conflict.test,v 1.6 2002/02/03 03:34:09 drh Exp $
|
||||||
|
|
||||||
set testdir [file dirname $argv0]
|
set testdir [file dirname $argv0]
|
||||||
source $testdir/tester.tcl
|
source $testdir/tester.tcl
|
||||||
@@ -367,6 +367,7 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
|
|||||||
UPDATE t3 SET x=0;
|
UPDATE t3 SET x=0;
|
||||||
BEGIN $conf2;
|
BEGIN $conf2;
|
||||||
$cmd t3 SET x=1;
|
$cmd t3 SET x=1;
|
||||||
|
$cmd t1 SET b=b*2;
|
||||||
$cmd t1 SET a=c+5;
|
$cmd t1 SET a=c+5;
|
||||||
}]} r1]
|
}]} r1]
|
||||||
execsql {COMMIT}
|
execsql {COMMIT}
|
||||||
|
Reference in New Issue
Block a user