mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Simplify the b-tree logic by taking advantage of the fact that all b-trees
are either intkey+leafdata or zerodata. (CVS 5431) FossilOrigin-Name: 29d3bfd7c9a68078385354394052612bf812859b
This commit is contained in:
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
||||
C Fix\sthe\stest\sharness\sso\sthat\sit\sdoes\snot\stry\sto\slink\sagainst\nsqlite3_mutex_alloc()\sif\scompiled\swith\s-DSQLITE_THREADSAFE=0.\s(CVS\s5430)
|
||||
D 2008-07-17T17:34:20
|
||||
C Simplify\sthe\sb-tree\slogic\sby\staking\sadvantage\sof\sthe\sfact\sthat\sall\sb-trees\nare\seither\sintkey+leafdata\sor\szerodata.\s(CVS\s5431)
|
||||
D 2008-07-17T18:39:58
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@@ -96,9 +96,9 @@ F src/attach.c b18ba42c77f7d3941f5d23d2ca20fa1d841a4e91
|
||||
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
|
||||
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
|
||||
F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
|
||||
F src/btree.c 5dcc47a35d12bc8584d7c89ed113d24fb9fbc2ca
|
||||
F src/btree.c c618d62fb41642216f8fc5be403c36f32e1b25d6
|
||||
F src/btree.h 03256ed7ee42b5ecacbe887070b0f8249e7d069d
|
||||
F src/btreeInt.h a6a5ffab12fa2c15392b85242cd5568371949046
|
||||
F src/btreeInt.h 2aa6dc53b1801bb22815a5be22e03be121f3bd8f
|
||||
F src/build.c bac7233d984be3805aaa41cf500f7ee12dc97249
|
||||
F src/callback.c aa492a0ad8c2d454edff9fb8a57fae13743cf71d
|
||||
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
|
||||
@@ -608,7 +608,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P 08fe49f62f8a91c36ad4bb9a1d8c89806c37f600
|
||||
R 514cbf07ace43083faff0e77954a2fe0
|
||||
P 26a203d894edd0091ac60862956e42d22167011e
|
||||
R 0aa24510df7c6bac75839ea22cde6884
|
||||
U drh
|
||||
Z 0a72bbba17dc41aabdaed96d70dac8a1
|
||||
Z 2661cde038f2c435549bd085c583b89a
|
||||
|
@@ -1 +1 @@
|
||||
26a203d894edd0091ac60862956e42d22167011e
|
||||
29d3bfd7c9a68078385354394052612bf812859b
|
49
src/btree.c
49
src/btree.c
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.483 2008/07/16 18:17:56 danielk1977 Exp $
|
||||
** $Id: btree.c,v 1.484 2008/07/17 18:39:58 drh Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** See the header comment on "btreeInt.h" for additional information.
|
||||
@@ -871,27 +871,38 @@ static void freeSpace(MemPage *pPage, int start, int size){
|
||||
/*
|
||||
** Decode the flags byte (the first byte of the header) for a page
|
||||
** and initialize fields of the MemPage structure accordingly.
|
||||
**
|
||||
** Only the following combinations are supported. Anything different
|
||||
** indicates a corrupt database files:
|
||||
**
|
||||
** PTF_ZERODATA
|
||||
** PTF_ZERODATA | PTF_LEAF
|
||||
** PTF_LEAFDATA | PTF_INTKEY
|
||||
** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF
|
||||
*/
|
||||
static void decodeFlags(MemPage *pPage, int flagByte){
|
||||
static int decodeFlags(MemPage *pPage, int flagByte){
|
||||
BtShared *pBt; /* A copy of pPage->pBt */
|
||||
|
||||
assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
|
||||
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
|
||||
pPage->intKey = (flagByte & (PTF_INTKEY|PTF_LEAFDATA))!=0;
|
||||
pPage->zeroData = (flagByte & PTF_ZERODATA)!=0;
|
||||
pPage->leaf = (flagByte & PTF_LEAF)!=0;
|
||||
pPage->childPtrSize = 4*(pPage->leaf==0);
|
||||
pPage->leaf = flagByte>>3; assert( PTF_LEAF == 1<<3 );
|
||||
flagByte &= ~PTF_LEAF;
|
||||
pPage->childPtrSize = 4-4*pPage->leaf;
|
||||
pBt = pPage->pBt;
|
||||
if( flagByte & PTF_LEAFDATA ){
|
||||
pPage->leafData = 1;
|
||||
if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
|
||||
pPage->intKey = 1;
|
||||
pPage->hasData = pPage->leaf;
|
||||
pPage->maxLocal = pBt->maxLeaf;
|
||||
pPage->minLocal = pBt->minLeaf;
|
||||
}else{
|
||||
pPage->leafData = 0;
|
||||
}else if( flagByte==PTF_ZERODATA ){
|
||||
pPage->intKey = 0;
|
||||
pPage->hasData = 0;
|
||||
pPage->maxLocal = pBt->maxLocal;
|
||||
pPage->minLocal = pBt->minLocal;
|
||||
}else{
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
pPage->hasData = !(pPage->zeroData || (!pPage->leaf && pPage->leafData));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -941,7 +952,7 @@ int sqlite3BtreeInitPage(
|
||||
}
|
||||
hdr = pPage->hdrOffset;
|
||||
data = pPage->aData;
|
||||
decodeFlags(pPage, data[hdr]);
|
||||
if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
|
||||
pPage->nOverflow = 0;
|
||||
pPage->idxShift = 0;
|
||||
usableSize = pBt->usableSize;
|
||||
@@ -3757,7 +3768,7 @@ int sqlite3BtreeMoveto(
|
||||
}
|
||||
if( c==0 ){
|
||||
pCur->info.nKey = nCellKey;
|
||||
if( pPage->leafData && !pPage->leaf ){
|
||||
if( pPage->intKey && !pPage->leaf ){
|
||||
lwr = pCur->idx;
|
||||
upr = lwr - 1;
|
||||
break;
|
||||
@@ -3884,7 +3895,7 @@ int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
|
||||
pPage = pCur->pPage;
|
||||
}while( pCur->idx>=pPage->nCell );
|
||||
*pRes = 0;
|
||||
if( pPage->leafData ){
|
||||
if( pPage->intKey ){
|
||||
rc = sqlite3BtreeNext(pCur, pRes);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
@@ -3951,7 +3962,7 @@ int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
|
||||
pCur->idx--;
|
||||
pCur->info.nSize = 0;
|
||||
pCur->validNKey = 0;
|
||||
if( pPage->leafData && !pPage->leaf ){
|
||||
if( pPage->intKey && !pPage->leaf ){
|
||||
rc = sqlite3BtreePrevious(pCur, pRes);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
@@ -4946,12 +4957,12 @@ static int balance_nonroot(MemPage *pPage){
|
||||
*/
|
||||
if( pPage->leaf &&
|
||||
pPage->intKey &&
|
||||
pPage->leafData &&
|
||||
pPage->nOverflow==1 &&
|
||||
pPage->aOvfl[0].idx==pPage->nCell &&
|
||||
pPage->pParent->pgno!=1 &&
|
||||
get4byte(&pParent->aData[pParent->hdrOffset+8])==pPage->pgno
|
||||
){
|
||||
assert( pPage->intKey );
|
||||
/*
|
||||
** TODO: Check the siblings to the left of pPage. It may be that
|
||||
** they are not full and no new page is required.
|
||||
@@ -5095,7 +5106,7 @@ static int balance_nonroot(MemPage *pPage){
|
||||
*/
|
||||
nCell = 0;
|
||||
leafCorrection = pPage->leaf*4;
|
||||
leafData = pPage->leafData && pPage->leaf;
|
||||
leafData = pPage->hasData;
|
||||
for(i=0; i<nOld; i++){
|
||||
MemPage *pOld = apCopy[i];
|
||||
int limit = pOld->nCell+pOld->nOverflow;
|
||||
@@ -5772,7 +5783,7 @@ int sqlite3BtreeInsert(
|
||||
|
||||
pPage = pCur->pPage;
|
||||
assert( pPage->intKey || nKey>=0 );
|
||||
assert( pPage->leaf || !pPage->leafData );
|
||||
assert( pPage->leaf || !pPage->intKey );
|
||||
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
|
||||
pCur->pgnoRoot, nKey, nData, pPage->pgno,
|
||||
loc==0 ? "overwrite" : "new entry"));
|
||||
@@ -5888,7 +5899,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){
|
||||
unsigned char *pNext;
|
||||
int notUsed;
|
||||
unsigned char *tempCell = 0;
|
||||
assert( !pPage->leafData );
|
||||
assert( !pPage->intKey );
|
||||
sqlite3BtreeGetTempCursor(pCur, &leafCur);
|
||||
rc = sqlite3BtreeNext(&leafCur, ¬Used);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btreeInt.h,v 1.26 2008/07/12 14:52:20 drh Exp $
|
||||
** $Id: btreeInt.h,v 1.27 2008/07/17 18:39:58 drh Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** For a detailed discussion of BTrees, refer to
|
||||
@@ -275,8 +275,6 @@ struct MemPage {
|
||||
u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
|
||||
u8 intKey; /* True if intkey flag is set */
|
||||
u8 leaf; /* True if leaf flag is set */
|
||||
u8 zeroData; /* True if table stores keys only */
|
||||
u8 leafData; /* True if tables stores data on leaves only */
|
||||
u8 hasData; /* True if this page stores data */
|
||||
u8 hdrOffset; /* 100 for page 1. 0 otherwise */
|
||||
u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
|
||||
|
Reference in New Issue
Block a user