mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Fix an auto-vacuum bug that occurs when a btree cell is promoted to the parent page during a delete. (CVS 2043)
FossilOrigin-Name: b7d953e1195897de4869ec241a65e8a3d1320efb
This commit is contained in:
16
manifest
16
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Fix\sa\sproblem\sin\sthe\spragma.test\sscript.\s(CVS\s2041)
|
C Fix\san\sauto-vacuum\sbug\sthat\soccurs\swhen\sa\sbtree\scell\sis\spromoted\sto\sthe\sparent\spage\sduring\sa\sdelete.\s(CVS\s2043)
|
||||||
D 2004-11-02T18:15:49
|
D 2004-11-03T03:01:17
|
||||||
F Makefile.in 9e90c685d69f09039015a6b1f3b0a48e9738c9e5
|
F Makefile.in 9e90c685d69f09039015a6b1f3b0a48e9738c9e5
|
||||||
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 0d0993b87602145b0fb3d38fa983cb5ef7cb7176
|
F src/btree.c 2f7cfc724b2c34a046cee11ca12582d786e50308
|
||||||
F src/btree.h 94dfec0a1722d33359b23e7e310f2b64ffedf029
|
F src/btree.h 94dfec0a1722d33359b23e7e310f2b64ffedf029
|
||||||
F src/build.c bb896c5f85ab749d17ae5d730235134c12c08033
|
F src/build.c bb896c5f85ab749d17ae5d730235134c12c08033
|
||||||
F src/date.c 34bdb0082db7ec2a83ef00063f7b44e61ee19dad
|
F src/date.c 34bdb0082db7ec2a83ef00063f7b44e61ee19dad
|
||||||
@@ -87,7 +87,7 @@ F test/attach.test 6ad560eb3e77751a4faecd77da09deac9e38cc41
|
|||||||
F test/attach2.test f7795123d3051ace1672b6d23973da6435de3745
|
F test/attach2.test f7795123d3051ace1672b6d23973da6435de3745
|
||||||
F test/attach3.test 6d060986ff004ebb89e1876a331d96c6bb62269e
|
F test/attach3.test 6d060986ff004ebb89e1876a331d96c6bb62269e
|
||||||
F test/auth.test 1cc252d9e7b3bdc1314199cbf3a0d3c5ed026c21
|
F test/auth.test 1cc252d9e7b3bdc1314199cbf3a0d3c5ed026c21
|
||||||
F test/autovacuum.test 9ab4fcfb98ac1537548d61ce1e1718794aac4719
|
F test/autovacuum.test 176a9a541726ee6bbc8ed64cf2d41934dc4df63b
|
||||||
F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f
|
F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f
|
||||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||||
F test/bind.test a8682ba41433b93bb36a4213a43f282ca9aec5a9
|
F test/bind.test a8682ba41433b93bb36a4213a43f282ca9aec5a9
|
||||||
@@ -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 8378c144c1e1cedb7deea271fa274182d08198b8
|
P a2c9c45c803350f45911a72eb61efa9c3089f8ca
|
||||||
R 848edcf7b102a68d3a9a6c2cf44e2d8c
|
R c5211669f5d9e58d9ee4a32f7514f865
|
||||||
U drh
|
U danielk1977
|
||||||
Z 690835edd5903b7dbaa32b08cc18b618
|
Z a5ce17377bb4e63f27099031250fb3aa
|
||||||
|
@@ -1 +1 @@
|
|||||||
a2c9c45c803350f45911a72eb61efa9c3089f8ca
|
b7d953e1195897de4869ec241a65e8a3d1320efb
|
36
src/btree.c
36
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.199 2004/11/02 18:05:09 drh Exp $
|
** $Id: btree.c,v 1.200 2004/11/03 03:01:17 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
|
||||||
@@ -1753,11 +1753,6 @@ autovacuum_out:
|
|||||||
/* TODO: A goto autovacuum_out; will fail to call releasePage() on
|
/* TODO: A goto autovacuum_out; will fail to call releasePage() on
|
||||||
** outstanding references. Fix.
|
** outstanding references. Fix.
|
||||||
*/
|
*/
|
||||||
#ifndef NDEBUG
|
|
||||||
if( nRef!=*sqlite3pager_stats(pPager) ){
|
|
||||||
sqlite3pager_refdump(pPager);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
assert( nRef==*sqlite3pager_stats(pPager) );
|
assert( nRef==*sqlite3pager_stats(pPager) );
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
sqlite3pager_rollback(pPager);
|
sqlite3pager_rollback(pPager);
|
||||||
@@ -3174,7 +3169,7 @@ static int reparentChildPages(MemPage *pPage){
|
|||||||
if( pBt->autoVacuum ){
|
if( pBt->autoVacuum ){
|
||||||
CellInfo info;
|
CellInfo info;
|
||||||
parseCellPtr(pPage, pCell, &info);
|
parseCellPtr(pPage, pCell, &info);
|
||||||
if( info.iOverflow ){
|
if( (info.nData+(pPage->intKey?0:info.nKey))>info.nLocal ){
|
||||||
Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
|
Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
|
||||||
rc = ptrmapPut(pBt, pgnoOvfl, PTRMAP_OVERFLOW1, pPage->pgno);
|
rc = ptrmapPut(pBt, pgnoOvfl, PTRMAP_OVERFLOW1, pPage->pgno);
|
||||||
if( rc!=SQLITE_OK ) return rc;
|
if( rc!=SQLITE_OK ) return rc;
|
||||||
@@ -3234,7 +3229,7 @@ static void dropCell(MemPage *pPage, int idx, int sz){
|
|||||||
** Allocating a new entry in pPage->aCell[] implies that
|
** Allocating a new entry in pPage->aCell[] implies that
|
||||||
** pPage->nOverflow is incremented.
|
** pPage->nOverflow is incremented.
|
||||||
*/
|
*/
|
||||||
static void insertCell(
|
static int insertCell(
|
||||||
MemPage *pPage, /* Page into which we are copying */
|
MemPage *pPage, /* Page into which we are copying */
|
||||||
int i, /* New cell becomes the i-th cell of the page */
|
int i, /* New cell becomes the i-th cell of the page */
|
||||||
u8 *pCell, /* Content of the new cell */
|
u8 *pCell, /* Content of the new cell */
|
||||||
@@ -3291,6 +3286,22 @@ static void insertCell(
|
|||||||
pPage->idxShift = 1;
|
pPage->idxShift = 1;
|
||||||
pageIntegrity(pPage);
|
pageIntegrity(pPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||||
|
if( pPage->pBt->autoVacuum ){
|
||||||
|
/* The cell may contain a pointer to an overflow page. If so, write
|
||||||
|
** the entry for the overflow page into the pointer map.
|
||||||
|
*/
|
||||||
|
CellInfo info;
|
||||||
|
parseCellPtr(pPage, pCell, &info);
|
||||||
|
if( (info.nData+(pPage->intKey?0:info.nKey))>info.nLocal ){
|
||||||
|
Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
|
||||||
|
int rc = ptrmapPut(pPage->pBt, pgnoOvfl, PTRMAP_OVERFLOW1, pPage->pgno);
|
||||||
|
if( rc!=SQLITE_OK ) return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3760,7 +3771,8 @@ static int balance_nonroot(MemPage *pPage){
|
|||||||
iSpace += sz;
|
iSpace += sz;
|
||||||
assert( iSpace<=pBt->psAligned*5 );
|
assert( iSpace<=pBt->psAligned*5 );
|
||||||
}
|
}
|
||||||
insertCell(pParent, nxDiv, pCell, sz, pTemp);
|
rc = insertCell(pParent, nxDiv, pCell, sz, pTemp);
|
||||||
|
if( rc!=SQLITE_OK ) goto balance_cleanup;
|
||||||
put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno);
|
put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno);
|
||||||
j++;
|
j++;
|
||||||
nxDiv++;
|
nxDiv++;
|
||||||
@@ -4067,7 +4079,8 @@ int sqlite3BtreeInsert(
|
|||||||
}else{
|
}else{
|
||||||
assert( pPage->leaf );
|
assert( pPage->leaf );
|
||||||
}
|
}
|
||||||
insertCell(pPage, pCur->idx, newCell, szNew, 0);
|
rc = insertCell(pPage, pCur->idx, newCell, szNew, 0);
|
||||||
|
if( rc!=SQLITE_OK ) goto end_insert;
|
||||||
rc = balance(pPage);
|
rc = balance(pPage);
|
||||||
/* sqlite3BtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
|
/* sqlite3BtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
|
||||||
/* fflush(stdout); */
|
/* fflush(stdout); */
|
||||||
@@ -4147,7 +4160,8 @@ int sqlite3BtreeDelete(BtCursor *pCur){
|
|||||||
assert( MX_CELL_SIZE(pBt)>=szNext+4 );
|
assert( MX_CELL_SIZE(pBt)>=szNext+4 );
|
||||||
tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
|
tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
|
||||||
if( tempCell==0 ) return SQLITE_NOMEM;
|
if( tempCell==0 ) return SQLITE_NOMEM;
|
||||||
insertCell(pPage, pCur->idx, pNext-4, szNext+4, tempCell);
|
rc = insertCell(pPage, pCur->idx, pNext-4, szNext+4, tempCell);
|
||||||
|
if( rc!=SQLITE_OK ) return rc;
|
||||||
put4byte(findOverflowCell(pPage, pCur->idx), pgnoChild);
|
put4byte(findOverflowCell(pPage, pCur->idx), pgnoChild);
|
||||||
rc = balance(pPage);
|
rc = balance(pPage);
|
||||||
sqliteFree(tempCell);
|
sqliteFree(tempCell);
|
||||||
|
@@ -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.2 2004/11/02 14:40:32 danielk1977 Exp $
|
# $Id: autovacuum.test,v 1.3 2004/11/03 03:01:17 danielk1977 Exp $
|
||||||
|
|
||||||
set testdir [file dirname $argv0]
|
set testdir [file dirname $argv0]
|
||||||
source $testdir/tester.tcl
|
source $testdir/tester.tcl
|
||||||
@@ -28,7 +28,7 @@ proc file_pages {} {
|
|||||||
do_test autovacuum-1.1 {
|
do_test autovacuum-1.1 {
|
||||||
execsql {
|
execsql {
|
||||||
CREATE TABLE av1(a);
|
CREATE TABLE av1(a);
|
||||||
-- CREATE INDEX av1_idx ON av1(a);
|
CREATE INDEX av1_idx ON av1(a);
|
||||||
}
|
}
|
||||||
} {}
|
} {}
|
||||||
|
|
||||||
@@ -39,12 +39,10 @@ lappend delete_orders {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
|||||||
lappend delete_orders {20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1}
|
lappend delete_orders {20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1}
|
||||||
lappend delete_orders {8 18 2 4 14 11 13 3 10 7 9 5 12 17 19 15 20 6 16 1}
|
lappend delete_orders {8 18 2 4 14 11 13 3 10 7 9 5 12 17 19 15 20 6 16 1}
|
||||||
lappend delete_orders {10 3 11 17 19 20 7 4 13 6 1 14 16 12 9 18 8 15 5 2}
|
lappend delete_orders {10 3 11 17 19 20 7 4 13 6 1 14 16 12 9 18 8 15 5 2}
|
||||||
|
|
||||||
lappend delete_orders {{1 2 3 4 5 6 7 8 9 10} {11 12 13 14 15 16 17 18 19 20}}
|
lappend delete_orders {{1 2 3 4 5 6 7 8 9 10} {11 12 13 14 15 16 17 18 19 20}}
|
||||||
lappend delete_orders \
|
lappend delete_orders \
|
||||||
{{19 8 17 15} {16 11 9 14} {18 5 3 1} {13 20 7 2} {6 12 4 10}}
|
{{19 8 17 15} {16 11 9 14} {18 5 3 1} {13 20 7 2} {6 12 4 10}}
|
||||||
|
|
||||||
|
|
||||||
set tn 0
|
set tn 0
|
||||||
foreach delete_order $delete_orders {
|
foreach delete_order $delete_orders {
|
||||||
incr tn
|
incr tn
|
||||||
@@ -56,8 +54,6 @@ foreach delete_order $delete_orders {
|
|||||||
lappend ::tbl_data [make_str $i $ENTRY_LEN]
|
lappend ::tbl_data [make_str $i $ENTRY_LEN]
|
||||||
}
|
}
|
||||||
|
|
||||||
# puts "File has [file_pages] pages"
|
|
||||||
|
|
||||||
do_test autovacuum-1.$tn.1 {
|
do_test autovacuum-1.$tn.1 {
|
||||||
execsql {
|
execsql {
|
||||||
pragma integrity_check
|
pragma integrity_check
|
||||||
@@ -65,13 +61,11 @@ foreach delete_order $delete_orders {
|
|||||||
} {ok}
|
} {ok}
|
||||||
|
|
||||||
foreach delete $delete_order {
|
foreach delete $delete_order {
|
||||||
# if {$delete==6} { set btree_trace 1 ; breakpoint }
|
|
||||||
do_test autovacuum-1.$tn.($delete).1 {
|
do_test autovacuum-1.$tn.($delete).1 {
|
||||||
execsql "
|
execsql "
|
||||||
DELETE FROM av1 WHERE oid IN ([join $delete ,])
|
DELETE FROM av1 WHERE oid IN ([join $delete ,])
|
||||||
"
|
"
|
||||||
} {}
|
} {}
|
||||||
set btree_trace 0
|
|
||||||
|
|
||||||
do_test autovacuum-1.$tn.($delete).2 {
|
do_test autovacuum-1.$tn.($delete).2 {
|
||||||
execsql {
|
execsql {
|
||||||
@@ -88,12 +82,11 @@ set btree_trace 0
|
|||||||
select a from av1
|
select a from av1
|
||||||
}
|
}
|
||||||
} $::tbl_data
|
} $::tbl_data
|
||||||
# if {$::nErr>0} finish_test
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_test autovacuum-1.$tn.3 {
|
do_test autovacuum-1.$tn.3 {
|
||||||
file_pages
|
file_pages
|
||||||
} {3}
|
} {4}
|
||||||
}
|
}
|
||||||
|
|
||||||
finish_test
|
finish_test
|
||||||
|
Reference in New Issue
Block a user