Use 16-bit integers for indexing within a page in btree. Tighter

bounds on the maximum number of cells within one page. (CVS 4796)

FossilOrigin-Name: 8fdbe4abab4e9c292111579b03471f68c1e855fb
This commit is contained in:
drh 2008-02-19 14:59:35 +00:00
parent eee4c8ca11
commit a9121e4c8e
4 changed files with 34 additions and 33 deletions

View File

@ -1,5 +1,5 @@
C Add\sthe\smemory\sfault\ssimulator\sto\smem5.c.\s\sEnable\ssoft\sheap\slimit\son\smem5.c.\nLimit\sthe\ssize\sof\shash\stables\sand\sthe\svdbefifo\swhen\susing\smem5.c.\s(CVS\s4795)
D 2008-02-18T22:24:58
C Use\s16-bit\sintegers\sfor\sindexing\swithin\sa\spage\sin\sbtree.\s\sTighter\nbounds\son\sthe\smaximum\snumber\sof\scells\swithin\sone\spage.\s(CVS\s4796)
D 2008-02-19T14:59:35
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in bc2b5df3e3d0d4b801b824b7ef6dec43812b049b
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -84,9 +84,9 @@ F src/attach.c e13d62597e8725075b27186817f7e745122af24e
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c bc5b52a590dc38a48fdded1f098b84af673448c9
F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
F src/btree.c 29ea577155f39be65bdec1c7782301ff2ee9eb3f
F src/btree.c 134a152a27e049ba6093333aa22e5f6d5013d7ae
F src/btree.h 19dcf5ad23c17b98855da548e9a8e3eb4429d5eb
F src/btreeInt.h 1c5a9da165718ef7de81e35ce9ab5d9ba9283f76
F src/btreeInt.h 97a68823481e769874f9a61ef43719c856c71860
F src/build.c 7d93ee565b5676746d014acdc638adee87cfd27e
F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
@ -621,7 +621,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 7c57bdbcdb84d95419ec7029d2e13c593854a8d8
R 0bada69c2b0e42668cf12f285946c6e2
P 63da5d97542e4f54c33329833477c8d96ce05dd0
R c8ab8ac21acd2b72e6ae16ee8ae7de7c
U drh
Z af6bec9b1fbe082648fe2162d8c6bd6a
Z a0e228bb49973ef017165e1ce93bd308

View File

