From d33d5a8978231e77e8c472195430bd3920017db8 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Apr 2007 12:11:28 +0000 Subject: [PATCH] In the pager, load the content of pages which were initialized with noContent==1 if they are subsequently requested with noContent==0. (CVS 3875) FossilOrigin-Name: d0745a43b6e037d16e1ec38c7c4d961a80d1ef48 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index f72d2611fd..468280e0d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssegfaults\sthat\scan\soccur\sif\sa\smalloc\sfailure\shappens\sjust\sbefore\na\sbuilt-in\sfunction\scalls\ssqlite3_value_text().\s(CVS\s3874) -D 2007-04-25T18:23:53 +C In\sthe\spager,\sload\sthe\scontent\sof\spages\swhich\swere\sinitialized\swith\nnoContent==1\sif\sthey\sare\ssubsequently\srequested\swith\snoContent==0.\s(CVS\s3875) +D 2007-04-26T12:11:28 F Makefile.in 8cab54f7c9f5af8f22fd97ddf1ecfd1e1860de62 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -87,7 +87,7 @@ F src/os_unix.c 426b4c03c304ad78746d65d9ba101e0b72e18e23 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c e94903c7dc1c0599c8ddce42efa0b6928068ddc5 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c 33c632ce9c228d87f14879a139fa123d43e4bf25 +F src/pager.c cd2770b0f8bd1900b46121009336e7ad03fb274f F src/pager.h d652ddf092d2318d00e41f8539760fe8e57c157c F src/parse.y b6cfbadb6d5b21b5087d30698ee5af0ebb098767 F src/pragma.c 3b992b5b2640d6ae25cef05aa6a42cd1d6c43234 @@ -462,7 +462,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 66646d6fda067e19240808aef65fafd8fa177cdd -R 48b7346bd8cf5e77d4009859f7c6c683 +P 9cb0ed6ee9827bc6884a0195044d5b6ad0de698e +R 654420a2ec3eb1f548ed11aa685883b0 U drh -Z fd08492b87e717e5d32a8be7d387293c +Z 352203b1a39e1bdcedb9d02c8002561c diff --git a/manifest.uuid b/manifest.uuid index 1a153c3032..18747468d4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9cb0ed6ee9827bc6884a0195044d5b6ad0de698e \ No newline at end of file +d0745a43b6e037d16e1ec38c7c4d961a80d1ef48 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index b7fae8ed87..032902499b 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.329 2007/04/16 15:02:19 drh Exp $ +** @(#) $Id: pager.c,v 1.330 2007/04/26 12:11:28 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -2922,13 +2922,32 @@ pager_allocate_out: return rc; } +/* +** Make sure we have the content for a page. If the page was +** previously acquired with noContent==1, then the content was +** just initialized to zeros instead of being read from disk. +** But now we need the real data off of disk. So make sure we +** have it. Read it in if we do not have it already. +*/ +static int pager_get_content(PgHdr *pPg){ + if( pPg->needRead ){ + int rc = readDbPage(pPg->pPager, pPg, pPg->pgno); + if( rc==SQLITE_OK ){ + pPg->needRead = 0; + }else{ + return rc; + } + } + return SQLITE_OK; +} + /* ** Acquire a page. ** ** A read lock on the disk file is obtained when the first page is acquired. ** This read lock is dropped when the last page is released. ** -** A _get works for any page number greater than 0. If the database +** This routine works for any page number greater than 0. If the database ** file is smaller than the requested page, then no actual disk ** read occurs and the memory image of the page is initialized to ** all zeros. The extra data appended to a page is always initialized @@ -2937,12 +2956,12 @@ pager_allocate_out: ** The acquisition might fail for several reasons. In all cases, ** an appropriate error code is returned and *ppPage is set to NULL. ** -** See also sqlite3PagerLookup(). Both this routine and _lookup() attempt +** See also sqlite3PagerLookup(). Both this routine and Lookup() attempt ** to find a page in the in-memory cache first. If the page is not already -** in memory, this routine goes to disk to read it in whereas _lookup() +** in memory, this routine goes to disk to read it in whereas Lookup() ** just returns 0. This routine acquires a read-lock the first time it ** has to go to disk, and could also playback an old journal if necessary. -** Since _lookup() never goes to disk, it never has to deal with locks +** Since Lookup() never goes to disk, it never has to deal with locks ** or journal files. ** ** If noContent is false, the page contents are actually read from disk. @@ -2950,8 +2969,9 @@ pager_allocate_out: ** of the page at this time, so do not do a disk read. Just fill in the ** page content with zeros. But mark the fact that we have not read the ** content by setting the PgHdr.needRead flag. Later on, if -** sqlite3PagerWrite() is called on this page, that means that the -** content is needed and the disk read should occur at that point. +** sqlite3PagerWrite() is called on this page or if this routine is +** called again with noContent==0, that means that the content is needed +** and the disk read should occur at that point. */ int sqlite3PagerAcquire( Pager *pPager, /* The pager open on the database file */ @@ -3060,6 +3080,12 @@ int sqlite3PagerAcquire( /* The requested page is in the page cache. */ assert(pPager->nRef>0 || pgno==1); PAGER_INCR(pPager->nHit); + if( !noContent ){ + rc = pager_get_content(pPg); + if( rc ){ + return rc; + } + } page_ref(pPg); } *ppPage = pPg; @@ -3367,13 +3393,9 @@ static int pager_write(PgHdr *pPg){ ** can be stored in the rollback journal. So do the read at this ** time. */ - if( pPg->needRead ){ - rc = readDbPage(pPager, pPg, pPg->pgno); - if( rc==SQLITE_OK ){ - pPg->needRead = 0; - }else{ - return rc; - } + rc = pager_get_content(pPg); + if( rc ){ + return rc; } /* Mark the page as dirty. If the page has already been written