Lines Matching refs:pgno
14250 typedef u32 Pgno;
14270 #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
14366 SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
14367 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
14376 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
14400 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno);
14434 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
14436 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
14444 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
14492 PgHdr *pDirty; /* Transient list of dirty sorted by pgno */
14494 Pgno pgno; /* Page number for this page */
14556 SQLITE_PRIVATE sqlite3_pcache_page *sqlite3PcacheFetch(PCache*, Pgno, int createFlag);
14557 SQLITE_PRIVATE int sqlite3PcacheFetchStress(PCache*, Pgno, sqlite3_pcache_page**);
14558 SQLITE_PRIVATE PgHdr *sqlite3PcacheFetchFinish(PCache*, Pgno, sqlite3_pcache_page *pPage);
14568 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
14570 /* Remove all pages with pgno>x. Reset the cache if x==0 */
14571 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
17321 SQLITE_PRIVATE int sqlite3CorruptPgnoError(int,Pgno);
18014 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
18747 Pgno pgnoRoot; /* Root page of the open btree cursor */
45289 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
45341 pPage->pgno));
45408 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
45541 Pgno pgno, /* Page number to obtain */
45563 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
45564 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
45582 Pgno pgno, /* Page number to obtain */
45611 pPg->pgno, pgno,
45615 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
45623 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
45638 Pgno pgno, /* Page number obtained */
45651 pPgHdr->pgno = pgno;
45653 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
45664 Pgno pgno, /* Page number obtained */
45673 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
45733 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
45752 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
45796 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
45801 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
45802 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
45803 p->pgno = newPgno;
45810 ** Drop every cache entry whose page number is greater than "pgno". The
45812 ** other than page 1 with a page number greater than pgno.
45814 ** If there is a reference to page 1 and the pgno parameter passed to this
45818 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
45822 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
45825 /* This routine never gets call with a positive pgno except right
45827 ** it must be that pgno==0.
45829 assert( p->pgno>0 );
45830 if( p->pgno>pgno ){
45835 if( pgno==0 && pCache->nRefSum ){
45841 pgno = 1;
45844 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
45865 ** Merge two lists of pages connected by pDirty and in pgno order.
45873 if( pA->pgno<pB->pgno ){
45895 ** Sort the list of pages in accending order by pgno. Pages are
46684 unsigned int iLimit /* Drop pages with this pgno or larger */
47913 SQLITE_PRIVATE int sqlite3WalFindFrame(Wal *, Pgno, u32 *);
47917 SQLITE_PRIVATE Pgno sqlite3WalDbsize(Wal *pWal);
47924 SQLITE_PRIVATE int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx);
47935 SQLITE_PRIVATE int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int);
48416 Pgno nOrig; /* Original number of pages in file */
48417 Pgno iSubRec; /* Index of first record in sub-journal */
48630 Pgno dbSize; /* Number of pages in the database */
48631 Pgno dbOrigSize; /* dbSize before the current transaction */
48632 Pgno dbFileSize; /* Number of pages in the database file */
48633 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
48662 Pgno mxPgno; /* Maximum allowed size of the database */
48673 int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */
48675 void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
48794 ** Return true if this pager uses a write-ahead log to read page pgno.
48795 ** Return false if the pager reads pgno directly from the database.
48798 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno pgno){
48802 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
49009 static int getPageNormal(Pager*,Pgno,DbPage**,int);
49010 static int getPageError(Pager*,Pgno,DbPage**,int);
49012 static int getPageMMap(Pager*,Pgno,DbPage**,int);
49047 Pgno pgno = pPg->pgno;
49051 if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){
49063 return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
49756 ** Set the bit number pgno in the PagerSavepoint.pInSavepoint
49760 static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
49766 if( pgno<=p->nOrig ){
49767 rc |= sqlite3BitvecSet(p->pInSavepoint, pgno);
49906 static int pager_truncate(Pager *pPager, Pgno nPage);
50251 Pgno pgno; /* The page number of a page in journal */
50286 rc = read32bits(jfd, *pOffset, &pgno);
50297 if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
50301 if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){
50315 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
50321 if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
50364 pPg = sqlite3PagerLookup(pPager, pgno);
50369 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
50381 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
50393 CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
50395 CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
50400 if( pgno>pPager->dbFileSize ){
50401 pPager->dbFileSize = pgno;
50406 CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
50407 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
50408 CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);
50411 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
50433 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
50458 if( pgno==1 ){
50464 if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); }
50624 static int pager_truncate(Pager *pPager, Pgno nPage){
50772 Pgno mxPg = 0; /* Size of the original file in pages */
50985 u32 iFrame = 0; /* Frame of WAL containing pgno */
50991 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50999 i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
51006 if( pPg->pgno==1 ){
51026 CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM_BKPT);
51030 IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno));
51032 PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));
51072 static int pagerUndoCallback(void *pCtx, Pgno iPg){
51123 rc = pagerUndoCallback((void *)pPager, pList->pgno);
51142 Pgno nTruncate, /* Database size after this commit */
51154 assert( p->pgno < p->pDirty->pgno );
51167 if( p->pgno<=nTruncate ){
51178 if( pList->pgno==1 ) pager_write_changecounter(pList);
51184 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
51239 static int pagerPagecount(Pager *pPager, Pgno *pnPage){
51240 Pgno nPage; /* Value to return via *pnPage */
51265 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
51273 pPager->mxPgno = (Pgno)nPage;
51311 Pgno nPage; /* Size of the database file */
51755 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
51932 assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize );
51952 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
51996 ** Obtain a reference to a memory mapped page object for page number pgno.
52007 Pgno pgno, /* Page number */
52022 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1) * pPager->pageSize, pData);
52037 p->pgno = pgno;
52056 sqlite3OsUnfetch(pPager->fd, (i64)(pPg->pgno-1)*pPager->pageSize, pPg->pData);
52147 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage *pPg){
52148 return pPg->pgno;
52361 && (pList->pDirty || pList->pgno>pPager->dbHintSize)
52369 Pgno pgno = pList->pgno;
52379 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
52380 i64 offset = (pgno-1)*(i64)pPager->pageSize; /* Offset to write */
52384 if( pList->pgno==1 ) pager_write_changecounter(pList);
52387 CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM_BKPT, pData);
52396 if( pgno==1 ){
52399 if( pgno>pPager->dbFileSize ){
52400 pPager->dbFileSize = pgno;
52405 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)pList->pData);
52408 PAGERID(pPager), pgno, pager_pagehash(pList)));
52409 IOTRACE(("PGOUT %p %d\n", pPager, pgno));
52412 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno));
52447 ** If successful, set the bit corresponding to pPg->pgno in the bitvecs
52466 || pPg->pgno>pPager->dbOrigSize
52479 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
52483 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
52484 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
52493 rc = addToSavepointBitvecs(pPager, pPg->pgno);
52590 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
53023 Pgno nPage; /* Number of pages in database file */
53338 ** page with page number pgno. If the requested reference is
53376 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
53395 Pgno pgno, /* Page number to fetch */
53409 if( pgno==0 ) return SQLITE_CORRUPT_BKPT;
53410 pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
53413 rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
53420 pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
53422 assert( pPg->pgno==pgno );
53429 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
53440 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
53448 pgno || noContent ){
53449 if( pgno>pPager->mxPgno ){
53461 if( pgno<=pPager->dbOrigSize ){
53462 TESTONLY( rc = ) sqlite3BitvecSet(pPager->pInJournal, pgno);
53465 TESTONLY( rc = ) addToSavepointBitvecs(pPager, pgno);
53470 IOTRACE(("ZERO %p %d\n", pPager, pgno));
53497 Pgno pgno, /* Page number to fetch */
53509 const int bMmapOk = (pgno>1
53518 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
53519 ** allows the compiler optimizer to reuse the results of the "pgno>1"
53520 ** test in the previous statement, and avoid testing pgno==0 in the
53521 ** common case where pgno is large. */
53522 if( pgno<=1 && pgno==0 ){
53531 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
53540 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
53544 pPg = sqlite3PagerLookup(pPager, pgno);
53547 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
53549 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
53562 return getPageNormal(pPager, pgno, ppPage, flags);
53569 Pgno pgno, /* Page number to fetch */
53573 UNUSED_PARAMETER(pgno);
53585 Pgno pgno, /* Page number to fetch */
53589 return pPager->xGet(pPager, pgno, ppPage, flags);
53603 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
53606 assert( pgno!=0 );
53608 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
53611 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
53630 assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */
53644 assert( pPg->pgno==1 );
53841 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
53844 CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
53856 rc = write32bits(pPager->jfd, iOff, pPg->pgno);
53863 IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
53867 PAGERID(pPager), pPg->pgno,
53873 rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
53876 rc |= addToSavepointBitvecs(pPager, pPg->pgno);
53930 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
53933 if( pPg->pgno<=pPager->dbOrigSize ){
53943 PAGERID(pPager), pPg->pgno,
53963 if( pPager->dbSize<pPg->pgno ){
53964 pPager->dbSize = pPg->pgno;
53982 Pgno nPageCount; /* Total number of pages in database file */
53983 Pgno pg1; /* First page of the sector pPg is located on. */
53988 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
54002 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
54005 if( pPg->pgno>nPageCount ){
54006 nPage = (pPg->pgno - pg1)+1;
54013 assert(pg1<=pPg->pgno);
54014 assert((pg1+nPage)>pPg->pgno);
54017 Pgno pg = pg1+ii;
54019 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
54079 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
54126 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
54127 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
54486 Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager));
54941 void *(*xCodec)(void*,void*,Pgno,int),
54967 CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData);
54981 ** Move the page pPg to location pgno in the file.
54984 ** pgno (which we call pPgOld) though that page is allowed to be
54985 ** in cache. If the page previously located at pgno is not already
55005 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
55007 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
55009 Pgno origPgno; /* The original page number */
55040 ** subjournalPage() may need to allocate space to store pPg->pgno into
55051 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
55052 IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
55054 /* If the journal needs to be sync()ed before page pPg->pgno can
55055 ** be written to, store pPg->pgno in local variable needSyncPgno.
55058 ** the journal needs to be sync()ed before database page pPg->pgno
55062 needSyncPgno = pPg->pgno;
55064 pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
55068 /* If the cache contains a page with page-number pgno, remove it
55070 ** page pgno before the 'move' operation, it needs to be retained
55074 pPgOld = sqlite3PagerLookup(pPager, pgno);
55087 origPgno = pPg->pgno;
55088 sqlite3PcacheMove(pPg, pgno);
55139 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
55140 assert( pPg->pgno!=iNew );
56353 u32 pgno; /* Page number of the frame */
56365 pgno = sqlite3Get4byte(&aFrame[0]);
56366 if( pgno==0 ){
56388 *piPage = pgno;
56812 u32 pgno; /* Database page number for frame */
56819 isValid = walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame);
56821 rc = walIndexAppend(pWal, iFrame, pgno);
57002 u32 iMin; /* Result pgno must be greater than iMin */
57067 Pgno dbpage;
57931 u32 pgno; /* Database page number for frame */
57937 if( !walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame) ) break;
58266 u32 pgno; /* Page number in db file */
58272 pgno = aPgno[i-iZero];
58273 iDbOff = (i64)(pgno-1) * szPage;
58415 ** Search the wal file for page pgno. If found, set *piRead to the frame that
58416 ** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
58424 Pgno pgno, /* Database page number to read data for */
58447 ** pgno. Each iteration of the following for() loop searches one
58464 ** (aPgno[iFrame]==pgno):
58485 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
58487 if( iFrame<=iLast && iFrame>=pWal->minFrame && aPgno[aHash[iKey]]==pgno ){
58506 if( walFramePgno(pWal, iTest)==pgno ){
58544 SQLITE_PRIVATE Pgno sqlite3WalDbsize(Wal *pWal){
58625 SQLITE_PRIVATE int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
58628 Pgno iMax = pWal->hdr.mxFrame;
58629 Pgno iFrame;
58818 walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame);
58887 Pgno nTruncate, /* Database size after this commit */
58992 VVA_ONLY(rc =) sqlite3WalFindFrame(pWal, p->pgno, &iWrite);
59084 rc = walIndexAppend(pWal, iFrame, p->pgno);
59089 rc = walIndexAppend(pWal, iFrame, pLast->pgno);
59681 Pgno pgno; /* Page number for this page */
59717 Pgno iTable; /* Root page of table */
59913 Pgno *aOverflow; /* Cache of overflow page locations */
59917 Pgno pgnoRoot; /* The root page of this tree */
59993 ** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
59994 ** then pgno is returned. So (pgno==PTRMAP_PAGENO(pgsz, pgno)) can be
59995 ** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
59998 #define PTRMAP_PAGENO(pBt, pgno) ptrmapPageno(pBt, pgno)
59999 #define PTRMAP_PTROFFSET(pgptrmap, pgno) (5*(pgno-pgptrmap-1))
60000 #define PTRMAP_ISPAGE(pBt, pgno) (PTRMAP_PAGENO((pBt),(pgno))==(pgno))
60076 Pgno nPage; /* Number of pages in the database */
60532 (int)p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0)
60543 # define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno)
60573 Pgno iRoot, /* Root page of b-tree */
60578 Pgno iTab = 0;
60658 static int hasReadConflicts(Btree *pBtree, Pgno iRoot){
60678 static int querySharedCacheTableLock(Btree *p, Pgno iTab, u8 eLock){
60750 static int setSharedCacheTableLock(Btree *p, Pgno iTable, u8 eLock){
60935 Pgno pgnoRoot, /* The table that might be changing */
60959 ** Set bit pgno of the BtShared.pHasContent bitvec. This is called
60993 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
60996 assert( pgno<=pBt->nPage );
61002 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
61003 rc = sqlite3BitvecSet(pBt->pHasContent, pgno);
61015 static int btreeGetHasContent(BtShared *pBt, Pgno pgno){
61017 return (p && (pgno>sqlite3BitvecSize(p) || sqlite3BitvecTest(p, pgno)));
61116 static int SQLITE_NOINLINE saveCursorsOnList(BtCursor*,Pgno,BtCursor*);
61139 static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
61158 Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */
61342 ** Return 0 (not a valid page) for pgno==1 since there is
61346 static Pgno ptrmapPageno(BtShared *pBt, Pgno pgno){
61348 Pgno iPtrMap, ret;
61350 if( pgno<2 ) return 0;
61352 iPtrMap = (pgno-2)/nPagesPerMapPage;
61364 ** so that it maps to type 'eType' and parent page number 'pgno'.
61370 static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){
61373 Pgno iPtrmap; /* The pointer map page number */
61422 static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
61759 Pgno ovfl = get4byte(&pCell[info.nSize-4]);
61760 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
62179 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
62249 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
62378 assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
62409 static MemPage *btreePageFromDbPage(DbPage *pDbPage, Pgno pgno, BtShared *pBt){
62411 if( pgno!=pPage->pgno ){
62415 pPage->pgno = pgno;
62416 pPage->hdrOffset = pgno==1 ? 100 : 0;
62435 Pgno pgno, /* Number of the page to fetch */
62444 rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, flags);
62446 *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
62455 static MemPage *btreePageLookup(BtShared *pBt, Pgno pgno){
62458 pDbPage = sqlite3PagerLookup(pBt->pPager, pgno);
62460 return btreePageFromDbPage(pDbPage, pgno, pBt);
62469 static Pgno btreePagecount(BtShared *pBt){
62493 Pgno pgno, /* Number of the page to get */
62505 if( pgno>btreePagecount(pBt) ){
62509 rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
62515 btreePageFromDbPage(pDbPage, pgno, pBt);
62522 assert( (*ppPage)->pgno==pgno );
62528 rc = SQLITE_CORRUPT_PGNO(pgno);
62539 testcase( pgno==0 );
62540 assert( pgno!=0 || rc==SQLITE_CORRUPT );
62584 Pgno pgno, /* Number of the page to fetch */
62588 int rc = btreeGetPage(pBt, pgno, ppPage, flags);
62797 assert( sizeof(Pgno)==4 );
63846 Pgno pgno = pPage->pgno;
63859 Pgno childPgno = get4byte(pCell);
63860 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
63865 Pgno childPgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
63866 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
63886 static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
63943 ** the journal needs to be sync()ed before database page pDbPage->pgno
63951 Pgno iPtrPage, /* Pointer map 'page-no' entry for pDbPage */
63952 Pgno iFreePage, /* The location to move pDbPage to */
63956 Pgno iDbPage = pDbPage->pgno;
63972 pDbPage->pgno = iFreePage;
63988 Pgno nextOvfl = get4byte(pDbPage->aData);
64021 static int allocateBtreePage(BtShared *, MemPage **, Pgno *, Pgno, u8);
64040 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
64041 Pgno nFreeList; /* Number of pages still on the free-list */
64049 Pgno iPtrPage;
64071 Pgno iFreePg;
64081 Pgno iFreePg; /* Index of free page to move pLastPg to */
64084 Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */
64136 static Pgno finalDbSize(BtShared *pBt, Pgno nOrig, Pgno nFree){
64138 Pgno nPtrmap; /* Number of PtrMap pages to be freed */
64139 Pgno nFin; /* Return value */
64171 Pgno nOrig = btreePagecount(pBt);
64172 Pgno nFree = get4byte(&pBt->pPage1->aData[36]);
64173 Pgno nFin = finalDbSize(pBt, nOrig, nFree);
64213 Pgno nFin; /* Number of pages in database after autovacuuming */
64214 Pgno nFree; /* Number of pages on the freelist initially */
64215 Pgno iFree; /* The next page to be freed */
64216 Pgno nOrig; /* Database size before freeing */
64692 pCur->pgnoRoot = (Pgno)iTable;
64702 if( pX->pgnoRoot==(Pgno)iTable ){
64850 return (i64)pCur->pBt->pageSize*((i64)pCur->pPage->pgno - 1) +
64892 Pgno ovfl, /* Current overflow page number */
64894 Pgno *pPgnoNext /* OUT: Next overflow page number */
64896 Pgno next = 0;
64911 Pgno pgno;
64912 Pgno iGuess = ovfl+1;
64920 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
64921 if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
65061 Pgno nextPage;
65075 Pgno *aNew = (Pgno*)sqlite3Realloc(
65076 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
65085 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
65348 static void assertParentIndex(MemPage *pParent, int iIdx, Pgno iChild){
65379 pCur->pPage->pgno
65453 assert( pRoot->pgno==pCur->pgnoRoot );
65479 Pgno subpage;
65480 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
65499 Pgno pgno;
65507 pgno = get4byte(findCell(pPage, pCur->ix));
65508 rc = moveToChild(pCur, pgno);
65524 Pgno pgno;
65531 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
65533 rc = moveToChild(pCur, pgno);
65716 Pgno chldPg;
66141 Pgno *pPgno, /* Store the page number here */
66142 Pgno nearby, /* Search for a page near this one */
66151 Pgno mxPage; /* Total size of the database file */
66166 Pgno iTrunk;
66218 rc = SQLITE_CORRUPT_PGNO(pPrevTrunk ? pPrevTrunk->pgno : 1);
66279 Pgno iNewTrunk = get4byte(&pTrunk->aData[8]);
66315 Pgno iPage;
66357 *pPgno, closest+1, k, pTrunk->pgno, n-1));
66460 static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
66462 Pgno iTrunk = 0; /* Page number of free-list trunk page */
66470 assert( !pMemPage || pMemPage->pgno==iPage );
66557 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
66578 TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, iTrunk));
66590 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
66605 Pgno ovflPgno;
66628 Pgno iNext = 0;
66694 Pgno pgnoOvfl;
66759 ** pPrior Where to write the pgno of the first overflow page
66806 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
66931 Pgno iChild, /* If non-zero, replace first 4 bytes with this value */
67383 Pgno pgnoNew; /* Page number of pNew */
67422 ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
67450 0, pPage->pgno, &rc);
67473 Pgno n;
67486 Pgno ovfl = get4byte(&z[info.nSize-4]);
67488 assert( n==pPage->pgno && e==PTRMAP_OVERFLOW1 );
67491 Pgno child = get4byte(z);
67493 assert( n==pPage->pgno && e==PTRMAP_BTREE );
67497 Pgno child = get4byte(&pPage->aData[pPage->hdrOffset+8]);
67499 assert( n==pPage->pgno && e==PTRMAP_BTREE );
67529 int const iToHdr = ((pTo->pgno==1) ? 100 : 0);
67633 Pgno pgno; /* Temp var to store a page number in */
67635 Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
67636 Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
67648 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
67694 pgno = get4byte(pRight);
67696 rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
67706 pgno = get4byte(apDiv[i]);
67711 pgno = get4byte(apDiv[i]);
67992 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
67994 apOld[0]->pgno, apOld[0]->nCell,
67995 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
67996 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
68013 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
68022 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
68043 aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
68064 pgno = aPgOrder[iBest];
68070 sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
68071 apNew[i]->pgno = pgno;
68077 apNew[0]->pgno, szNew[0], cntNew[0],
68078 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
68080 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
68082 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
68084 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
68089 put4byte(pRight, apNew[nNew-1]->pgno);
68142 || pNew->pgno!=aPgno[iOld]
68146 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
68204 insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
68305 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
68368 Pgno pgnoChild = 0; /* Page number of the new child page */
68380 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
68383 ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
68395 TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
68468 && pParent->pgno!=1
68668 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
68882 Pgno n;
68886 n = pCur->apPage[iCellDepth+1]->pgno;
68888 n = pCur->pPage->pgno;
68968 Pgno
68983 Pgno pgnoMove; /* Move a page here to make room for the root-page */
69027 Pgno iPtrPage = 0;
69122 Pgno pgno, /* Page number to clear */
69134 if( pgno>btreePagecount(pBt) ){
69137 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
69193 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
69199 invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
69200 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
69235 static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
69244 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
69259 Pgno maxRootPgno;
69517 static int getPageReferenced(IntegrityCk *pCheck, Pgno iPg){
69525 static void setPageReferenced(IntegrityCk *pCheck, Pgno iPg){
69539 static int checkRef(IntegrityCk *pCheck, Pgno iPage){
69561 Pgno iChild, /* Child page number */
69563 Pgno iParent /* Expected pointer map parent page number */
69567 Pgno iPtrmapParent;
69607 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
69625 Pgno iFreePage = get4byte(&pOvflData[8+i*4]);
69734 int pgno; /* Page number */
69764 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
69801 pgno = get4byte(&data[hdr+8]);
69805 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
69808 depth = checkTreePage(pCheck, pgno, &maxKey, maxKey);
69853 Pgno pgnoOvfl; /* First page of the overflow chain */
69867 pgno = get4byte(pCell);
69870 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
69873 d2 = checkTreePage(pCheck, pgno, &maxKey, maxKey);
69996 Pgno i;
70414 Pgno iNext; /* Page number of the next source page to copy */
70423 Pgno nRemaining; /* Number of pages left to copy */
70424 Pgno nPagecount; /* Total number of pages to copy */
70616 Pgno iSrcPg, /* Source database page to backup */
70674 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
70808 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
70809 const Pgno iSrcPg = p->iNext; /* Source page number */
70823 if( p->iNext>(Pgno)nSrcPage ){
70890 Pgno iPg;
70909 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
70931 const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
71079 Pgno iPage,
71102 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *pBackup, Pgno iPage, const u8 *aData){
83571 int pgno;
83573 rc = sqlite3BtreeCreateTable(pCx->pBtx, &pgno, BTREE_BLOBKEY | pOp->p5);
83575 assert( pgno==MASTER_ROOT+1 );
83578 rc = sqlite3BtreeCursor(pCx->pBtx, pgno, BTREE_WRCSR,
85522 int pgno;
85526 pgno = 0;
85533 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, pOp->p3);
85535 pOut->u.i = pgno;
146740 SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){
146742 sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno);
178330 ** SELECT data FROM sqlite_dbpage('aux1') WHERE pgno=123;
178351 int pgno; /* Current page number */
178385 "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
178413 ** 1 schema=main, pgno=?1
178415 ** 3 schema=?1, pgno=?2
178446 /* Check for constraints against pgno */
178482 pCsr->pgno = -1;
178505 pCsr->pgno++;
178511 return pCsr->pgno > pCsr->mxPgno;
178518 ** 1 schema=main, pgno=?1
178520 ** 3 schema=?1, pgno=?2
178536 pCsr->pgno = 1;
178555 pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]);
178556 if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){
178557 pCsr->pgno = 1;
178560 pCsr->mxPgno = pCsr->pgno;
178563 assert( pCsr->pgno==1 );
178578 case 0: { /* pgno */
178579 sqlite3_result_int(ctx, pCsr->pgno);
178584 rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
178603 *pRowid = pCsr->pgno;
178614 Pgno pgno;
178628 pgno = sqlite3_value_int(argv[0]);
178629 if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
178640 if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){
178652 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0);
194446 #define fts5_dri(segid, dlidx, height, pgno) ( \
194450 ((i64)(pgno)) \
194453 #define FTS5_SEGMENT_ROWID(segid, pgno) fts5_dri(segid, 0, 0, pgno)
194454 #define FTS5_DLIDX_ROWID(segid, height, pgno) fts5_dri(segid, 1, height, pgno)
194564 int pgno; /* Page number for this page */
194571 int pgno; /* Page number for this page */
196340 int pgno;
196345 for(pgno=pIter->iLeafPgno+1; !p->rc && pgno<=pSeg->pgnoLast; pgno++){
196346 i64 iAbs = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
196354 pgnoLast = pgno;
196559 "SELECT pgno FROM '%q'.'%q_idx' WHERE "
197267 int pgno = pSeg->iLeafPgno;
197274 pgnoSave = pgno+1;
197284 pgno++;
197285 pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
197289 if( pgno==pgnoSave ){
197861 assert( pDlidx->pgno!=0 );
197863 FTS5_DLIDX_ROWID(pWriter->iSegid, i, pDlidx->pgno),
197961 pWriter->iBtPage = pWriter->writer.pgno;
198018 FTS5_DLIDX_ROWID(pWriter->iSegid, i, pDlidx->pgno),
198027 pDlidx[1].pgno = pDlidx->pgno;
198029 sqlite3Fts5BufferAppendVarint(&p->rc, &pDlidx[1].buf, pDlidx->pgno);
198037 pDlidx->pgno++;
198045 i64 iPgno = (i==0 ? pWriter->writer.pgno : pDlidx[-1].pgno);
198079 iRowid = FTS5_SEGMENT_ROWID(pWriter->iSegid, pPage->pgno);
198087 pPage->pgno++;
198137 if( pPage->pgno!=1 ){
198176 pWriter->aDlidx[0].pgno = pPage->pgno;
198257 assert( pLeaf->pgno>=1 );
198261 *pnLeaf = pLeaf->pgno-1;
198262 if( pLeaf->pgno>1 ){
198288 pWriter->writer.pgno = 1;
198302 "INSERT INTO '%q'.'%q_idx'(segid,term,pgno
198425 writer.writer.pgno = pSeg->pgnoLast+1;
199420 "segid, term, pgno, PRIMARY KEY(segid, term)",
199796 ** Instead, it tests that the same set of pgno/rowid combinations are
199814 int pgno = fts5DlidxIterPgno(pDlidx);
199815 assert( pgno>iLeaf );
199816 cksum1 += iRowid + ((i64)pgno<<32);
199826 int pgno = fts5DlidxIterPgno(pDlidx);
199828 cksum2 += iRowid + ((i64)pgno<<32);
200039 "SELECT segid, term, (pgno>>1), (pgno&1) FROM %Q.'%q_idx' WHERE segid=%d",
200292 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{%ssegid=%d h=%d pgno=%d}",
200661 int segid, pgno;
200664 "should be: fts5_rowid('segment', segid, pgno))", -1
200668 pgno = sqlite3_value_int(apVal[2]);
200669 iRowid = FTS5_SEGMENT_ROWID(segid, pgno);