Pager performance enhancements. (CVS 3125)
FossilOrigin-Name: 9c26570743d878dee963e37728969fb30a2fb436
This commit is contained in:
parent
f1d83a7134
commit
c001c58a72
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\stypo\sin\sdocumentation.\s\sTicket\s#1578.\s(CVS\s3124)
|
||||
D 2006-03-03T21:39:54
|
||||
C Pager\sperformance\senhancements.\s(CVS\s3125)
|
||||
D 2006-03-06T18:23:17
|
||||
F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b
|
||||
F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
|
||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||
@ -59,8 +59,8 @@ F src/os_unix.c 757a7b726764367f7b0595c4302969582c04413d
|
||||
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
|
||||
F src/os_win.c 8ced9ac82670bbf77492961a2f7ff80a87f1404f
|
||||
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
|
||||
F src/pager.c f65d0b05182ff6059e9566b2eed1ec5f0cddc2f6
|
||||
F src/pager.h 425a9e52d5404158de016799715cbc2c3d685178
|
||||
F src/pager.c dcc9966177d6fad54aefbcdb4fc49ed2cdda8672
|
||||
F src/pager.h 43f32f3847421f7502cfbb66f4eb2302b8033818
|
||||
F src/parse.y c2daaa24fa2c8e256af740f29d3d61ac552fbd49
|
||||
F src/pragma.c 27d5e395c5d950931c7ac4fe610e7c2993e2fa55
|
||||
F src/prepare.c cf0fc8ebaf94409955ecb09ffeb0099c9ef44693
|
||||
@ -355,7 +355,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||
P 34b560e81170b33b766a6a7cd462a227425c15d9
|
||||
R e2c712bd2bb5bc47bf91421593e8acaf
|
||||
P cb2e009f1748e8c4945e85a3d36b4435003412f0
|
||||
R a08949d926616be5599aabd575dcd92e
|
||||
U drh
|
||||
Z 0e21f9a12d523b738cd926bd7dc2a5b0
|
||||
Z 5dda9791f2fd667e7a224f45611c21fd
|
||||
|
@ -1 +1 @@
|
||||
cb2e009f1748e8c4945e85a3d36b4435003412f0
|
||||
9c26570743d878dee963e37728969fb30a2fb436
|
70
src/pager.c
70
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.260 2006/02/24 03:09:37 drh Exp $
|
||||
** @(#) $Id: pager.c,v 1.261 2006/03/06 18:23:17 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
#include "sqliteInt.h"
|
||||
@ -52,8 +52,8 @@
|
||||
** associated file-descriptor is returned. FILEHANDLEID() takes an OsFile
|
||||
** struct as it's argument.
|
||||
*/
|
||||
#define PAGERID(p) FILEHANDLEID(&(p)->fd)
|
||||
#define FILEHANDLEID(fd) (sqlite3OsFileHandle(&fd))
|
||||
#define PAGERID(p) ((int)(p->fd))
|
||||
#define FILEHANDLEID(fd) ((int)fd)
|
||||
|
||||
/*
|
||||
** The page cache as a whole is always in one of the following
|
||||
@ -190,9 +190,11 @@ struct PgHistory {
|
||||
** A macro used for invoking the codec if there is one
|
||||
*/
|
||||
#ifdef SQLITE_HAS_CODEC
|
||||
# define CODEC(P,D,N,X) if( P->xCodec ){ P->xCodec(P->pCodecArg,D,N,X); }
|
||||
# define CODEC1(P,D,N,X) if( P->xCodec!=0 ){ P->xCodec(P->pCodecArg,D,N,X); }
|
||||
# define CODEC2(P,D,N,X) ((char*)(P->xCodec!=0?P->xCodec(P->pCodecArg,D,N,X):D))
|
||||
#else
|
||||
# define CODEC(P,D,N,X)
|
||||
# define CODEC1(P,D,N,X) /* NO-OP */
|
||||
# define CODEC2(P,D,N,X) ((char*)D)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -290,7 +292,7 @@ struct Pager {
|
||||
#endif
|
||||
void (*xDestructor)(void*,int); /* Call this routine when freeing pages */
|
||||
void (*xReiniter)(void*,int); /* Call this routine when reloading pages */
|
||||
void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
|
||||
void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
|
||||
void *pCodecArg; /* First argument to xCodec() */
|
||||
PgHdr *aHash[N_PG_HASH]; /* Hash table to map page number to PgHdr */
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
@ -435,16 +437,6 @@ static int write32bits(OsFile *fd, u32 val){
|
||||
return sqlite3OsWrite(fd, ac, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the 32-bit integer 'val' into the page identified by page header
|
||||
** 'p' at offset 'offset'.
|
||||
*/
|
||||
static void store32bits(u32 val, PgHdr *p, int offset){
|
||||
char *ac;
|
||||
ac = &((char*)PGHDR_TO_DATA(p))[offset];
|
||||
put32bits(ac, val);
|
||||
}
|
||||
|
||||
/*
|
||||
** Read a 32-bit integer at offset 'offset' from the page identified by
|
||||
** page header 'p'.
|
||||
@ -1041,7 +1033,7 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
|
||||
#ifdef SQLITE_CHECK_PAGES
|
||||
pPg->pageHash = pager_pagehash(pPg);
|
||||
#endif
|
||||
CODEC(pPager, pData, pPg->pgno, 3);
|
||||
CODEC1(pPager, pData, pPg->pgno, 3);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@ -1154,7 +1146,7 @@ static int pager_reload_cache(Pager *pPager){
|
||||
}
|
||||
TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
if( rc ) break;
|
||||
CODEC(pPager, zBuf, pPg->pgno, 2);
|
||||
CODEC1(pPager, zBuf, pPg->pgno, 2);
|
||||
}else{
|
||||
memset(zBuf, 0, pPager->pageSize);
|
||||
}
|
||||
@ -2274,11 +2266,9 @@ static int pager_write_pagelist(PgHdr *pList){
|
||||
** any such pages to the file.
|
||||
*/
|
||||
if( pList->pgno<=pPager->dbSize ){
|
||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
|
||||
char *pData = CODEC2(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
|
||||
TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
|
||||
rc = sqlite3OsWrite(pPager->fd, PGHDR_TO_DATA(pList),
|
||||
pPager->pageSize);
|
||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
|
||||
rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize);
|
||||
TEST_INCR(pPager->nWrite);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
@ -2683,7 +2673,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
||||
pPager->pageSize);
|
||||
}
|
||||
TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
|
||||
CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
|
||||
if( rc!=SQLITE_OK ){
|
||||
i64 fileSize;
|
||||
int rc2 = sqlite3OsFileSize(pPager->fd, &fileSize);
|
||||
@ -3002,7 +2992,6 @@ int sqlite3pager_write(void *pData){
|
||||
if( !pPg->inJournal && (pPager->useJournal || MEMDB) ){
|
||||
if( (int)pPg->pgno <= pPager->origDbSize ){
|
||||
int szPg;
|
||||
u32 saved;
|
||||
if( MEMDB ){
|
||||
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
|
||||
TRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
@ -3012,24 +3001,25 @@ int sqlite3pager_write(void *pData){
|
||||
memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize);
|
||||
}
|
||||
}else{
|
||||
u32 cksum;
|
||||
u32 cksum, saved;
|
||||
char *pData2, *pEnd;
|
||||
/* We should never write to the journal file the page that
|
||||
** contains the database locks. The following assert verifies
|
||||
** that we do not. */
|
||||
assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
|
||||
CODEC(pPager, pData, pPg->pgno, 7);
|
||||
cksum = pager_cksum(pPager, pData);
|
||||
saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager);
|
||||
store32bits(cksum, pPg, pPager->pageSize);
|
||||
pData2 = CODEC2(pPager, pData, pPg->pgno, 7);
|
||||
cksum = pager_cksum(pPager, pData2);
|
||||
pEnd = pData2 + pPager->pageSize;
|
||||
pData2 -= 4;
|
||||
saved = *(u32*)pEnd;
|
||||
put32bits(pEnd, cksum);
|
||||
szPg = pPager->pageSize+8;
|
||||
store32bits(pPg->pgno, pPg, -4);
|
||||
|
||||
rc = sqlite3OsWrite(pPager->jfd, &((char*)pData)[-4], szPg);
|
||||
put32bits(pData2, pPg->pgno);
|
||||
rc = sqlite3OsWrite(pPager->jfd, pData2, szPg);
|
||||
pPager->journalOff += szPg;
|
||||
TRACE4("JOURNAL %d page %d needSync=%d\n",
|
||||
PAGERID(pPager), pPg->pgno, pPg->needSync);
|
||||
CODEC(pPager, pData, pPg->pgno, 0);
|
||||
*(u32*)PGHDR_TO_EXTRA(pPg, pPager) = saved;
|
||||
*(u32*)pEnd = saved;
|
||||
|
||||
/* An error has occured writing to the journal file. The
|
||||
** transaction will be rolled back by the layer above.
|
||||
@ -3074,12 +3064,10 @@ int sqlite3pager_write(void *pData){
|
||||
}
|
||||
TRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
}else{
|
||||
store32bits(pPg->pgno, pPg, -4);
|
||||
CODEC(pPager, pData, pPg->pgno, 7);
|
||||
rc = sqlite3OsWrite(pPager->stfd,((char*)pData)-4,
|
||||
pPager->pageSize+4);
|
||||
char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7)-4;
|
||||
put32bits(pData2, pPg->pgno);
|
||||
rc = sqlite3OsWrite(pPager->stfd, pData2, pPager->pageSize+4);
|
||||
TRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
CODEC(pPager, pData, pPg->pgno, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
@ -3551,7 +3539,7 @@ int sqlite3pager_nosync(Pager *pPager){
|
||||
*/
|
||||
void sqlite3pager_set_codec(
|
||||
Pager *pPager,
|
||||
void (*xCodec)(void*,void*,Pgno,int),
|
||||
void *(*xCodec)(void*,void*,Pgno,int),
|
||||
void *pCodecArg
|
||||
){
|
||||
pPager->xCodec = xCodec;
|
||||
@ -3580,7 +3568,7 @@ static int pager_incr_changecounter(Pager *pPager){
|
||||
|
||||
/* Increment the value just read and write it back to byte 24. */
|
||||
change_counter++;
|
||||
store32bits(change_counter, pPgHdr, 24);
|
||||
put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter);
|
||||
|
||||
/* Release the page reference. */
|
||||
sqlite3pager_unref(pPage);
|
||||
|
@ -13,7 +13,7 @@
|
||||
** subsystem. The page cache subsystem reads and writes a file a page
|
||||
** at a time and provides a journal for rollback.
|
||||
**
|
||||
** @(#) $Id: pager.h,v 1.49 2006/02/11 01:25:51 drh Exp $
|
||||
** @(#) $Id: pager.h,v 1.50 2006/03/06 18:23:17 drh Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PAGER_H_
|
||||
@ -105,7 +105,7 @@ const char *sqlite3pager_dirname(Pager*);
|
||||
const char *sqlite3pager_journalname(Pager*);
|
||||
int sqlite3pager_nosync(Pager*);
|
||||
int sqlite3pager_rename(Pager*, const char *zNewName);
|
||||
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
void sqlite3pager_set_codec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
|
||||
int sqlite3pager_movepage(Pager*,void*,Pgno);
|
||||
int sqlite3pager_reset(Pager*);
|
||||
int sqlite3pager_release_memory(int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user