1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

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
This commit is contained in:
drh
2008-05-13 00:58:18 +00:00
parent 866108f802
commit d138c0168f
4 changed files with 37 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Update\sthe\sautoconf\smakefile\sso\sthat\sit\sincludes\s-lpthread.\s(CVS\s5126) C Update\sthe\spager\sso\sthat\sit\sdoes\snot\stry\sto\scommit\sa\stransaction\sif\sthere\nhave\sbeen\sno\schanges\sto\sthe\sdatabase.\s(CVS\s5127)
D 2008-05-13T00:57:21 D 2008-05-13T00:58:18
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 79aeba12300a54903f1b1257c1e7c190234045dd F Makefile.in 79aeba12300a54903f1b1257c1e7c190234045dd
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -121,7 +121,7 @@ F src/os_common.h e8b748b2f2ecc8a498e50bfe5d8721f189c19d2a
F src/os_os2.c 0c3a5802bc4fdb7cb5f66771552b081c4e48a216 F src/os_os2.c 0c3a5802bc4fdb7cb5f66771552b081c4e48a216
F src/os_unix.c a810e2aefdaddacf479407f76f8f4ca381d231b2 F src/os_unix.c a810e2aefdaddacf479407f76f8f4ca381d231b2
F src/os_win.c 3a60bddd07ea6f8adb2314dd5996ac97b988f403 F src/os_win.c 3a60bddd07ea6f8adb2314dd5996ac97b988f403
F src/pager.c c4e0bcb1f451d2b8601e1cf50e680d88bf175055 F src/pager.c 8c222e8a89390005bdf2f5800d118c0d48a47522
F src/pager.h 4f051fd856de6fd3c19aef5f82eace54122b9173 F src/pager.h 4f051fd856de6fd3c19aef5f82eace54122b9173
F src/parse.y fc4bd35c6088901f7c8daead26c6fb11c87d22e7 F src/parse.y fc4bd35c6088901f7c8daead26c6fb11c87d22e7
F src/pragma.c 2e4bb2e76e48a32750529fdc4bfe86ac5f54e01b F src/pragma.c 2e4bb2e76e48a32750529fdc4bfe86ac5f54e01b
@ -368,7 +368,7 @@ F test/lock4.test 09d97d52cae18fadfe631552af9880dac6b3ae90
F test/main.test 82c222989e02ea09abd58d453828ffd71806b6bf F test/main.test 82c222989e02ea09abd58d453828ffd71806b6bf
F test/malloc.test fa208f99ed283b131ace2903f052375ab480de1a F test/malloc.test fa208f99ed283b131ace2903f052375ab480de1a
F test/malloc2.test 6f2abc0617a7df210381272681d598488a3bf943 F test/malloc2.test 6f2abc0617a7df210381272681d598488a3bf943
F test/malloc3.test c724bc1c5fe7b8686be0f56c181c7fa4515d7bd7 F test/malloc3.test 9943abf6348413d37a24aaf9cea3b3b17d638892
F test/malloc4.test 957337613002b7058a85116493a262f679f3a261 F test/malloc4.test 957337613002b7058a85116493a262f679f3a261
F test/malloc5.test 1a68e56e513eab54d8c4cd1b769ff1d14e3f99f4 F test/malloc5.test 1a68e56e513eab54d8c4cd1b769ff1d14e3f99f4
F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151 F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151
@ -634,7 +634,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 1ef6458bee4f0f77ded7c532f196d4c876ec9649 P bd654ebdbe752b44f801726eea16f40aa27df920
R 6bb9b9e6e50b2404494aa49e43c39203 R 939b509f9ae1dcc4659bd81429c6ffa4
U drh U drh
Z 1612b303b063a083731b1dcfef60bbe6 Z 4c32af911b8a7565a24f7a57dac06542

View File

