From: drh Date: Mon, 29 Jan 2001 01:27:19 +0000 (+0000) Subject: :-) (CVS 1713) X-Git-Tag: version-3.6.10~5889 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1881e616578238ec49899dedfe6ca1b05e939d6;p=thirdparty%2Fsqlite.git :-) (CVS 1713) FossilOrigin-Name: 3259a53111bd19417e78160174bd67c69098494a --- diff --git a/manifest b/manifest index c83c70d72c..0fadde9c78 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C :-)\s(CVS\s1712) -D 2001-01-25T01:45:40 +C :-)\s(CVS\s1713) +D 2001-01-29T01:27:20 F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4 F Makefile.in 7efa81e2985b45ba73db27d55b70cc927f5abfd7 F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958 @@ -10,8 +10,8 @@ F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47 F doc/report1.txt ad0a41513479f1be0355d1f3f074e66779ff2282 F src/TODO 38a68a489e56e9fd4a96263e0ff9404a47368ad4 F src/build.c 7aa5879bf58ea6bbff22c26c59d1130021fa6ca4 -F src/db.c 387cbf95f95bf4d2668cd01f64a60ffd59f43874 -F src/db.h f5ab793ad888c7905fbaaf9a675f576f4a3918bc +F src/db.c c789cd4491afcdeddc2327107dcf3d15d4558e1a +F src/db.h 7109f0acd9694c58529fbf98ad6f51a74fb95bc8 F src/dbbe.c 162d29b09ac379f160892c5795efc14099dcc8eb F src/dbbe.h 0435a36906a839cce062608f51bd9d3e79878fec F src/dbbegdbm.c 5bfcb1b4ee47a98c5eae83041e9716cd3233fd0e @@ -84,7 +84,7 @@ F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f F www/tclsqlite.tcl 06f81c401f79a04f2c5ebfb97e7c176225c0aef2 F www/vdbe.tcl 0c8aaa529dd216ccbf7daaabd80985e413d5f9ad -P 98da825312fd4bb8a20ff33293131c02beb3ae63 -R 65625e73d51d03039a82df767d26bb25 +P edb01b1275c3de7c398522b5826c898917811247 +R fad18d8d52121b49568c3b69513e9996 U drh -Z aad6c859441db92bc7fcd45e2633d4de +Z f548d6e222a005fc922c38f88384f46b diff --git a/manifest.uuid b/manifest.uuid index d1cb80e42d..b9e9b0d222 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -edb01b1275c3de7c398522b5826c898917811247 \ No newline at end of file +3259a53111bd19417e78160174bd67c69098494a \ No newline at end of file diff --git a/src/db.c b/src/db.c index 440f6931bb..d6abffc378 100644 --- a/src/db.c +++ b/src/db.c @@ -21,7 +21,7 @@ ** http://www.hwaci.com/drh/ ** ************************************************************************* -** $Id: db.c,v 1.4 2001/01/25 01:45:40 drh Exp $ +** $Id: db.c,v 1.5 2001/01/29 01:27:20 drh Exp $ */ #include "sqliteInt.h" #include "pg.h" @@ -68,6 +68,27 @@ struct DbCursor { DbIdxpt aLevel[MX_LEVEL]; /* The index levels */ }; +/* +** Used for rebalancing +*/ +typedef struct DbEntry DbEntry; +struct DbEntry { + int nByte; /* Space needed on leaf to record this entry */ + int pgno; /* Page on which this entry is currently found */ + int idx; /* Index slot in part that points to leaf "pgno" */ + u32 *aPage; /* Pointer to the leaf for this entry */ + u32 *aEntry; /* Pointer to the actual text of this entry */ + DbEntry *pNext; /* Next entry in a list of them all */ +}; +typedef struct DbEntrySet DbEntrySet; +struct DbEntrySet { + u32 *pIndex; /* The index node above the leaf pages being balanced */ + int nAlloc; /* Number of slots allocated in aEntry[] */ + int nEntry; /* Number of slots in aEntry[] actually used */ + DbEntry *pFirst; /* First entry in hash order */ + DbEntry aEntry[100]; /* Descriptions of actual database entries */ +}; + /* ** The first word of every page is some combination of these values ** used to indicate its function. @@ -664,7 +685,7 @@ int sqliteDbOpen(const char *filename, Db **ppDb){ pDb->nAlloc = 0; rc = sqliteDbExpandContent(pDb, pDb->nContent); if( rc!=SQLITE_OK ) goto open_err; - rc = payloadRead(pDb, &aPage1[3], 0, aPage[2], pDb->aContent); + rc = payloadRead(pDb, &aPage1[3], 0, aPage1[2], pDb->aContent); sqlitePgUnref(aPage1); if( rc!=SQLITE_OK ) goto open_err; *ppDb = pDb; @@ -673,8 +694,10 @@ int sqliteDbOpen(const char *filename, Db **ppDb){ open_err: *ppDb = 0; if( pPgr ) sqlitePgClose(pPgr); - if( pDb && pDb->aContent ) sqliteFree(pDb->aContent); - if( pDb ) sqliteFree(pDb); + if( pDb ){ + sqliteFree(pDb->aContent); + sqliteFree(pDb); + } return rc; } @@ -745,7 +768,7 @@ int sqliteDbRollback(Db *pDb){ if( sqliteDbExpandContent(pDb, pDb->nContent)!=SQLITE_OK ){ return SQLITE_NOMEM; } - sqliteDbReadOvfl(pDb, 1, aPage1, 0, pDb->nContent*sizeof(u32), pDb->aContent); + payloadRead(pDb, &aPage1[3], 0, pDb->nContent*sizeof(u32), pDb->aContent); pDb->inTransaction = 0; return SQLITE_OK; } @@ -773,25 +796,23 @@ int sqliteDbCreateTable(Db *pDb, int *pTblno){ } } if( tblno<0 ){ - tblno = SWB(pDb->aContent[1]); + tblno = pDb->aContent[1]; } if( tblno+2 >= pDb->nContent ){ sqliteDbExpandContent(pDb, tblno+2); } if( pDb->aContent==0 ){ - return SQLITE_NOMEM; + rc = SQLITE_NOMEM; + }else{ + pDb->aContent[tblno+2] = pgno; + pPage[0] = SWB(BLOCK_MAGIC | BLOCK_LEAF); + memset(&pPage[1], 0, SQLITE_PAGE_SIZE - sizeof(u32)); + sqlitePgTouch(pPage); } - pDb->aContent[tblno+2] = SWB(pgno); - pPage[0] = SWB(BLOCK_MAGIC | BLOCK_LEAF); - memset(&pPage[1], 0, SQLITE_PAGE_SIZE - sizeof(u32)); - sqlitePgTouch(pPage); sqlitePgUnref(pPage); - return SQLITE_OK; + return rc; } -/* forward reference */ -static int sqliteDbClearEntry(Db *pDb, u32 *pEntry); - /* ** Recursively add a page to the free list */ @@ -806,18 +827,18 @@ static int sqliteDbDropPage(Db *pDb, u32 pgno){ int n, i; n = aPage[2]; for(i=0; i0 ) sqliteDbDropPage(pDb, subpgno); } freePage(pDb, pgno, aPage); break; } case BLOCK_MAGIC | BLOCK_LEAF: { - int i = 1; - while( i=pDb->nContent || pDb->aContent[tblno+2]==0 ){ return SQLITE_NOTFOUND; } - pgno = SWB(pDb->aContent[tblno+2]); + pgno = pDb->aContent[tblno+2]; + pDb->aContent[tblno+2] = 0; - /* Reset any cursors point to the table that is about to + /* Reset any cursors pointing to the table that is about to ** be dropped */ for(pCur=pDb->pCursor; pCur; pCur=pCur->pNext){ if( pCur->rootPgno==pgno ){ @@ -1066,8 +1079,8 @@ int sqliteDbCursorDatasize(DbCursor *pCur){ idx = pCur->aLevel[i].idx; aPage = pCur->aLevel[i].aPage; assert( aPage ); - assert( idx>=2 && idx+4<(SQLITE_PAGE_SIZE/sizeof(u32)) - return SWB(aPage[idx+3]) & 0x80000000; + assert( idx>=2 && idx+4aLevel[i].idx; aPage = pCur->aLevel[i].aPage; assert( aPage ); - assert( idx>=2 && idx+4<(SQLITE_PAGE_SIZE/sizeof(u32)) - return SWB(aPage[idx+2]) & 0x80000000; + assert( idx>=2 && idx+4onEntry ){ memset(cbuf, 0, amt); return SQLITE_OK; @@ -1107,25 +1118,19 @@ int sqliteDbCursorRead(DbCursor *pCur, int amt, int offset, void *buf){ idx = pCur->aLevel[i].idx; aPage = pCur->aLevel[i].aPage; assert( aPage ); - assert( idx>=2 && idx+4<(SQLITE_PAGE_SIZE/sizeof(u32)) - nData = SWB(aPage[idx+3]); - nKey = SWB(aPage[idx+2]); - dstart = idx + 4; - if( nKey!=4 ) dstart++; - if( nData & 0x80000000 ){ - return sqliteDbReadOvfl(pCur->pDb, SWB(aPage[dstart]), 0, amt, offset, buf); - } - cfrom = (char*)&aPage[dstart]; - cfrom += offset; - nData -= offset; - if( nData<0 ) nData = 0; - if( amt>nData ){ - memset(&cbuf[nData], 0, amt-nData); - } - if( amt=2 && idx+4=nData ){ + memset(buf, 0, amt); + return SQLITE_OK; + } + nKey = aPage[idx+2]; + if( nDatapDb, &aPage[idx+4], amt, offset + nKey, buf); + return SQLITE_OK; } /* @@ -1133,11 +1138,9 @@ int sqliteDbCursorRead(DbCursor *pCur, int amt, int offset, void *buf){ */ int sqliteDbCursorReadKey(DbCursor *pCur, int amt, int offset, void *buf){ u32 *aPage; - int idx, i, kstart; + int idx, i; int nData; int nKey; - char *cbuf = buf; - char *cfrom; if( !pCur->onEntry ){ memset(cbuf, 0, amt); return SQLITE_OK; @@ -1150,26 +1153,17 @@ int sqliteDbCursorReadKey(DbCursor *pCur, int amt, int offset, void *buf){ aPage = pCur->aLevel[i].aPage; assert( aPage ); assert( idx>=2 && idx+4<(SQLITE_PAGE_SIZE/sizeof(u32)) - nKey = SWB(aPage[idx+2]); - if( nKey & 0x80000000 ){ - return sqliteDbReadOvfl(pCur->pDb, SWB(aPage[idx+4]), 0, amt, offset, buf); - } - if( nKey==4 ){ - kstart = idx + 1; - }else{ - kstart = idx + 4; - } - cfrom = (char*)&aPage[kstart]; - cfrom += offset; - nKey -= offset; - if( nKey<0 ) nKey = 0; - if( amt>nKey ){ - memset(&cbuf[nKey], 0, amt-nKey); + nKey = aPage[idx+2]; + if( offset>=nKey ){ + memset(buf, 0, amt); + return SQLITE_OK; } - if( amtpDb, &aPage[idx+4], amt, offset, buf); + return SQLITE_OK; } /* diff --git a/src/db.h b/src/db.h index 667d42ce9d..d0d32ecbdd 100644 --- a/src/db.h +++ b/src/db.h @@ -21,7 +21,7 @@ ** http://www.hwaci.com/drh/ ** ************************************************************************* -** $Id: db.h,v 1.3 2001/01/25 01:45:40 drh Exp $ +** $Id: db.h,v 1.4 2001/01/29 01:27:20 drh Exp $ */ typedef struct Db Db; @@ -45,6 +45,7 @@ int sqliteDbCursorDatasize(DbCursor*); int sqliteDbCursorKeysize(DbCursor*); int sqliteDbCursorRead(DbCursor*, int amt, int offset, void *buf); int sqliteDbCursorReadKey(DbCursor*, int amt, int offset, void *buf); +int sqliteDbCursorWrite(DbCursor*, int amt, int offset, const void *buf); + int sqliteDbCursorFind(DbCursor*, int nKey, const void *pKey, int createSize); int sqliteDbCursorResize(DbCursor*, int nData); -int sqliteDbCursorWrite(DbCursor*, int amt, int offset, const void *buf);