Home | History | Annotate | Download | only in dist

Lines Matching refs:pPage

10358   sqlite3_pcache_page *pPage;    /* Pcache object page handle */
10425 SQLITE_PRIVATE PgHdr *sqlite3PcacheFetchFinish(PCache*, Pgno, sqlite3_pcache_page *pPage);
12797 void *pPage; /* Page cache memory */
12798 int szPage; /* Size of each page in pPage[] */
12799 int nPage; /* Number of pages in pPage[] */
13975 (void*)0, /* pPage */
20709 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
20711 sqlite3GlobalConfig.pPage = 0;
39308 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
39309 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
39310 #define PCACHE_DIRTYLIST_FRONT 3 /* Move pPage to the front of the list */
39313 ** Manage pPage's participation on the dirty list. Bits of the addRemove
39315 ** remove pPage from the dirty list. The 0x02 means add pPage back to
39316 ** the dirty list. Doing both moves pPage to the front of the dirty list.
39318 static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
39319 PCache *p = pPage->pCache;
39322 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
39323 assert( pPage->pDirtyPrev || pPage==p->pDirty );
39326 if( p->pSynced==pPage ){
39327 PgHdr *pSynced = pPage->pDirtyPrev;
39334 if( pPage->pDirtyNext ){
39335 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
39337 assert( pPage==p->pDirtyTail );
39338 p->pDirtyTail = pPage->pDirtyPrev;
39340 if( pPage->pDirtyPrev ){
39341 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
39343 assert( pPage==p->pDirty );
39344 p->pDirty = pPage->pDirtyNext;
39350 pPage->pDirtyNext = 0;
39351 pPage->pDirtyPrev = 0;
39354 assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage );
39356 pPage->pDirtyNext = p->pDirty;
39357 if( pPage->pDirtyNext ){
39358 assert( pPage->pDirtyNext->pDirtyPrev==0 );
39359 pPage->pDirtyNext->pDirtyPrev = pPage;
39361 p->pDirtyTail = pPage;
39367 p->pDirty = pPage;
39368 if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
39369 p->pSynced = pPage;
39383 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
39594 sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
39597 assert( pPage!=0 );
39598 pPgHdr = (PgHdr*)pPage->pExtra;
39599 assert( pPgHdr->pPage==0 );
39601 pPgHdr->pPage = pPage;
39602 pPgHdr->pData = pPage->pBuf;
39607 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
39619 sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
39623 if( pPage==0 ) return 0;
39624 pPgHdr = (PgHdr *)pPage->pExtra;
39626 if( !pPgHdr->pPage ){
39627 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
39679 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
39737 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
40349 PgHdr1 *pPage;
40351 while( (pPage = pNext)!=0 ){
40352 unsigned int h = pPage->iKey % nNew;
40353 pNext = pPage->pNext;
40354 pPage->pNext = apNew[h];
40355 apNew[h] = pPage;
40365 ** This function is used internally to remove the page pPage from the
40366 ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
40371 static void pcache1PinPage(PgHdr1 *pPage){
40375 assert( pPage!=0 );
40376 assert( pPage->isPinned==0 );
40377 pCache = pPage->pCache;
40379 assert( pPage->pLruNext || pPage==pGroup->pLruTail );
40380 assert( pPage->pLruPrev || pPage==pGroup->pLruHead );
40382 if( pPage->pLruPrev ){
40383 pPage->pLruPrev->pLruNext = pPage->pLruNext;
40385 pGroup->pLruHead = pPage->pLruNext;
40387 if( pPage->pLruNext ){
40388 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
40390 pGroup->pLruTail = pPage->pLruPrev;
40392 pPage->pLruNext = 0;
40393 pPage->pLruPrev = 0;
40394 pPage->isPinned = 1;
40405 static void pcache1RemoveFromHash(PgHdr1 *pPage){
40407 PCache1 *pCache = pPage->pCache;
40411 h = pPage->iKey % pCache->nHash;
40412 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
40450 PgHdr1 *pPage;
40451 while( (pPage = *pp)!=0 ){
40452 if( pPage->iKey>=iLimit ){
40454 *pp = pPage->pNext;
40455 if( !pPage->isPinned ) pcache1PinPage(pPage);
40456 pcache1FreePage(pPage);
40458 pp = &pPage->pNext;
40625 PgHdr1 *pPage = 0;
40650 pPage = pGroup->pLruTail;
40651 assert( pPage->isPinned==0 );
40652 pcache1RemoveFromHash(pPage);
40653 pcache1PinPage(pPage);
40654 pOther = pPage->pCache;
40664 pcache1FreePage(pPage);
40665 pPage = 0;
40674 if( !pPage ){
40676 pPage = pcache1AllocPage(pCache);
40680 if( pPage ){
40683 pPage->iKey = iKey;
40684 pPage->pNext = pCache->apHash[h];
40685 pPage->pCache = pCache;
40686 pPage->pLruPrev = 0;
40687 pPage->pLruNext = 0;
40688 pPage->isPinned = 1;
40689 *(void **)pPage->page.pExtra = 0;
40690 pCache->apHash[h] = pPage;
40695 return pPage;
40758 PgHdr1 *pPage = 0;
40769 pPage = pCache->apHash[iKey % pCache->nHash];
40770 while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
40773 if( pPage ){
40774 if( !pPage->isPinned ) pcache1PinPage(pPage);
40777 pPage = pcache1FetchStage2(pCache, iKey, createFlag);
40779 assert( pPage==0 || pCache->iMaxKey>=iKey );
40781 return (sqlite3_pcache_page*)pPage;
40796 PgHdr1 *pPage = (PgHdr1 *)pPg;
40799 assert( pPage->pCache==pCache );
40805 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
40806 assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
40807 assert( pPage->isPinned==1 );
40810 pcache1RemoveFromHash(pPage);
40811 pcache1FreePage(pPage);
40815 pGroup->pLruHead->pLruPrev = pPage;
40816 pPage->pLruNext = pGroup->pLruHead;
40817 pGroup->pLruHead = pPage;
40819 pGroup->pLruTail = pPage;
40820 pGroup->pLruHead = pPage;
40823 pPage->isPinned = 0;
40839 PgHdr1 *pPage = (PgHdr1 *)pPg;
40842 assert( pPage->iKey==iOld );
40843 assert( pPage->pCache==pCache );
40849 while( (*pp)!=pPage ){
40852 *pp = pPage->pNext;
40855 pPage->iKey = iNew;
40856 pPage->pNext = pCache->apHash[h];
40857 pCache->apHash[h] = pPage;
42826 ** Return a 32-bit hash of the page data for pPage.
42836 static u32 pager_pagehash(PgHdr *pPage){
42837 return pager_datahash(pPage->pPager->pageSize, (unsigned char *)pPage->pData);
42839 static void pager_set_pagehash(PgHdr *pPage){
42840 pPage->pageHash = pager_pagehash(pPage);
45564 assert( p->pPage==0 );
47091 sqlite3_pcache_page *pPage;
47095 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
47096 assert( pPage==0 || pPager->hasBeenUsed );
47097 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
47482 PgHdr *pPage;
47485 rc = sqlite3PagerGet(pPager, pg, &pPage);
47487 rc = pager_write(pPage);
47488 if( pPage->flags&PGHDR_NEED_SYNC ){
47491 sqlite3PagerUnrefNotNull(pPage);
47494 }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
47495 if( pPage->flags&PGHDR_NEED_SYNC ){
47498 sqlite3PagerUnrefNotNull(pPage);
47511 PgHdr *pPage = sqlite3PagerLookup(pPager, pg1+ii);
47512 if( pPage ){
47513 pPage->flags |= PGHDR_NEED_SYNC;
47514 sqlite3PagerUnrefNotNull(pPage);
48069 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
48070 return sqlite3PcachePageRefcount(pPage);
49890 ** pPage into WAL frame iFrame.
51662 PgHdr *pPage, /* The page of the frame to be written */
51670 if( (pData = sqlite3PagerCodec(pPage))==0 ) return SQLITE_NOMEM;
51672 pData = pPage->pData;
51674 walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame);
53511 static void releasePage(MemPage *pPage); /* Forward reference */
54035 static u8 *findOverflowCell(MemPage *pPage, int iCell){
54037 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54038 for(i=pPage->nOverflow-1; i>=0; i--){
54040 k = pPage->aiOvfl[i];
54043 return pPage->apOvfl[i];
54048 return findCell(pPage, iCell);
54058 MemPage *pPage, /* Page containing the cell */
54065 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54066 assert( pPage->leaf==0 || pPage->leaf==1 );
54067 if( pPage->intKeyLeaf ){
54068 assert( pPage->childPtrSize==0 );
54071 }else if( pPage->noPayload ){
54072 assert( pPage->childPtrSize==4 );
54080 pIter = pCell + pPage->childPtrSize;
54086 testcase( nPayload==pPage->maxLocal );
54087 testcase( nPayload==pPage->maxLocal+1 );
54088 if( nPayload<=pPage->maxLocal ){
54110 minLocal = pPage->minLocal;
54111 maxLocal = pPage->maxLocal;
54112 surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize - 4);
54125 MemPage *pPage, /* Page containing the cell */
54129 btreeParseCellPtr(pPage, findCell(pPage, iCell), pInfo);
54138 static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
54139 u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
54149 btreeParseCellPtr(pPage, pCell, &debuginfo);
54152 if( pPage->noPayload ){
54155 assert( pPage->childPtrSize==4 );
54167 if( pPage->intKey ){
54174 testcase( nSize==pPage->maxLocal );
54175 testcase( nSize==pPage->maxLocal+1 );
54176 if( nSize<=pPage->maxLocal ){
54180 int minLocal = pPage->minLocal;
54181 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
54182 testcase( nSize==pPage->maxLocal );
54183 testcase( nSize==pPage->maxLocal+1 );
54184 if( nSize>pPage->maxLocal ){
54196 static u16 cellSize(MemPage *pPage, int iCell){
54197 return cellSizePtr(pPage, findCell(pPage, iCell));
54203 ** If the cell pCell, part of page pPage contains a pointer
54207 static void ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell, int *pRC){
54211 btreeParseCellPtr(pPage, pCell, &info);
54214 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
54231 static int defragmentPage(MemPage *pPage){
54247 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
54248 assert( pPage->pBt!=0 );
54249 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
54250 assert( pPage->nOverflow==0 );
54251 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54253 src = data = pPage->aData;
54254 hdr = pPage->hdrOffset;
54255 cellOffset = pPage->cellOffset;
54256 nCell = pPage->nCell;
54258 usableSize = pPage->pBt->usableSize;
54277 size = cellSizePtr(pPage, &src[pc]);
54295 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
54308 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
54309 if( cbrk-iCellFirst!=pPage->nFree ){
54380 ** as the first argument. Write into *pIdx the index into pPage->aData[]
54391 static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
54392 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
54393 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
54398 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
54399 assert( pPage->pBt );
54400 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54402 assert( pPage->nFree>=nByte );
54403 assert( pPage->nOverflow==0 );
54404 assert( nByte < (int)(pPage->pBt->usableSize-8) );
54406 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
54407 gap = pPage->cellOffset + 2*pPage->nCell;
54426 u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag);
54442 assert( pPage->nCell>0 || CORRUPT_DB );
54443 rc = defragmentPage(pPage);
54458 assert( top+nByte <= (int)pPage->pBt->usableSize );
54464 ** Return a section of the pPage->aData to the freelist.
54465 ** The first byte of the new free block is pPage->aData[iStart]
54476 static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
54482 u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
54484 unsigned char *data = pPage->aData; /* Page content */
54486 assert( pPage->pBt!=0 );
54487 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
54488 assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
54489 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
54490 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54496 if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){
54503 hdr = pPage->hdrOffset;
54558 pPage->nFree += iOrigSize;
54574 static int decodeFlags(MemPage *pPage, int flagByte){
54575 BtShared *pBt; /* A copy of pPage->pBt */
54577 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
54578 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54579 pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
54581 pPage->childPtrSize = 4-4*pPage->leaf;
54582 pBt = pPage->pBt;
54590 pPage->intKey = 1;
54591 pPage->intKeyLeaf = pPage->leaf;
54592 pPage->noPayload = !pPage->leaf;
54593 pPage->maxLocal = pBt->maxLeaf;
54594 pPage->minLocal = pBt->minLeaf;
54602 pPage->intKey = 0;
54603 pPage->intKeyLeaf = 0;
54604 pPage->noPayload = 0;
54605 pPage->maxLocal = pBt->maxLocal;
54606 pPage->minLocal = pBt->minLocal;
54612 pPage->max1bytePayload = pBt->max1bytePayload;
54625 static int btreeInitPage(MemPage *pPage){
54627 assert( pPage->pBt!=0 );
54628 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54629 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
54630 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
54631 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
54633 if( !pPage->isInit ){
54634 u16 pc; /* Address of a freeblock within pPage->aData[] */
54636 u8 *data; /* Equal to pPage->aData */
54645 pBt = pPage->pBt;
54647 hdr = pPage->hdrOffset;
54648 data = pPage->aData;
54651 if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
54653 pPage->maskPage = (u16)(pBt->pageSize - 1);
54654 pPage->nOverflow = 0;
54656 pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
54657 pPage->aDataEnd = &data[usableSize];
54658 pPage->aCellIdx = &data[cellOffset];
54665 pPage->nCell = get2byte(&data[hdr+3]);
54666 if( pPage->nCell>MX_CELL(pBt) ){
54670 testcase( pPage->nCell==MX_CELL(pBt) );
54675 assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );
54684 iCellFirst = cellOffset + 2*pPage->nCell;
54691 if( !pPage->leaf ) iCellLast--;
54692 for(i=0; i<pPage->nCell; i++){
54699 sz = cellSizePtr(pPage, &data[pc]);
54705 if( !pPage->leaf ) iCellLast++;
54746 pPage->nFree = (u16)(nFree - iCellFirst);
54747 pPage->isInit = 1;
54756 static void zeroPage(MemPage *pPage, int flags){
54757 unsigned char *data = pPage->aData;
54758 BtShared *pBt = pPage->pBt;
54759 u8 hdr = pPage->hdrOffset;
54762 assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
54763 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
54764 assert( sqlite3PagerGetData(pPage->pDbPage) == data );
54765 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
54775 pPage->nFree = (u16)(pBt->usableSize - first);
54776 decodeFlags(pPage, flags);
54777 pPage->cellOffset = first;
54778 pPage->aDataEnd = &data[pBt->usableSize];
54779 pPage->aCellIdx = &data[first];
54780 pPage->nOverflow = 0;
54782 pPage->maskPage = (u16)(pBt->pageSize - 1);
54783 pPage->nCell = 0;
54784 pPage->isInit = 1;
54793 MemPage *pPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
54794 pPage->aData = sqlite3PagerGetData(pDbPage);
54795 pPage->pDbPage = pDbPage;
54796 pPage->pBt = pBt;
54797 pPage->pgno = pgno;
54798 pPage->hdrOffset = pPage->pgno==1 ? 100 : 0;
54799 return pPage;
54897 static void releasePage(MemPage *pPage){
54898 if( pPage ){
54899 assert( pPage->aData );
54900 assert( pPage->pBt );
54901 assert( pPage->pDbPage!=0 );
54902 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
54903 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
54904 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54905 sqlite3PagerUnrefNotNull(pPage->pDbPage);
54918 MemPage *pPage;
54919 pPage = (MemPage *)sqlite3PagerGetExtra(pData);
54921 if( pPage->isInit ){
54922 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54923 pPage->isInit = 0;
54925 /* pPage might not be a btree page; it might be an overflow page
54931 btreeInitPage(pPage);
56089 ** Set the pointer-map entries for all children of page pPage. Also, if
56090 ** pPage contains cells that point to overflow pages, set the pointer
56093 static int setChildPtrmaps(MemPage *pPage){
56095 int nCell; /* Number of cells in page pPage */
56097 BtShared *pBt = pPage->pBt;
56098 u8 isInitOrig = pPage->isInit;
56099 Pgno pgno = pPage->pgno;
56101 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
56102 rc = btreeInitPage(pPage);
56106 nCell = pPage->nCell;
56109 u8 *pCell = findCell(pPage, i);
56111 ptrmapPutOvflPtr(pPage, pCell, &rc);
56113 if( !pPage->leaf ){
56119 if( !pPage->leaf ){
56120 Pgno childPgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
56125 pPage->isInit = isInitOrig;
56130 ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
56134 ** PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child
56135 ** page of pPage.
56137 ** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow
56138 ** page pointed to by one of the cells on pPage.
56140 ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
56143 static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
56144 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
56145 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
56148 if( get4byte(pPage->aData)!=iFrom ){
56151 put4byte(pPage->aData, iTo);
56153 u8 isInitOrig = pPage->isInit;
56157 btreeInitPage(pPage);
56158 nCell = pPage->nCell;
56161 u8 *pCell = findCell(pPage, i);
56164 btreeParseCellPtr(pPage, pCell, &info);
56166 && pCell+info.iOverflow+3<=pPage->aData+pPage->maskPage
56182 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
56185 put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
56188 pPage->isInit = isInitOrig;
57147 MemPage *pPage = 0;
57181 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
57182 assert( rc==SQLITE_OK || pPage==0 );
57184 next = get4byte(pPage->aData);
57190 *ppPage = pPage;
57192 releasePage(pPage);
57269 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
57276 assert( pPage );
57278 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
57289 if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
57300 rc = copyPayload(&aPayload[offset], pBuf, a, (eOp & 0x01), pPage->pDbPage);
57503 ** the key if index btrees (pPage->intKey==0) and is the data for
57504 ** table btrees (pPage->intKey==1). The number of bytes of available
57743 MemPage *pPage;
57747 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
57748 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
57749 pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
57768 MemPage *pPage = 0;
57772 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
57773 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
57774 pCur->aiIdx[pCur->iPage] = pPage->nCell;
57778 pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
57937 MemPage *pPage = pCur->apPage[pCur->iPage];
57938 u8 *pCell; /* Pointer to current cell in pPage */
57940 /* pPage->nCell must be greater than zero. If this is the root-page
57943 ** would have already detected db corruption. Similarly, pPage must
57946 assert( pPage->nCell>0 );
57947 assert( pPage->intKey==(pIdxKey==0) );
57949 upr = pPage->nCell-1;
57956 pCell = findCell(pPage, idx) + pPage->childPtrSize;
57957 if( pPage->intKeyLeaf ){
57959 if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
57974 if( !pPage->leaf ){
57989 pCell = findCell(pPage, idx) + pPage->childPtrSize;
58000 if( nCell<=pPage->max1bytePayload ){
58004 testcase( pCell+nCell+1==pPage->aDataEnd );
58007 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
58011 testcase( pCell+nCell+2==pPage->aDataEnd );
58019 u8 * const pCellBody = pCell - pPage->childPtrSize;
58020 btreeParseCellPtr(pPage, pCellBody, &pCur->info);
58057 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
58058 assert( pPage->isInit );
58059 if( pPage->leaf ){
58067 if( lwr>=pPage->nCell ){
58068 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
58070 chldPg = get4byte(findCell(pPage, lwr));
58122 MemPage *pPage;
58148 pPage = pCur->apPage[pCur->iPage];
58150 assert( pPage->isInit );
58157 testcase( idx>pPage->nCell );
58159 if( idx>=pPage->nCell ){
58160 if( !pPage->leaf ){
58161 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
58172 pPage = pCur->apPage[pCur->iPage];
58173 }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
58174 if( pPage->intKey ){
58180 if( pPage->leaf ){
58187 MemPage *pPage;
58196 pPage = pCur->apPage[pCur->iPage];
58197 if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
58201 if( pPage->leaf ){
58231 MemPage *pPage;
58259 pPage = pCur->apPage[pCur->iPage];
58260 assert( pPage->isInit );
58261 if( !pPage->leaf ){
58263 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
58279 pPage = pCur->apPage[pCur->iPage];
58280 if( pPage->intKey && !pPage->leaf ){
58661 MemPage *pPage; /* Page being freed. May be NULL. */
58670 pPage = pMemPage;
58671 sqlite3PagerRef(pPage->pDbPage);
58673 pPage = btreePageLookup(pBt, iPage);
58686 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
58687 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
58691 memset(pPage->aData, 0, pPage->pBt->pageSize);
58748 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
58749 sqlite3PagerDontWrite(pPage->pDbPage);
58753 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
58764 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
58767 rc = sqlite3PagerWrite(pPage->pDbPage);
58771 put4byte(pPage->aData, iTrunk);
58772 put4byte(&pPage->aData[4], 0);
58774 TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, iTrunk));
58777 if( pPage ){
58778 pPage->isInit = 0;
58780 releasePage(pPage);
58784 static void freePage(MemPage *pPage, int *pRC){
58786 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
58796 MemPage *pPage, /* The page that contains the Cell */
58800 BtShared *pBt = pPage->pBt;
58807 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58808 btreeParseCellPtr(pPage, pCell, &info);
58813 if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
58863 ** Create the byte sequence used to represent a cell on page pPage
58869 ** Note that pCell does not necessary need to point to the pPage->aData
58871 ** be constructed in this temporary area then copied into pPage->aData
58875 MemPage *pPage, /* The page that contains the cell */
58890 BtShared *pBt = pPage->pBt;
58894 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58896 /* pPage is not necessarily writeable since pCell might be auxiliary
58897 ** buffer space that is separate from the pPage buffer area */
58898 assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
58899 || sqlite3PagerIswriteable(pPage->pDbPage) );
58902 nHeader = pPage->childPtrSize;
58904 if( pPage->intKeyLeaf ){
58913 if( pPage->intKey ){
58925 if( nPayload<=pPage->maxLocal ){
58934 int mn = pPage->minLocal;
58935 n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
58936 testcase( n==pPage->maxLocal );
58937 testcase( n==pPage->maxLocal+1 );
58938 if( n > pPage->maxLocal ) n = mn;
58960 btreeParseCellPtr(pPage, pCell, &info);
59011 /* If pPrior is part of the data area of pPage, then make sure pPage
59013 assert( pPrior<pPage->aData || pPrior>=&pPage->aData[pBt->pageSize]
59014 || sqlite3PagerIswriteable(pPage->pDbPage) );
59031 /* If pPayload is part of the data area of pPage, then make sure pPage
59033 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
59034 || sqlite3PagerIswriteable(pPage->pDbPage) );
59058 ** Remove the i-th cell from pPage. This routine effects pPage only.
59061 ** removes the reference to the cell from pPage.
59065 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
59067 u8 *data; /* pPage->aData */
59074 assert( idx>=0 && idx<pPage->nCell );
59075 assert( sz==cellSize(pPage, idx) );
59076 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
59077 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
59078 pPage->aData;
59079 ptr = &pPage->aCellIdx[2*idx];
59081 hdr = pPage->hdrOffset;
59083 testcase( pc+sz==pPage->pBt->usableSize );
59084 if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){
59088 rc = freeSpace(pPage, pc, sz);
59093 pPage->nCell--;
59094 if( pPage->nCell==0 ){
59097 put2byte(&data[hdr+5], pPage->pBt->usableSize);
59098 pPage->nFree = pPage->pBt->usableSize - pPage->hdrOffset
59099 - pPage->childPtrSize - 8;
59101 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
59102 put2byte(&data[hdr+3], pPage->nCell);
59103 pPage->nFree += 2;
59108 ** Insert a new cell on pPage at cell index "i". pCell points to the
59114 ** in pPage->apOvfl[] and make it point to the cell content (either
59116 ** Allocating a new entry in pPage->aCell[] implies that
59117 ** pPage->nOverflow is incremented.
59120 MemPage *pPage, /* Page into which we are copying */
59137 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
59138 assert( MX_CELL(pPage->pBt)<=10921 );
59139 assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
59140 assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
59141 assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
59142 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
59148 assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
59149 if( pPage->nOverflow || sz+2>pPage->nFree ){
59157 j = pPage->nOverflow++;
59158 assert( j<(int)(sizeof(pPage->apOvfl)/sizeof(pPage->apOvfl[0])) );
59159 pPage->apOvfl[j] = pCell;
59160 pPage->aiOvfl[j] = (u16)i;
59162 int rc = sqlite3PagerWrite(pPage->pDbPage);
59167 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
59168 data = pPage->aData;
59169 cellOffset = pPage->cellOffset;
59170 end = cellOffset + 2*pPage->nCell;
59172 rc = allocateSpace(pPage, sz, &idx);
59177 assert( idx+sz <= (int)pPage->pBt->usableSize );
59178 pPage->nCell++;
59179 pPage->nFree -= (u16)(2 + sz);
59186 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
59188 if( pPage->pBt->autoVacuum ){
59192 ptrmapPutOvflPtr(pPage, pCell, pRC);
59478 #define NN 1 /* Number of neighbors on either side of pPage */
59496 ** pPage is the leaf page which is the right-most page in the tree.
59497 ** pParent is its parent. pPage must have a single overflow entry
59506 static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
59507 BtShared *const pBt = pPage->pBt; /* B-Tree Database */
59512 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
59514 assert( pPage->nOverflow==1 );
59517 if( NEVER(pPage->nCell==0) ) return SQLITE_CORRUPT_BKPT;
59520 ** pPage. Make the parent page writable, so that the new divider cell
59528 pPage->apOvfl[0];
59529 u16 szCell = cellSizePtr(pPage, pCell);
59533 assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
59555 ** consists of a 4-byte page number (the page number of pPage) and
59557 ** largest key on pPage).
59559 ** To find the largest key value on pPage, first find the right-most
59560 ** cell on pPage. The first two fields of this cell are the
59565 ** cell on pPage into the pSpace buffer.
59567 pCell = findCell(pPage, pPage->nCell-1);
59575 0, pPage->pgno, &rc);
59599 MemPage *pPage = apPage[i];
59600 BtShared *pBt = pPage->pBt;
59601 assert( pPage->isInit );
59603 for(j=0; j<pPage->nCell; j++){
59607 z = findCell(pPage, j);
59608 btreeParseCellPtr(pPage, z, &info);
59612 assert( n==pPage->pgno && e==PTRMAP_OVERFLOW1 );
59614 if( !pPage->leaf ){
59617 assert( n==pPage->pgno && e==PTRMAP_BTREE );
59620 if( !pPage->leaf ){
59621 Pgno child = get4byte(&pPage->aData[pPage->hdrOffset+8]);
59623 assert( n==pPage->pgno && e==PTRMAP_BTREE );
59746 u16 leafCorrection; /* 4 if pPage is a leaf. 0 if not */
59747 int leafData; /* True if pPage is a leaf of a LEAFDATA tree */
59748 int usableSpace; /* Bytes in pPage beyond the header */
59749 int pageFlags; /* Value of pPage->aData[0] */
59754 MemPage *apOld[NB]; /* pPage and up to two siblings */
59755 MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
59776 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
59793 ** either side of pPage. More siblings are taken from one side, however,
59908 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
59909 ** leafData: 1 if pPage holds key+data and pParent holds only keys.
60041 ** (2) pPage is a virtual root page. A virtual root page is when
60433 ** page that will become the new right-child of pPage. Copy the contents
60491 MemPage *pPage = pCur->apPage[iPage];
60494 if( pPage->nOverflow ){
60501 rc = balance_deeper(pPage, &pCur->apPage[1]);
60511 }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
60520 if( pPage->intKeyLeaf
60521 && pPage->nOverflow==1
60522 && pPage->aiOvfl[0]==pPage->nCell
60526 /* Call balance_quick() to create a new sibling of pPage on which
60540 rc = balance_quick(pParent, pPage, aBalanceQuickSpace);
60545 ** between pPage and up to 2 of its sibling pages. This involves
60579 pPage->nOverflow = 0;
60582 releasePage(pPage);
60629 MemPage *pPage;
60687 pPage = pCur->apPage[pCur->iPage];
60688 assert( pPage->intKey || nKey>=0 );
60689 assert( pPage->leaf || !pPage->intKey );
60692 pCur->pgnoRoot, nKey, nData, pPage->pgno,
60694 assert( pPage->isInit );
60697 rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
60699 assert( szNew==cellSizePtr(pPage, newCell) );
60704 assert( idx<pPage->nCell );
60705 rc = sqlite3PagerWrite(pPage->pDbPage);
60709 oldCell = findCell(pPage, idx);
60710 if( !pPage->leaf ){
60713 rc = clearCell(pPage, oldCell, &szOld);
60714 dropCell(pPage, idx, szOld, &rc);
60716 }else if( loc<0 && pPage->nCell>0 ){
60717 assert( pPage->leaf );
60720 assert( pPage->leaf );
60722 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
60723 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
60725 /* If no error has occurred and pPage has an overflow cell, call balance()
60746 if( rc==SQLITE_OK && pPage->nOverflow ){
60771 MemPage *pPage; /* Page to delete cell from */
60792 pPage
60793 pCell = findCell(pPage, iCellIdx);
60802 if( !pPage->leaf ){
60822 rc = sqlite3PagerWrite(pPage->pDbPage);
60824 rc = clearCell(pPage, pCell, &szCell);
60825 dropCell(pPage, iCellIdx, szCell, &rc);
60833 if( !pPage->leaf ){
60845 insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
61050 MemPage *pPage;
61061 rc = getAndInitPage(pBt, pgno, &pPage, 0);
61063 if( pPage->bBusy ){
61067 pPage->bBusy = 1;
61068 hdr = pPage->hdrOffset;
61069 for(i=0; i<pPage->nCell; i++){
61070 pCell = findCell(pPage, i);
61071 if( !pPage->leaf ){
61075 rc = clearCell(pPage, pCell, &szCell);
61078 if( !pPage->leaf ){
61079 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
61082 assert( pPage->intKey );
61083 *pnChange += pPage->nCell;
61086 freePage(pPage, &rc);
61087 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
61088 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
61092 pPage->bBusy = 0;
61093 releasePage(pPage);
61160 MemPage *pPage = 0;
61179 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
61183 releasePage(pPage);
61191 freePage(pPage, &rc);
61192 releasePage(pPage);
61202 freePage(pPage, &rc);
61203 releasePage(pPage);
61213 releasePage(pPage);
61247 freePage(pPage, &rc);
61248 releasePage(pPage);
61256 zeroPage(pPage, PTF_INTKEY|PTF_LEAF );
61257 releasePage(pPage);
61368 MemPage *pPage; /* Current page of the b-tree */
61374 pPage = pCur->apPage[pCur->iPage];
61375 if( pPage->leaf || !pPage->intKey ){
61376 nEntry += pPage->nCell;
61379 /* pPage is a leaf node. This loop navigates the cursor so that it
61389 if( pPage->leaf ){
61400 pPage = pCur->apPage[pCur->iPage];
61404 ** points at. This is the right-child if (iIdx==pPage->nCell).
61407 if( iIdx==pPage->nCell ){
61408 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
61410 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
61676 MemPage *pPage;
61699 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
61708 pPage->isInit = 0;
61709 if( (rc = btreeInitPage(pPage))!=0 ){
61713 releasePage(pPage);
61721 for(i=0; i<pPage->nCell && pCheck->mxErr; i++){
61731 pCell = findCell(pPage,i);
61732 btreeParseCellPtr(pPage, pCell, &info);
61736 if( pPage->intKey ){
61746 && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
61760 if( !pPage->leaf ){
61775 if( !pPage->leaf ){
61776 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
61784 checkTreePage(pCheck, pgno, NULL, !pPage->nCell?NULL:&nMaxKey);
61792 if( pPage->leaf && pPage->intKey ){
61827 data = pPage->aData;
61828 hdr = pPage->hdrOffset;
61843 cellStart = hdr + 12 - 4*pPage->leaf;
61850 size = cellSizePtr(pPage, &data[pc]);
61908 releasePage(pPage);
128236 sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
128448 sqlite3GlobalConfig.pPage = va_arg(ap, void*);