1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Turn on quick-balance by default. (CVS 2221)

FossilOrigin-Name: d0356dee55bd43f361ede1344e90d1ba6b5cde1e
This commit is contained in:
drh
2005-01-16 23:21:00 +00:00
parent 0d477437ac
commit 615ae553fc
4 changed files with 50 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
C Drop\ssupport\sfor\sMAC\sOS9.\s\sSQLite\s3\shas\snever\sworked\sfor\sthat\sOS\sbecause\nthe\sdevelopers\sdo\snot\shave\saccess\sto\sa\smachine\srunning\sit\sand\snobody\sfrom\nthe\scommunity\shas\sstepped\sforward\sto\sprovide\sa\sport.\s\sBy\smoving\sthe\nos_mac.c\sfile\sinto\sthe\sattic,\swe\smake\sthe\slack\sof\ssupport\sofficial.\s(CVS\s2220) C Turn\son\squick-balance\sby\sdefault.\s(CVS\s2221)
D 2005-01-16T20:47:41 D 2005-01-16T23:21:00
F Makefile.in 78d6d0af3725aef32468ac9923444d7645d21a28 F Makefile.in 78d6d0af3725aef32468ac9923444d7645d21a28
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 4a9313065dcfb31c702158ed4c5c0e1ed69889a8 F src/btree.c 528a661ae10ee7513b3db724a4acfd0e90991798
F src/btree.h 74d19cf40ab49fd69abe9e4e12a6c321ad86c497 F src/btree.h 74d19cf40ab49fd69abe9e4e12a6c321ad86c497
F src/build.c af1296e8a21a406b4f4c4f1e1365e075071219f3 F src/build.c af1296e8a21a406b4f4c4f1e1365e075071219f3
F src/cursor.c f883813759742068890b1f699335872bfa8fdf41 F src/cursor.c f883813759742068890b1f699335872bfa8fdf41
@@ -113,7 +113,7 @@ F test/collate4.test 2d6e38e6b871073313f6d4eebfe1435c7173ebfa
F test/collate5.test 7999fb3122386bae38acd8ccd61e0b7c5a30e289 F test/collate5.test 7999fb3122386bae38acd8ccd61e0b7c5a30e289
F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638 F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87 F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87
F test/corrupt.test 0080ddcece23e8ba47c44608c4fb73fd4d1d8ce2 F test/corrupt.test 4b289dfd45b5987a4f12bef9693c49e42b6e76ea
F test/corrupt2.test cb1f813df7559de3021e01170af0bba31507a9a5 F test/corrupt2.test cb1f813df7559de3021e01170af0bba31507a9a5
F test/crash.test fa5d79ece85e8f6677bd81703db5f869a15963aa F test/crash.test fa5d79ece85e8f6677bd81703db5f869a15963aa
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
@@ -267,7 +267,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 6237c294d1211d5848bafb1310574e2486a43757 P de9ad673d037f7bfca3a2d439259a63c9ed954db
R ca099b3c791f0b796eb74e72a082b2c7 R a3c633ca18ad9c504d2c45368f1d4e12
U drh U drh
Z 5cc4e0ef8392da0ae950aaff44fc3d28 Z 9410eca575f29e730c32c01825919813

View File

@@ -1 +1 @@
de9ad673d037f7bfca3a2d439259a63c9ed954db d0356dee55bd43f361ede1344e90d1ba6b5cde1e

View File

