aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2008-05-13 00:58:18 +0000
committerdrh <drh@noemail.net>2008-05-13 00:58:18 +0000
commitd138c0168f64a84f57d11f3247a3a93388c8f364 (patch)
tree36964c7bf2424357ef9315619205835cf226c940 /src
parent866108f802aadc4a2a1ac1f4bc5fc42564ce8f56 (diff)
downloadsqlite-d138c0168f64a84f57d11f3247a3a93388c8f364.tar.gz
sqlite-d138c0168f64a84f57d11f3247a3a93388c8f364.zip
Update the pager so that it does not try to commit a transaction if there
have been no changes to the database. (CVS 5127) FossilOrigin-Name: f1ed3689239098e0630e8d61f52971bcdf2801b6
Diffstat (limited to 'src')
-rw-r--r--src/pager.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/pager.c b/src/pager.c
index 75f069de6..58b69cb2d 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.444 2008/05/09 16:57:51 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.445 2008/05/13 00:58:18 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -351,6 +351,7 @@ struct Pager {
u8 doNotSync; /* Boolean. While true, do not spill the cache */
u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
u8 journalMode; /* On of the PAGER_JOURNALMODE_* values */
+ u8 dbModified; /* True if there are any changes to the Db */
u8 changeCountDone; /* Set after incrementing the change-counter */
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
int errCode; /* One of several kinds of errors */
@@ -1440,6 +1441,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
pPager->needSync = 0;
lruListSetFirstSynced(pPager);
pPager->dbSize = -1;
+ pPager->dbModified = 0;
return (rc==SQLITE_OK?rc2:rc);
}
@@ -4058,10 +4060,11 @@ int sqlite3PagerBegin(DbPage *pPg, int exFlag){
}
}
}else if( pPager->journalOpen && pPager->journalOff==0 ){
- /* This happens when the pager was in exclusive-access mode last
+ /* This happens when the pager was in exclusive-access mode the last
** time a (read or write) transaction was successfully concluded
** by this connection. Instead of deleting the journal file it was
- ** kept open and truncated to 0 bytes.
+ ** kept open and either was truncated to 0 bytes or its header was
+ ** overwritten with zeros.
*/
assert( pPager->nRec==0 );
assert( pPager->origDbSize==0 );
@@ -4175,6 +4178,7 @@ static int pager_write(PgHdr *pPg){
makeDirty(pPg);
if( pPg->inJournal && (pageInStatement(pPg) || pPager->stmtInUse==0) ){
pPager->dirtyCache = 1;
+ pPager->dbModified = 1;
}else{
/* If we get this far, it means that the page needs to be
@@ -4196,6 +4200,7 @@ static int pager_write(PgHdr *pPg){
if( rc!=SQLITE_OK ) return rc;
}
pPager->dirtyCache = 1;
+ pPager->dbModified = 1;
/* The transaction journal now exists and we have a RESERVED or an
** EXCLUSIVE lock on the main database file. Write the current page to
@@ -4606,6 +4611,15 @@ int sqlite3PagerCommitPhaseOne(
){
int rc = SQLITE_OK;
+ /* If no changes have been made, we can leave the transaction early.
+ */
+ if( pPager->dbModified==0 &&
+ (pPager->journalMode!=PAGER_JOURNALMODE_DELETE ||
+ pPager->exclusiveMode!=0) ){
+ assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
+ return SQLITE_OK;
+ }
+
PAGERTRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n",
pPager->zFilename, zMaster, nTrunc);
pagerEnter(pPager);
@@ -4757,6 +4771,12 @@ int sqlite3PagerCommitPhaseTwo(Pager *pPager){
if( pPager->state<PAGER_RESERVED ){
return SQLITE_ERROR;
}
+ if( pPager->dbModified==0 &&
+ (pPager->journalMode!=PAGER_JOURNALMODE_DELETE ||
+ pPager->exclusiveMode!=0) ){
+ assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
+ return SQLITE_OK;
+ }
pagerEnter(pPager);
PAGERTRACE2("COMMIT %d\n", PAGERID(pPager));
if( MEMDB ){
@@ -5174,6 +5194,7 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
makeDirty(pPg);
pPager->dirtyCache = 1;
+ pPager->dbModified = 1;
if( needSyncPgno ){
/* If needSyncPgno is non-zero, then the journal file needs to be