From 8c0a959f356177e582b628bfc3d1e14bc97ad25b Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Mon, 30 Apr 2007 16:55:00 +0000 Subject: [PATCH] Try to avoid reading pages when moving overflow chains to the free-list. (CVS 3886) FossilOrigin-Name: 8cccec68bd9073b2b19d3d31cf0b77b0ce76172e --- manifest | 12 +++++----- manifest.uuid | 2 +- src/btree.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 067ed2bd7c..4ee4f13320 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssome\stests\s(and\s2\sresulting\sbug\sfixes)\sto\sincr\svacuum\smode.\s(CVS\s3885) -D 2007-04-28T15:47:44 +C Try\sto\savoid\sreading\spages\swhen\smoving\soverflow\schains\sto\sthe\sfree-list.\s(CVS\s3886) +D 2007-04-30T16:55:01 F Makefile.in 8cab54f7c9f5af8f22fd97ddf1ecfd1e1860de62 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -59,7 +59,7 @@ F src/alter.c 2c79ec40f65e33deaf90ca493422c74586e481a3 F src/analyze.c 4bbf5ddf9680587c6d4917e02e378b6037be3651 F src/attach.c a16ada4a4654a0d126b8223ec9494ebb81bc5c3c F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f -F src/btree.c 066ca57368d814ba8940d926a491f70c6866033f +F src/btree.c abdbd0261d2ab4fed65332cc93f959906c185d22 F src/btree.h 4c0b5855cef3e4e6627358aa69541d21a2015947 F src/build.c 02e01ec7907c7d947ab3041fda0e81eaed05db42 F src/callback.c 6414ed32d55859d0f65067aa5b88d2da27b3af9e @@ -465,7 +465,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 9466367d65f43d58020e709428268dc2ff98aa35 -R 7cca5d0f43767198fb71376aeea99069 +P 89b1b3f897bda1fffceb9cf72fa4d42b809ccb8e +R 25da30ea21a3fd3e2f878c36734a5bb9 U danielk1977 -Z 03907aab221cf0da66dda4d095ab65a6 +Z f3a814360f6db57fb203458a6b31fb7b diff --git a/manifest.uuid b/manifest.uuid index a4bc6b26fd..a39bd2cabe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -89b1b3f897bda1fffceb9cf72fa4d42b809ccb8e \ No newline at end of file +8cccec68bd9073b2b19d3d31cf0b77b0ce76172e \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 7be48daded..085d4e8085 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.361 2007/04/28 15:47:44 danielk1977 Exp $ +** $Id: btree.c,v 1.362 2007/04/30 16:55:01 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -4046,6 +4046,60 @@ static int freePage(MemPage *pPage){ return rc; } +/* +** Get a MemPage structure for overflow page number ovfl. If it +** is not zero, the page number of the overflow page following the +** one retrieved is written to *pPgnoNext. +** +** If it is possible to figure out the page-number of the next +** overflow page without reading the data of page ovfl, then +** sqlite3PagerAcquire() is passed the "noContent" flag when +** page ovfl is retrieved. +*/ +static int getOverflowPage( + BtShared *pBt, + Pgno ovfl, + MemPage **ppPage, + Pgno *pPgnoNext +){ + Pgno next = 0; + int rc; + + if( !pPgnoNext ){ + return getPage(pBt, ovfl, ppPage, 1); + } + +#ifndef SQLITE_OMIT_AUTOVACUUM + if( pBt->autoVacuum ){ + Pgno pgno; + Pgno iGuess = ovfl+1; + u8 eType; + + while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){ + iGuess++; + } + + if( iGuesspPager) ){ + rc = ptrmapGet(pBt, iGuess, &eType, &pgno); + if( rc!=SQLITE_OK ){ + return rc; + } + if( eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){ + next = iGuess; + } + } + } +#endif + + rc = getPage(pBt, ovfl, ppPage, 0); + if( rc==SQLITE_OK ){ + assert(next==0 || next==get4byte((*ppPage)->aData)); + next = get4byte((*ppPage)->aData); + } + *pPgnoNext = next; + return rc; +} + /* ** Free any overflow pages associated with the given Cell. */ @@ -4070,11 +4124,9 @@ static int clearCell(MemPage *pPage, unsigned char *pCell){ if( ovflPgno==0 || ovflPgno>sqlite3PagerPagecount(pBt->pPager) ){ return SQLITE_CORRUPT_BKPT; } - rc = getPage(pBt, ovflPgno, &pOvfl, nOvfl==0); + + rc = getOverflowPage(pBt, ovflPgno, &pOvfl, (nOvfl==0)?0:&ovflPgno); if( rc ) return rc; - if( nOvfl ){ - ovflPgno = get4byte(pOvfl->aData); - } rc = freePage(pOvfl); sqlite3PagerUnref(pOvfl->pDbPage); if( rc ) return rc;