From a168045f7d82dbc0754730a1618a61388f6f2e43 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 18 Apr 2002 01:56:57 +0000 Subject: [PATCH] Fix for ticket #19: Do not call sqliteOsSync() if the only changes were changes to TEMP tables. (CVS 530) FossilOrigin-Name: 33da20b9c1a8eef16ad7ab5929bb8937c75090f2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1b3a2afa8d..132b6c9ce0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sdoing\sa\s".dump"\scommand\sin\sthe\scommand-line\sshell,\smake\ssure\sVIEWs\nare\screated\safter\sTABLEs.\s(CVS\s529) -D 2002-04-13T23:42:24 +C Fix\sfor\sticket\s#19:\sDo\snot\scall\ssqliteOsSync()\sif\sthe\sonly\schanges\swere\nchanges\sto\sTEMP\stables.\s(CVS\s530) +D 2002-04-18T01:56:58 F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0 @@ -33,7 +33,7 @@ F src/main.c df43fe585d2bfb925c837b6822783c0ee3dd6e1c F src/md5.c b2b1a34fce66ceca97f4e0dabc20be8be7933c92 F src/os.c 5ab8b6b4590d0c1ab8e96c67996c170e4462e0fc F src/os.h 4a361fccfbc4e7609b3e1557f604f94c1e96ad10 -F src/pager.c f136f5ba82c896d500a10b6a2e5caea62abf716b +F src/pager.c ba5740104cc27b342cd43eebfdc44d60f64a3ded F src/pager.h 6fddfddd3b73aa8abc081b973886320e3c614f0e F src/parse.y 9a8a2311dd95101bb02b3991042e619eea49729a F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d @@ -131,7 +131,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P 977abbaebe5433c66516d0376a1c229e45b5ab1f -R 1d18e0543c9a9e3b6f1f1a88dc469706 +P 7edd13468e24d79939f0fa1e58f3b686422ca826 +R d6ef54d3be3cb5d13a1592b37489d27e U drh -Z c041d10ac3286386a2e3e11a69a41456 +Z aa513408483afd37049a6b0b765b2614 diff --git a/manifest.uuid b/manifest.uuid index 5f5f652d4c..18fa85fdde 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7edd13468e24d79939f0fa1e58f3b686422ca826 \ No newline at end of file +33da20b9c1a8eef16ad7ab5929bb8937c75090f2 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index ced0016bb2..79bb1e90b7 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.44 2002/03/06 22:01:36 drh Exp $ +** @(#) $Id: pager.c,v 1.45 2002/04/18 01:56:58 drh Exp $ */ #include "sqliteInt.h" #include "pager.h" @@ -120,6 +120,7 @@ struct Pager { u8 tempFile; /* zFilename is a temporary file */ u8 readOnly; /* True for a read-only database */ u8 needSync; /* True if an fsync() is needed on the journal */ + u8 dirtyFile; /* True if database file has changed in any way */ u8 *aInJournal; /* One bit for each page in the database file */ u8 *aInCkpt; /* One bit for each page in the database */ PgHdr *pFirst, *pLast; /* List of free pages */ @@ -444,7 +445,7 @@ end_ckpt_playback: */ void sqlitepager_set_cachesize(Pager *pPager, int mxPage){ if( mxPage>=0 ){ - pPager->noSync = 0; + pPager->noSync = pPager->tempFile; }else{ pPager->noSync = 1; mxPage = -mxPage; @@ -538,6 +539,7 @@ int sqlitepager_open( pPager->tempFile = tempFile; pPager->readOnly = readOnly; pPager->needSync = 0; + pPager->noSync = pPager->tempFile; pPager->pFirst = 0; pPager->pLast = 0; pPager->nExtra = nExtra; @@ -1036,7 +1038,8 @@ int sqlitepager_begin(void *pData){ return SQLITE_CANTOPEN; } pPager->journalOpen = 1; - pPager->needSync = !pPager->noSync; + pPager->needSync = 0; + pPager->dirtyFile = 0; pPager->state = SQLITE_WRITELOCK; sqlitepager_pagecount(pPager); pPager->origDbSize = pPager->dbSize; @@ -1088,6 +1091,7 @@ int sqlitepager_write(void *pData){ */ pPg->dirty = 1; if( pPg->inJournal && (pPg->inCkpt || pPager->ckptOpen==0) ){ + pPager->dirtyFile = 1; return SQLITE_OK; } @@ -1100,6 +1104,7 @@ int sqlitepager_write(void *pData){ */ assert( pPager->state!=SQLITE_UNLOCK ); rc = sqlitepager_begin(pData); + pPager->dirtyFile = 1; if( rc!=SQLITE_OK ) return rc; assert( pPager->state==SQLITE_WRITELOCK ); assert( pPager->journalOpen ); @@ -1238,6 +1243,13 @@ int sqlitepager_commit(Pager *pPager){ return SQLITE_ERROR; } assert( pPager->journalOpen ); + if( pPager->dirtyFile==0 ){ + /* Exit early (without doing the time-consuming sqliteOsSync() calls) + ** if there have been no changes to the database file. */ + rc = pager_unwritelock(pPager); + pPager->dbSize = -1; + return rc; + } if( pPager->needSync && sqliteOsSync(&pPager->jfd)!=SQLITE_OK ){ goto commit_abort; }