From: drh Date: Tue, 23 Jun 2015 14:49:42 +0000 (+0000) Subject: Improvements to the way balance_nonroot() constructs the b.apCell array of X-Git-Tag: version-3.8.11~142^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4edfdd38fb16c75d03403e3da2ae1860bb44e0bc;p=thirdparty%2Fsqlite.git Improvements to the way balance_nonroot() constructs the b.apCell array of pointers to cells. FossilOrigin-Name: ee44bb25b2a88e25ba2afe37cf03ba199692a3a0 --- diff --git a/manifest b/manifest index ea07d936b3..44f122c617 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\scompound\sSELECT\soperator\sfix\sfrom\strunk. -D 2015-06-23T13:02:10.077 +C Improvements\sto\sthe\sway\sbalance_nonroot()\sconstructs\sthe\sb.apCell\sarray\sof\npointers\sto\scells. +D 2015-06-23T14:49:42.852 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1063c58075b7400d93326b0eb332b48a54f53025 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -192,7 +192,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c e6ac65de1742116fb5abbb106a26eb5bf48cd79e +F src/btree.c 8d772673dc249aee6b6e65e4285291f7f2565ffd F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 6ece2dd9c8e2eac05f0a8ded8772a44e96486c65 F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70 @@ -1286,7 +1286,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 43844537e8a372953386663f8177202901ba7566 4df852ce26c95d5d23c83dbe9c59d2c3435acddf -R 5a31f6e2047c6b2a76413665b07fcf29 +P a7be554f4b8534fc237fa4c6defc38fcd4049707 +R 4ad5f5185dfc9700d38a61349b40bf79 U drh -Z ef941435462213fb596e80b11c30b19f +Z 77f5541f0ad6043b85ab2e262249ce69 diff --git a/manifest.uuid b/manifest.uuid index c792bcaca0..c1bc1337b1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a7be554f4b8534fc237fa4c6defc38fcd4049707 \ No newline at end of file +ee44bb25b2a88e25ba2afe37cf03ba199692a3a0 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 9693b0d393..adba9ec45e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -958,27 +958,25 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ ((P)->aData + ((P)->maskPage & get2byte(&(P)->aCellIdx[2*(I)]))) #define findCellv2(D,M,O,I) (D+(M&get2byte(D+(O+2*(I))))) - /* -** This a more complex version of findCell() that works for -** pages that do contain overflow cells. +** Sort the overflow cells of a page into index order. +** +** An O(N*N) algorithm is used. But that should not be a problem +** since N is only very rarely more than 1. */ -static u8 *findOverflowCell(MemPage *pPage, int iCell){ - int i; - assert( sqlite3_mutex_held(pPage->pBt->mutex) ); - for(i=pPage->nOverflow-1; i>=0; i--){ - int k; - k = pPage->aiOvfl[i]; - if( k<=iCell ){ - if( k==iCell ){ - return pPage->apOvfl[i]; +static void btreeSortOverflow(MemPage *p){ + int j, k; + for(j=0; jnOverflow-1; j++){ + for(k=j+1; knOverflow; k++){ + if( p->aiOvfl[j]>p->aiOvfl[k] ){ + SWAP(u16, p->aiOvfl[j], p->aiOvfl[k]); + SWAP(u8*, p->apOvfl[j], p->apOvfl[k]); } - iCell--; } } - return findCell(pPage, iCell); } + /* ** This is common tail processing for btreeParseCellPtr() and ** btreeParseCellPtrIndex() for the case when the cell does not fit entirely @@ -7057,8 +7055,11 @@ static int balance_nonroot( leafCorrection = b.pRef->leaf*4; leafData = b.pRef->intKeyLeaf; for(i=0; inCell; + u8 *aData = pOld->aData; + u16 maskPage = pOld->maskPage; + u16 cellOffset = pOld->cellOffset; /* Verify that all sibling pages are of the same "type" (table-leaf, ** table-interior, index-leaf, or index-interior). @@ -7068,24 +7069,38 @@ static int balance_nonroot( goto balance_cleanup; } - limit = pOld->nCell+pOld->nOverflow; + /* Load b.apCell[] with pointers to all cells in pOld. Intersperse + ** overflow cells in the correct sequence. + ** + ** This must be done in advance. Once the balance starts, the cell + ** offset section of the btree page will be overwritten and we will no + ** long be able to find the cells if a pointer to each cell is not saved + ** first. + */ memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*limit); + j = 0; if( pOld->nOverflow>0 ){ - for(j=0; jaData; - u16 maskPage = pOld->maskPage; - u16 cellOffset = pOld->cellOffset; - for(j=0; jnOverflow); + btreeSortOverflow(pOld); + for(k=0; knOverflow; k++){ + limit = pOld->aiOvfl[k] - k; + while( japOvfl[k]; b.nCell++; } + limit = pOld->nCell; } + while( j