@@ -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.237 2005/01/16 11:07:07 danielk1977 Exp $ ** $Id: btree.c,v 1.238 2005/01/16 23:21:00 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
@@ -358,12 +358,24 @@ struct BtCursor {
u8 isValid; /* TRUE if points to a valid entry */ u8 isValid; /* TRUE if points to a valid entry */
}; };
/*
** The TRACE macro will print high-level status information about the
** btree operation when the global variable sqlite3_btree_trace is
** enabled.
*/
#if SQLITE_TEST
# define TRACE(X) if( sqlite3_btree_trace )\
{ sqlite3DebugPrintf X; fflush(stdout); }
#else
# define TRACE(X)
#endif
int sqlite3_btree_trace=0; /* True to enable tracing */
/* /*
** Forward declaration ** Forward declaration
*/ */
static int checkReadLocks(Btree*,Pgno,BtCursor*); static int checkReadLocks(Btree*,Pgno,BtCursor*);
/* /*
** Read or write a two- and four-byte big-endian integer values. ** Read or write a two- and four-byte big-endian integer values.
*/ */
@@ -420,12 +432,18 @@ static void put4byte(unsigned char *p, u32 v){
#define PTRMAP_ISPAGE(pgsz, pgno) (PTRMAP_PAGENO(pgsz,pgno)==pgno) #define PTRMAP_ISPAGE(pgsz, pgno) (PTRMAP_PAGENO(pgsz,pgno)==pgno)
/* /*
** The pointer map is a lookup table that contains an entry for each database ** The pointer map is a lookup table that identifies the parent page for
** page in the file except for page 1. In this context 'database page' refers ** each child page in the database file. The parent page is the page that
** to any page that is not part of the pointer map itself. Each pointer map ** contains a pointer to the child. Every page in the database contains
** entry consists of a single byte 'type' and a 4 byte page number. The ** 0 or 1 parent pages. (In this context 'database page' refers
** PTRMAP_XXX identifiers below are the valid types. The interpretation ** to any page that is not part of the pointer map itself.) Each pointer map
** of the page-number depends on the type, as follows: ** entry consists of a single byte 'type' and a 4 byte parent page number.
** The PTRMAP_XXX identifiers below are the valid types.
**
** The purpose of the pointer map is to facility moving pages from one
** position in the file to another as part of autovacuum. When a page
** is moved, the pointer in its parent must be updated to point to the
** new location. The pointer map is used to locate the parent page quickly.
** **
** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not ** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
** used in this case. ** used in this case.
@@ -457,7 +475,7 @@ static void put4byte(unsigned char *p, u32 v){
** so that it maps to type 'eType' and parent page number 'pgno'. ** so that it maps to type 'eType' and parent page number 'pgno'.
** An error code is returned if something goes wrong, otherwise SQLITE_OK. ** An error code is returned if something goes wrong, otherwise SQLITE_OK.
*/ */
static int ptrmapPut(Btree *pBt, Pgno key, u8 eType, Pgno pgno){ static int ptrmapPut(Btree *pBt, Pgno key, u8 eType, Pgno parent){
u8 *pPtrmap; /* The pointer map page */ u8 *pPtrmap; /* The pointer map page */
Pgno iPtrmap; /* The pointer map page number */ Pgno iPtrmap; /* The pointer map page number */
int offset; /* Offset in pointer map page */ int offset; /* Offset in pointer map page */
@@ -472,13 +490,14 @@ static int ptrmapPut(Btree *pBt, Pgno key, u8 eType, Pgno pgno){
} }
offset = PTRMAP_PTROFFSET(pBt->usableSize, key); offset = PTRMAP_PTROFFSET(pBt->usableSize, key);
if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=pgno ){ if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
rc = sqlite3pager_write(pPtrmap); rc = sqlite3pager_write(pPtrmap);
if( rc!=0 ){ if( rc!=0 ){
return rc; return rc;
} }
pPtrmap[offset] = eType; pPtrmap[offset] = eType;
put4byte(&pPtrmap[offset+1], pgno); put4byte(&pPtrmap[offset+1], parent);
} }
sqlite3pager_unref(pPtrmap); sqlite3pager_unref(pPtrmap);
@@ -1563,19 +1582,6 @@ int sqlite3BtreeBeginTrans(Btree *pBt, int wrflag){
return rc; return rc;
} }
/*
** The TRACE macro will print high-level status information about the
** btree operation when the global variable sqlite3_btree_trace is
** enabled.
*/
#if SQLITE_TEST
# define TRACE(X) if( sqlite3_btree_trace )\
{ sqlite3DebugPrintf X; fflush(stdout); }
#else
# define TRACE(X)
#endif
int sqlite3_btree_trace=0; /* True to enable tracing */
#ifndef SQLITE_OMIT_AUTOVACUUM #ifndef SQLITE_OMIT_AUTOVACUUM
/* /*
@@ -3571,6 +3577,7 @@ static void assemblePage(
/* Forward reference */ /* Forward reference */
static int balance(MemPage*, int); static int balance(MemPage*, int);
#ifndef SQLITE_OMIT_QUICKBALANCE
/* /*
** This version of balance() handles the common special case where ** This version of balance() handles the common special case where
** a new entry is being inserted on the extreme right-end of the ** a new entry is being inserted on the extreme right-end of the
@@ -3658,6 +3665,7 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){
releasePage(pNew); releasePage(pNew);
return balance(pParent, 0); return balance(pParent, 0);
} }
#endif /* SQLITE_OMIT_QUICKBALANCE */
/* /*
** The ISAUTOVACUUM macro is used within balance_nonroot() to determine ** The ISAUTOVACUUM macro is used within balance_nonroot() to determine
@@ -3747,7 +3755,7 @@ static int balance_nonroot(MemPage *pPage){
assert( pParent ); assert( pParent );
TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno)); TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
#ifdef SQLITE_BALANCE_QUICK #ifndef SQLITE_OMIT_QUICKBALANCE
/* /*
** A special case: If a new entry has just been inserted into a ** A special case: If a new entry has just been inserted into a
** table (that is, a btree with integer keys and all data at the leaves) ** table (that is, a btree with integer keys and all data at the leaves)

View File

@@ -13,7 +13,7 @@
# This file implements tests to make sure SQLite does not crash or # This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file. # segfault if it sees a corrupt database file.
# #
# $Id: corrupt.test,v 1.1 2004/08/30 16:52:19 drh Exp $ # $Id: corrupt.test,v 1.2 2005/01/16 23:21:00 drh Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@@ -44,7 +44,7 @@ do_test corrupt-1.1 {
} }
} {ok} } {ok}
# Copy a file # Copy file $from into $to
# #
proc copy_file {from to} { proc copy_file {from to} {
set f [open $from] set f [open $from]
@@ -56,14 +56,19 @@ proc copy_file {from to} {
close $f close $f
} }
# Setup for the tests. # Setup for the tests. Make a backup copy of the good database in test.bu.
# Create a string of garbage data that is 256 bytes long.
#
copy_file test.db test.bu copy_file test.db test.bu
set fsize [file size test.db] set fsize [file size test.db]
set junk "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" set junk "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while {[string length $junk]<256} {append junk $junk} while {[string length $junk]<256} {append junk $junk}
set junk [string range $junk 0 255] set junk [string range $junk 0 255]
# Go through the database and write garbage data into each 256 segment
# of the file. Then do various operations on the file to make sure that
# the database engine can recover gracefully from the corruption.
#
for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} { for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} {
set tn [expr {$i/256}] set tn [expr {$i/256}]
db close db close
@@ -99,7 +104,6 @@ for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} {
catchsql {DROP TABLE t1} catchsql {DROP TABLE t1}
set x {} set x {}
} {} } {}
if {$tn==724} btree_breakpoint
do_test corrupt-2.$tn.7 { do_test corrupt-2.$tn.7 {
catchsql {PRAGMA integrity_check} catchsql {PRAGMA integrity_check}
set x {} set x {}