Store the page number for the PENDING_BYTE page in the Pager object, rather
than computing the page number every time it is needed, because it turns out that number is needed quite frequently. This saves a few hundred thousand CPU cycles and a few bytes of code space. FossilOrigin-Name: 5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a
This commit is contained in:
parent
f2a777fa5d
commit
584bfcaeb6
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C For\sthe\s"PRAGMA\sdatabase_list"\sstatement,\sdo\snot\scheck\sto\ssee\sif\sthe\sschema\nis\sup-to-date\sand\sdo\snot\stry\sto\sreload\sthe\sschema.
|
||||
D 2022-02-22T20:29:31.035
|
||||
C Store\sthe\spage\snumber\sfor\sthe\sPENDING_BYTE\spage\sin\sthe\sPager\sobject,\srather\nthan\scomputing\sthe\spage\snumber\severy\stime\sit\sis\sneeded,\sbecause\sit\sturns\sout\nthat\snumber\sis\sneeded\squite\sfrequently.\s\sThis\ssaves\sa\sfew\shundred\sthousand\nCPU\scycles\sand\sa\sfew\sbytes\sof\scode\sspace.
|
||||
D 2022-02-23T17:00:44.801
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -494,7 +494,7 @@ F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d
|
||||
F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
|
||||
F src/btree.c 117808943727d27e38c69de4e79237e52c89ee40f6f1a70de4e6e14b5e596cbc
|
||||
F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22
|
||||
F src/btreeInt.h ee9348c4cb9077243b049edc93a82c1f32ca48baeabf2140d41362b9f9139ff7
|
||||
F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2
|
||||
F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8
|
||||
F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1c
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
@ -539,8 +539,8 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
|
||||
F src/os_unix.c f5ad51cfd024116db8531feab9efd831c2621436dca1464e4ff1e8af9bf3252e
|
||||
F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9
|
||||
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
|
||||
F src/pager.c cda9e2d1df7c5fb4d777d09e23e69d78c518550d8873ed08b4a66c41d8cf2543
|
||||
F src/pager.h 4bf9b3213a4b2bebbced5eaa8b219cf25d4a82f385d093cd64b7e93e5285f66f
|
||||
F src/pager.c 198e037aa1f945e19cc4b4e89a80a40c31fc6beafacfe068fb3ca88cb602b523
|
||||
F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3
|
||||
F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924
|
||||
F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b
|
||||
F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
|
||||
@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab
|
||||
R 8e774d76a97f244938c2cd31e6e650dd
|
||||
P 710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689
|
||||
R 31db230ec1e00447c3c5dedc2a12edf4
|
||||
U drh
|
||||
Z 87215546f30ba5e5b58306e47d0efae5
|
||||
Z d8442a86814fe9e42893b593cc0d0a34
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689
|
||||
5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a
|
@ -598,7 +598,7 @@ struct BtCursor {
|
||||
/*
|
||||
** The database page the PENDING_BYTE occupies. This page is never used.
|
||||
*/
|
||||
# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
|
||||
#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1))
|
||||
|
||||
/*
|
||||
** These macros define the location of the pointer-map entry for a
|
||||
|
20
src/pager.c
20
src/pager.c
@ -681,6 +681,7 @@ struct Pager {
|
||||
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
|
||||
u32 sectorSize; /* Assumed sector size during rollback */
|
||||
Pgno mxPgno; /* Maximum allowed size of the database */
|
||||
Pgno lckPgno; /* Page number for the locking page */
|
||||
i64 pageSize; /* Number of bytes in a page */
|
||||
i64 journalSizeLimit; /* Size limit for persistent journal files */
|
||||
char *zFilename; /* Name of the database file */
|
||||
@ -1667,7 +1668,7 @@ static int readJournalHdr(
|
||||
** journal file descriptor is advanced to the next sector boundary before
|
||||
** anything is written. The format is:
|
||||
**
|
||||
** + 4 bytes: PAGER_MJ_PGNO.
|
||||
** + 4 bytes: PAGER_SJ_PGNO.
|
||||
** + N bytes: super-journal filename in utf-8.
|
||||
** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
|
||||
** + 4 bytes: super-journal name checksum.
|
||||
@ -1715,7 +1716,7 @@ static int writeSuperJournal(Pager *pPager, const char *zSuper){
|
||||
/* Write the super-journal data to the end of the journal file. If
|
||||
** an error occurs, return the error code to the caller.
|
||||
*/
|
||||
if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
|
||||
if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager))))
|
||||
|| (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
|
||||
|| (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
|
||||
|| (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
|
||||
@ -2225,7 +2226,7 @@ static u32 pager_cksum(Pager *pPager, const u8 *aData){
|
||||
** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
|
||||
** two circumstances:
|
||||
**
|
||||
** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
|
||||
** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
|
||||
** * If the record is being rolled back from the main journal file
|
||||
** and the checksum field does not match the record content.
|
||||
**
|
||||
@ -2285,7 +2286,7 @@ static int pager_playback_one_page(
|
||||
** it could cause invalid data to be written into the journal. We need to
|
||||
** detect this invalid data (with high probability) and ignore it.
|
||||
*/
|
||||
if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
|
||||
if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){
|
||||
assert( !isSavepnt );
|
||||
return SQLITE_DONE;
|
||||
}
|
||||
@ -3740,6 +3741,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){
|
||||
pPager->pTmpSpace = pNew;
|
||||
pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
|
||||
pPager->pageSize = pageSize;
|
||||
pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1;
|
||||
}else{
|
||||
sqlite3PageFree(pNew);
|
||||
}
|
||||
@ -5509,7 +5511,7 @@ static int getPageNormal(
|
||||
if( pPg->pPager && !noContent ){
|
||||
/* In this case the pcache already contains an initialized copy of
|
||||
** the page. Return without further ado. */
|
||||
assert( pgno!=PAGER_MJ_PGNO(pPager) );
|
||||
assert( pgno!=PAGER_SJ_PGNO(pPager) );
|
||||
pPager->aStat[PAGER_STAT_HIT]++;
|
||||
return SQLITE_OK;
|
||||
|
||||
@ -5520,7 +5522,7 @@ static int getPageNormal(
|
||||
** (*) obsolete. Was: maximum page number is 2^31
|
||||
** (2) Never try to fetch the locking page
|
||||
*/
|
||||
if( pgno==PAGER_MJ_PGNO(pPager) ){
|
||||
if( pgno==PAGER_SJ_PGNO(pPager) ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto pager_acquire_err;
|
||||
}
|
||||
@ -5919,7 +5921,7 @@ static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg){
|
||||
/* 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) );
|
||||
assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) );
|
||||
|
||||
assert( pPager->journalHdr<=pPager->journalOff );
|
||||
pData2 = pPg->pData;
|
||||
@ -6098,7 +6100,7 @@ static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
|
||||
Pgno pg = pg1+ii;
|
||||
PgHdr *pPage;
|
||||
if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
|
||||
if( pg!=PAGER_MJ_PGNO(pPager) ){
|
||||
if( pg!=PAGER_SJ_PGNO(pPager) ){
|
||||
rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = pager_write(pPage);
|
||||
@ -6576,7 +6578,7 @@ int sqlite3PagerCommitPhaseOne(
|
||||
** last page is never written out to disk, leaving the database file
|
||||
** undersized. Fix this now if it is the case. */
|
||||
if( pPager->dbSize>pPager->dbFileSize ){
|
||||
Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager));
|
||||
Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager));
|
||||
assert( pPager->eState==PAGER_WRITER_DBMOD );
|
||||
rc = pager_truncate(pPager, nNew);
|
||||
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
|
||||
|
@ -43,14 +43,15 @@ typedef struct Pager Pager;
|
||||
typedef struct PgHdr DbPage;
|
||||
|
||||
/*
|
||||
** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
|
||||
** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is
|
||||
** reserved for working around a windows/posix incompatibility). It is
|
||||
** used in the journal to signify that the remainder of the journal file
|
||||
** is devoted to storing a super-journal name - there are no more pages to
|
||||
** roll back. See comments for function writeSuperJournal() in pager.c
|
||||
** for details.
|
||||
*/
|
||||
#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
|
||||
#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
|
||||
#define PAGER_SJ_PGNO(x) ((x)->lckPgno)
|
||||
|
||||
/*
|
||||
** Allowed values for the flags parameter to sqlite3PagerOpen().
|
||||
|
Loading…
Reference in New Issue
Block a user