@ -1 +1 @@
63da5d97542e4f54c33329833477c8d96ce05dd0
8fdbe4abab4e9c292111579b03471f68c1e855fb

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.438 2008/01/31 14:54:44 drh Exp $
** $Id: btree.c,v 1.439 2008/02/19 14:59:35 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@ -622,13 +622,13 @@ void sqlite3BtreeParseCell(
** the space used by the cell pointer.
*/
#ifndef NDEBUG
static int cellSize(MemPage *pPage, int iCell){
static u16 cellSize(MemPage *pPage, int iCell){
CellInfo info;
sqlite3BtreeParseCell(pPage, iCell, &info);
return info.nSize;
}
#endif
static int cellSizePtr(MemPage *pPage, u8 *pCell){
static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
CellInfo info;
sqlite3BtreeParseCellPtr(pPage, pCell, &info);
return info.nSize;
@ -4593,7 +4593,7 @@ static void assemblePage(
MemPage *pPage, /* The page to be assemblied */
int nCell, /* The number of cells to add to this page */
u8 **apCell, /* Pointers to cell bodies */
int *aSize /* Sizes of the cells */
u16 *aSize /* Sizes of the cells */
){
int i; /* Loop counter */
int totalSize; /* Total size of all cells */
@ -4671,7 +4671,7 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){
MemPage *pNew;
Pgno pgnoNew;
u8 *pCell;
int szCell;
u16 szCell;
CellInfo info;
BtShared *pBt = pPage->pBt;
int parentIdx = pParent->nCell; /* pParent new divider cell index */
@ -4797,7 +4797,7 @@ static int balance_nonroot(MemPage *pPage){
int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
int szNew[NB+2]; /* Combined size of cells place on i-th page */
u8 **apCell = 0; /* All cells begin balanced */
int *szCell; /* Local size of all cells in apCell[] */
u16 *szCell; /* Local size of all cells in apCell[] */
u8 *aCopy[NB]; /* Space for holding data of apCopy[] */
u8 *aSpace; /* Space to hold copies of dividers cells */
#ifndef SQLITE_OMIT_AUTOVACUUM
@ -4910,25 +4910,25 @@ static int balance_nonroot(MemPage *pPage){
nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
}
/* Make nMaxCells a multiple of 2 in order to preserve 8-byte
/* Make nMaxCells a multiple of 4 in order to preserve 8-byte
** alignment */
nMaxCells = (nMaxCells + 1)&~1;
nMaxCells = (nMaxCells + 3)&~3;
/*
** Allocate space for memory structures
*/
apCell = sqlite3_malloc(
nMaxCells*sizeof(u8*) /* apCell */
+ nMaxCells*sizeof(int) /* szCell */
+ ROUND8(sizeof(MemPage))*NB /* aCopy */
+ pBt->pageSize*(5+NB) /* aSpace */
+ nMaxCells*sizeof(u16) /* szCell */
+ (ROUND8(sizeof(MemPage))+pBt->pageSize)*NB /* aCopy */
+ pBt->pageSize*5 /* aSpace */
+ (ISAUTOVACUUM ? nMaxCells : 0) /* aFrom */
);
if( apCell==0 ){
rc = SQLITE_NOMEM;
goto balance_cleanup;
}
szCell = (int*)&apCell[nMaxCells];
szCell = (u16*)&apCell[nMaxCells];
aCopy[0] = (u8*)&szCell[nMaxCells];
assert( ((aCopy[0] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
for(i=1; i<NB; i++){
@ -4997,7 +4997,7 @@ static int balance_nonroot(MemPage *pPage){
nCell++;
}
if( i<nOld-1 ){
int sz = cellSizePtr(pParent, apDiv[i]);
u16 sz = cellSizePtr(pParent, apDiv[i]);
if( leafData ){
/* With the LEAFDATA flag, pParent cells hold only INTKEYs that
** are duplicates of keys on the child pages. We need to remove
@ -5351,16 +5351,16 @@ static int balance_shallower(MemPage *pPage){
BtShared *pBt; /* The main BTree structure */
int mxCellPerPage; /* Maximum number of cells per page */
u8 **apCell; /* All cells from pages being balanced */
int *szCell; /* Local size of all cells */
u16 *szCell; /* Local size of all cells */
assert( pPage->pParent==0 );
assert( pPage->nCell==0 );
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
pBt = pPage->pBt;
mxCellPerPage = MX_CELL(pBt);
apCell = sqlite3_malloc( mxCellPerPage*(sizeof(u8*)+sizeof(int)) );
apCell = sqlite3_malloc( mxCellPerPage*(sizeof(u8*)+sizeof(u16)) );
if( apCell==0 ) return SQLITE_NOMEM;
szCell = (int*)&apCell[mxCellPerPage];
szCell = (u16*)&apCell[mxCellPerPage];
if( pPage->leaf ){
/* The table is completely empty */
TRACE(("BALANCE: empty table %d\n", pPage->pgno));
@ -5630,7 +5630,7 @@ int sqlite3BtreeInsert(
assert( szNew==cellSizePtr(pPage, newCell) );
assert( szNew<=MX_CELL_SIZE(pBt) );
if( loc==0 && CURSOR_VALID==pCur->eState ){
int szOld;
u16 szOld;
assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
rc = sqlite3PagerWrite(pPage->pDbPage);
if( rc ){
@ -5742,7 +5742,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){
rc = sqlite3PagerWrite(leafCur.pPage->pDbPage);
}
if( rc==SQLITE_OK ){
int szNext;
u16 szNext;
TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno));
dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell));
@ -6527,7 +6527,7 @@ static int checkTreePage(
cellStart = hdr + 12 - 4*pPage->leaf;
for(i=0; i<nCell; i++){
int pc = get2byte(&data[cellStart+i*2]);
int size = cellSizePtr(pPage, &data[pc]);
u16 size = cellSizePtr(pPage, &data[pc]);
int j;
if( (pc+size-1)>=usableSize || pc<0 ){
checkAppendMsg(pCheck, 0,

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btreeInt.h,v 1.15 2007/12/21 04:47:26 danielk1977 Exp $
** $Id: btreeInt.h,v 1.16 2008/02/19 14:59:35 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@ -221,10 +221,11 @@
#define MX_CELL_SIZE(pBt) (pBt->pageSize-8)
/* The maximum number of cells on a single page of the database. This
** assumes a minimum cell size of 3 bytes. Such small cells will be
** exceedingly rare, but they are possible.
** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself
** plus 2 bytes for the index to the cell in the page header). Such
** small cells will be rare, but they are possible.
*/
#define MX_CELL(pBt) ((pBt->pageSize-8)/3)
#define MX_CELL(pBt) ((pBt->pageSize-8)/6)
/* Forward declarations */
typedef struct MemPage MemPage;