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
26219 ** the first page of the database, no damage is done.
36235 ** This file implements that page cache.
36239 ** A complete page cache is an instance of this structure.
36243 PgHdr *pSynced; /* Last synced page in dirty page list */
36246 int szPage; /* Size of every page in this cache */
36247 int szExtra; /* Size of extra space for each page */
36249 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
36252 PgHdr *pPage1; /* Reference to page 1 */
36287 ** Remove page pPage from the list of dirty pages.
36323 ** Add page pPage to the head of the dirty list (PCache1.pDirty is set to
36362 ** Initialize and shutdown the page cache subsystem. Neither of these
36368 ** built-in default page cache is used instead of the application defined
36369 ** page cache. */
36393 int szPage, /* Size of every page */
36394 int szExtra, /* Extra space associated with each page */
36410 ** Change the page size for PCache object. The caller must ensure that there
36411 ** are no outstanding page references when this function is called.
36435 ** Try to obtain a page from the cache.
36438 PCache *pCache, /* Obtain the page from this cache */
36439 Pgno pgno, /* Page number to obtain */
36440 int createFlag, /* If true, create page if it does not exist already */
36441 PgHdr **ppPage /* Write the page here */
36474 /* Find a dirty page to write-out and recycle. First try to find a
36475 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
36477 ** unreferenced dirty page.
36492 "spill page %d making room for %d - cache used: %d/%d",
36536 ** Decrement the reference count on a page. If the page is clean and the
36548 /* Move the page to the head of the dirty list. */
36556 ** Increase the reference count of a supplied page by 1.
36564 ** Drop a page from the cache. There must be exactly one reference to the
36565 ** page. This function deletes that reference, so after it returns the
36566 ** page pointed to by p is invalid.
36583 ** Make sure the page is marked as dirty. If it isn't dirty already,
36596 ** Make sure the page is marked as clean. If it isn't clean already,
36610 ** Make every page in the cache clean.
36631 ** Change the page number of page p to newPgno.
36646 ** Drop every cache entry whose page number is greater than "pgno". The
36648 ** other than page 1 with a page number greater than pgno.
36650 ** If there is a reference to page 1 and the pgno parameter passed to this
36651 ** function is 0, then the data area associated with page 1 is zeroed, but
36652 ** the page object is not dropped.
36765 ** Return a list of all dirty pages in the cache, sorted by page number.
36783 ** Return the number of references to the page supplied as an argument.
36821 ** Free up as much memory as possible from the page cache.
36857 ** This file implements the default page cache implementation (the
36860 ** If the default page cache implementation is overriden, then neither of
36870 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
36875 ** This page cache implementation works in one of two modes:
36901 /* Each page cache is an instance of the following object. Every
36903 ** temporary or transient database) has a single page cache which
36910 /* Cache configuration parameters. Page size (szPage) and the purgeable
36940 sqlite3_pcache_page page;
36941 unsigned int iKey; /* Key value (page number) */
36943 PCache1 *pCache; /* Cache that currently owns this page */
36974 PgFreeslot *pFree; /* Free page blocks */
36997 /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
37001 ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
37117 ** Allocate a new page object initially associated with cache pCache.
37143 p->page.pBuf = pPg;
37144 p->page.pExtra = &p[1];
37154 ** Free a page object allocated by pcache1AllocPage().
37164 pcache1Free(p->page.pBuf);
37192 ** Return true if it desirable to avoid allocating a new page cache
37195 ** If memory was allocated specifically to the page cache using
37197 ** it is desirable to avoid allocating a new page cache entry because
37199 ** for all page cache needs and we should not need to spill the
37202 ** Or, the heap is used for all page cache memory but the heap is
37204 ** allocating a new page cache entry in order to avoid stressing
37262 ** This function is used internally to remove the page pPage from the
37299 ** Remove the page supplied as an argument from the hash table
37333 ** Discard all pages from cache pCache with a page number (key value)
37400 PCache1 *pCache; /* The newly created page cache */
37401 PGroup *pGroup; /* The group the new page cache will belong to */
37503 ** Fetch a page by key value.
37505 ** Whether or not a new page may be allocated by this function depends on
37507 ** page. 1 means allocate a new page if space is easily available. 2
37508 ** means to try really hard to allocate a new page.
37515 ** There are three different approaches to obtaining space for a page,
37519 ** copy of the requested page. If one is found, it is returned.
37521 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
37524 ** 3. If createFlag is 1, and the page is not already in the cache, then
37525 ** return NULL (do not allocate a new page) if any of the following
37548 ** then attempt to recycle a page from the LRU list. If it is the right
37552 ** 5. Otherwise, allocate and return a new page buffer.
37576 /* Step 2: Abort if no existing page is found and createFlag is 0 */
37610 /* Step 4. Try to recycle a page. */
37637 /* Step 5. If a usable page buffer has still not been found,
37654 *(void **)pPage->page.pExtra = 0;
37663 return &pPage->page;
37670 ** Mark a page as unpinned (eligible for asynchronous recycling).
37684 /* It is an error to call this function if the page is already
37694 /* Add the page to the PGroup LRU list. */
37748 ** Discard all unpinned pages in the cache with a page number equal to
37749 ** or greater than parameter iLimit. Any pinned pages with a page number
37826 nFree += pcache1MemSize(p->page.pBuf);
38300 ** This is the implementation of the page cache subsystem or "pager".
38383 /* Read a page from the write-ahead log, if it is present. */
38440 ** stored in each frame (i.e. the db page-size when the WAL was created).
38458 ** Within this comment block, a page is deemed to have been synced
38460 ** Otherwise, the page is not synced until the xSync method of the VFS
38461 ** is called successfully on the file containing the page.
38463 ** Definition: A page of the database file is said to be "overwriteable" if
38464 ** one or more of the following are true about the page:
38466 ** (a) The original content of the page as it was at the beginning of
38470 ** (b) The page was a freelist leaf page at the start of the transaction.
38472 ** (c) The page number is greater than the largest page that existed in
38475 ** (1) A page of the database file is never overwritten unless one of the
38478 ** (a) The page and all other pages on the same sector are overwriteable.
38480 ** (b) The atomic page write optimization is enabled, and the entire
38482 ** number consists of a single page change.
38484 ** (2) The content of a page written into the rollback journal exactly matches
38489 ** (3) Writes to the database file are an integer multiple of the page size
38490 ** in length and are aligned on a page boundary.
38492 ** (4) Reads from the database file are either aligned on a page boundary and
38493 ** an integer multiple of the page size in length or are taken from the
38663 ** A pager moves from WRITER_LOCKED state to this state when a page is
38672 ** * The contents of the page cache have been modified.
38685 ** * The contents of the page cache have been modified (and possibly
38717 ** the contents of the page-cache may be left in an inconsistent state.
38729 ** page-cache and any other in-memory state at the same time. Everything
38883 ** A open page cache is an instance of struct Pager. A description of
38957 ** to allocate a new page to prevent the journal file from being written
38963 ** the database page-size in order to prevent a journal sync from happening
38984 ** is not an integer multiple of the page-size, the value stored in
38985 ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
38987 ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
38990 ** During a write-transaction, if pages with page-numbers greater than
39074 Bitvec *pInJournal; /* One bit for each page in the database file */
39088 u16 nExtra; /* Add this many bytes to each in-memory page */
39089 i16 nReserve; /* Number of unused bytes at end of each page */
39092 int pageSize; /* Number of bytes in a page */
39106 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
39111 PCache *pPCache; /* Pointer to page cache object */
39147 ** of a 32-bit checksum on each page of data. The checksum covers both
39148 ** the page number and the pPager->pageSize bytes of data for the page.
39162 ** The size of the of each page record in the journal is given by
39186 ** The maximum legal page number is (2^31 - 1).
39410 ** Return true if it is necessary to write page *pPg into the sub-journal.
39411 ** A page needs to be written into the sub-journal if there exists one
39414 ** * The page
39415 ** * The bit corresponding to the page-number is not set in
39432 ** Return true if the page is already in the journal file.
39525 ** a database page may be written atomically, and
39527 ** to the page size.
39535 ** contains rollback data for exactly one page.
39543 int szPage; /* Page size */
39568 ** Return a 32-bit hash of the page data for pPage.
39588 ** that the page is either dirty or still matches the calculated page-hash.
39757 ** - 4 bytes: Random number used for page hash.
39758 ** - 4 bytes: Initial database page count.
39760 ** - 4 bytes: Database page size.
39790 ** Write the nRec Field - the number of page records that follow this
39798 ** rest of the journal file contains valid page records. This assumption
39827 /* The page size */
39851 ** database page size. Since the zHeader buffer is only Pager.pageSize
39873 ** page records following this header and *pDbSize is set to the size of the
39932 u32 iPageSize; /* Page-size field of journal header */
39935 /* Read the page-size and sector-size journal header fields. */
39942 /* Versions of SQLite prior to 3.5.8 set the page-size field of the
39944 ** variable is already set to the correct page size.
39950 /* Check that the values read from the page-size and sector-size fields
39959 /* If the either the page-size or sector-size in the journal-header is
39967 /* Update the page-size to match the value read from the journal.
40001 ** The master journal page checksum is the sum of the bytes in the master
40033 ** the master journal name. This is in case the previous page written to
40073 ** Find a page in the hash table given its page number. Return
40074 ** a pointer to the page or NULL if the requested page is not
40088 ** Discard the entire contents of the in-memory page-cache.
40444 ** page of data and the current value of pPager->cksumInit.
40448 ** of the page data, starting with byte offset (pPager->pageSize%200).
40471 ** Report the current page size and number of reserved bytes back
40486 ** Read a single page from either the journal file (if isMainJrnl==1) or
40487 ** from the sub-journal (if isMainJrnl==0) and playback that page.
40488 ** The page begins at offset *pOffset into the file. The *pOffset
40489 ** value is increased to the start of the next page in the journal.
40494 ** If the page number of the page record read from the (sub-)journal file
40499 ** been played back. If the page at *pOffset has already been played back
40501 ** Make sure the pDone bit corresponding to the *pOffset page is set
40504 ** If the page record is successfully read from the (sub-)journal file
40512 ** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
40530 PgHdr *pPg; /* An existing page in the cache */
40531 Pgno pgno; /* The page number of a page in journal */
40533 char *aData; /* Temporary storage for the page */
40535 int isSynced; /* True if journal page is synced */
40557 /* Read the page number and page data from the journal or sub-journal
40567 /* Sanity checking on the page. This is more important that I originally
40587 /* If this page has already been played by before during the current
40594 /* When playing back page 1, restore the nReserve setting
40602 ** page in the pager cache. In this case just update the pager cache,
40603 ** not the database file. The page is left marked dirty in this case.
40606 ** and a page is moved during an incremental vacuum then the page may
40608 ** during a Movepage() call, then the page may not be in the cache
40613 ** pager cache if it exists and the main file. The page is then marked
40615 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
40618 ** Ticket #1171: The statement journal might contain page content that is
40619 ** different from the page content at the start of the transaction.
40620 ** This occurs when a page is changed prior to the start of a statement
40623 ** for certain that original page contents are synced into the main rollback
40628 ** locked. (2) we know that the original page content is fully synced
40629 ** in the main journal either because the page is not in cache or else
40630 ** the page is marked as needSync==0.
40643 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
40670 ** the database and the page is not in-memory, there is a potential
40671 ** problem. When the page is next fetched by the b-tree layer, it
40677 ** if the page is on the free-list at the start of the transaction, then
40680 ** The solution is to add an in-memory page to the cache containing
40681 ** the data just read from the sub-journal. Mark the page as dirty
40682 ** and if the pager requires a journal-sync, then mark the page as
40696 /* No page should ever be explicitly rolled back that is in use, except
40697 ** for page 1 which is held in use in order to keep the lock on the
40698 ** database active. However such a page may be rolled back as a result
40707 /* If the contents of this page were just restored from the main
40709 ** transaction was first opened. In this case we can mark the page
40713 ** There is one exception to this rule. If the page is being rolled
40716 ** to mark the page as clean. This is because marking the page as
40717 ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
40719 ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
40731 /* If this was page 1, then restore the value of Pager.dbFileVers.
40737 /* Decode the page just read from disk */
40784 ** a couple of kilobytes or so - potentially larger than the page
40982 ** (2) 4 byte big-endian integer which is the number of valid page records
40984 ** number of page records from the journal size.
40991 ** (6) 4 byte big-endian integer which is the page size.
40994 ** + 4 byte page number.
41002 ** valid page entries in the journal. In most cases, you can compute the
41017 ** journal file then all pages up to the first corrupted page are rolled
41041 int needPagerReset; /* True to reset page prior to first page rollback */
41134 ** database file and/or page cache.
41223 ** Read the content for page pPg out of the database file and into
41227 ** If page 1 is read, then the value of Pager.dbFileVers[] is set to
41234 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
41235 Pgno pgno = pPg->pgno; /* Page number to read */
41237 int isInWal = 0; /* True if page is in log file */
41250 /* Try to pull the page from the write-ahead log. */
41266 ** zero or the size of the database in page. Bytes 32..35 and 35..39
41267 ** should be page numbers which are never 0xffffffff. So filling
41286 PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
41316 ** This function is invoked once for each page that has already been
41318 ** Parameter iPg is the page number of said page. The pCtx argument
41321 ** If page iPg is present in the cache, and has no outstanding references,
41323 ** references, the page content is reloaded from the database. If the
41369 ** + Discard the cached page (if refcount==0), or
41370 ** + Reload page content from the database (if refcount>0).
41390 ** The list of pages passed into this routine is always sorted by page number.
41391 ** Hence, if page 1 appears anywhere on the list, it will be the first page.
41407 /* Verify that the page list is in accending order */
41415 ** any pages with page numbers greater than nTruncate into the WAL file.
41481 ** in pages (assuming the page size currently stored in Pager.pageSize).
41502 ** of the database file is not an integer multiple of the page-size,
41503 page. Except, any file larger than 0
41504 ** bytes in size is considered to contain at least one page.
41604 ** Throughout the rollback process, each time a page is rolled back, the
41606 ** implementation below). This is used to ensure that a page is only
41614 ** (or transaction). No page with a page-number greater than this value
41654 ** There might be records in the main journal that have a page number
41699 /* Finally, rollback pages from the sub-journal. Page that were
41885 ** Change the page size used by the Pager object. The new page size
41894 ** * the new page size (value of *pPageSize) is valid (a power
41897 ** * there are no outstanding page references, and
41902 ** then the pager object page size is set to *pPageSize.
41904 ** If the page size is changed, then this function uses sqlite3PagerMalloc()
41906 ** fails, SQLITE_NOMEM is returned and the page size remains unchanged.
41909 ** If the page size is not changed, either because one of the enumerated
41912 ** then *pPageSize is set to the old, retained page size before returning.
41923 ** there is at least one outstanding page reference, this function
41965 ** Return a pointer to the "temporary page" buffer held internally
41967 ** entire content of a database page. This buffer is used internally
41977 ** Attempt to set the maximum database page count if mxPage is positive.
41979 ** maximum page count below the current size of the database.
41981 ** Regardless of mxPage, return the current maximum page count.
42055 ** However, if the file is between 1 and <page-size> bytes in size, then
42056 ** this is considered a 1 page file.
42100 ** following is true for all dirty pages currently in the page-cache:
42102 ** a) The page number is less than or equal to the size of the
42105 ** b) if the page content were written at this time, it would not
42110 ** dirty page were to be discarded from the cache via the pagerStress()
42111 ** routine, pagerStress() would not write the current page content to
42114 ** content of the page. However, since this content is not present in either
42172 ** Shutdown the page cache. Free all memory and close all files.
42176 ** and their memory is freed. Any attempt to use a page associated
42177 ** with this page cache after this function returns will likely
42239 ** Return the page number for page pPg.
42247 ** Increment the reference count for page pPg.
42285 ** page currently held in memory before returning SQLITE_OK. If an IO
42417 ** a page is skipped if it meets either of the following criteria:
42419 ** * The page number is greater than Pager.dbSize, or
42420 ** * The PGHDR_DONT_WRITE flag is set on the page.
42422 ** If writing out a page causes the database file to grow, Pager.dbFileSize
42423 ** is updated accordingly. If page 1 is written out, then the value cached
42461 /* If there are dirty pages in the page cache with page numbers greater
42466 ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
42479 /* Write out the page data. */
42482 /* If page 1 was just written, update Pager.dbFileVers to match
42484 ** page caused the database file to grow, update dbFileSize.
42496 PAGERTRACE(("STORE %d page %d hash(%08x)\n",
42502 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno));
42532 ** Append a record of the current state of page pPg to the sub-journal.
42567 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
42586 ** database). The second argument is a reference to a page that is
42587 ** currently dirty but has no outstanding references. The page
42595 ** If successful, sqlite3PcacheMakeClean() is called on the page and
42597 ** page clean, the IO error code is returned. If the page cannot be
42631 /* Write a single frame for this page to the log. */
42647 /* If the page number of this page is larger than the current size of
42655 ** <journal page X>
42656 ** <modify page X>
42659 ** pagerStress(page X)
42662 ** If (X>Y), then when pagerStress is called page X will not be written
42664 ** following the "ROLLBACK TO sp" statement, reading page X will read
42665 ** data from the database file. This will be the copy of page X as it
42669 ** The solution is to write the current data for page X into the
42680 /* Write the contents of the page out to the database file. */
42687 /* Mark the page as clean. */
42689 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
42710 ** along with each page reference. This space is available to the user
42731 int nExtra, /* Extra bytes append to each in-memory page */
42747 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
42876 ** choose a default page size in case we have to create the
42877 ** database file. The default page size is the maximum of:
42881 ** + The largest page size that can be written atomically.
42910 ** In this case we accept the default page size and delay actually
43149 ** the contents of the page cache and rolling back any open journal
43274 ** to be in ERROR state when there are zero outstanding page
43371 ** Acquire a reference to page number pgno in pager pPager (a page
43375 ** If the requested page is already in the cache, it is returned.
43376 ** Otherwise, a new page object is allocated and populated with data
43378 ** choose not to allocate a new page object and may reuse an existing
43381 ** The extra data appended to a page is always initialized to zeros the
43382 ** first time a page is loaded into memory. If the page requested is
43384 ** data is left as it was when the page object was last used.
43386 ** If the database image is smaller than the requested page or if a
43388 ** requested page is not already stored in the cache, then no
43390 ** page is initialized to all zeros.
43393 ** of the page. This occurs in two seperate scenarios:
43395 ** a) When reading a free-list leaf page from the database, and
43398 ** a new page into the cache to be filled with the data read
43405 ** savepoints are set. This means if the page is made writable at any
43413 ** to find a page in the in-memory cache first. If the page is not already
43422 Pgno pgno, /* Page number to fetch */
43423 DbPage **ppPage, /* Write a pointer to the page here */
43437 ** Otherwise, request the page from the PCache layer. */
43456 ** the page. Return without further ado. */
43462 /* The pager cache has created a new page. Its content needs to
43468 /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
43469 ** number greater than this, or the unused locking-page, is requested. */
43483 ** page that does not need to be journaled. Nevertheless, be sure
43523 ** Acquire a page if it is already in the in-memory cache. Do
43524 ** not read the page from disk. Return a pointer to the page,
43525 ** or 0 if the page is not in cache.
43529 ** in the page if the page is not already in cache. This routine
43530 ** returns NULL if the page is not in cache or if a disk I/O error
43544 ** Release a page reference.
43546 ** If the number of references to the page drop to zero, then the
43547 ** page is added to the LRU list. When all references to all pages
43711 ** file as well as into the page cache. Which would be incorrect in
43731 ** Mark a single data page as writeable. The page is written into the
43732 ** main journal or sub-journal as required. If the page is written into
43766 ** This is done before calling sqlite3PcacheMakeDirty() on the page.
43778 /* Mark the page as dirty. If the page has already been written
43787 ** EXCLUSIVE lock on the main database file. Write the current page to
43797 /* We should never write to the journal file the page that
43807 ** page in the block above, set the need-sync flag for the page.
43809 ** playback_one_page() will think that the page needs to be restored
43825 PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
43844 PAGERTRACE(("APPEND %d page %d needSync=%d\n",
43850 /* If the statement journal is open and the page is not in it,
43851 ** then write the current page to the statement journal. Note that
43869 ** Mark a data page as writeable. This routine must be called before
43870 ** making changes to a page. The caller must check the return value
43871 ** of this function and be careful not to change any page data unless
43895 Pgno pg1; /* First page of the sector pPg is located on. */
43898 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
43908 /* This trick assumes that both the page-size and sector-size are
43910 ** of the first page of the sector pPg is located on.
43974 ** Return TRUE if the page given in the argument was previously passed
43976 ** to change the content of the page.
43986 ** write the information on page pPg back to the disk, even though
43987 ** that page might be marked as dirty. This happens, for example, when
43988 ** the page has been added as a leaf of the freelist and so its
43992 ** on the given page is unused. The pager marks the page as clean so
44001 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
44015 ** To avoid excess churning of page 1, the update only happens once.
44020 ** sqlite3PagerWrite() on page 1, then modifying the contents of the
44021 ** page data. In this case the file will be updated when the current
44027 ** by writing an updated version of page 1 using a call to the
44057 PgHdr *pPgHdr; /* Reference to page 1 */
44061 /* Open page 1 of the file for writing. */
44065 /* If page one was fetched successfully, and this function is not
44066 ** operating in direct-mode, make page 1 writable. When not in
44067 ** direct mode, page 1 is always held in cache and hence the PagerGet()
44078 /* If running in direct mode, write the contents of page 1 to the file. */
44094 /* Release the page reference. */
44206 /* Must have at least one page for the WAL commit flag.
44227 ** blocks of size page-size, and
44229 ** * Exactly one page has been modified and store in the journal file.
44256 ** following call will modify the in-memory representation of page 1
44257 ** to include the updated change counter and then write page 1
44277 ** Before reading the pages with page numbers larger than the
44288 const Pgno iSkip = PAGER_MJ_PGNO(pPager); /* Pending lock page */
44293 PgHdr *pPage; /* Page to journal */
44316 ** Because the change-counter page was just modified, unless the
44510 ** Return the number of references to the specified page.
44768 ** Move the page pPg to location pgno in the file.
44770 ** There must be no references to the page previously located at
44771 ** pgno (which we call pPgOld) though that page is allowed to be
44772 ** in cache. If the page previously located at pgno is not already
44775 ** References to the page pPg remain valid. Updating any
44777 ** allocated along with the page) is the responsibility of the caller.
44781 ** has been removed (CREATE INDEX needs to move a page when a statement
44784 ** If the fourth argument, isCommit, is non-zero, then this page is being
44786 ** is being committed. In this case, it is guaranteed that the database page
44793 PgHdr *pPgOld; /* The page being overwritten. */
44796 Pgno origPgno; /* The original page number */
44805 ** the page we are moving from.
44812 /* If the page being moved is dirty and has not been saved by the latest
44813 ** savepoint, then save the current contents of the page into the
44817 ** <journal page X, then modify it in memory>
44819 ** <Move page X to location Y>
44822 ** If page X were not written to the sub-journal here, it would not
44837 PAGERTRACE(("MOVE %d page %d (needSync=%d) moves to %d\n",
44841 /* If the journal needs to be sync()ed before page pPg->pgno can
44845 ** the journal needs to be sync()ed before database page pPg->pgno
44854 /* If the cache contains a page with page-number pgno, remove it
44856 ** page pgno before the 'move' operation, it needs to be retained
44857 ** for the page moved there.
44866 ** need to rollback later. Just move the page out of the way. */
44877 /* For an in-memory database, make sure the original page continues
44879 ** as the original page since it has already been allocated.
44889 ** sync()ed before any data is written to database file page needSyncPgno.
44890 ** Currently, no such page exists in the page-cache and the
44892 ** loading the page into the pager-cache and setting the PGHDR_NEED_SYNC
44895 ** If the attempt to load the page into the page-cache fails, (due
44897 ** array. Otherwise, if the page is loaded and written again in
44921 ** Return a pointer to the data for the specified page.
44930 ** allocated along with the specified page.
45304 ** frames, return the size in bytes of the page images stored within the
45316 ** This function is called by the wal module when writing page content
45320 ** page content. If a malloc fails, this function may return NULL.
45353 ** Each frame records the revised content of a single page from the
45373 ** 8: Database page size. Example: 1024
45381 ** frame consists of a 24-byte frame-header followed by a <page-size> bytes
45382 ** of page data. The frame-header is six big-endian 32-bit unsigned
45385 ** 0: Page number.
45436 ** To read a page from the database (call it page number P), a reader
45437 ** first checks the WAL to see if it contains page P. If so, then the
45438 ** last valid instance of page P that is a followed by a commit frame
45440 ** contains no copies of page P that are valid and which are a commit
45441 ** frame or are followed by a commit frame, then page P is read from
45454 ** because frames for page P can appear anywhere within the WAL, the
45455 ** reader has to scan the entire WAL looking for page P frames. If the
45459 ** search for frames of a particular page.
45479 ** a page number P, return the index of the last frame for page P in the WAL,
45480 ** or return NULL if there are no frames for page P in the WAL.
45495 ** Each index block contains two sections, a page-mapping that contains the
45496 ** database page number associated with each wal frame, and a hash-table
45497 ** that allows readers to query an index block for a specific page number.
45498 ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
45499 ** for the first index block) 32-bit page numbers. The first entry in the
45500 ** first index-block contains the database page number corresponding to the
45506 ** complement of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE) page-numbers,
45508 ** allocated size of the page-mapping array - the page-mapping array merely
45511 ** Even without using the hash table, the last frame for page P
45512 ** can be found by scanning the page-mapping sections of each index block
45516 ** holding the content for that page.
45520 ** hash table for each page number in the mapping section, so the hash
45530 ** To look for page P in the hash table, first compute a hash iKey on
45543 ** no hash slot such that aHash[i]==p) then page P is not in the
45546 ** page P.
45549 ** first index block, looking for entries corresponding to page P. On
45551 ** examined in order to either find the last entry for page P, or to
45630 ** Or it can be 1 to represent a 65536-byte page. The latter case was
45639 u16 szPage; /* Database page size in bytes. 1==64K */
45732 ** assuming a database page size of szPage bytes. The offset returned
45752 u32 szPage; /* Database page size */
45785 ** Each page of the wal-index mapping contains a hash-table made up of
45792 ** all frames in the WAL in database page order. Where two or more frames
45793 ** correspond to the same database page, the iterator visits only the
45811 u32 *aPgno; /* Array of page numbers. */
45814 } aSegment[1]; /* One for every 32KB page in the wal-index */
45819 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
45830 ** The block of page numbers associated with the first hash-table in a
45832 ** hash-table on each aligned 32KB page of the wal-index.
45842 ** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
45847 ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
45868 /* Request a pointer to the required page from the VFS */
45993 ** 0: Page number.
46003 u32 iPage, /* Database page number for frame */
46005 u8 *aData, /* Pointer to page data */
46030 u32 *piPage, /* OUT: Database page number for frame */
46032 u8 *aData, /* Pointer to page data (for checksum) */
46037 u32 pgno; /* Page number of the frame */
46047 /* A frame is only valid if the page number is creater than zero.
46069 /* If we reach this point, the frame is valid. Return the page number
46142 ** Compute a hash on a page number. The resulting hash value must land
46156 ** Return pointers to the hash table and page number array stored on
46157 ** page iHash of the wal-index. The wal-index is broken into 32KB pages
46166 ** Finally, set *paPgno so that *paPgno[1] is the page number of the
46173 volatile u32 **paPgno, /* OUT: Pointer to page number array */
46202 ** Return the number of the wal-index page that contains the hash-table
46203 ** and page
46219 ** Return the page number associated with frame iFrame in this WAL.
46243 volatile u32 *aPgno = 0; /* Page number array for hash table */
46256 /* Obtain pointers to the hash-table and page-number array containing
46258 ** that the page said hash-table and array reside on is already mapped.
46300 ** Set an entry in the wal-index that will map database page number
46306 volatile u32 *aPgno = 0; /* Page number array */
46312 ** page number array and hash table entry.
46431 int szPage; /* Page size according to the log */
46442 /* If the database page size is not a power of two, or is greater than
46491 u32 pgno; /* Database page number for frame */
46658 ** Find the smallest page number out of all pages held in the WAL that
46661 ** that page was last written into the WAL. Write into *piPage the page
46664 page
46669 u32 *piPage, /* OUT: The page number of the next page */
46670 u32 *piFrame /* OUT: Wal frame index of next page */
46673 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
46950 ** Return the page-size in bytes used by the database.
46961 ** by active readers. This routine will never overwrite a database page
46996 int szPage; /* Database page-size */
46998 u32 iDbpage = 0; /* Next database page to write */
47001 u32 mxPage; /* Max database page to write */
47235 /* The first page of the wal-index must be mapped at this point. */
47293 /* Ensure that page 0 of the wal-index (the page that contains the
47303 /* If the first page of the wal-index has been mapped, try to read the
47388 ** access any database page that is modified by a WAL frame up to and
47420 ** paged out or take a page-fault that is time-consuming to resolve,
47458 ** must be zeroed before the requested page is returned.
47621 ** Read a page from the WAL, if it is present in the WAL and if the
47624 ** The *pInWal is set to 1 if the requested page is in the WAL and
47625 ** has been loaded. Or *pInWal is set to 0 if the page was not in
47630 Pgno pgno, /* Database page number to read data for */
47633 u8 *pOut /* Buffer to write page data to */
47636 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
47642 /* If the "last page" field of the wal-index header snapshot is 0, then
47653 /* Search the hash table or tables for an entry matching page number
47680 volatile u32 *aPgno; /* Pointer to array of page numbers */
47721 ** required page. Read and return data from the log file.
47838 /* This call cannot fail. Unless the page for which the page number
47841 ** (if (a) is false) or simply expels the page from the cache (if (b)
47845 ** are no outstanding references to any page other than page 1. And
47846 ** page 1 is never written to the log until the transaction is
47979 int szPage; /* Size of one page */
48017 PgHdr *pPage, /* The page of the frame to be written */
48032 /* Write the page data */
48043 int szPage, /* Database page-size in bytes */
48053 int nExtra = 0; /* Number of extra copies of last page */
48407 ** read-lock. This function returns the database page-size if it is known,
48457 ** The basic idea is that each page of the file contains N database
48464 ** All of the keys on the page that Ptr(0) points to have values less
48465 ** than Key(0). All of the keys on page Ptr(1) and its subpages have
48474 ** BTrees. Each BTree is identified by the index of its root page. The
48477 ** page. If the payload is larger than the preset amount then surplus
48480 ** page has a small header which contains the Ptr(N) pointer and other
48485 ** The file is divided into pages. The first page is called page 1,
48486 ** the second is page 2, and so forth. A page number of zero indicates
48487 ** "no such page". The page size can be any power of 2 between 512 and 65536.
48488 ** Each page can be either a btree page, a freelist page, an overflow
48489 ** page, or a pointer-map page.
48491 ** The first page is always a btree page. The first 100 bytes of the first
48492 ** page contain a special header (the "file header") that describes the file.
48497 ** 16 2 Page size in bytes.
48500 ** 20 1 Bytes of unused space at the end of each page
48506 ** 32 4 First freelist page
48512 ** 48 4 Size of page cache
48513 ** 52 4 Largest root-page (auto/incr_vacuum)
48528 ** space in a page that can be consumed by a single cell for standard
48531 ** on one page. Thus the default max embedded payload fraction is 64.
48534 ** payload is spilled to overflow pages. Once an overflow page is allocated,
48544 ** cell pointer array, and the cell content area. Page 1 also has a 100-byte
48545 ** file header that occurs before the page header.
48548 ** | file header | 100 bytes. Page 1 only.
48550 ** | page header | 8 bytes for leaves. 12 bytes for interior nodes
48563 ** The page headers looks like this:
48568 ** 3 2 number of cells on this page
48573 ** The flags define the format of this btree page. The leaf flag means that
48574 ** this page has no children. The zerodata flag means that this page carries
48579 ** The cell pointer array begins on the first byte after the page header.
48581 ** offsets from the beginning of the page to the cell content in the cell
48584 ** be easily added without having to defragment the page.
48586 ** Cell content is stored at the very end of the page and grows toward the
48587 ** beginning of the page.
48596 ** in the page header at offset 7.
48603 ** the end of the page. Pointers to the cells are in the cell pointer array
48604 ** that immediately follows the page header. Cells is not necessarily
48629 ** 4 Page number of the left child. Omitted if leaf flag is set.
48633 ** 4 First page of the overflow chain. Omitted if no overflow
48635 ** Overflow pages form a linked list. Each page except the last is completely
48636 ** filled with data (pagesize - 4 bytes). The last page can have as little
48640 ** 4 Page number of next overflow page
48644 ** file header points to the first in a linked list of trunk page. Each trunk
48645 ** page points to multiple leaf pages. The content of a leaf page is
48646 ** unspecified. A trunk page looks like this:
48649 ** 4 Page number of next trunk page
48650 ** 4 Number of leaf pointers on this page
48655 /* The following value is the maximum cell size assuming a maximum page
48660 /* The maximum number of cells on a single page of the database. This
48662 ** plus 2 bytes for the index to the cell in the page header). Such
48688 ** Page type flags. An ORed combination of these flags appear as the
48689 ** first byte of on-disk image of every BTree page.
48697 ** As each page of the file is loaded into memory, an instance of the following
48699 ** information about the page that is decoded from the raw file page.
48701 ** The pParent field points back to the parent page. This allows us to
48703 ** unref() the parent page pointer when this page is no longer referenced.
48714 u8 hasData; /* True if this page stores data */
48715 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
48721 u16 nFree; /* Number of free bytes on the page */
48722 u16 nCell; /* Number of cells on this page, local and ovfl */
48723 u16 maskPage; /* Mask for page offset */
48727 BtShared *pBt; /* Pointer to BtShared that this page is part of */
48728 u8 *aData; /* Pointer to disk image of the page data */
48731 DbPage *pDbPage; /* Pager page handle */
48732 Pgno pgno; /* Page number for this page */
48736 ** The in-memory image of a disk page has the auxiliary information appended
48745 ** is opened on the table with root page BtShared.iTable. Locks are removed
48751 Pgno iTable; /* Root page of table */
48792 BtLock lock; /* Object used to lock page 1 */
48843 Pager *pPager; /* The page cache */
48846 MemPage *pPage1; /* First page of the database */
48859 u32 pageSize; /* Total number of bytes on a page */
48860 u32 usableSize; /* Number of usable bytes on each page */
48880 #define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
48890 ** based on information extract from the raw disk page.
48900 u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
48901 u16 nSize; /* Size of the cell content on the main b-tree page */
48935 Pgno *aOverflow; /* Cache of overflow page locations */
48937 Pgno pgnoRoot; /* The root page of this tree */
48950 i16 iPage; /* Index of current page in apPage */
48952 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
48986 ** The database page the PENDING_BYTE occupies. This page is never used.
48992 ** database page. The first argument to each is the number of usable
48993 ** bytes on each page of the database (often 1024). The second is the
48994 ** page number to look up in the pointer map.
48996 ** PTRMAP_PAGENO returns the database page number of the pointer-map
48997 ** page that stores the required pointer. PTRMAP_PTROFFSET returns
49000 ** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
49002 ** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
49010 ** The pointer map is a lookup table that identifies the parent page for
49011 ** each child page in the database file. The parent page is the page that
49012 ** contains a pointer to the child. Every page in the database contains
49013 ** 0 or 1 parent pages. (In this context 'database page' refers
49014 ** to any page that is not part of the pointer map itself.) Each pointer map
49015 ** entry consists of a single byte 'type' and a 4 byte parent page number.
49019 ** position in the file to another as part of autovacuum. When a page
49021 ** new location. The pointer map is used to locate the parent page quickly.
49023 ** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
49026 ** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
49029 ** PTRMAP_OVERFLOW1: The database page is the first page in a list of
49030 ** overflow pages. The page number identifies the page that
49031 ** contains the cell with a pointer to this overflow page.
49033 ** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
49034 ** overflow pages. The page-number identifies the previous
49035 ** page in the overflow page list.
49037 ** PTRMAP_BTREE: The database page is a non-root btree page. The page number
49038 ** identifies the parent page in the btree.
49076 int *anRef; /* Number of times each page is referenced */
49404 ** from the header of a btree page. If the page size is 65536 and the page
49467 ** table with root page iRoot. Return 1 if it does and 0 if not.
49469 ** For example, when writing to a table with root-page iRoot via
49475 ** caller should have first obtained a lock specifying the root page of
49481 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
49482 ** hold a write-lock on the schema table (root page 1). This is also
49487 Pgno iRoot, /* Root page of b-tree */
49514 /* Figure out the root-page that the lock should be held on. For table
49515 ** b-trees, this is just the root page of the b-tree being read or
49516 ** written. For index b-trees, it is the root page of the associated
49530 /* Search for the required lock. Either a write-lock on root-page iTab, a
49562 ** rooted at page iRoot, one should call:
49582 ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
49642 ** Add a lock on the table with root-page iTable to the shared-btree used
49797 ** Invalidate the overflow page-list cache for cursor pCur, if any.
49806 ** Invalidate the overflow page-list cache for all cursors opened
49824 ** cursors open on any row within the table with root-page pgnoRoot.
49854 ** when a page that previously contained data becomes a free-list leaf
49855 ** page.
49861 ** 1) When all data is deleted from a page and the page becomes
49862 ** a free-list leaf page, the page is not written to the database
49864 ** such a page is not even journalled (as it will not be modified,
49867 ** 2) When a free-list leaf page is reused, its content is not read
49873 ** a page is moved to the free-list and then reused within the same
49874 ** transaction, a problem comes up. If the page is not journalled when
49880 ** The solution is the BtShared.pHasContent bitvec. Whenever a page is
49881 ** moved to become a free-list leaf page, the corresponding bit is
49882 ** set in the bitvec. Whenever a leaf page is extracted from the free-list,
49905 ** This function is called when a free-list leaf page is removed from the
49907 ** page from the pager layer with the 'no-content' flag set. True otherwise.
49977 ** the table with root-page iRoot. Usually, this is called just before cursor
50095 ** Given a page number of a regular database page, return the page
50096 ** number for the pointer-map page that contains the entry for the
50097 ** input page number.
50099 ** Return 0 (not a valid page) for pgno==1 since there is
50100 ** no pointer map associated with page 1. The integrity_check logic
50120 ** This routine updates the pointer map entry for page number 'key'
50121 ** so that it maps to type 'eType' and parent page number 'pgno'.
50128 DbPage *pDbPage; /* The pointer map page */
50130 Pgno iPtrmap; /* The pointer map page number */
50131 int offset; /* Offset in pointer map page */
50137 /* The master-journal page number must never be used as a pointer map page */
50175 ** This routine retrieves the pointer map entry for page 'key', writing
50176 ** the type and parent page number to *pEType and *pPgno respectively.
50180 DbPage *pDbPage; /* The pointer map page */
50181 int iPtrmap; /* Pointer map page index */
50182 u8 *pPtrmap; /* Pointer map page data */
50217 ** Given a btree page and a cell index (0 means the first cell on
50218 ** the page, 1 means the second cell, and so forth) return a pointer
50258 MemPage *pPage, /* Page containing the cell */
50290 ** on the local page. No overflow is required.
50296 /* If the payload will not fit completely on the local page, we have
50326 MemPage *pPage, /* Page containing the cell */
50335 ** data area of the btree-page. The return number includes the cell
50336 ** data header and the local payload, but not any overflow page or
50402 ** If the cell pCell, part of page pPage contains a pointer
50403 ** to an overflow page, insert an entry into the pointer-map
50404 ** for the overflow page.
50421 ** Defragment the page given. All Cells are moved to the
50422 ** end of the page and all free space is collected into one
50429 int hdr; /* Offset to the page header */
50431 int usableSize; /* Number of usable bytes on a page */
50434 int nCell; /* Number of cells on the page */
50435 unsigned char *data; /* The page data */
50504 ** Allocate nByte bytes of space from within the B-Tree page passed
50523 int usableSize; /* Usable size of the page */
50566 ** fragmented bytes within the page. */
50597 ** is no way that the allocation can extend off the end of the page.
50637 ** cell content area exceeds the value in the page header. If these
50697 ** Decode the flags byte (the first byte of the header) for a page
50737 ** Return SQLITE_OK on success. If we see that the page does
50738 ** not contain a well-formed database page, then return
50740 ** guarantee that the page is well-formed. It only shows that
50753 u8 hdr; /* Offset to beginning of page header */
50756 int usableSize; /* Amount of usable space on each page */
50757 u16 cellOffset; /* Offset from start of page to first cell pointer */
50758 int nFree; /* Number of unused bytes on the page */
50778 /* To many cells for a single page. The page must be corrupt */
50783 /* A malformed database page might cause us to read past the end
50784 ** of page when parsing a cell.
50787 ** past the end of a page boundary and causes SQLITE_CORRUPT to be
50815 /* Compute the total free space on the page */
50821 /* Start of free block is off the page */
50828 ** the free-block must lie on the database page. */
50838 ** of the page, then the page must be corrupted. This check also
50840 ** area, according to the page header, lies within the page.
50852 ** Set up a raw page so that it looks like a database page holding
50903 ** Get a page from the pager. Initialize the MemPage.pBt and
50907 ** the content of the page at this time. So do not go to the disk
50909 ** If in the future we call sqlite3PagerWrite() on this page, that
50915 Pgno pgno, /* Number of the page to fetch */
50916 MemPage **ppPage, /* Return the page in this parameter */
50917 int noContent /* Do not load page content if true */
50930 ** Retrieve a page from the pager cache. If the requested page is not
50958 ** Get a page from the pager and initialize it. This routine is just a
50967 Pgno pgno, /* Number of the page to get */
50968 MemPage **ppPage /* Write the page pointer here */
51008 ** the transaction, for each page restored this routine is called.
51011 ** page to agree with the restored data.
51021 /* pPage might not be a btree page; it might be an overflow page
51022 ** or ptrmap page or a free page. In those cases, the following
51025 ** btreeInitPage() be called on every btree page so we make
51026 ** the call for every page that comes in for re-initing. */
51075 u8 nReserve; /* Byte of unused space on each page */
51508 ** Change the default pages size and the number of reserved bytes per page.
51509 ** Or, if the page size has already been fixed, return SQLITE_READONLY
51512 ** The page size must be a power of 2 between 512 and 65536. If the page
51513 ** size supplied does not meet this constraint then the page size is not
51516 ** Page sizes are constrained to be a power of two so that the region
51519 ** at the beginning of a page.
51522 ** bytes per page is left unchanged.
51524 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
51555 ** Return the currently defined page size
51563 ** Return the number of bytes of space at the end of every page that
51576 ** Set the maximum page count for a database if mxPage is positive.
51578 ** Regardless of the value of mxPage, return the maximum page count.
51665 MemPage *pPage1; /* Page 1 of the database file */
51713 ** required as the version of page 1 currently in the page1 buffer
51748 /* After reading the first page of the database assuming a page size
51749 ** of BtShared.pageSize, we have discovered that the page-size is
51752 ** again with the correct page-size.
51779 ** cells can will fit on one page. We assume a 10-byte page header.
51785 ** 4-byte overflow page pointer
51788 ** page pointer.
51813 ** this routine unrefs the first page of the database file which
51832 ** into a new empty database by initializing the first page of
51957 ** page 1. So if some other shared-cache client already has a write-lock
51958 ** on page 1, the transaction cannot be opened. */
51968 ** reading page 1 it discovers that the page-size of the database
51970 ** pBt->pageSize to the page-size of the file on disk.
52019 ** re-read the database size from page 1 if a savepoint or transaction
52049 ** Set the pointer-map entries for all children of page pPage. Also, if
52055 int nCell; /* Number of cells in page pPage */
52090 ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
52094 ** PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child
52095 ** page of pPage.
52097 ** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow
52098 ** page pointed to by one of the cells on pPage.
52100 ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
52101 ** overflow page in the list.
52107 /* The pointer is always the first 4 bytes of the page in this case. */
52155 ** Move the open database page pDbPage to location iFreePage in the
52159 ** the journal needs to be sync()ed before database page pDbPage->pgno
52161 ** page.
52165 MemPage *pDbPage, /* Open page to move */
52167 Pgno iPtrPage, /* Pointer map 'page-no' entry for pDbPage */
52171 MemPage *pPtrPage; /* The page that contains a pointer to pDbPage */
52181 /* Move page iDbPage from its current location to page number iFreePage */
52182 TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n",
52190 /* If pDbPage was a btree-page, then it may have child pages and/or cells
52194 ** If pDbPage is an overflow page, then the first 4 bytes may store a
52195 ** pointer to a subsequent overflow page. If this is the case, then
52196 ** the pointer map needs to be updated for the subsequent overflow page.
52213 /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
52245 ** database so that the last page of the file currently in use
52283 /* Remove the page from the files free-list. This is not required
52298 Pgno iFreePg; /* Index of free page to move pLastPg to */
52306 /* If nFin is zero, this loop runs exactly once and page pLastPg
52307 ** is swapped with the first free page pulled off the free list.
52310 ** looping until a free-page located within the first nFin pages
52407 Pgno iFree; /* The next page to be freed */
52408 int nEntry; /* Number of entries on one ptrmap page */
52413 /* It is not possible to create a database for which the final page
52414 ** is either a pointer-map page or the pending-byte page. If one
52696 ** call btreeGetPage() on page 1 again to make
52790 ** Create a new cursor for the BTree whose root is on the page
52814 ** No checking is done to make sure that page iTable really is the
52815 ** root page of a b-tree. If it is not, then the cursor acquired
52823 int iTable, /* Root page of table to open */
52872 int iTable, /* Root page of table to open */
52910 ** as pCur and having the same root page number as pCur. The value is
53073 ** Given the page number of an overflow page in the database (parameter
53074 ** ovfl), this function finds the page number of the next page in the
53076 ** pointer-map data instead of reading the content of page ovfl to do so.
53080 ** The page number of the next overflow page in the linked list is
53081 ** written to *pPgnoNext. If pagepage in its linked
53085 ** to page number pOvfl was obtained, then *ppPage is set to point to that
53093 Pgno ovfl, /* Current overflow page number */
53095 Pgno *pPgnoNext /* OUT: Next overflow page number */
53105 /* Try to find the next page in the overflow list using the
53106 ** autovacuum pointer-map pages. Guess that the next page in
53107 ** the overflow list is page number (ovfl+1). If that guess turns
53108 ** out to be wrong, fall back to loading the data of page
53109 ** number ovfl to determine the next page number.
53149 ** Copy data from a buffer to a page, or from a page to a buffer.
53151 ** pPayload is a pointer to data stored on database page pDbPage.
53160 void *pPayload, /* Pointer to page data */
53163 int eOp, /* 0 -> copy from page, 1 -> copy to page */
53164 DbPage *pDbPage /* Page containing pPayload */
53167 /* Copy data from buffer to page (a write operation) */
53174 /* Copy data from page to buffer (a read operation) */
53190 ** The content being read or written might appear on the main page
53195 ** allocates space for and lazily popluates the overflow page-list
53199 ** Once an overflow page-list cache has been allocated, it may be
53202 ** mode, the following events may invalidate an overflow page-list cache.
53206 ** * Creating a table (may require moving an overflow page).
53219 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
53238 /* Check if data must be read/written to/from the btree page itself. */
53253 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
53261 ** one entry for each overflow page in the overflow chain. The
53262 ** page number of the first overflow page is stored in aOverflow[0],
53276 /* If the overflow page-list cache has been allocated and the
53277 ** entry for the first required overflow page is valid, skip
53290 /* If required, populate the overflow page-list cache. */
53298 /* The only reason to read this page is to obtain the page
53299 ** number for the next page in the overflow chain. The page
53301 ** page-list cache, if any, then fall back to the getOverflowPage()
53312 /* Need to read this page properly. It contains some of the
53327 ** 2) data is required from the start of this overflow page, and
53333 ** output buffer, bypassing the page-cache altogether. This speeds
53432 ** and data to fit on the local page and for there to be no overflow
53439 ** page of the database. The data might change or move the next time
53483 ** b-tree page. Write the number of available bytes into *pAmt.
53515 ** Move the cursor down to a new child page. The newPgno argument is the
53516 ** page number of the child page to move to.
53518 ** This function returns SQLITE_CORRUPT if the page-header flags field of
53519 ** the new child page does not match the flags field of the parent (i.e.
53520 ** if an intkey page appears to be the parent of a non-intkey page, or
53551 ** Page pParent is an internal (non-leaf) tree page. This function
53552 ** asserts that page number iChild is the left-child if the iIdx'th
53553 ** cell in page pParent. Or, if iIdx is equal to the total number of
53554 ** cells in pParent, that page number iChild is the right-child of
53555 ** the page.
53570 ** Move the cursor up to the parent page.
53573 ** to the page we are coming from. If we are coming from the
53574 ** right-most child page then pCur->idx is set to one more than
53585 ** one cursor has modified page pParent while a reference to it is held
53586 ** by a second cursor. Which can only happen if a single page is linked
53604 ** Move the cursor to point to the root page of its b-tree structure.
53606 ** If the table has a virtual root page, then the cursor is moved to point
53607 ** to the virtual root page instead of the actual root page. A table has a
53608 ** virtual root page when the actual root page contains no cells and a
53609 ** single child page. This can only happen with the table rooted at page 1.
53613 ** cell located on the root (or virtual root) page and the cursor state
53617 ** page-header flags indicate that the [virtual] root-page is the expected
53618 ** kind of b-tree page (i.e. if when opening the cursor the caller did not
53669 /* Assert that the root page is of the correct type. This must be the
53670 ** case as the call to this function that loaded the root-page (either
53674 ** to the page. */
53720 ** page to which it is currently pointing. Notice the difference
53723 ** finds the right-most entry beneath the *page*.
53819 ** left pointing at a leaf page which would hold the entry if it
53887 /* pPage->nCell must be greater than zero. If this is the root-page
53889 ** not run. If this is not the root-page, then the moveToChild() routine
53891 ** be the right kind (index or table) of b-tree page. Otherwise
53926 /* The maximum supported page-size is 65536 bytes. This means that
53928 ** page is less than 16384 bytes and may be stored as a 2-byte
53931 ** stored entirely within the b-tree page by inspecting the first
53940 ** b-tree page. */
53948 ** fits entirely on the main b-tree page. */
54069 ** the page while cursor pCur is holding a reference to it. Which can
54071 ** page into more than one b-tree structure. */
54171 ** Allocate a new page from the database file.
54173 ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
54174 ** has already been called on the new page.) The new page has also
54176 ** sqlite3PagerUnref() on the new page when it is done.
54183 ** locate a page close to the page number "nearby". This can be used in an
54187 ** If the "exact" parameter is not 0, and the page-number nearby exists
54220 ** shows that the page 'nearby' is somewhere on the free-list, then
54221 ** the entire-list will be searched for that page.
54238 ** first free-list trunk page. iPrevTrunk is initially 1.
54245 ** is not true. Otherwise, it runs once for each trunk-page on the
54246 ** free-list until the page 'nearby' is located.
54268 k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
54271 ** So extract the trunk page itself and use it as the newly
54272 ** allocated page */
54289 /* The list is being searched and this trunk page is the page
54310 /* The trunk page is required by the caller but it contains
54312 ** page in this case.
54403 /* There are no pages on the freelist, so create a new page at the
54412 /* If *pPgno refers to a pointer-map page, allocate two new pages
54413 ** at the end of the file instead of one. The first allocated page
54414 ** becomes a new pointer-map page, the second is used by the caller.
54417 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
54461 ** This function is used to add page iPage to the database file free-list.
54462 ** It is assumed that the page is not already a part of the free-list.
54466 ** corresponding to page iPage handy, it may pass it as the second value.
54473 MemPage *pTrunk = 0; /* Free-list trunk page */
54474 Pgno iTrunk = 0; /* Page number of free-list trunk page */
54475 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
54476 MemPage *pPage; /* Page being freed. May be NULL. */
54491 /* Increment the free page count on pPage1 */
54510 ** to indicate that the page is free.
54519 ** trunk page in the free-list is full, then this page will become a
54520 ** new free-list trunk page. Otherwise, it will become a leaf of the
54521 ** first trunk page in the current free-list. This block tests if it
54522 ** is possible to add the page as a new free-list leaf.
54525 u32 nLeaf; /* Initial number of leaf cells on trunk page */
54540 /* In this case there is room on the trunk page to insert the page
54543 ** Note that the trunk page is not really full until it contains
54563 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
54569 ** the page being freed as a leaf page of the first trunk in the free-list.
54571 ** first trunk in the free-list is full. Either way, the page being freed
54572 ** will become the new first trunk page in the free-list.
54584 TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, iTrunk));
54617 return SQLITE_CORRUPT; /* Cell extends past end of page */
54628 /* 0 is not a legal page number and page 1 cannot be an
54629 ** overflow page. Therefore if ovflPgno<2 or past the end of the
54642 ** to an overflow page belonging to a cell that is being deleted/updated.
54643 ** So if there exists more than one reference to this page, then it
54644 ** must not really be an overflow page and the database must be corrupt.
54646 ** freePage2() may zero the page contents if secure-delete mode is
54647 ** enabled. If this 'overflow' page happens to be a page that the
54666 ** Create the byte sequence used to represent a cell on page pPage
54678 MemPage *pPage, /* The page that contains the cell */
54743 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
54755 ** overflow page is being allocated, add an entry to the pointer-map
54756 ** for that page now.
54758 ** If this is the first overflow page, then write a partial entry
54841 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
54879 ** If the cell content will fit on the page, then put it there. If it
54893 MemPage *pPage, /* Page into which we are copying */
54894 int i, /* New cell becomes the i-th cell of the page */
54906 u8 *data; /* The content of the whole page */
54920 ** malformed cell from a leaf page to an interior page, if the cell size
54971 /* The cell may contain a pointer to an overflow page. If so, write
54972 ** the entry for the overflow page into the pointer map.
54981 ** Add a list of cells to a page. The page should be initially empty.
54982 ** The cells are guaranteed to fit on the page.
54985 MemPage *pPage, /* The page to be assemblied */
54986 int nCell, /* The number of cells to add to this page */
54995 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
55003 /* Check that the page has just been zeroed by zeroPage() */
55025 ** of the page that participate in the balancing operation. NB is the
55026 ** total number of pages that participate, including the target page and
55046 ** a new page to the right-hand side and put the one new entry in
55047 ** that page. This leaves the right side of the tree somewhat
55049 ** at the end soon afterwards so the nearly empty page will quickly
55052 ** pPage is the leaf page which is the right-most page in the tree.
55054 ** which is also the right-most entry on the page.
55058 ** byte page number followed by a variable length integer. In other
55064 MemPage *pNew; /* Newly allocated page */
55066 Pgno pgnoNew; /* Page number of pNew */
55075 /* Allocate a new page. This page will become the right-sibling of
55076 ** pPage. Make the parent page writable, so that the new divider cell
55094 ** with entries for the new page, and any pointer from the
55095 ** cell on the page to an overflow page. If either of these
55097 ** of the parent page are still manipulated by thh code below.
55098 ** That is Ok, at this point the parent page is guaranteed to
55100 ** rollback, undoing any changes made to the parent page.
55110 ** consists of a 4-byte page number (the page number of pPage) and
55132 /* Set the right-child pointer of pParent to point to the new page. */
55135 /* Release the reference to the new page. */
55187 ** on page pFrom to page pTo. If page pFrom was not a leaf page, then
55188 ** the pointer-map entries for each child page are updated so that the
55189 ** parent page stored in the pointer map is page pTo. If pFrom contained
55190 ** any cells with overflow page pointers, then the corresponding pointer
55191 ** map entries are also updated so that the parent page is page pTo.
55196 ** Before returning, page pTo is reinitialized using btreeInitPage().
55217 /* Copy the b-tree node content from page pFrom to page pTo. */
55222 /* Reinitialize page pTo so that the contents of the MemPage structure
55225 ** page pFrom.
55245 ** (hereafter "the page") and up to 2 siblings so that all pages have about the
55247 ** page are used in the balancing, though both siblings might come from one
55248 ** side if the page is the first or last child of its parent. If the page
55249 ** has fewer than 2 siblings (something which can only happen if the page
55250 ** is a root page or a child of a root page) then all available siblings
55253 ** The number of siblings of the page might be increased or decreased by
55256 ** Note that when this routine is called, some of the cells on the page
55258 ** if the page is overfull. This routine ensures that all cells allocated
55259 ** to the page and its siblings fit into MemPage.aData[] before returning.
55261 ** In the course of balancing the page and its siblings, cells may be
55262 ** inserted into or removed from the parent page (pParent). Doing so
55263 ** may cause the parent page to become overfull or underfull. If this
55272 ** buffer big enough to hold one page. If while inserting cells into the parent
55273 ** page (pParent) the parent page becomes overfull, this buffer is
55275 ** a maximum of four divider cells into the parent page, and the maximum
55277 ** of the page-size, the aOvflSpace[] buffer is guaranteed to be large
55284 MemPage *pParent, /* Parent page of siblings being balanced */
55285 int iParentIdx, /* Index of "the page" in pParent */
55286 u8 *aOvflSpace, /* page-size bytes of space for parent ovfl */
55287 int isRoot /* True if pParent is a root-page */
55301 int subtotal; /* Subtotal of bytes in cells on one page */
55310 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
55311 int szNew[NB+2]; /* Combined size of cells place on i-th page */
55315 Pgno pgno; /* Temp var to store a page number in */
55322 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
55343 ** This loop also drops the divider cells from the parent page. This
55345 ** overflow cells in the parent page, since if any existed they will
55388 /* Drop the cell from the parent page. apDiv[i] still points to
55429 + k*nOld; /* Page copies (apCopy) */
55504 /* The right pointer of the child page pOld becomes the left
55521 ** size of all cells on the i-th page and cntNew[] which is the index
55522 ** in apCell[] of the cell that divides page i from page i+1.
55528 ** szNew[i]: Spaced used on the i-th sibling page.
55530 ** the right of the i-th sibling page.
55583 ** a virtual root page. A virtual root page is when the real root
55584 ** page is page 1 and we are the only child of that page.
55623 /* Set the pointer-map entry for the new sibling page. */
55689 /* Assemble the new sibling page. */
55699 /* If the sibling page assembled above was not the right-most sibling,
55700 ** insert a divider cell into the parent page.
55718 ** the sibling-page assembled above only.
55764 /* The root page of the b-tree now contains no cells. The only sibling
55765 ** page is the right-child of the parent. Copy the contents of the
55766 ** child page into the parent, decreasing the overall height of the
55774 ** The second assert below verifies that the child page is defragmented
55776 ** is important if the parent page happens to be page 1 of the database
55797 ** page in any overflow chains used by new divider cells. These
55821 j = 0; /* Current 'old' sibling page */
55822 k = 0; /* Current 'new' sibling page */
55827 ** sibling page j. If the siblings are not leaf pages of an
55851 ** sibling page k. If the siblings are not leaf pages of an
55861 ** page before the balancing, then the pointer map entries associated
55911 ** This function is called when the root page of a b-tree structure is
55914 ** A new child page is allocated and the contents of the current root
55915 ** page, including overflow cells, are copied into the child. The root
55916 ** page is then overwritten to make it an empty page with the right-child
55917 ** pointer pointing to the new page.
55920 ** that the new child-page now contains pointers to are updated. The
55922 ** page is also updated.
55925 ** page and SQLITE_OK is returned. In this case the caller is required
55931 MemPage *pChild = 0; /* Pointer to a new child page */
55932 Pgno pgnoChild = 0; /* Page number of the new child page */
55938 /* Make pRoot, the root page of the b-tree, writable. Allocate a new
55939 ** page that will become the new right-child of pPage. Copy the contents
55940 ** of the node stored on pRoot into the new child page.
55977 ** The page that pCur currently points to has just been modified in
56001 /* The root page of the b-tree is overfull. In this case call the
56002 ** balance_deeper() function to create a new child for the root-page
56003 ** and copy the current contents of the root-page to it. The
56004 ** next iteration of the do-loop will balance the child page.
56054 ** will balance the parent page to correct this.
56056 ** If the parent page becomes overfull, the overflow cell or cells
56061 ** different page). Once this subsequent call to balance_nonroot()
56064 ** copied either into the body of a database page or into the new
56086 /* The next iteration of the do-loop balances the parent page. */
56186 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
56228 ** back to the root page as balance() used to invalidate the contents
56268 MemPage *pPage; /* Page to delete cell from */
56297 /* If the page containing the entry to delete is not a leaf page, move
56302 ** sub-tree headed by the child page of the cell being deleted. This makes
56311 ** making any modifications. Make the page containing the entry to be
56313 ** entry and finally remove the cell itself from within the page.
56323 /* If the cell deleted was not located on a leaf page, then the cursor
56325 ** by the child-page of the cell that was just deleted from an internal
56347 /* Balance the tree. If the entry deleted was located on a leaf page,
56348 ** then the cursor still points to that page. In this case the first
56352 ** Otherwise, if the entry deleted was on an internal node page, then
56353 ** pCur is pointing to the leaf page from which a cell was removed to
56377 ** Create a new BTree table. Write into *piTable the page
56378 ** number for the root page of the new table.
56392 int ptfFlags; /* Page-type flage for the root page of new table */
56405 Pgno pgnoMove; /* Move a page here to make room for the root-page */
56406 MemPage *pPageMove; /* The page to move to. */
56409 ** to make room for the new tables root page. In case this page turns
56410 ** out to be an overflow page, delete all overflow page-map caches
56416 ** root page of the new table should go. meta[3] is the largest root-page
56417 ** created so far, so the new root-page is (meta[3]+1).
56422 /* The new root-page may not be allocated on a pointer-map page, or the
56423 ** PENDING_BYTE page.
56431 /* Allocate a page. The page that currently resides at pgnoRoot will
56432 ** be moved to the allocated page (unless the allocated page happens
56441 /* pgnoRoot is the page that will be used for the root-page of
56444 ** by extending the file), the current page at position pgnoMove
56452 /* Move the page currently at pgnoRoot to pgnoMove. */
56470 /* Obtain the page at pgnoRoot */
56487 /* Update the pointer-map and meta-data with the new root-page number. */
56494 /* When the new root page was allocated, page 1 was made writable in
56531 ** Erase the given database page and all its children. Return
56532 ** the page to the freelist.
56536 Pgno pgno, /* Page number to clear */
56537 int freePageFlag, /* Deallocate page if true */
56581 ** the page number of the root of the table. After this routine returns,
56582 ** the root page is empty, but still exists.
56614 ** page 1) is never added to the freelist.
56619 ** If AUTOVACUUM is enabled and the page at iTable is not the last
56620 ** root page in the database file, then the last root page
56622 ** iTable and that last slot formerly occupied by the last root page
56626 ** page number that used to be the last root page in the file before
56627 ** the move. If no page gets moved, *piMoved is set to 0.
56628 ** The last root page is recorded in meta[3] and the value of
56641 ** need to move another root-page to fill a gap left by the deleted
56642 ** root page. If an open cursor was using this page a problem would
56672 /* If the table being dropped is the table with the largest root-page
56673 ** number in the database, put the root page on the free list.
56681 /* The table being dropped does not have the largest root-page
56682 ** number in the database. So move the page that does into the
56683 ** gap left by the deleted root-page.
56706 /* Set the new 'max-root-page' value in the database header. This
56708 ** be a root-page number, less one again if that is the
56725 /* If sqlite3BtreeDropTable was called on page 1.
56826 ** page in the B-Tree structure (not including overflow pages).
56830 MemPage *pPage; /* Current page of the b-tree */
56832 /* If this is a leaf page or the tree is not an int-key tree, then
56833 ** this page contains countable entries. Increment the entry counter
56843 ** the next page in the tree that has not yet been visited. The
56845 ** of the page, or to the number of cells in the page if the next page
56920 ** Add 1 to the reference count for page iPage. If this is the second
56921 ** reference to the page, add an error message to pCheck->zErrMsg.
56922 ** Return 1 if there are 2 ore more references to the page and 0 if
56923 ** if this is the first reference to the page.
56925 ** Also check that the page number is in bounds.
56930 checkAppendMsg(pCheck, zContext, "invalid page number %d", iPage);
56934 checkAppendMsg(pCheck, zContext, "2nd reference to page %d", iPage);
56942 ** Check that the entry in the pointer-map for page iChild maps to
56943 ** page iParent, pointer type ptrType. If not, append an error message
56948 Pgno iChild, /* Child page number */
56950 Pgno iParent, /* Expected pointer map parent page number */
56973 ** Check the integrity of the freelist or of an overflow page list.
56978 int isFreeList, /* True for a freelist. False for overflow page list */
56979 int iPage, /* Page number for first page in the list */
56997 checkAppendMsg(pCheck, zContext, "failed to get page %d", iPage);
57010 "freelist leaf count too big on page %d", iPage);
57028 ** page in this overflow list, check that the pointer-map entry for
57029 ** the following page matches iPage.
57045 ** Do various sanity checks on a single page of a tree. Return
57052 ** but combine to completely cover the page.
57059 ** 8. Make sure this page is at least 33% full or else it is
57064 int iPage, /* Page number of the page to check */
57081 sqlite3_snprintf(sizeof(zContext), zContext, "Page %d: ", iPage);
57083 /* Check that the page exists
57091 "unable to get the page. error code=%d", rc);
57117 "On tree page %d cell %d: ", iPage, i);
57146 /* Check sanity of left child page.
57157 checkAppendMsg(pCheck, zContext, "Child page depth differs");
57166 "On page %d at right child: ", iPage);
57179 /* if we are a left child page */
57181 /* if we are the left most child page */
57201 /* else if we're a right child page */
57211 /* Check for complete coverage of the page
57234 "Corruption detected in cell %d on page %d",i,iPage);
57256 "Multiple uses for byte %d of page %d", i, iPage);
57262 "Fragmentation of %d bytes reported as %d on page %d",
57275 ** an array of pages numbers were each page number is the root page of
57344 /* Make sure every page in the file is referenced
57349 checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
57357 checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
57361 checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
57372 "Outstanding page count goes from %d to %d during this analysis",
57513 ** Obtain a lock on the table whose root page is iTab. The
57586 ** This function sets a flag only. The actual page location cache
57667 Pgno iNext; /* Page number of the next source page to copy */
57696 ** the page cache associated with the source database. The mutex
57755 ** Attempt to set the page size of the destination to match the page size
57847 ** page iSrcPg from the source database. Copy this data into the
57870 ** page sizes of the source and destination differ.
57877 /* Backup is not possible if the page size of the destination is changing
57896 /* This loop runs once for each destination page spanned by the source
57897 ** page. For each iteration, variable iOff is set to the byte offset
57898 ** of the destination page.
57911 /* Copy the data from the source page into the destination page.
57914 ** of the page 'extra' space to invalidate the Btree layers
57915 ** cached parse of the page). MemPage.isInit is marked
57963 int pgszSrc = 0; /* Source page size */
57964 int pgszDest = 0; /* Destination page size */
58007 ** and the page sizes are different between source and destination */
58021 const Pgno iSrcPg = p->iNext; /* Source page number */
58023 DbPage *pSrcPg; /* Source page object */
58060 ** database. The complication here is that the destination page
58061 ** size may be different to the source page size.
58063 ** If the source page size is smaller than the destination page size,
58067 ** destination file that lie beyond the nDestTruncate page mark are
58085 /* If the source page-size is smaller than the destination page-size,
58091 ** pending-byte page in the source database may need to be
58243 ** This function is called after the contents of page iPage of the
58244 ** source database have been modified. If page iPage has already been
58259 /* The backup process p has already copied page iPage. But now it
59258 int available = 0; /* Number of bytes available on the local btree page */
67180 ** record header if the record header does not fit on a single page
67934 ** Open a read-only cursor for the database table whose root page is
67942 ** If P5!=0 then use the content of register P2 as the root page, not
67965 ** page is P2. Or if P5!=0 use the content of register P2 to find the
67966 ** root page.
68054 ** SQLite used to check if the root-page flags were sane at this point
68117 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69599 ** Delete an entire database table or index whose root page in the database
69606 ** If AUTOVACUUM is enabled then it is possible that another root page
69607 ** might be moved into the newly deleted root page in order to keep all
69609 ** value of the root page that moved - its value before the move occurred -
69610 ** is stored in register P2. If no page
69659 ** Delete all contents of the database table or index whose root page
69700 ** P1>1. Write the root page number of the new table into
69713 ** P1>1. Write the root page number of the new table into
69862 ** The root page numbers of all tables in the database are integer
70590 ** P2 contains the root-page of the table to lock.
71003 ** Try to set the maximum page count for database P1 to the value in P3.
71004 ** Do not let the maximum page count fall below the current page count and
71005 ** do not change the maximum page count value if P3==0.
71007 ** Store the maximum page count after the change in register P2.
72030 int pgsz; /* Page size of main database */
72279 ** than (page-size * cache-size), or
72282 ** than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
81239 int iTab; /* The root page of the table to be locked */
81247 ** The table to be locked has root page iTab and is found in database iDb.
81257 int iTab, /* Root page number of the table to be locked */
82090 ** The root page number of the new table is left in reg pParse->regRoot.
82091 ** The rowid and root page number values are needed by the code that
82695 ** So do not write to the disk again. Extract the root page number
82696 ** for the table from the db->init.newTnum field. (The page number
82737 ** statement to populate the new table. The root-page number for the
83051 ** used by SQLite when the btree layer moves a table root page. The
83052 ** root-page of a table or index in database iDb has changed from iFrom
83092 ** Write code to erase the table with root-page iTable from database iDb.
83094 ** if a root-page of another table is moved by the btree-layer whilst
83104 ** is non-zero, then it is the root page number of a table moved to
83122 ** in case a root-page belonging to another table is moved by the btree layer
83137 ** largest root-page number. This guarantees that none of the root-pages
83145 ** and root page 5 happened to be the largest root-page number in the
83146 ** database, then root page 5 would be moved to page 4 by the
83148 ** a free-list page.
83529 ** root page number of the index. If memRootPage is negative, then
83531 ** the root page number of the index is taken from pIndex->tnum.
83540 int tnum; /* Root page of index */
92449 ** page cache size. The value returned is the maximum number of
92450 ** pages in the page cache. The second form sets both the current
92451 ** page cache size value and the persistent page cache size value
92500 ** database page size in bytes. The second form sets the
92501 ** database page size value. The value can only be set if
92511 /* Malloc may fail when setting the page-size, as there is an internal
92788 ** page cache size. The second form sets the local
92789 ** page cache size value. If N is positive then that is the
93685 ** argv[1] = root page number for table or index. 0 for trigger or view.
93745 ** to do here is record the root page number for that index.
93873 ** meta[2] Size of the page cache.
98875 int iRoot = pTab->tnum; /* Root page of scanned b-tree */
98884 ** In this case set iRoot to the root page number of the index b-tree
101220 int nRes; /* Bytes of reserved space at the end of each page */
101298 ** to ensure that we do not try to change the page-size on a WAL database.
101305 /* Do not attempt to change the page size for a WAL database */
101402 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
101413 ** we already have page 1 loaded into cache and marked dirty. */
105708 ** on one page and hence more pages have to be fetched.
112800 /* Designate a buffer for page cache memory space */
112818 /* Specify an alternative page cache implementation */
116604 int nPgsz; /* Page size for host database */
117278 ** Store the current database page-size in bytes in p->nPgsz.
117966 /* Figure out the page-size for the database. This is required in order to
118231 int isFirstTerm = 1; /* True when processing first term on page */
120765 ** of data that will fit on a single leaf page of an intkey table in
127113 int nReq; /* Number of bytes required on leaf page */
130167 ** child page.
130775 ** an internal node, then the 64-bit integer is a child page number.
130997 ** Cursor pCursor currently points to a cell in a non-leaf page.
131673 RtreeNode **ppLeaf /* OUT: Selected leaf page */
133099 ** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
133100 ** This ensures that each node is stored on a single database page. If the
133101 ** database page-size is so large that more than RTREE_MAXCELLS entries