Lines Matching defs:page
218 /* Maximum page size. The upper bound on this value is 65536. This a limit
219 ** imposed by the use of 16-bit offsets within each page.
225 ** with a page-size of 65536 bytes crashes, then an instance of SQLite
226 ** compiled with the default page-size limit will not be able to rollback
236 ** The default size of a database page.
248 ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
1495 ** file will be doing page-aligned sector reads and writes in a random
1980 ** times the database page size. ^If SQLite needs needs additional
1986 ** the database page cache with the default page cache implementation.
1987 ** This configuration should not be used if an application-define page
1990 ** memory, the size of each page buffer (sz), and the number of pages (N).
1991 ** The sz argument should be the size of the largest database page
1993 ** page header. ^The page header size is 20 to 40 bytes depending on
1999 ** page cache memory is needed beyond what is provided by this option, then
2060 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
2061 ** object and uses it for page cache memory allocations.</dd>
2066 ** page cache implementation into that object.)^ </dd>
2450 ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
5241 ** limit by reducing the number of pages held in the page cache
5265 ** <li> An alternative page cache implementation is specified using
5267 ** <li> The page cache allocates from its own memory pool supplied
5277 ** when memory is allocated by the page cache. Testing suggests that because
5278 ** the page cache is the predominate memory user in SQLite, most
6242 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
6384 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
6408 ** <dd>This parameter returns the number of bytes of page cache
6414 ** no space was left in the page cache.</dd>)^
6631 ** CAPI3REF: Custom Page Cache Object
6644 ** CAPI3REF: Custom Page Cache Object
6646 ** The sqlite3_pcache_page object represents a single page in the
6647 ** page cache. The page cache will allocate instances of this
6648 ** object. Various methods of the page cache use pointers to instances
6655 void *pBuf; /* The content of the page */
6656 void *pExtra; /* Extra information associated with the page */
6660 ** CAPI3REF: Application Defined Page Cache.
6661 ** KEYWORDS: {page cache}
6664 ** register an alternative page cache implementation by passing in an
6667 ** SQLite is used for the page cache.
6669 ** custom page cache using this API, an application can better control
6675 ** The alternative page cache mechanism is an
6677 ** The built-in page cache is recommended for most uses.
6684 ** [[the xInit() page cache method]]
6690 ** required by the custom page cache implementation.
6692 ** built-in default page cache is used instead of the application defined
6693 ** page cache.)^
6695 ** [[the xShutdown() page cache method]]
6710 ** [[the xCreate() page cache methods]]
6717 ** associated with each page cache entry. ^The szExtra parameter will
6719 ** extra szExtra bytes on each page to store metadata about the underlying
6720 ** database page on disk. The value passed into szExtra depends
6727 ** never invoke xUnpin() except to deliberately delete a page.
6733 ** [[the xCachesize() page cache method]]
6741 ** [[the xPagecount() page cache methods]]
6745 ** [[the xFetch() page cache methods]]
6746 ** The xFetch() method locates a page in the cache and returns a pointer to
6747 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
6750 ** single database page. The pExtra element of sqlite3_pcache_page will be
6752 ** for each entry in the page cache.
6754 ** The page to be fetched is determined by the key. ^The minimum key value
6755 ** is 1. After it has been retrieved using xFetch, the page is considered
6758 ** If the requested page is already in the page cache, then the page cache
6759 ** implementation must return a pointer to the page buffer with its content
6760 ** intact. If the requested page is not already in the cache, then the
6765 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
6766 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
6767 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6769 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
6770 ** NULL if allocating a new page is effectively impossible.
6779 ** [[the xUnpin() page cache method]]
6780 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6782 ** then the page must be evicted from the cache.
6784 ** zero, then the page may be discarded or retained at the discretion of
6785 ** page cache implementation. ^The page cache implementation
6789 ** call to xUnpin() unpins the page regardless of the number of prior calls
6792 ** [[the xRekey() page cache methods]]
6794 ** page passed as the second argument. If the cache
6800 ** existing cache entries with page numbers (keys) greater than or equal
6805 ** [[the xDestroy() page cache method]]
6812 ** [[the xShrink() page cache method]]
6813 ** ^SQLite invokes the xShrink() method when it wants the page cache to
6814 ** free up as much of heap memory as possible. The page cache implementation
6944 ** and the destination and source page sizes differ, or
6946 ** destination and source page sizes differ.
8051 ** The root-page of the master database table.
8299 ** For example, the free-page-count field is located at byte offset 36 of
8314 int iTable, /* Index of root page */
8860 ** This header file defines the interface that the sqlite page cache
8861 ** subsystem. The page cache subsystem reads and writes a file a page
8878 ** The type used to represent a page number. The first page in a file
8879 ** is called page 1. 0 is used to represent "not a page".
8894 ** Page
8962 /* Functions used to obtain and release page references. */
8969 /* Operations on page references. */
9051 ** This header file defines the interface that the sqlite page cache
9061 ** Every page in the cache is controlled by an instance of the following
9065 sqlite3_pcache_page *pPage; /* Pcache object page handle */
9066 void *pData; /* Page data */
9069 Pager *pPager; /* The pager this page is part of */
9070 Pgno pgno; /* Page number for this page */
9072 u32 pageHash; /* Hash of page content */
9080 i16 nRef; /* Number of users of this page */
9081 PCache *pCache; /* Cache that owns this page */
9088 #define PGHDR_DIRTY 0x002 /* Page has changed */
9090 ** writing this page to the database */
9095 /* Initialize and shutdown the page cache subsystem */
9099 /* Page cache buffer management:
9109 int szPage, /* Size of every page */
9110 int szExtra, /* Extra space associated with each page */
9117 /* Modify the page-size after the cache has been created. */
9125 /* One release per successful fetch. Page is pinned until released.
9131 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
9132 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
9133 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
9136 /* Change a page number. Used by incr-vacuum. */
9142 /* Get a list of all dirty pages in the cache, sorted by page number */
9148 /* Clear flags from pages of the page cache */
9154 /* Return the total number of outstanding page references */
9157 /* Increment the reference count of an existing page */
9184 /* Free up as much memory as possible from the page cache */
9431 ** that all locks will fit on a single page even at the minimum page size.
9433 ** is set high so that we don't have to allocate an unused page except
9434 ** for very large databases. But one should test the page skipping logic
10163 ** Table.tnum is the page number for the root BTree page of the table in the
10170 ** page number. Transient tables are used to hold the results of a
10382 int tnum; /* Page containing root of this index in database file */
11121 int regRoot; /* Register holding root page number for new objects */
11345 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */
11352 void *pPage; /* Page cache memory */
11353 int szPage; /* Size of each page in pPage[] */
12181 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
12381 ** the database page that contains the pending byte. It never attempts
12382 ** to read or write that page. The pending byte page is set assign
12917 u8 *aRow; /* Data for the current row, if all on one page */
13749 ** Reference: Meeus page 61
26230 ** the first page of the database, no damage is done.
36246 ** This file implements that page cache.
36250 ** A complete page cache is an instance of this structure.
36254 PgHdr *pSynced; /* Last synced page in dirty page list */
36257 int szPage; /* Size of every page in this cache */
36258 int szExtra; /* Size of extra space for each page */
36260 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
36263 PgHdr *pPage1; /* Reference to page 1 */
36298 ** Remove page pPage from the list of dirty pages.
36334 ** Add page pPage to the head of the dirty list (PCache1.pDirty is set to
36373 ** Initialize and shutdown the page cache subsystem. Neither of these
36379 ** built-in default page cache is used instead of the application defined
36380 ** page cache. */
36404 int szPage, /* Size of every page */
36405 int szExtra, /* Extra space associated with each page */
36421 ** Change the page size for PCache object. The caller must ensure that there
36422 ** are no outstanding page references when this function is called.
36446 ** Try to obtain a page from the cache.
36449 PCache *pCache, /* Obtain the page from this cache */
36450 Pgno pgno, /* Page number to obtain */
36451 int createFlag, /* If true, create page if it does not exist already */
36452 PgHdr **ppPage /* Write the page here */
36485 /* Find a dirty page to write-out and recycle. First try to find a
36486 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
36488 ** unreferenced dirty page.
36503 "spill page %d making room for %d - cache used: %d/%d",
36547 ** Decrement the reference count on a page. If the page is clean and the
36559 /* Move the page to the head of the dirty list. */
36567 ** Increase the reference count of a supplied page by 1.
36575 ** Drop a page from the cache. There must be exactly one reference to the
36576 ** page. This function deletes that reference, so after it returns the
36577 ** page pointed to by p is invalid.
36594 ** Make sure the page is marked as dirty. If it isn't dirty already,
36607 ** Make sure the page is marked as clean. If it isn't clean already,
36621 ** Make every page in the cache clean.
36642 ** Change the page number of page p to newPgno.
36657 ** Drop every cache entry whose page number is greater than "pgno". The
36659 ** other than page 1 with a page number greater than pgno.
36661 ** If there is a reference to page 1 and the pgno parameter passed to this
36662 ** function is 0, then the data area associated with page 1 is zeroed, but
36663 ** the page object is not dropped.
36776 ** Return a list of all dirty pages in the cache, sorted by page number.
36794 ** Return the number of references to the page supplied as an argument.
36832 ** Free up as much memory as possible from the page cache.
36868 ** This file implements the default page cache implementation (the
36871 ** If the default page cache implementation is overriden, then neither of
36881 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
36886 ** This page cache implementation works in one of two modes:
36912 /* Each page cache is an instance of the following object. Every
36914 ** temporary or transient database) has a single page cache which
36921 /* Cache configuration parameters. Page size (szPage) and the purgeable
36951 sqlite3_pcache_page page;
36952 unsigned int iKey; /* Key value (page number) */
36954 PCache1 *pCache; /* Cache that currently owns this page */
36985 PgFreeslot *pFree; /* Free page blocks */
37008 /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
37012 ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
37128 ** Allocate a new page object initially associated with cache pCache.
37154 p->page.pBuf = pPg;
37155 p->page.pExtra = &p[1];
37165 ** Free a page object allocated by pcache1AllocPage().
37175 pcache1Free(p->page.pBuf);
37203 ** Return true if it desirable to avoid allocating a new page cache
37206 ** If memory was allocated specifically to the page cache using
37208 ** it is desirable to avoid allocating a new page cache entry because
37210 ** for all page cache needs and we should not need to spill the
37213 ** Or, the heap is used for all page cache memory but the heap is
37215 ** allocating a new page cache entry in order to avoid stressing
37273 ** This function is used internally to remove the page pPage from the
37310 ** Remove the page supplied as an argument from the hash table
37344 ** Discard all pages from cache pCache with a page number (key value)
37411 PCache1 *pCache; /* The newly created page cache */
37412 PGroup *pGroup; /* The group the new page cache will belong to */
37514 ** Fetch a page by key value.
37516 ** Whether or not a new page may be allocated by this function depends on
37518 ** page. 1 means allocate a new page if space is easily available. 2
37519 ** means to try really hard to allocate a new page.
37526 ** There are three different approaches to obtaining space for a page,
37530 ** copy of the requested page. If one is found, it is returned.
37532 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
37535 ** 3. If createFlag is 1, and the page is not already in the cache, then
37536 ** return NULL (do not allocate a new page) if any of the following
37559 ** then attempt to recycle a page from the LRU list. If it is the right
37563 ** 5. Otherwise, allocate and return a new page buffer.
37587 /* Step 2: Abort if no existing page is found and createFlag is 0 */
37621 /* Step 4. Try to recycle a page. */
37648 /* Step 5. If a usable page buffer has still not been found,
37665 *(void **)pPage->page.pExtra = 0;
37674 return &pPage->page;
37681 ** Mark a page as unpinned (eligible for asynchronous recycling).
37695 /* It is an error to call this function if the page is already
37705 /* Add the page to the PGroup LRU list. */
37759 ** Discard all unpinned pages in the cache with a page number equal to
37760 ** or greater than parameter iLimit. Any pinned pages with a page number
37837 nFree += pcache1MemSize(p->page.pBuf);
38311 ** This is the implementation of the page cache subsystem or "pager".
38394 /* Read a page from the write-ahead log, if it is present. */
38451 ** stored in each frame (i.e. the db page-size when the WAL was created).
38469 ** Within this comment block, a page is deemed to have been synced
38471 ** Otherwise, the page is not synced until the xSync method of the VFS
38472 ** is called successfully on the file containing the page.
38474 ** Definition: A page of the database file is said to be "overwriteable" if
38475 ** one or more of the following are true about the page:
38477 ** (a) The original content of the page as it was at the beginning of
38481 ** (b) The page was a freelist leaf page at the start of the transaction.
38483 ** (c) The page number is greater than the largest page that existed in
38486 ** (1) A page of the database file is never overwritten unless one of the
38489 ** (a) The page and all other pages on the same sector are overwriteable.
38491 ** (b) The atomic page write optimization is enabled, and the entire
38493 ** number consists of a single page change.
38495 ** (2) The content of a page written into the rollback journal exactly matches
38500 ** (3) Writes to the database file are an integer multiple of the page size
38501 ** in length and are aligned on a page boundary.
38503 ** (4) Reads from the database file are either aligned on a page boundary and
38504 ** an integer multiple of the page size in length or are taken from the
38674 ** A pager moves from WRITER_LOCKED state to this state when a page is
38683 ** * The contents of the page
38696 ** * The contents of the page cache have been modified (and possibly
38728 ** the contents of the page-cache may be left in an inconsistent state.
38740 ** page-cache and any other in-memory state at the same time. Everything
38894 ** A open page cache is an instance of struct Pager. A description of
38968 ** to allocate a new page to prevent the journal file from being written
38974 ** the database page-size in order to prevent a journal sync from happening
38995 ** is not an integer multiple of the page-size, the value stored in
38996 ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
38998 ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
39001 ** During a write-transaction, if pages with page-numbers greater than
39085 Bitvec *pInJournal; /* One bit for each page in the database file */
39099 u16 nExtra; /* Add this many bytes to each in-memory page */
39100 i16 nReserve; /* Number of unused bytes at end of each page */
39103 int pageSize; /* Number of bytes in a page */
39117 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
39122 PCache *pPCache; /* Pointer to page cache object */
39158 ** of a 32-bit checksum on each page of data. The checksum covers both
39159 ** the page number and the pPager->pageSize bytes of data for the page.
39173 ** The size of the of each page record in the journal is given by
39197 ** The maximum legal page number is (2^31 - 1).
39421 ** Return true if it is necessary to write page *pPg into the sub-journal.
39422 ** A page needs to be written into the sub-journal if there exists one
39425 ** * The page-number is less than or equal to PagerSavepoint.nOrig, and
39426 ** * The bit corresponding to the page-number is not set in
39443 ** Return true if the page is already in the journal file.
39536 ** a database page may be written atomically, and
39538 ** to the page size.
39546 ** contains rollback data for exactly one page.
39554 int szPage; /* Page size */
39579 ** Return a 32-bit hash of the page data for pPage.
39599 ** that the page is either dirty or still matches the calculated page-hash.
39768 ** - 4 bytes: Random number used for page hash.
39769 ** - 4 bytes: Initial database page count.
39771 ** - 4 bytes: Database page size.
39801 ** Write the nRec Field - the number of page records that follow this
39809 ** rest of the journal file contains valid page records. This assumption
39838 /* The page size */
39862 ** database page
39884 ** page records following this header and *pDbSize is set to the size of the
39943 u32 iPageSize; /* Page-size field of journal header */
39946 /* Read the page-size and sector-size journal header fields. */
39953 /* Versions of SQLite prior to 3.5.8 set the page-size field of the
39955 ** variable is already set to the correct page size.
39961 /* Check that the values read from the page-size and sector-size fields
39970 /* If the either the page-size or sector-size in the journal-header is
39978 /* Update the page-size to match the value read from the journal.
40012 ** The master journal page checksum is the sum of the bytes in the master
40044 ** the master journal name. This is in case the previous page written to
40084 ** Find a page in the hash table given its page number. Return
40085 ** a pointer to the page or NULL if the requested page is not
40099 ** Discard the entire contents of the in-memory page-cache.
40455 ** page of data and the current value of pPager->cksumInit.
40459 ** of the page data, starting with byte offset (pPager->pageSize%200).
40482 ** Report the current page size and number of reserved bytes back
40497 ** Read a single page from either the journal file (if isMainJrnl==1) or
40498 ** from the sub-journal (if isMainJrnl==0) and playback that page.
40499 ** The page begins at offset *pOffset into the file. The *pOffset
40500 ** value is increased to the start of the next page in the journal.
40505 ** If the page number of the page record read from the (sub-)journal file
40510 ** been played back. If the page at *pOffset has already been played back
40512 ** Make sure the pDone bit corresponding to the *pOffset page is set
40515 ** If the page record is successfully read from the (sub-)journal file
40523 ** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
40541 PgHdr *pPg; /* An existing page in the cache */
40542 Pgno pgno; /* The page number of a page in journal */
40544 char *aData; /* Temporary storage for the page */
40546 int isSynced; /* True if journal page is synced */
40568 /* Read the page number and page data from the journal or sub-journal
40578 /* Sanity checking on the page. This is more important that I originally
40598 /* If this page has already been played by before during the current
40605 /* When playing back page 1, restore the nReserve setting
40613 ** page in the pager cache. In this case just update the pager cache,
40614 ** not the database file. The page is left marked dirty in this case.
40617 ** and a page is moved during an incremental vacuum then the page may
40619 ** during a Movepage() call, then the page may not be in the cache
40624 ** pager cache if it exists and the main file. The page is then marked
40626 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
40629 ** Ticket #1171: The statement journal might contain page content that is
40630 ** different from the page content at the start of the transaction.
40631 ** This occurs when a page is changed prior to the start of a statement
40634 ** for certain that original page contents are synced into the main rollback
40639 ** locked. (2) we know that the original page content is fully synced
40640 ** in the main journal either because the page is not in cache or else
40641 ** the page is marked as needSync==0.
40654 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
40681 ** the database and the page is not in-memory, there is a potential
40682 ** problem. When the page is next fetched by the b-tree layer, it
40688 ** if the page is on the free-list at the start of the transaction, then
40691 ** The solution is to add an in-memory page to the cache containing
40692 ** the data just read from the sub-journal. Mark the page as dirty
40693 ** and if the pager requires a journal-sync, then mark the page as
40707 /* No page should ever be explicitly rolled back that is in use, except
40708 ** for page 1 which is held in use in order to keep the lock on the
40709 ** database active. However such a page may be rolled back as a result
40718 /* If the contents of this page were just restored from the main
40720 ** transaction was first opened. In this case we can mark the page
40724 ** There is one exception to this rule. If the page is being rolled
40727 ** to mark the page as clean. This is because marking the page as
40728 ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
40730 ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
40742 /* If this was page 1, then restore the value of Pager.dbFileVers.
40748 /* Decode the page just read from disk */
40795 ** a couple of kilobytes or so - potentially larger than the page
40993 ** (2) 4 byte big-endian integer which is the number of valid page records
40995 ** number of page records from the journal size.
41002 ** (6) 4 byte big-endian integer which is the page size.
41005 ** + 4 byte page number.
41013 ** valid page entries in the journal. In most cases, you can compute the
41028 ** journal file then all pages up to the first corrupted page are rolled
41052 int needPagerReset; /* True to reset page prior to first page rollback */
41145 ** database file and/or page cache.
41234 ** Read the content for page pPg out of the database file and into
41238 ** If page 1 is read, then the value of Pager.dbFileVers[] is set to
41245 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
41246 Pgno pgno = pPg->pgno; /* Page number to read */
41248 int isInWal = 0; /* True if page is in log file */
41261 /* Try to pull the page from the write-ahead log. */
41277 ** zero or the size of the database in page. Bytes 32..35 and 35..39
41278 ** should be page numbers which are never 0xffffffff. So filling
41297 PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
41327 ** This function is invoked once for each page that has already been
41329 ** Parameter iPg is the page number of said page. The pCtx argument
41332 ** If page iPg is present in the cache, and has no outstanding references,
41334 ** references, the page content is reloaded from the database. If the
41380 ** + Discard the cached page (if refcount==0), or
41381 ** + Reload page content from the database (if refcount>0).
41401 ** The list of pages passed into this routine is always sorted by page number.
41402 ** Hence, if page 1 appears anywhere on the list, it will be the first page.
41418 /* Verify that the page list is in accending order */
41426 ** any pages with page numbers greater than nTruncate into the WAL file.
41492 ** in pages (assuming the page size currently stored in Pager.pageSize).
41513 ** of the database file is not an integer multiple of the page-size,
41514 ** round down to the nearest page. Except, any file larger than 0
41515 ** bytes in size is considered to contain at least one page.
41615 ** Throughout the rollback process, each time a page is rolled back, the
41617 ** implementation below). This is used to ensure that a page is only
41625 ** (or transaction). No page with a page-number greater than this value
41665 ** There might be records in the main journal that have a page number
41710 /* Finally, rollback pages from the sub-journal. Page that were
41896 ** Change the page size used by the Pager object. The new page size
41905 ** * the new page size (value of *pPageSize) is valid (a power
41908 ** * there are no outstanding page references, and
41913 ** then the pager object page size is set to *pPageSize.
41915 ** If the page size is changed, then this function uses sqlite3PagerMalloc()
41917 ** fails, SQLITE_NOMEM is returned and the page size remains unchanged.
41920 ** If the page size is not changed, either because one of the enumerated
41923 ** then *pPageSize is set to the old, retained page size before returning.
41934 ** there is at least one outstanding page reference, this function
41976 ** Return a pointer to the "temporary page" buffer held internally
41978 ** entire content of a database page. This buffer is used internally
41988 ** Attempt to set the maximum database page count if mxPage is positive.
41990 ** maximum page count below the current size of the database.
41992 ** Regardless of mxPage, return the current maximum page count.
42066 ** However, if the file is between 1 and <page-size> bytes in size, then
42067 ** this is considered a 1 page file.
42111 ** following is true for all dirty pages currently in the page-cache:
42113 ** a) The page number is less than or equal to the size of the
42116 ** b) if the page content were written at this time, it would not
42121 ** dirty page were to be discarded from the cache via the pagerStress()
42122 ** routine, pagerStress() would not write the current page content to
42125 ** content of the page. However, since this content is not present in either
42183 ** Shutdown the page cache. Free all memory and close all files.
42187 ** and their memory is freed. Any attempt to use a page associated
42188 ** with this page cache after this function returns will likely
42250 ** Return the page number for page pPg.
42258 ** Increment the reference count for page pPg.
42296 ** page currently held in memory before returning SQLITE_OK. If an IO
42428 ** a page is skipped if it meets either of the following criteria:
42430 ** * The page number is greater than Pager.dbSize, or
42431 ** * The PGHDR_DONT_WRITE flag is set on the page.
42433 ** If writing out a page causes the database file to grow, Pager.dbFileSize
42434 ** is updated accordingly. If page 1 is written out, then the value cached
42472 /* If there are dirty pages in the page cache with page numbers greater
42477 ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
42490 /* Write out the page data. */
42493 /* If page 1 was just written, update Pager.dbFileVers to match
42495 ** page caused the database file to grow, update dbFileSize.
42507 PAGERTRACE(("STORE %d page %d hash(%08x)\n",
42513 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno));
42543 ** Append a record of the current state of page pPg to the sub-journal.
42578 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
42597 ** database). The second argument is a reference to a page that is
42598 ** currently dirty but has no outstanding references. The page
42606 ** If successful, sqlite3PcacheMakeClean() is called on the page and
42608 ** page clean, the IO error code is returned. If the page cannot be
42642 /* Write a single frame for this page to the log. */
42658 /* If the page number of this page is larger than the current size of
42666 ** <journal page X>
42667 ** <modify page X>
42670 ** pagerStress(page X)
42673 ** If (X>Y), then when pagerStress is called page X will not be written
42675 ** following the "ROLLBACK TO sp" statement, reading page X will read
42676 ** data from the database file. This will be the copy of page X as it
42680 ** The solution is to write the current data for page X into the
42691 /* Write the contents of the page out to the database file. */
42698 /* Mark the page as clean. */
42700 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
42721 ** along with each page reference. This space is available to the user
42742 int nExtra, /* Extra bytes append to each in-memory page */
42758 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
42887 ** choose a default page size in case we have to create the
42888 ** database file. The default page size is the maximum of:
42892 ** + The largest page size that can be written atomically.
42921 ** In this case we accept the default page size and delay actually
43160 ** the contents of the page cache and rolling back any open journal
43285 ** to be in ERROR state when there are zero outstanding page
43382 ** Acquire a reference to page number pgno in pager pPager (a page
43386 ** If the requested page is already in the cache, it is returned.
43387 ** Otherwise, a new page object is allocated and populated with data
43389 ** choose not to allocate a new page object and may reuse an existing
43392 ** The extra data appended to a page is always initialized to zeros the
43393 ** first time a page is loaded into memory. If the page requested is
43395 ** data is left as it was when the page object was last used.
43397 ** If the database image is smaller than the requested page or if a
43399 ** requested page is not already stored in the cache, then no
43401 ** page is initialized to all zeros.
43404 ** of the page. This occurs in two seperate scenarios:
43406 ** a) When reading a free-list leaf page from the database, and
43409 ** a new page into the cache to be filled with the data read
43416 ** savepoints are set. This means if the page is made writable at any
43424 ** to find a page in the in-memory cache first. If the page is not already
43433 Pgno pgno, /* Page number to fetch */
43434 DbPage **ppPage, /* Write a pointer to the page here */
43448 ** Otherwise, request the page from the PCache layer. */
43467 ** the page. Return without further ado. */
43473 /* The pager cache has created a new page. Its content needs to
43479 /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
43480 ** number greater than this, or the unused locking-page, is requested. */
43494 ** page that does not need to be journaled. Nevertheless, be sure
43534 ** Acquire a page if it is already in the in-memory cache. Do
43535 ** not read the page from disk. Return a pointer to the page,
43536 ** or 0 if the page is not in cache.
43540 ** in the page if the page is not already in cache. This routine
43541 ** returns NULL if the page is not in cache or if a disk I/O error
43555 ** Release a page reference.
43557 ** If the number of references to the page drop to zero, then the
43558 ** page is added to the LRU list. When all references to all pages
43722 ** file as well as into the page cache. Which would be incorrect in
43742 ** Mark a single data page as writeable. The page is written into the
43743 ** main journal or sub-journal as required. If the page is written into
43777 ** This is done before calling sqlite3PcacheMakeDirty() on the page.
43789 /* Mark the page as dirty. If the page has already been written
43798 ** EXCLUSIVE lock on the main database file. Write the current page to
43808 /* We should never write to the journal file the page that
43818 ** page in the block above, set the need-sync flag for the page.
43820 ** playback_one_page() will think that the page needs to be restored
43836 PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
43855 PAGERTRACE(("APPEND %d page %d needSync=%d\n",
43861 /* If the statement journal is open and the page is not in it,
43862 ** then write the current page to the statement journal. Note that
43880 ** Mark a data page as writeable. This routine must be called before
43881 ** making changes to a page. The caller must check the return value
43882 ** of this function and be careful not to change any page data unless
43906 Pgno pg1; /* First page of the sector pPg is located on. */
43909 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
43919 /* This trick assumes that both the page-size and sector-size are
43921 ** of the first page of the sector pPg is located on.
43985 ** Return TRUE if the page given in the argument was previously passed
43987 ** to change the content of the page.
43997 ** write the information on page pPg back to the disk, even though
43998 ** that page might be marked as dirty. This happens, for example, when
43999 ** the page has been added as a leaf of the freelist and so its
44003 ** on the given page is unused. The pager marks the page as clean so
44012 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
44026 ** To avoid excess churning of page 1, the update only happens once.
44031 ** sqlite3PagerWrite() on page 1, then modifying the contents of the
44032 ** page data. In this case the file will be updated when the current
44038 ** by writing an updated version of page 1 using a call to the
44068 PgHdr *pPgHdr; /* Reference to page 1 */
44072 /* Open page 1 of the file for writing. */
44076 /* If page one was fetched successfully, and this function is not
44077 ** operating in direct-mode, make page 1 writable. When not in
44078 ** direct mode, page 1 is always held in cache and hence the PagerGet()
44089 /* If running in direct mode, write the contents of page 1 to the file. */
44105 /* Release the page reference. */
44217 /* Must have at least one page for the WAL commit flag.
44238 ** blocks of size page-size, and
44240 ** * Exactly one page has been modified and store in the journal file.
44267 ** following call will modify the in-memory representation of page 1
44268 ** to include the updated change counter and then write page 1
44288 ** Before reading the pages with page numbers larger than the
44299 const Pgno iSkip = PAGER_MJ_PGNO(pPager); /* Pending lock page */
44304 PgHdr *pPage; /* Page to journal */
44327 ** Because the change-counter page was just modified, unless the
44521 ** Return the number of references to the specified page.
44779 ** Move the page pPg to location pgno in the file.
44781 ** There must be no references to the page previously located at
44782 ** pgno (which we call pPgOld) though that page is allowed to be
44783 ** in cache. If the page previously located at pgno is not already
44786 ** References to the page pPg remain valid. Updating any
44788 ** allocated along with the page) is the responsibility of the caller.
44792 ** has been removed (CREATE INDEX needs to move a page when a statement
44795 ** If the fourth argument, isCommit, is non-zero, then this page is being
44797 ** is being committed. In this case, it is guaranteed that the database page
44804 PgHdr *pPgOld; /* The page being overwritten. */
44807 Pgno origPgno; /* The original page number */
44816 ** the page we are moving from.
44823 /* If the page being moved is dirty and has not been saved by the latest
44824 ** savepoint, then save the current contents of the page into the
44828 ** <journal page X, then modify it in memory>
44830 ** <Move page X to location Y>
44833 ** If page X were not written to the sub-journal here, it would not
44848 PAGERTRACE(("MOVE %d page %d (needSync=%d) moves to %d\n",
44852 /* If the journal needs to be sync()ed before page pPg->pgno can
44856 ** the journal needs to be sync()ed before database page pPg->pgno
44865 /* If the cache contains a page with page-number pgno, remove it
44867 ** page pgno before the 'move' operation, it needs to be retained
44868 ** for the page moved there.
44877 ** need to rollback later. Just move the page out of the way. */
44888 /* For an in-memory database, make sure the original page continues
44890 ** as the original page since it has already been allocated.
44900 ** sync()ed before any data is written to database file page needSyncPgno.
44901 ** Currently, no such page exists in the page-cache and the
44903 ** loading the page into the pager-cache and setting the PGHDR_NEED_SYNC
44906 ** If the attempt to load the page into the page-cache fails, (due
44908 ** array. Otherwise, if the page is loaded and written again in
44932 ** Return a pointer to the data for the specified page.
44941 ** allocated along with the specified page.
45315 ** frames, return the size in bytes of the page images stored within the
45327 ** This function is called by the wal module when writing page content
45331 ** page content. If a malloc fails, this function may return NULL.
45364 ** Each frame records the revised content of a single page from the
45384 ** 8: Database page size. Example: 1024
45392 ** frame consists of a 24-byte frame-header followed by a <page-size> bytes
45393 ** of page data. The frame-header is six big-endian 32-bit unsigned
45396 ** 0: Page number.
45447 ** To read a page from the database (call it page number P), a reader
45448 ** first checks the WAL to see if it contains page P. If so, then the
45449 ** last valid instance of page P that is a followed by a commit frame
45451 ** contains no copies of page P that are valid and which are a commit
45452 ** frame or are followed by a commit frame, then page P is read from
45465 ** because frames for page P can appear anywhere within the WAL, the
45466 ** reader has to scan the entire WAL looking for page P frames. If the
45470 ** search for frames of a particular page.
45490 ** a page number P, return the index of the last frame for page P in the WAL,
45491 ** or return NULL if there are no frames for page P in the WAL.
45506 ** Each index block contains two sections, a page-mapping that contains the
45507 ** database page number associated with each wal frame, and a hash-table
45508 ** that allows readers to query an index block for a specific page number.
45509 ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
45510 ** for the first index block) 32-bit page numbers. The first entry in the
45511 ** first index-block contains the database page number corresponding to the
45517 ** complement of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE) page-numbers,
45519 ** allocated size of the page-mapping array - the page-mapping array merely
45522 ** Even without using the hash table, the last frame for page P
45523 ** can be found by scanning the page-mapping sections of each index block
45527 ** holding the content for that page.
45531 ** hash table for each page number in the mapping section, so the hash
45541 ** To look for page P in the hash table, first compute a hash iKey on
45554 ** no hash slot such that aHash[i]==p) then page P is not in the
45557 ** page P.
45560 ** first index block, looking for entries corresponding to page P. On
45562 ** examined in order to either find the last entry for page P, or to
45641 ** Or it can be 1 to represent a 65536-byte page. The latter case was
45650 u16 szPage; /* Database page size in bytes. 1==64K */
45743 ** assuming a database page size of szPage bytes. The offset returned
45763 u32 szPage; /* Database page size */
45796 ** Each page of the wal-index mapping contains a hash-table made up of
45803 ** all frames in the WAL in database page order. Where two or more frames
45804 ** correspond to the same database page, the iterator visits only the
45822 u32 *aPgno; /* Array of page numbers. */
45825 } aSegment[1]; /* One for every 32KB page in the wal-index */
45830 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
45841 ** The block of page numbers associated with the first hash-table in a
45843 ** hash-table on each aligned 32KB page of the wal-index.
45853 ** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
45858 ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
45879 /* Request a pointer to the required page from the VFS */
46004 ** 0: Page number.
46014 u32 iPage, /* Database page number for frame */
46016 u8 *aData, /* Pointer to page data */
46041 u32 *piPage, /* OUT: Database page number for frame */
46043 u8 *aData, /* Pointer to page data (for checksum) */
46048 u32 pgno; /* Page number of the frame */
46058 /* A frame is only valid if the page number is creater than zero.
46080 /* If we reach this point, the frame is valid. Return the page number
46153 ** Compute a hash on a page number. The resulting hash value must land
46167 ** Return pointers to the hash table and page number array stored on
46168 ** page iHash of the wal-index. The wal-index is broken into 32KB pages
46177 ** Finally, set *paPgno so that *paPgno[1] is the page number of the
46184 volatile u32 **paPgno, /* OUT: Pointer to page number array */
46213 ** Return the number of the wal-index page that contains the hash-table
46214 ** and page-number array that contain entries corresponding to WAL frame
46230 ** Return the page number associated with frame iFrame in this WAL.
46254 volatile u32 *aPgno = 0; /* Page number array for hash table */
46267 /* Obtain pointers to the hash-table and page-number array containing
46269 ** that the page said hash-table and array reside on is already mapped.
46311 ** Set an entry in the wal-index that will map database page number
46317 volatile u32 *aPgno = 0; /* Page number array */
46323 ** page number array and hash table entry.
46442 int szPage; /* Page size according to the log */
46453 /* If the database page size is not a power of two, or is greater than
46502 u32 pgno; /* Database page number for frame */
46669 page number out of all pages held in the WAL that
46672 ** that page was last written into the WAL. Write into *piPage the page
46675 ** Return 0 on success. If there are no pages in the WAL with a page
46680 u32 *piPage, /* OUT: The page number of the next page */
46681 u32 *piFrame /* OUT: Wal frame index of next page */
46684 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
46961 ** Return the page-size in bytes used by the database.
46972 ** by active readers. This routine will never overwrite a database page
47007 int szPage; /* Database page-size */
47009 u32 iDbpage = 0; /* Next database page to write */
47012 u32 mxPage; /* Max database page to write */
47246 /* The first page of the wal-index must be mapped at this point. */
47304 /* Ensure that page 0 of the wal-index (the page that contains the
47314 /* If the first page of the wal-index has been mapped, try to read the
47399 ** access any database page that is modified by a WAL frame up to and
47431 ** paged out or take a page-fault that is time-consuming to resolve,
47469 ** must be zeroed before the requested page is returned.
47632 ** Read a page from the WAL, if it is present in the WAL and if the
47635 ** The *pInWal is set to 1 if the requested page is in the WAL and
47636 ** has been loaded. Or *pInWal is set to 0 if the page was not in
47641 Pgno pgno, /* Database page number to read data for */
47644 u8 *pOut /* Buffer to write page data to */
47647 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
47653 /* If the "last page" field of the wal-index header snapshot is 0, then
47664 /* Search the hash table or tables for an entry matching page number
47691 volatile u32 *aPgno; /* Pointer to array of page numbers */
47732 ** required page. Read and return data from the log file.
47849 /* This call cannot fail. Unless the page for which the page number
47852 ** (if (a) is false) or simply expels the page from the cache (if (b)
47856 ** are no outstanding references to any page other than page 1. And
47857 ** page 1 is never written to the log until the transaction is
47990 int szPage; /* Size of one page */
48028 PgHdr *pPage, /* The page of the frame to be written */
48043 /* Write the page data */
48054 int szPage, /* Database page-size in bytes */
48064 int nExtra = 0; /* Number of extra copies of last page */
48418 ** read-lock. This function returns the database page-size if it is known,
48468 ** The basic idea is that each page of the file contains N database
48475 ** All of the keys on the page that Ptr(0) points to have values less
48476 ** than Key(0). All of the keys on page Ptr(1) and its subpages have
48485 ** BTrees. Each BTree is identified by the index of its root page. The
48488 ** page. If the payload is larger than the preset amount then surplus
48491 ** page has a small header which contains the Ptr(N) pointer and other
48496 ** The file is divided into pages. The first page is called page 1,
48497 ** the second is page 2, and so forth. A page number of zero indicates
48498 ** "no such page". The page size can be any power of 2 between 512 and 65536.
48499 ** Each page can be either a btree page, a freelist page, an overflow
48500 ** page, or a pointer-map page.
48502 ** The first page is always a btree page. The first 100 bytes of the first
48503 ** page contain a special header (the "file header") that describes the file.
48508 ** 16 2 Page size in bytes.
48511 ** 20 1 Bytes of unused space at the end of each page
48517 ** 32 4 First freelist page
48523 ** 48 4 Size of page cache
48524 ** 52 4 Largest root-page (auto/incr_vacuum)
48539 ** space in a page that can be consumed by a single cell for standard
48542 ** on one page. Thus the default max embedded payload fraction is 64.
48545 ** payload is spilled to overflow pages. Once an overflow page is allocated,
48555 ** cell pointer array, and the cell content area. Page 1 also has a 100-byte
48556 ** file header that occurs before the page header.
48559 ** | file header | 100 bytes. Page 1 only.
48561 ** | page header | 8 bytes for leaves. 12 bytes for interior nodes
48574 ** The page headers looks like this:
48579 ** 3 2 number of cells on this page
48584 ** The flags define the format of this btree page. The leaf flag means that
48585 ** this page has no children. The zerodata flag means that this page carries
48590 ** The cell pointer array begins on the first byte after the page header.
48592 ** offsets from the beginning of the page to the cell content in the cell
48595 ** be easily added without having to defragment the page.
48597 ** Cell content is stored at the very end of the page and grows toward the
48598 ** beginning of the page.
48607 ** in the page header at offset 7.
48614 ** the end of the page. Pointers to the cells are in the cell pointer array
48615 ** that immediately follows the page header. Cells is not necessarily
48640 ** 4 Page number of the left child. Omitted if leaf flag is set.
48644 ** 4 First page of the overflow chain. Omitted if no overflow
48646 ** Overflow pages form a linked list. Each page except the last is completely
48647 ** filled with data (pagesize - 4 bytes). The last page can have as little
48651 ** 4 Page number of next overflow page
48655 ** file header points to the first in a linked list of trunk page. Each trunk
48656 ** page points to multiple leaf pages. The content of a leaf page is
48657 ** unspecified. A trunk page looks like this:
48660 ** 4 Page number of next trunk page
48661 ** 4 Number of leaf pointers on this page
48666 /* The following value is the maximum cell size assuming a maximum page
48671 /* The maximum number of cells on a single page of the database. This
48673 ** plus 2 bytes for the index to the cell in the page header). Such
48699 ** Page type flags. An ORed combination of these flags appear as the
48700 ** first byte of on-disk image of every BTree page.
48708 ** As each page of the file is loaded into memory, an instance of the following
48710 ** information about the page that is decoded from the raw file page.
48712 ** The pParent field points back to the parent page. This allows us to
48714 ** unref() the parent page pointer when this page is no longer referenced.
48725 u8 hasData; /* True if this page stores data */
48726 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
48732 u16 nFree; /* Number of free bytes on the page */
48733 u16 nCell; /* Number of cells on this page, local and ovfl */
48734 u16 maskPage; /* Mask for page offset */
48738 BtShared *pBt; /* Pointer to BtShared that this page is part of */
48739 u8 *aData; /* Pointer to disk image of the page data */
48742 DbPage *pDbPage; /* Pager page handle */
48743 Pgno pgno; /* Page number for this page */
48747 ** The in-memory image of a disk page has the auxiliary information appended
48756 ** is opened on the table with root page BtShared.iTable. Locks are removed
48762 Pgno iTable; /* Root page of table */
48803 BtLock lock; /* Object used to lock page 1 */
48854 Pager *pPager; /* The page cache */
48857 MemPage *pPage1; /* First page of the database */
48870 u32 pageSize; /* Total number of bytes on a page */
48871 u32 usableSize; /* Number of usable bytes on each page */
48891 #define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
48901 ** based on information extract from the raw disk page.
48911 u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
48912 u16 nSize; /* Size of the cell content on the main b-tree page */
48946 Pgno *aOverflow; /* Cache of overflow page locations */
48948 Pgno pgnoRoot; /* The root page of this tree */
48961 i16 iPage; /* Index of current page in apPage */
48963 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
48997 ** The database page the PENDING_BYTE occupies. This page is never used.
49003 ** database page. The first argument to each is the number of usable
49004 ** bytes on each page of the database (often 1024). The second is the
49005 ** page number to look up in the pointer map.
49007 ** PTRMAP_PAGENO returns the database page number of the pointer-map
49008 ** page that stores the required pointer. PTRMAP_PTROFFSET returns
49011 ** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
49013 ** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
49021 ** The pointer map is a lookup table that identifies the parent page for
49022 ** each child page in the database file. The parent page is the page that
49023 ** contains a pointer to the child. Every page in the database contains
49024 ** 0 or 1 parent pages. (In this context 'database page' refers
49025 ** to any page that is not part of the pointer map itself.) Each pointer map
49026 ** entry consists of a single byte 'type' and a 4 byte parent page number.
49030 ** position in the file to another as part of autovacuum. When a page
49032 ** new location. The pointer map is used to locate the parent page quickly.
49034 ** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
49037 ** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
49040 ** PTRMAP_OVERFLOW1: The database page is the first page in a list of
49041 ** overflow pages. The page number identifies the page that
49042 ** contains the cell with a pointer to this overflow page.
49044 ** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
49045 ** overflow pages. The page-number identifies the previous
49046 ** page in the overflow page list.
49048 ** PTRMAP_BTREE: The database page is a non-root btree page. The page number
49049 ** identifies the parent page in the btree.
49087 int *anRef; /* Number of times each page is referenced */
49415 ** from the header of a btree page. If the page size is 65536 and the page
49478 ** table with root page iRoot. Return 1 if it does and 0 if not.
49480 ** For example, when writing to a table with root-page iRoot via
49486 ** caller should have first obtained a lock specifying the root page of
49492 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
49493 ** hold a write-lock on the schema table (root page 1). This is also
49498 Pgno iRoot, /* Root page of b-tree */
49525 /* Figure out the root-page that the lock should be held on. For table
49526 ** b-trees, this is just the root page of the b-tree being read or
49527 ** written. For index b-trees, it is the root page of the associated
49541 /* Search for the required lock. Either a write-lock on root-page iTab, a
49573 ** rooted at page iRoot, one should call:
49593 ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
49653 ** Add a lock on the table with root-page iTable to the shared-btree used
49808 ** Invalidate the overflow page-list cache for cursor pCur, if any.
49817 ** Invalidate the overflow page-list cache for all cursors opened
49835 ** cursors open on any row within the table with root-page pgnoRoot.
49865 ** when a page that previously contained data becomes a free-list leaf
49866 ** page.
49872 ** 1) When all data is deleted from a page and the page becomes
49873 ** a free-list leaf page, the page is not written to the database
49875 ** such a page is not even journalled (as it will not be modified,
49878 ** 2) When a free-list leaf page is reused, its content is not read
49884 ** a page is moved to the free-list and then reused within the same
49885 ** transaction, a problem comes up. If the page is not journalled when
49891 ** The solution is the BtShared.pHasContent bitvec. Whenever a page is
49892 ** moved to become a free-list leaf page, the corresponding bit is
49893 ** set in the bitvec. Whenever a leaf page is extracted from the free-list,
49916 ** This function is called when a free-list leaf page is removed from the
49918 ** page from the pager layer with the 'no-content' flag set. True otherwise.
49988 ** the table with root-page iRoot. Usually, this is called just before cursor
50106 ** Given a page number of a regular database page, return the page
50107 ** number for the pointer-map page that contains the entry for the
50108 ** input page number.
50110 ** Return 0 (not a valid page) for pgno==1 since there is
50111 ** no pointer map associated with page 1. The integrity_check logic
50131 ** This routine updates the pointer map entry for page number 'key'
50132 ** so that it maps to type 'eType' and parent page number 'pgno'.
50139 DbPage *pDbPage; /* The pointer map page */
50141 Pgno iPtrmap; /* The pointer map page number */
50142 int offset; /* Offset in pointer map page */
50148 /* The master-journal page number must never be used as a pointer map page */
50186 ** This routine retrieves the pointer map entry for page 'key', writing
50187 ** the type and parent page number to *pEType and *pPgno respectively.
50191 DbPage *pDbPage; /* The pointer map page */
50192 int iPtrmap; /* Pointer map page index */
50193 u8 *pPtrmap; /* Pointer map page data */
50228 ** Given a btree page and a cell index (0 means the first cell on
50229 ** the page, 1 means the second cell, and so forth) return a pointer
50269 MemPage *pPage, /* Page containing the cell */
50301 ** on the local page. No overflow is required.
50307 /* If the payload will not fit completely on the local page, we have
50337 MemPage *pPage, /* Page containing the cell */
50346 ** data area of the btree-page. The return number includes the cell
50347 ** data header and the local payload, but not any overflow page or
50413 ** If the cell pCell, part of page pPage contains a pointer
50414 ** to an overflow page, insert an entry into the pointer-map
50415 ** for the overflow page.
50432 ** Defragment the page given. All Cells are moved to the
50433 ** end of the page and all free space is collected into one
50440 int hdr; /* Offset to the page header */
50442 int usableSize; /* Number of usable bytes on a page */
50445 int nCell; /* Number of cells on the page */
50446 unsigned char *data; /* The page data */
50515 ** Allocate nByte bytes of space from within the B-Tree page passed
50534 int usableSize; /* Usable size of the page */
50577 ** fragmented bytes within the page. */
50608 ** is no way that the allocation can extend off the end of the page.
50648 ** cell content area exceeds the value in the page header. If these
50708 ** Decode the flags byte (the first byte of the header) for a page
50748 ** Return SQLITE_OK on success. If we see that the page does
50749 ** not contain a well-formed database page, then return
50751 ** guarantee that the page is well-formed. It only shows that
50764 u8 hdr; /* Offset to beginning of page header */
50767 int usableSize; /* Amount of usable space on each page */
50768 u16 cellOffset; /* Offset from start of page to first cell pointer */
50769 int nFree; /* Number of unused bytes on the page */
50789 /* To many cells for a single page. The page must be corrupt */
50794 /* A malformed database page might cause us to read past the end
50795 ** of page when parsing a cell.
50798 ** past the end of a page boundary and causes SQLITE_CORRUPT to be
50826 /* Compute the total free space on the page */
50832 /* Start of free block is off the page */
50839 ** the free-block must lie on the database page. */
50849 ** of the page, then the page must be corrupted. This check also
50851 ** area, according to the page header, lies within the page.
50863 ** Set up a raw page so that it looks like a database page holding
50914 ** Get a page from the pager. Initialize the MemPage.pBt and
50918 ** the content of the page at this time. So do not go to the disk
50920 ** If in the future we call sqlite3PagerWrite() on this page, that
50926 Pgno pgno, /* Number of the page to fetch */
50927 MemPage **ppPage, /* Return the page in this parameter */
50928 int noContent /* Do not load page content if true */
50941 ** Retrieve a page from the pager cache. If the requested page is not
50969 ** Get a page from the pager and initialize it. This routine is just a
50978 Pgno pgno, /* Number of the page to get */
50979 MemPage **ppPage /* Write the page pointer here */
51019 ** the transaction, for each page restored this routine is called.
51022 ** page to agree with the restored data.
51032 /* pPage might not be a btree page; it might be an overflow page
51033 ** or ptrmap page or a free page. In those cases, the following
51036 ** btreeInitPage() be called on every btree page so we make
51037 ** the call for every page that comes in for re-initing. */
51086 u8 nReserve; /* Byte of unused space on each page */
51519 ** Change the default pages size and the number of reserved bytes per page.
51520 ** Or, if the page size has already been fixed, return SQLITE_READONLY
51523 ** The page size must be a power of 2 between 512 and 65536. If the page
51524 ** size supplied does not meet this constraint then the page size is not
51527 ** Page sizes are constrained to be a power of two so that the region
51530 ** at the beginning of a page.
51533 ** bytes per page is left unchanged.
51535 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
51566 ** Return the currently defined page size
51574 ** Return the number of bytes of space at the end of every page that
51587 ** Set the maximum page count for a database if mxPage is positive.
51589 ** Regardless of the value of mxPage, return the maximum page count.
51676 MemPage *pPage1; /* Page 1 of the database file */
51724 ** required as the version of page 1 currently in the page1 buffer
51759 /* After reading the first page of the database assuming a page size
51760 ** of BtShared.pageSize, we have discovered that the page-size is
51763 ** again with the correct page-size.
51790 ** cells can will fit on one page. We assume a 10-byte page header.
51796 ** 4-byte overflow page pointer
51799 ** page pointer.
51824 ** this routine unrefs the first page of the database file which
51843 ** into a new empty database by initializing the first page of
51968 ** page 1. So if some other shared-cache client already has a write-lock
51969 ** on page 1, the transaction cannot be opened. */
51979 ** reading page 1 it discovers that the page-size of the database
51981 ** pBt->pageSize to the page-size of the file on disk.
52030 ** re-read the database size from page 1 if a savepoint or transaction
52060 ** Set the pointer-map entries for all children of page pPage. Also, if
52066 int nCell; /* Number of cells in page pPage */
52101 ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
52105 ** PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child
52106 ** page of pPage.
52108 ** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow
52109 ** page pointed to by one of the cells on pPage.
52111 ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
52112 ** overflow page in the list.
52118 /* The pointer is always the first 4 bytes of the page in this case. */
52166 ** Move the open database page pDbPage to location iFreePage in the
52170 ** the journal needs to be sync()ed before database page pDbPage->pgno
52172 ** page.
52176 MemPage *pDbPage, /* Open page to move */
52178 Pgno iPtrPage, /* Pointer map 'page-no' entry for pDbPage */
52182 MemPage *pPtrPage; /* The page that contains a pointer to pDbPage */
52192 /* Move page iDbPage from its current location to page number iFreePage */
52193 TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n",
52201 /* If pDbPage was a btree-page, then it may have child pages and/or cells
52205 ** If pDbPage is an overflow page, then the first 4 bytes may store a
52206 ** pointer to a subsequent overflow page. If this is the case, then
52207 ** the pointer map needs to be updated for the subsequent overflow page.
52224 /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
52256 ** database so that the last page of the file currently in use
52294 /* Remove the page from the files free-list. This is not required
52309 Pgno iFreePg; /* Index of free page to move pLastPg to */
52317 /* If nFin is zero, this loop runs exactly once and page pLastPg
52318 ** is swapped with the first free page pulled off the free list.
52321 ** looping until a free-page located within the first nFin pages
52418 Pgno iFree; /* The next page to be freed */
52419 int nEntry; /* Number of entries on one ptrmap page */
52424 /* It is not possible to create a database for which the final page
52425 ** is either a pointer-map page or the pending-byte page. If one
52707 ** call btreeGetPage() on page 1 again to make
52801 ** Create a new cursor for the BTree whose root is on the page
52825 ** No checking is done to make sure that page iTable really is the
52826 ** root page of a b-tree. If it is not, then the cursor acquired
52834 int iTable, /* Root page of table to open */
52883 int iTable, /* Root page of table to open */
52921 ** as pCur and having the same root page number as pCur. The value is
53084 ** Given the page number of an overflow page in the database (parameter
53085 ** ovfl), this function finds the pagepage in the
53087 ** pointer-map data instead of reading the content of page ovfl to do so.
53091 ** The page number of the next overflow page in the linked list is
53092 ** written to *pPgnoNext. If page ovfl is the last page in its linked
53096 ** to page number pOvfl was obtained, then *ppPage is set to point to that
53104 Pgno ovfl, /* Current overflow page number */
53106 Pgno *pPgnoNext /* OUT: Next overflow page number */
53116 /* Try to find the next page in the overflow list using the
53117 ** autovacuum pointer-map pages. Guess that the next page in
53118 ** the overflow list is page number (ovfl+1). If that guess turns
53119 ** out to be wrong, fall back to loading the data of page
53120 ** number ovfl to determine the next page number.
53160 ** Copy data from a buffer to a page, or from a page to a buffer.
53162 ** pPayload is a pointer to data stored on database page pDbPage.
53171 void *pPayload, /* Pointer to page data */
53174 int eOp, /* 0 -> copy from page, 1 -> copy to page */
53175 DbPage *pDbPage /* Page containing pPayload */
53178 /* Copy data from buffer to page (a write operation) */
53185 /* Copy data from page to buffer (a read operation) */
53201 ** The content being read or written might appear on the main page
53206 ** allocates space for and lazily popluates the overflow page-list
53210 ** Once an overflow page-list cache has been allocated, it may be
53213 ** mode, the following events may invalidate an overflow page-list cache.
53217 ** * Creating a table (may require moving an overflow page).
53230 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
53249 /* Check if data must be read/written to/from the btree page itself. */
53264 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
53272 ** one entry for each overflow page in the overflow chain. The
53273 ** page number of the first overflow page is stored in aOverflow[0],
53287 /* If the overflow page-list cache has been allocated and the
53288 ** entry for the first required overflow page is valid, skip
53301 /* If required, populate the overflow page-list cache. */
53309 /* The only reason to read this page is to obtain the page
53310 ** number for the next page in the overflow chain. The page
53312 ** page-list cache, if any, then fall back to the getOverflowPage()
53323 /* Need to read this page properly. It contains some of the
53338 ** 2) data is required from the start of this overflow page, and
53344 ** output buffer, bypassing the page-cache altogether. This speeds
53443 ** and data to fit on the local page and for there to be no overflow
53450 ** page of the database. The data might change or move the next time
53494 ** b-tree page. Write the number of available bytes into *pAmt.
53526 ** Move the cursor down to a new child page. The newPgno argument is the
53527 ** page number of the child page to move to.
53529 ** This function returns SQLITE_CORRUPT if the page-header flags field of
53530 ** the new child page does not match the flags field of the parent (i.e.
53531 ** if an intkey page appears to be the parent of a non-intkey page, or
53562 Page pParent is an internal (non-leaf) tree page. This function
53563 ** asserts that page number iChild is the left-child if the iIdx'th
53564 ** cell in page pParent. Or, if iIdx is equal to the total number of
53565 ** cells in pParent, that page number iChild is the right-child of
53566 ** the page.
53581 ** Move the cursor up to the parent page.
53584 ** to the page we are coming from. If we are coming from the
53585 ** right-most child page then pCur->idx is set to one more than
53596 ** one cursor has modified page pParent while a reference to it is held
53597 ** by a second cursor. Which can only happen if a single page is linked
53615 ** Move the cursor to point to the root page of its b-tree structure.
53617 ** If the table has a virtual root page, then the cursor is moved to point
53618 ** to the virtual root page instead of the actual root page. A table has a
53619 ** virtual root page when the actual root page contains no cells and a
53620 ** single child page. This can only happen with the table rooted at page 1.
53624 ** cell located on the root (or virtual root) page and the cursor state
53628 ** page-header flags indicate that the [virtual] root-page is the expected
53629 ** kind of b-tree page (i.e. if when opening the cursor the caller did not
53680 /* Assert that the root page is of the correct type. This must be the
53681 ** case as the call to this function that loaded the root-page (either
53685 ** to the page. */
53731 ** page to which it is currently pointing. Notice the difference
53734 ** finds the right-most entry beneath the *page*.
53830 ** left pointing at a leaf page which would hold the entry if it
53898 /* pPage->nCell must be greater than zero. If this is the root-page
53900 ** not run. If this is not the root-page, then the moveToChild() routine
53902 ** be the right kind (index or table) of b-tree page. Otherwise
53937 /* The maximum supported page-size is 65536 bytes. This means that
53939 ** page is less than 16384 bytes and may be stored as a 2-byte
53942 ** stored entirely within the b-tree page by inspecting the first
53951 ** b-tree page. */
53959 ** fits entirely on the main b-tree page. */
54080 ** the page while cursor pCur is holding a reference to it. Which can
54082 ** page into more than one b-tree structure. */
54182 ** Allocate a new page from the database file.
54184 ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
54185 ** has already been called on the new page.) The new page has also
54187 ** sqlite3PagerUnref() on the new page when it is done.
54194 ** locate a page close to the page number "nearby". This can be used in an
54198 ** If the "exact" parameter is not 0, and the page-number nearby exists
54231 ** shows that the page 'nearby' is somewhere on the free-list, then
54232 ** the entire-list will be searched for that page.
54249 ** first free-list trunk page. iPrevTrunk is initially 1.
54256 ** is not true. Otherwise, it runs once for each trunk-page on the
54257 ** free-list until the page 'nearby' is located.
54279 k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
54282 ** So extract the trunk page itself and use it as the newly
54283 ** allocated page */
54300 /* The list is being searched and this trunk page is the page
54321 /* The trunk page is required by the caller but it contains
54323 ** page in this case.
54414 /* There are no pages on the freelist, so create a new page at the
54423 /* If *pPgno refers to a pointer-map page, allocate two new pages
54424 ** at the end of the file instead of one. The first allocated page
54425 ** becomes a new pointer-map page, the second is used by the caller.
54428 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
54472 ** This function is used to add page iPage to the database file free-list.
54473 ** It is assumed that the page is not already a part of the free-list.
54477 ** corresponding to page iPage handy, it may pass it as the second value.
54484 MemPage *pTrunk = 0; /* Free-list trunk page */
54485 Pgno iTrunk = 0; /* Page number of free-list trunk page */
54486 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
54487 MemPage *pPage; /* Page being freed. May be NULL. */
54502 /* Increment the free page count on pPage1 */
54521 ** to indicate that the page is free.
54530 ** trunk page in the free-list is full, then this page will become a
54531 ** new free-list trunk page. Otherwise, it will become a leaf of the
54532 ** first trunk page in the current free-list. This block tests if it
54533 ** is possible to add the page as a new free-list leaf.
54536 u32 nLeaf; /* Initial number of leaf cells on trunk page */
54551 /* In this case there is room on the trunk page to insert the page
54554 page is not really full until it contains
54574 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
54580 ** the page being freed as a leaf page of the first trunk in the free-list.
54582 ** first trunk in the free-list is full. Either way, the page being freed
54583 ** will become the new first trunk page in the free-list.
54595 TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, iTrunk));
54628 return SQLITE_CORRUPT; /* Cell extends past end of page */
54639 /* 0 is not a legal page number and page 1 cannot be an
54640 ** overflow page. Therefore if ovflPgno<2 or past the end of the
54653 ** to an overflow page belonging to a cell that is being deleted/updated.
54654 ** So if there exists more than one reference to this page, then it
54655 ** must not really be an overflow page and the database must be corrupt.
54657 ** freePage2() may zero the page contents if secure-delete mode is
54658 ** enabled. If this 'overflow' page happens to be a page that the
54677 ** Create the byte sequence used to represent a cell on page pPage
54689 MemPage *pPage, /* The page that contains the cell */
54754 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
54766 ** overflow page is being allocated, add an entry to the pointer-map
54767 ** for that page now.
54769 ** If this is the first overflow page, then write a partial entry
54852 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
54890 ** If the cell content will fit on the page, then put it there. If it
54904 MemPage *pPage, /* Page into which we are copying */
54905 int i, /* New cell becomes the i-th cell of the page */
54917 u8 *data; /* The content of the whole page */
54931 ** malformed cell from a leaf page to an interior page, if the cell size
54982 /* The cell may contain a pointer to an overflow page. If so, write
54983 ** the entry for the overflow page into the pointer map.
54992 ** Add a list of cells to a page. The page should be initially empty.
54993 ** The cells are guaranteed to fit on the page.
54996 MemPage *pPage, /* The page to be assemblied */
54997 int nCell, /* The number of cells to add to this page */
55006 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
55014 /* Check that the page
55036 ** of the page that participate in the balancing operation. NB is the
55037 ** total number of pages that participate, including the target page and
55057 ** a new page to the right-hand side and put the one new entry in
55058 ** that page. This leaves the right side of the tree somewhat
55060 ** at the end soon afterwards so the nearly empty page will quickly
55063 ** pPage is the leaf page which is the right-most page in the tree.
55065 ** which is also the right-most entry on the page.
55069 ** byte page number followed by a variable length integer. In other
55075 MemPage *pNew; /* Newly allocated page */
55077 Pgno pgnoNew; /* Page number of pNew */
55086 /* Allocate a new page. This page will become the right-sibling of
55087 ** pPage. Make the parent page writable, so that the new divider cell
55105 ** with entries for the new page, and any pointer from the
55106 ** cell on the page to an overflow page. If either of these
55108 ** of the parent page are still manipulated by thh code below.
55109 ** That is Ok, at this point the parent page is guaranteed to
55111 ** rollback, undoing any changes made to the parent page.
55121 ** consists of a 4-byte page number (the page number of pPage) and
55143 /* Set the right-child pointer of pParent to point to the new page. */
55146 /* Release the reference to the new page. */
55198 ** on page pFrom to page pTo. If page pFrom was not a leaf page, then
55199 ** the pointer-map entries for each child page are updated so that the
55200 ** parent page stored in the pointer map is page pTo. If pFrom contained
55201 ** any cells with overflow page pointers, then the corresponding pointer
55202 ** map entries are also updated so that the parent page is page pTo.
55207 ** Before returning, page pTo is reinitialized using btreeInitPage().
55228 /* Copy the b-tree node content from page pFrom to page pTo. */
55233 /* Reinitialize page pTo so that the contents of the MemPage structure
55236 ** page pFrom.
55256 ** (hereafter "the page") and up to 2 siblings so that all pages have about the
55258 ** page are used in the balancing, though both siblings might come from one
55259 ** side if the page is the first or last child of its parent. If the page
55260 ** has fewer than 2 siblings (something which can only happen if the page
55261 ** is a root page or a child of a root page) then all available siblings
55264 ** The number of siblings of the page might be increased or decreased by
55267 ** Note that when this routine is called, some of the cells on the page
55269 ** if the page is overfull. This routine ensures that all cells allocated
55270 ** to the page and its siblings fit into MemPage.aData[] before returning.
55272 ** In the course of balancing the page and its siblings, cells may be
55273 ** inserted into or removed from the parent page (pParent). Doing so
55274 ** may cause the parent page to become overfull or underfull. If this
55283 ** buffer big enough to hold one page. If while inserting cells into the parent
55284 ** page (pParent) the parent page becomes overfull, this buffer is
55286 ** a maximum of four divider cells into the parent page, and the maximum
55288 ** of the page-size, the aOvflSpace[] buffer is guaranteed to be large
55295 MemPage *pParent, /* Parent page of siblings being balanced */
55296 int iParentIdx, /* Index of "the page" in pParent */
55297 u8 *aOvflSpace, /* page-size bytes of space for parent ovfl */
55298 int isRoot /* True if pParent is a root-page */
55312 int subtotal; /* Subtotal of bytes in cells on one page */
55321 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
55322 int szNew[NB+2]; /* Combined size of cells place on i-th page */
55326 Pgno pgno; /* Temp var to store a page number in */
55333 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
55354 ** This loop also drops the divider cells from the parent page. This
55356 ** overflow cells in the parent page, since if any existed they will
55399 /* Drop the cell from the parent page. apDiv[i] still points to
55440 + k*nOld; /* Page copies (apCopy) */
55515 /* The right pointer of the child page pOld becomes the left
55532 ** size of all cells on the i-th page and cntNew[] which is the index
55533 ** in apCell[] of the cell that divides page i from page i+1.
55539 ** szNew[i]: Spaced used on the i-th sibling page.
55541 ** the right of the i-th sibling page.
55594 ** a virtual root page. A virtual root page is when the real root
55595 ** page is page 1 and we are the only child of that page.
55634 /* Set the pointer-map entry for the new sibling page. */
55700 /* Assemble the new sibling page. */
55710 /* If the sibling page assembled above was not the right-most sibling,
55711 ** insert a divider cell into the parent page.
55729 ** the sibling-page assembled above only.
55775 /* The root page of the b-tree now contains no cells. The only sibling
55776 ** page is the right-child of the parent. Copy the contents of the
55777 ** child page into the parent, decreasing the overall height of the
55785 ** The second assert below verifies that the child page is defragmented
55787 ** is important if the parent page happens to be page 1 of the database
55808 ** page in any overflow chains used by new divider cells. These
55832 j = 0; /* Current 'old' sibling page */
55833 k = 0; /* Current 'new' sibling page */
55838 ** sibling page j. If the siblings are not leaf pages of an
55862 ** sibling page
55872 ** page before the balancing, then the pointer map entries associated
55922 ** This function is called when the root page of a b-tree structure is
55925 ** A new child page is allocated and the contents of the current root
55926 ** page, including overflow cells, are copied into the child. The root
55927 ** page is then overwritten to make it an empty page with the right-child
55928 ** pointer pointing to the new page.
55931 ** that the new child-page now contains pointers to are updated. The
55933 ** page is also updated.
55936 ** page and SQLITE_OK is returned. In this case the caller is required
55942 MemPage *pChild = 0; /* Pointer to a new child page */
55943 Pgno pgnoChild = 0; /* Page number of the new child page */
55949 /* Make pRoot, the root page of the b-tree, writable. Allocate a new
55950 ** page that will become the new right-child of pPage. Copy the contents
55951 ** of the node stored on pRoot into the new child page.
55988 ** The page that pCur currently points to has just been modified in
56012 /* The root page of the b-tree is overfull. In this case call the
56013 ** balance_deeper() function to create a new child for the root-page
56014 ** and copy the current contents of the root-page to it. The
56015 ** next iteration of the do-loop will balance the child page.
56065 ** will balance the parent page to correct this.
56067 ** If the parent page becomes overfull, the overflow cell or cells
56072 ** different page). Once this subsequent call to balance_nonroot()
56075 ** copied either into the body of a database page or into the new
56097 /* The next iteration of the do-loop balances the parent page. */
56197 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
56239 ** back to the root page as balance() used to invalidate the contents
56279 MemPage *pPage; /* Page to delete cell from */
56308 /* If the page containing the entry to delete is not a leaf page, move
56313 ** sub-tree headed by the child page of the cell being deleted. This makes
56322 ** making any modifications. Make the page containing the entry to be
56324 ** entry and finally remove the cell itself from within the page.
56334 /* If the cell deleted was not located on a leaf page, then the cursor
56336 ** by the child-page of the cell that was just deleted from an internal
56358 /* Balance the tree. If the entry deleted was located on a leaf page,
56359 ** then the cursor still points to that page. In this case the first
56363 ** Otherwise, if the entry deleted was on an internal node page, then
56364 ** pCur is pointing to the leaf page from which a cell was removed to
56388 ** Create a new BTree table. Write into *piTable the page
56389 ** number for the root page of the new table.
56403 int ptfFlags; /* Page-type flage for the root page of new table */
56416 Pgno pgnoMove; /* Move a page here to make room for the root-page */
56417 MemPage *pPageMove; /* The page to move to. */
56420 ** to make room for the new tables root page. In case this page turns
56421 ** out to be an overflow page, delete all overflow page-map caches
56427 ** root page of the new table should go. meta[3] is the largest root-page
56428 ** created so far, so the new root-page is (meta[3]+1).
56433 /* The new root-page may not be allocated on a pointer-map page, or the
56434 ** PENDING_BYTE page.
56442 /* Allocate a page. The page that currently resides at pgnoRoot will
56443 ** be moved to the allocated page (unless the allocated page happens
56452 /* pgnoRoot is the page that will be used for the root-page of
56455 ** by extending the file), the current page at position pgnoMove
56463 /* Move the page currently at pgnoRoot to pgnoMove. */
56481 /* Obtain the page at pgnoRoot */
56498 /* Update the pointer-map and meta-data with the new root-page number. */
56505 /* When the new root page was allocated, page 1 was made writable in
56542 ** Erase the given database page and all its children. Return
56543 ** the page to the freelist.
56547 Pgno pgno, /* Page number to clear */
56548 int freePageFlag, /* Deallocate page if true */
56592 ** the page number of the root of the table. After this routine returns,
56593 ** the root page is empty, but still exists.
56625 ** page 1) is never added to the freelist.
56630 ** If AUTOVACUUM is enabled and the page at iTable is not the last
56631 ** root page in the database file, then the last root page
56633 ** iTable and that last slot formerly occupied by the last root page
56637 ** page number that used to be the last root page in the file before
56638 ** the move. If no page gets moved, *piMoved is set to 0.
56639 ** The last root page is recorded in meta[3] and the value of
56652 ** need to move another root-page to fill a gap left by the deleted
56653 ** root page. If an open cursor was using this page a problem would
56683 /* If the table being dropped is the table with the largest root-page
56684 ** number in the database, put the root page on the free list.
56692 /* The table being dropped does not have the largest root-page
56693 ** number in the database. So move the page that does into the
56694 ** gap left by the deleted root-page.
56717 /* Set the new 'max-root-page' value in the database header. This
56719 ** be a root-page number, less one again if that is the
56736 /* If sqlite3BtreeDropTable was called on page 1.
56837 ** page in the B-Tree structure (not including overflow pages).
56841 MemPage *pPage; /* Current page of the b-tree */
56843 /* If this is a leaf page or the tree is not an int-key tree, then
56844 ** this page contains countable entries. Increment the entry counter
56854 ** the next page in the tree that has not yet been visited. The
56856 ** of the page, or to the number of cells in the page if the next page
56931 ** Add 1 to the reference count for page iPage. If this is the second
56932 ** reference to the page, add an error message to pCheck->zErrMsg.
56933 ** Return 1 if there are 2 ore more references to the page and 0 if
56934 ** if this is the first reference to the page.
56936 ** Also check that the page number is in bounds.
56941 checkAppendMsg(pCheck, zContext, "invalid page number %d", iPage);
56945 checkAppendMsg(pCheck, zContext, "2nd reference to page %d", iPage);
56953 ** Check that the entry in the pointer-map for page iChild maps to
56954 ** page iParent, pointer type ptrType. If not, append an error message
56959 Pgno iChild, /* Child page number */
56961 Pgno iParent, /* Expected pointer map parent page number */
56984 ** Check the integrity of the freelist or of an overflow page list.
56989 int isFreeList, /* True for a freelist. False for overflow page list */
56990 int iPage, /* Page number for first page in the list */
57008 checkAppendMsg(pCheck, zContext, "failed to get page %d", iPage);
57021 "freelist leaf count too big on page %d", iPage);
57039 ** page in this overflow list, check that the pointer-map entry for
57040 ** the following page matches iPage.
57056 ** Do various sanity checks on a single page of a tree. Return
57063 ** but combine to completely cover the page.
57070 ** 8. Make sure this page is at least 33% full or else it is
57075 int iPage, /* Page number of the page to check */
57092 sqlite3_snprintf(sizeof(zContext), zContext, "Page %d: ", iPage);
57094 /* Check that the page exists
57102 "unable to get the page. error code=%d", rc);
57128 "On tree page %d cell %d: ", iPage, i);
57157 /* Check sanity of left child page.
57168 checkAppendMsg(pCheck, zContext, "Child page depth differs");
57177 "On page %d at right child: ", iPage);
57190 /* if we are a left child page */
57192 /* if we are the left most child page */
57212 /* else if we're a right child page */
57222 /* Check for complete coverage of the page
57245 "Corruption detected in cell %d on page %d",i,iPage);
57267 "Multiple uses for byte %d of page %d", i, iPage);
57273 "Fragmentation of %d bytes reported as %d on page %d",
57286 ** an array of pages numbers were each page number is the root page of
57355 /* Make sure every page in the file is referenced
57360 checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
57368 checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
57372 checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
57383 "Outstanding page count goes from %d to %d during this analysis",
57524 ** Obtain a lock on the table whose root page is iTab. The
57597 ** This function sets a flag only. The actual page location cache
57678 Pgno iNext; /* Page number of the next source page to copy */
57707 ** the page cache associated with the source database. The mutex
57766 ** Attempt to set the page size of the destination to match the page size
57858 ** page iSrcPg from the source database. Copy this data into the
57881 ** page sizes of the source and destination differ.
57888 /* Backup is not possible if the page size of the destination is changing
57907 /* This loop runs once for each destination page spanned by the source
57908 ** page. For each iteration, variable iOff is set to the byte offset
57909 ** of the destination page.
57922 /* Copy the data from the source page into the destination page.
57925 ** of the page 'extra' space to invalidate the Btree layers
57926 ** cached parse of the page). MemPage.isInit is marked
57974 int pgszSrc = 0; /* Source page size */
57975 int pgszDest = 0; /* Destination page size */
58018 ** and the page sizes are different between source and destination */
58032 const Pgno iSrcPg = p->iNext; /* Source page number */
58034 DbPage *pSrcPg; /* Source page object */
58071 ** database. The complication here is that the destination page
58072 ** size may be different to the source page size.
58074 ** If the source page size is smaller than the destination page size,
58078 ** destination file that lie beyond the nDestTruncate page mark are
58096 /* If the source page-size is smaller than the destination page-size,
58102 ** pending-byte page in the source database may need to be
58254 ** This function is called after the contents of page iPage of the
58255 ** source database have been modified. If page iPage has already been
58270 /* The backup process p has already copied page iPage. But now it
59269 int available = 0; /* Number of bytes available on the local btree page */
67191 ** record header if the record header does not fit on a single page
67945 ** Open a read-only cursor for the database table whose root page is
67953 ** If P5!=0 then use the content of register P2 as the root page, not
67976 ** page is P2. Or if P5!=0 use the content of register P2 to find the
67977 ** root page.
68065 ** SQLite used to check if the root-page flags were sane at this point
68128 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69610 ** Delete an entire database table or index whose root page in the database
69617 ** If AUTOVACUUM is enabled then it is possible that another root page
69618 ** might be moved into the newly deleted root page in order to keep all
69620 ** value of the root page that moved - its value before the move occurred -
69621 ** is stored in register P2. If no page
69670 ** Delete all contents of the database table or index whose root page
69711 ** P1>1. Write the root page number of the new table into
69724 ** P1>1. Write the root page number of the new table into
69873 ** The root page numbers of all tables in the database are integer
70601 ** P2 contains the root-page of the table to lock.
71014 ** Try to set the maximum page count for database P1 to the value in P3.
71015 ** Do not let the maximum page count fall below the current page count and
71016 ** do not change the maximum page count value if P3==0.
71018 ** Store the maximum page count after the change in register P2.
72041 int pgsz; /* Page size of main database */
72290 ** than (page-size * cache-size), or
72293 ** than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
81250 int iTab; /* The root page of the table to be locked */
81258 ** The table to be locked has root page iTab and is found in database iDb.
81268 int iTab, /* Root page number of the table to be locked */
82101 ** The root page number of the new table is left in reg pParse->regRoot.
82102 ** The rowid and root page number values are needed by the code that
82706 ** So do not write to the disk again. Extract the root page number
82707 ** for the table from the db->init.newTnum field. (The page number
82748 ** statement to populate the new table. The root-page number for the
83062 ** used by SQLite when the btree layer moves a table root page. The
83063 ** root-page of a table or index in database iDb has changed from iFrom
83103 ** Write code to erase the table with root-page iTable from database iDb.
83105 ** if a root-page of another table is moved by the btree-layer whilst
83115 ** is non-zero, then it is the root page number of a table moved to
83133 ** in case a root-page belonging to another table is moved by the btree layer
83148 ** largest root-page number. This guarantees that none of the root-pages
83156 ** and root page 5 happened to be the largest root-page number in the
83157 ** database, then root page 5 would be moved to page 4 by the
83159 ** a free-list page.
83540 ** root page number of the index. If memRootPage is negative, then
83542 ** the root page number of the index is taken from pIndex->tnum.
83551 int tnum; /* Root page of index */
92460 ** page cache size. The value returned is the maximum number of
92461 ** pages in the page cache. The second form sets both the current
92462 ** page cache size value and the persistent page cache size value
92511 ** database page size in bytes. The second form sets the
92512 ** database page size value. The value can only be set if
92522 /* Malloc may fail when setting the page-size, as there is an internal
92799 ** page cache size. The second form sets the local
92800 ** page cache size value. If N is positive then that is the
93696 ** argv[1] = root page number for table or index. 0 for trigger or view.
93756 ** to do here is record the root page number for that index.
93884 ** meta[2] Size of the page cache.
98886 int iRoot = pTab->tnum; /* Root page of scanned b-tree */
98895 ** In this case set iRoot to the root page number of the index b-tree
101231 int nRes; /* Bytes of reserved space at the end of each page */
101309 ** to ensure that we do not try to change the page-size on a WAL database.
101316 /* Do not attempt to change the page
101413 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
101424 ** we already have page 1 loaded into cache and marked dirty. */
105719 ** on one page and hence more pages have to be fetched.
112811 /* Designate a buffer for page cache memory space */
112829 /* Specify an alternative page cache implementation */
116630 int nPgsz; /* Page size for host database */
117304 ** Store the current database page-size in bytes in p->nPgsz.
117992 /* Figure out the page-size for the database. This is required in order to
118257 int isFirstTerm = 1; /* True when processing first term on page */
120794 ** of data that will fit on a single leaf page of an intkey table in
127142 int nReq; /* Number of bytes required on leaf page */
130196 ** child page.
130804 ** an internal node, then the 64-bit integer is a child page number.
131026 ** Cursor pCursor currently points to a cell in a non-leaf page.
131702 RtreeNode **ppLeaf /* OUT: Selected leaf page */
133128 ** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
133129 ** This ensures that each node is stored on a single database page. If the
133130 ** database page-size is so large that more than RTREE_MAXCELLS entries