aboutsummaryrefslogtreecommitdiff
path: root/src/wal.c
diff options
context:
space:
mode:
authordrh <>2022-07-11 18:11:51 +0000
committerdrh <>2022-07-11 18:11:51 +0000
commitfc7f8f81daea563caa61d62c282812f4f6bbf9df (patch)
tree9e01adca369cb730ef36e8084e46f7b6ded62945 /src/wal.c
parentcd9e86307911a04a211451569cdcee06af4b26a1 (diff)
downloadsqlite-fc7f8f81daea563caa61d62c282812f4f6bbf9df.tar.gz
sqlite-fc7f8f81daea563caa61d62c282812f4f6bbf9df.zip
Back out the optimization at [1a8c2e54375ee2cf7] because there are some
cases where it does not work. FossilOrigin-Name: fe39c8d5fd813308fb27a05ce257ff003d3c09c0372f500e8def5a528a2558b7
Diffstat (limited to 'src/wal.c')
-rw-r--r--src/wal.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/wal.c b/src/wal.c
index e7c1c053b..fdc4ac39b 100644
--- a/src/wal.c
+++ b/src/wal.c
@@ -3138,17 +3138,20 @@ int sqlite3WalFindFrame(
u32 *piRead /* OUT: Frame number (or zero) */
){
u32 iRead = 0; /* If !=0, WAL frame to return data from */
- u32 iLast; /* Last page in WAL for this reader */
+ u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
int iHash; /* Used to loop through N hash tables */
int iMinHash;
/* This routine is only be called from within a read transaction. */
assert( pWal->readLock>=0 || pWal->lockError );
- /* if pWal->readLock==0, then the WAL is ignored by the reader
- ** so return early, as if the WAL were empty.
+ /* If the "last page" field of the wal-index header snapshot is 0, then
+ ** no data will be read from the wal under any circumstances. Return early
+ ** in this case as an optimization. Likewise, if pWal->readLock==0,
+ ** then the WAL is ignored by the reader so return early, as if the
+ ** WAL were empty.
*/
- if( pWal->readLock==0 && pWal->bShmUnreliable==0 ){
+ if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){
*piRead = 0;
return SQLITE_OK;
}
@@ -3179,7 +3182,6 @@ int sqlite3WalFindFrame(
** table after the current read-transaction had started.
*/
iMinHash = walFramePage(pWal->minFrame);
- iLast = pWal->hdr.mxFrame;
for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){
WalHashLoc sLoc; /* Hash table location */
int iKey; /* Hash slot index */