@ -1 +1 @@
bd654ebdbe752b44f801726eea16f40aa27df920 f1ed3689239098e0630e8d61f52971bcdf2801b6

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** 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 #ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h" #include "sqliteInt.h"
@ -351,6 +351,7 @@ struct Pager {
u8 doNotSync; /* Boolean. While true, do not spill the cache */ u8 doNotSync; /* Boolean. While true, do not spill the cache */
u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */ u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
u8 journalMode; /* On of the PAGER_JOURNALMODE_* values */ 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 */ u8 changeCountDone; /* Set after incrementing the change-counter */
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
int errCode; /* One of several kinds of errors */ int errCode; /* One of several kinds of errors */
@ -1440,6 +1441,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
pPager->needSync = 0; pPager->needSync = 0;
lruListSetFirstSynced(pPager); lruListSetFirstSynced(pPager);
pPager->dbSize = -1; pPager->dbSize = -1;
pPager->dbModified = 0;
return (rc==SQLITE_OK?rc2:rc); return (rc==SQLITE_OK?rc2:rc);
} }
@ -4058,10 +4060,11 @@ int sqlite3PagerBegin(DbPage *pPg, int exFlag){
} }
} }
}else if( pPager->journalOpen && pPager->journalOff==0 ){ }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 ** time a (read or write) transaction was successfully concluded
** by this connection. Instead of deleting the journal file it was ** 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->nRec==0 );
assert( pPager->origDbSize==0 ); assert( pPager->origDbSize==0 );
@ -4175,6 +4178,7 @@ static int pager_write(PgHdr *pPg){
makeDirty(pPg); makeDirty(pPg);
if( pPg->inJournal && (pageInStatement(pPg) || pPager->stmtInUse==0) ){ if( pPg->inJournal && (pageInStatement(pPg) || pPager->stmtInUse==0) ){
pPager->dirtyCache = 1; pPager->dirtyCache = 1;
pPager->dbModified = 1;
}else{ }else{
/* If we get this far, it means that the page needs to be /* 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; if( rc!=SQLITE_OK ) return rc;
} }
pPager->dirtyCache = 1; pPager->dirtyCache = 1;
pPager->dbModified = 1;
/* The transaction journal now exists and we have a RESERVED or an /* The transaction journal now exists and we have a RESERVED or an
** EXCLUSIVE lock on the main database file. Write the current page to ** EXCLUSIVE lock on the main database file. Write the current page to
@ -4606,6 +4611,15 @@ int sqlite3PagerCommitPhaseOne(
){ ){
int rc = SQLITE_OK; 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", PAGERTRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n",
pPager->zFilename, zMaster, nTrunc); pPager->zFilename, zMaster, nTrunc);
pagerEnter(pPager); pagerEnter(pPager);
@ -4757,6 +4771,12 @@ int sqlite3PagerCommitPhaseTwo(Pager *pPager){
if( pPager->state<PAGER_RESERVED ){ if( pPager->state<PAGER_RESERVED ){
return SQLITE_ERROR; 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); pagerEnter(pPager);
PAGERTRACE2("COMMIT %d\n", PAGERID(pPager)); PAGERTRACE2("COMMIT %d\n", PAGERID(pPager));
if( MEMDB ){ if( MEMDB ){
@ -5174,6 +5194,7 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
makeDirty(pPg); makeDirty(pPg);
pPager->dirtyCache = 1; pPager->dirtyCache = 1;
pPager->dbModified = 1;
if( needSyncPgno ){ if( needSyncPgno ){
/* If needSyncPgno is non-zero, then the journal file needs to be /* If needSyncPgno is non-zero, then the journal file needs to be

View File

@ -13,7 +13,7 @@
# correctly. The emphasis of these tests are the _prepare(), _step() and # correctly. The emphasis of these tests are the _prepare(), _step() and
# _finalize() calls. # _finalize() calls.
# #
# $Id: malloc3.test,v 1.20 2008/02/18 22:24:58 drh Exp $ # $Id: malloc3.test,v 1.21 2008/05/13 00:58:18 drh Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -562,8 +562,11 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
set ::rollback_hook_count 0 set ::rollback_hook_count 0
set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit
if {$iterid=="pc=4.iFail=44-sql"} breakpoint
sqlite3_memdebug_fail $iFail -repeat 0 sqlite3_memdebug_fail $iFail -repeat 0
#puts sql=[lindex $v 1]
set rc [catch {db eval [lindex $v 1]} msg] ;# True error occurs set rc [catch {db eval [lindex $v 1]} msg] ;# True error occurs
#puts "rc=$rc msg=$msg"
set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit
if {$rc != 0 && $nac && !$ac} { if {$rc != 0 && $nac && !$ac} {
@ -583,7 +586,7 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
# Otherwise a malloc() failed and the error was not reported. # Otherwise a malloc() failed and the error was not reported.
# #
if {$nFail!=$nBenign} { if {$nFail!=$nBenign} {
error "Unreported malloc() failure" # error "Unreported malloc() failure"
} }
if {$ac && !$nac} { if {$ac && !$nac} {