• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-13-stable/contrib/sqlite3/

Lines Matching refs:page

2347 ** file will be doing page-aligned sector reads and writes in a random
2848 ** that SQLite can use for the database page cache with the default page
2850 ** This configuration option is a no-op if an application-defined page
2853 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
2855 ** The sz argument should be the size of the largest database page
2857 ** page header. ^The number of extra bytes needed by the page header
2865 ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
2866 ** a page cache line is larger than sz bytes or if all of the pMem buffer
2869 ** does an initial bulk allocation for page cache memory
2872 ** page cache memory is needed beyond what is provided by the initial
2934 ** the interface to a custom page cache implementation.)^
2940 ** the current page cache implementation into that object.)^ </dd>
3037 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
3049 ** to be sorted exceeds the page size times the minimum of the
7518 ** limit by reducing the number of pages held in the page cache
7563 ** <li> An alternative page cache implementation is specified using
7565 ** <li> The page cache allocates from its own memory pool supplied
8716 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
9077 ** and internal memory usage by the SQLite library. Auxiliary page-cache
9101 ** <dd>This parameter returns the number of bytes of page cache
9107 ** no space was left in the page cache.</dd>)^
9258 ** If an IO or other error occurs while writing a page to disk, the effect
9265 ** been written to disk in the middle of a transaction due to the page
9400 ** The sqlite3_pcache_page object represents a single page in the
9401 ** page cache. The page cache will allocate instances of this
9402 ** object. Various methods of the page cache use pointers to instances
9409 void *pBuf; /* The content of the page */
9410 void *pExtra; /* Extra information associated with the page */
9415 ** KEYWORDS: {page cache}
9418 ** register an alternative page cache implementation by passing in an
9421 ** SQLite is used for the page cache.
9423 ** custom page cache using this API, an application can better control
9429 ** The alternative page cache mechanism is an
9431 ** The built-in page cache is recommended for most uses.
9438 ** [[the xInit() page cache method]]
9444 ** required by the custom page cache implementation.
9446 ** built-in default page cache is used instead of the application defined
9447 ** page cache.)^
9449 ** [[the xShutdown() page cache method]]
9464 ** [[the xCreate() page cache methods]]
9471 ** associated with each page cache entry. ^The szExtra parameter will
9473 ** extra szExtra bytes on each page to store metadata about the underlying
9474 ** database page on disk. The value passed into szExtra depends
9481 ** never invoke xUnpin() except to deliberately delete a page.
9487 ** [[the xCachesize() page cache method]]
9495 ** [[the xPagecount() page cache methods]]
9499 ** [[the xFetch() page cache methods]]
9500 ** The xFetch() method locates a page in the cache and returns a pointer to
9501 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
9504 ** single database page. The pExtra element of sqlite3_pcache_page will be
9506 ** for each entry in the page cache.
9508 ** The page to be fetched is determined by the key. ^The minimum key value
9509 ** is 1. After it has been retrieved using xFetch, the page is considered
9512 ** If the requested page is already in the page cache, then the page cache
9513 ** implementation must return a pointer to the page buffer with its content
9514 ** intact. If the requested page is not already in the cache, then the
9519 ** <tr><th> createFlag <th> Behavior when page is not already in cache
9520 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9521 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
9523 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
9524 ** NULL if allocating a new page is effectively impossible.
9533 ** [[the xUnpin() page cache method]]
9534 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
9536 ** then the page must be evicted from the cache.
9538 ** zero, then the page may be discarded or retained at the discretion of
9539 ** page cache implementation. ^The page cache implementation
9543 ** call to xUnpin() unpins the page regardless of the number of prior calls
9546 ** [[the xRekey() page cache methods]]
9548 ** page passed as the second argument. If the cache
9554 ** existing cache entries with page numbers (keys) greater than or equal
9559 ** [[the xDestroy() page cache method]]
9566 ** [[the xShrink() page cache method]]
9567 ** ^SQLite invokes the xShrink() method when it wants the page cache to
9568 ** free up as much of heap memory as possible. The page cache implementation
9702 ** and the destination and source page sizes differ, or
9704 ** destination and source page sizes differ.
10490 ** to disk. A dirty page may be in use if a database cursor created by an
10491 ** active SQL statement is reading from it, or if it is page 1 of a database
10492 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
13480 /* Maximum page size. The upper bound on this value is 65536. This a limit
13481 ** imposed by the use of 16-bit offsets within each page.
13487 ** with a page-size of 65536 bytes crashes, then an instance of SQLite
13488 ** compiled with the default page-size limit will not be able to rollback
13498 ** The default size of a database page.
13510 ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
14696 ** The root-page of the schema table.
14884 ** This header file defines the interface that the sqlite page cache
14885 ** subsystem. The page cache subsystem reads and writes a file a page
14902 ** The type used to represent a page number. The first page in a file
14903 ** is called page 1. 0 is used to represent "not a page".
14961 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
15017 /* Functions used to obtain and release page references. */
15025 /* Operations on page references. */
15262 ** For example, the free-page-count field is located at byte offset 36 of
15355 Pgno iTable, /* Index of root page */
16173 ** This header file defines the interface that the sqlite page cache
16183 ** Every page in the cache is controlled by an instance of the following
16187 sqlite3_pcache_page *pPage; /* Pcache object page handle */
16190 PCache *pCache; /* PRIVATE: Cache that owns this page */
16192 Pager *pPager; /* The pager this page is part of */
16193 Pgno pgno; /* Page number for this page */
16195 u32 pageHash; /* Hash of page content */
16204 i16 nRef; /* Number of users of this page */
16216 ** writing this page to the database */
16218 #define PGHDR_MMAP 0x020 /* This is an mmap page object */
16222 /* Initialize and shutdown the page cache subsystem */
16236 int szPage, /* Size of every page */
16237 int szExtra, /* Extra space associated with each page */
16244 /* Modify the page-size after the cache has been created. */
16260 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
16261 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
16262 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
16266 /* Change a page number. Used by incr-vacuum. */
16272 /* Get a list of all dirty pages in the cache, sorted by page number */
16278 /* Clear flags from pages of the page cache */
16284 /* Return the total number of outstanding page references */
16287 /* Increment the reference count of an existing page */
16326 /* Free up as much memory as possible from the page cache */
16550 ** that all locks will fit on a single page even at the minimum page size.
16552 ** is set high so that we don't have to allocate an unused page except
16553 ** for very large databases. But one should test the page skipping logic
17662 Pgno tnum; /* Root BTree page for this table */
17947 ** used to store the address of a VDBE instruction, not a database page
17948 ** number (it cannot - the database page is not allocated until the VDBE
18921 int regRoot; /* Register holding root page number for new objects */
19209 Pgno mxPage; /* Maximum page number. 0 for no limit. */
19238 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */
19245 int szPage; /* Size of each page in pPage[] */
20803 ** page size in bytes.
20928 ** the database page that contains the pending byte. It never attempts
20929 ** to read or write that page. The pending byte page is set aside
21103 Pgno pgnoRoot; /* Root page of the open btree cursor */
21108 const u8 *aRow; /* Data for the current row, if all on one page */
22241 ** Reference: Meeus page 61
35256 ** the first page of the database, no damage is done.
38080 ** Return the system page size.
38261 ** current system page-size.
38269 int pgsz = osGetpagesize(); /* System page size */
38608 ** writing a single byte to the end of each (OS) page being
38610 ** last page in order to extend the file. But writing to all new
38618 /* Write to the last byte of each newly allocated or extended page */
42467 * possible initial heap size and the default page size, setting aside the
43833 ** code page.
43862 ** using the ANSI or OEM code page.
48568 /* Fetch a page of a memory-mapped file */
48585 /* Release a memory-mapped page */
49329 ** This file implements that page cache.
49334 ** A complete page cache is an instance of this structure. Every
49335 ** entry in the cache holds a single page of the database file. The
49338 ** A page cache entry is "clean" if it exactly matches what is currently
49339 ** on disk. A page is "dirty" if it has been modified and needs to be
49350 ** page to eject from the cache mid-transaction. It is better to eject
49351 ** a page that does not require a journal sync than one that does.
49353 ** to either the oldest page in the pDirty/pDirtyTail list that has a
49354 ** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
49355 ** (so that the right page to eject can be found by following pDirtyPrev
49360 PgHdr *pSynced; /* Last synced page in dirty page list */
49364 int szPage; /* Size of every page in this cache */
49365 int szExtra; /* Size of extra space for each page */
49368 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
49430 assert( pCache!=0 ); /* Every page has an associated PCache */
49446 ** in step 3, and page might be written into the database without first
49450 ** Another example is when the database page size is smaller than the
49451 ** disk sector size. When any page of a sector is journalled, all pages
49501 ** searching for a dirty page to eject from the cache when it might
49527 /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
49529 ** optimization, as if pSynced points to a page with the NEED_SYNC
49531 ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
49566 ** page size. */
49573 ** Initialize and shutdown the page cache subsystem. Neither of these
49579 ** built-in default page cache is used instead of the application defined
49580 ** page cache. */
49604 ** szExtra is some extra space allocated for each page. The first
49605 ** 8 bytes of the extra space will be zeroed as the page is allocated,
49611 int szPage, /* Size of every page */
49612 int szExtra, /* Extra space associated with each page */
49633 ** Change the page size for PCache object. The caller must ensure that there
49634 ** are no outstanding page references when this function is called.
49657 ** Try to obtain a page from the cache.
49665 ** be 3 (not 1, but 3) to try to create a new page.
49667 ** If the createFlag is 0, then NULL is always returned if the page
49668 ** is not already in the cache. If createFlag is 1, then a new page
49681 PCache *pCache, /* Obtain the page from this cache */
49683 int createFlag /* If true, create page if it does not exist already */
49693 /* eCreate defines what to do if the page does not exist.
49694 ** 0 Do not allocate a new page. (createFlag==0)
49695 ** 1 Allocate a new page if doing so is inexpensive.
49697 ** 2 Allocate a new page even it doing so is difficult.
49712 ** page because no clean pages are available for reuse and the cache
49714 ** try harder to allocate a page. This routine might invoke the stress
49716 ** allocate the new page and will only fail to allocate a new page on
49722 PCache *pCache, /* Obtain the page from this cache */
49730 /* Find a dirty page to write-out and recycle. First try to find a
49731 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
49733 ** unreferenced dirty page.
49735 ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
49737 ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
49751 "spill page %d making room for %d - cache used: %d/%d",
49771 ** In the uncommon case where the page being fetched has not been
49778 PCache *pCache, /* Obtain the page from this cache */
49804 PCache *pCache, /* Obtain the page from this cache */
49823 ** Decrement the reference count on a page. If the page is clean and the
49839 ** Increase the reference count of a supplied page by 1.
49849 ** Drop a page from the cache. There must be exactly one reference to the
49850 ** page. This function deletes that reference, so after it returns the
49851 ** page pointed to by p is invalid.
49864 ** Make sure the page is marked as dirty. If it isn't dirty already,
49883 ** Make sure the page is marked as clean. If it isn't clean already,
49901 ** Make every page in the cache clean.
49935 ** Change the page number of page p to newPgno.
49951 ** Drop every cache entry whose page number is greater than "pgno". The
49953 ** other than page 1 with a page number greater than pgno.
49955 ** If there is a reference to page 1 and the pgno parameter passed to this
49956 ** function is 0, then the data area associated with page 1 is zeroed, but
49957 ** the page object is not dropped.
50079 ** Return a list of all dirty pages in the cache, sorted by page number.
50100 ** Return the number of references to the page supplied as an argument.
50153 ** Free up as much memory as possible from the page cache.
50162 ** in the page-cache hierarchy.
50215 ** This file implements the default page cache implementation (the
50218 ** If the default page cache implementation is overridden, then neither of
50224 ** | database page content | PgHdr1 | MemPage | PgHdr |
50227 ** The database page content is up front (so that buffer overreads tend to
50230 ** as the database page number and how that database page is used. PgHdr
50234 ** PgHdr1 contains information needed to look up a page by its page number.
50236 ** database page content and sqlite3_pcache_page.pExtra points to PgHdr.
50245 ** using a separate memory allocation from the database page content. This
50259 ** Memory for a page might come from any of three sources:
50262 ** (2) Global page-cache memory provided using sqlite3_config() with
50267 ** that is allocated when the page cache is created. The size of the local
50301 ** in memory directly after the associated page data, if the database is
50302 ** corrupt, code at the b-tree layer may overread the page buffer and
50309 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
50310 unsigned int iKey; /* Key value (page number) */
50311 u16 isBulkLocal; /* This page from bulk local storage */
50314 PCache1 *pCache; /* Cache that currently owns this page */
50321 ** A page is pinned if it is not on the LRU list. To be "pinned" means
50322 ** that the page is in active use and must not be deallocated.
50327 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
50332 ** This page cache implementation works in one of two modes:
50358 /* Each page cache is an instance of the following object. Every
50360 ** temporary or transient database) has a single page cache which
50397 ** Free slots in the allocator used to divide up the global page cache
50421 void *pStart, *pEnd; /* Bounds of global page cache memory */
50424 PgFreeslot *pFree; /* Free page blocks */
50459 ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
50513 pX->page.pBuf = zBulk;
50514 pX->page.pExtra = &pX[1];
50621 ** Allocate a new page object initially associated with cache pCache.
50662 p->page.pBuf = pPg;
50663 p->page.pExtra = &p[1];
50673 ** Free a page object allocated by pcache1AllocPage().
50684 pcache1Free(p->page.pBuf);
50711 ** Return true if it desirable to avoid allocating a new page cache
50714 ** If memory was allocated specifically to the page cache using
50716 ** it is desirable to avoid allocating a new page cache entry because
50718 ** for all page cache needs and we should not need to spill the
50721 ** Or, the heap is used for all page cache memory but the heap is
50723 ** allocating a new page cache entry in order to avoid stressing
50778 ** This function is used internally to remove the page pPage from the
50803 ** Remove the page supplied as an argument from the hash table
50805 ** Also free the page if freePage is true.
50846 ** Discard all pages from cache pCache with a page number (key value)
50912 ** PGroup in pcache1.grp is used for all page caches (mode-2).
50917 ** configured a start-time buffer for use as page-cache memory using
50971 PCache1 *pCache; /* The newly created page cache */
50972 PGroup *pGroup; /* The group the new page cache will belong to */
51099 /* Step 4. Try to recycle a page. */
51118 /* Step 5. If a usable page buffer has still not been found,
51134 *(void **)pPage->page.pExtra = 0;
51146 ** Fetch a page by key value.
51148 ** Whether or not a new page may be allocated by this function depends on
51150 ** page. 1 means allocate a new page if space is easily available. 2
51151 ** means to try really hard to allocate a new page.
51158 ** There are three different approaches to obtaining space for a page,
51162 ** copy of the requested page. If one is found, it is returned.
51164 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
51167 ** 3. If createFlag is 1, and the page is not already in the cache, then
51168 ** return NULL (do not allocate a new page) if any of the following
51191 ** then attempt to recycle a page from the LRU list. If it is the right
51195 ** 5. Otherwise, allocate and return a new page buffer.
51214 /* Step 2: If the page was found in the hash table, then return it.
51215 ** If the page was not in the hash table and createFlag is 0, abort.
51216 ** Otherwise (page not in hash and createFlag!=0) continue with
51217 ** subsequent steps to try to create the page. */
51256 assert( offsetof(PgHdr1,page)==0 );
51276 ** Mark a page as unpinned (eligible for asynchronous recycling).
51290 /* It is an error to call this function if the page is already
51299 /* Add the page to the PGroup LRU list. */
51349 ** Discard all unpinned pages in the cache with a page number equal to
51350 ** or greater than parameter iLimit. Any pinned pages with a page number
51411 ** Return the size of the header on each page of this PCACHE implementation.
51444 nFree += pcache1MemSize(p->page.pBuf);
52000 ** This is the implementation of the page cache subsystem or "pager".
52086 /* Read a page from the write-ahead log, if it is present. */
52153 ** stored in each frame (i.e. the db page-size when the WAL was created).
52179 ** Within this comment block, a page is deemed to have been synced
52181 ** Otherwise, the page is not synced until the xSync method of the VFS
52182 ** is called successfully on the file containing the page.
52184 ** Definition: A page of the database file is said to be "overwriteable" if
52185 ** one or more of the following are true about the page:
52187 ** (a) The original content of the page as it was at the beginning of
52191 ** (b) The page was a freelist leaf page at the start of the transaction.
52193 ** (c) The page number is greater than the largest page that existed in
52196 ** (1) A page of the database file is never overwritten unless one of the
52199 ** (a) The page and all other pages on the same sector are overwriteable.
52201 ** (b) The atomic page write optimization is enabled, and the entire
52203 ** number consists of a single page change.
52205 ** (2) The content of a page written into the rollback journal exactly matches
52210 ** (3) Writes to the database file are an integer multiple of the page size
52211 ** in length and are aligned on a page boundary.
52213 ** (4) Reads from the database file are either aligned on a page boundary and
52214 ** an integer multiple of the page size in length or are taken from the
52384 ** A pager moves from WRITER_LOCKED state to this state when a page is
52393 ** * The contents of the page cache have been modified.
52406 ** * The contents of the page cache have been modified (and possibly
52438 ** the contents of the page-cache may be left in an inconsistent state.
52450 ** page-cache and any other in-memory state at the same time. Everything
52599 ** An open page cache is an instance of struct Pager. A description of
52674 ** to allocate a new page to prevent the journal file from being written
52681 ** is larger than the database page-size in order to prevent a journal sync
52702 ** is not an integer multiple of the page-size, the value stored in
52703 ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
52705 ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
52708 ** During a write-transaction, if pages with page-numbers greater than
52806 Bitvec *pInJournal; /* One bit for each page in the database file */
52820 PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
52825 u16 nExtra; /* Add this many bytes to each in-memory page */
52826 i16 nReserve; /* Number of unused bytes at end of each page */
52829 int pageSize; /* Number of bytes in a page */
52843 PCache *pPCache; /* Pointer to page cache object */
52889 ** of a 32-bit checksum on each page of data. The checksum covers both
52890 ** the page number and the pPager->pageSize bytes of data for the page.
52904 ** The size of the of each page record in the journal is given by
52953 ** Return true if page pgno can be read directly from the database file
52958 ** * the desired page is not currently in the wal file.
53181 /* Forward references to the various page getters */
53205 ** Return true if it is necessary to write page *pPg into the sub-journal.
53206 ** A page needs to be written into the sub-journal if there exists one
53209 ** * The page-number is less than or equal to PagerSavepoint.nOrig, and
53210 ** * The bit corresponding to the page-number is not set in
53232 ** Return true if the page is already in the journal file.
53328 ** a database page may be written atomically, and
53330 ** to the page size.
53333 ** file when it contains rollback data for exactly one page.
53385 ** Return a 32-bit hash of the page data for pPage.
53405 ** that the page is either dirty or still matches the calculated page-hash.
53578 ** - 4 bytes: Random number used for page hash.
53579 ** - 4 bytes: Initial database page count.
53581 ** - 4 bytes: Database page size.
53611 ** Write the nRec Field - the number of page records that follow this
53619 ** rest of the journal file contains valid page records. This assumption
53648 /* The page size */
53672 ** database page size. Since the zHeader buffer is only Pager.pageSize
53694 ** page records following this header and *pDbSize is set to the size of the
53756 /* Read the page-size and sector-size journal header fields. */
53763 /* Versions of SQLite prior to 3.5.8 set the page-size field of the
53765 ** variable is already set to the correct page size.
53771 /* Check that the values read from the page-size and sector-size fields
53780 /* If the either the page-size or sector-size in the journal-header is
53788 /* Update the page-size to match the value read from the journal.
53822 ** The super-journal page checksum is the sum of the bytes in thesuper-journal
53853 ** the super-journal name. This is in case the previous page written to
53894 ** Discard the entire contents of the in-memory page-cache.
54321 ** page of data and the current value of pPager->cksumInit.
54325 ** of the page data, starting with byte offset (pPager->pageSize%200).
54348 ** Read a single page from either the journal file (if isMainJrnl==1) or
54349 ** from the sub-journal (if isMainJrnl==0) and playback that page.
54350 ** The page begins at offset *pOffset into the file. The *pOffset
54351 ** value is increased to the start of the next page in the journal.
54356 ** If the page number of the page record read from the (sub-)journal file
54361 ** been played back. If the page at *pOffset has already been played back
54363 ** Make sure the pDone bit corresponding to the *pOffset page is set
54366 ** If the page record is successfully read from the (sub-)journal file
54374 ** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
54392 PgHdr *pPg; /* An existing page in the cache */
54393 Pgno pgno; /* The page number of a page in journal */
54395 char *aData; /* Temporary storage for the page */
54397 int isSynced; /* True if journal page is synced */
54419 /* Read the page number and page data from the journal or sub-journal
54429 /* Sanity checking on the page. This is more important that I originally
54449 /* If this page has already been played back before during the current
54456 /* When playing back page 1, restore the nReserve setting
54463 ** page in the pager cache. In this case just update the pager cache,
54464 ** not the database file. The page is left marked dirty in this case.
54467 ** and a page is moved during an incremental vacuum then the page may
54469 ** during a Movepage() call, then the page may not be in the cache
54474 ** pager cache if it exists and the main file. The page is then marked
54476 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
54479 ** Ticket #1171: The statement journal might contain page content that is
54480 ** different from the page content at the start of the transaction.
54481 ** This occurs when a page is changed prior to the start of a statement
54484 ** for certain that original page contents are synced into the main rollback
54489 ** locked. (2) we know that the original page content is fully synced
54490 ** in the main journal either because the page is not in cache or else
54491 ** the page is marked as needSync==0.
54504 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
54537 ** the database and the page is not in-memory, there is a potential
54538 ** problem. When the page is next fetched by the b-tree layer, it
54544 ** if the page is on the free-list at the start of the transaction, then
54547 ** The solution is to add an in-memory page to the cache containing
54548 ** the data just read from the sub-journal. Mark the page as dirty
54549 ** and if the pager requires a journal-sync, then mark the page as
54562 /* No page should ever be explicitly rolled back that is in use, except
54563 ** for page 1 which is held in use in order to keep the lock on the
54564 ** database active. However such a page may be rolled back as a result
54578 /* If this was page 1, then restore the value of Pager.dbFileVers.
54628 ** a couple of kilobytes or so - potentially larger than the page
54842 ** (2) 4 byte big-endian integer which is the number of valid page records
54844 ** number of page records from the journal size.
54851 ** (6) 4 byte big-endian integer which is the page size.
54854 ** + 4 byte page number.
54862 ** valid page entries in the journal. In most cases, you can compute the
54877 ** journal file then all pages up to the first corrupted page are rolled
54901 int needPagerReset; /* True to reset page prior to first page rollback */
54996 ** database file and/or page cache.
55098 ** Read the content for page pPg out of the database file (or out of
55103 ** If page 1 is read, then the value of Pager.dbFileVers[] is set to
55110 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
55140 ** zero or the size of the database in page. Bytes 32..35 and 35..39
55141 ** should be page numbers which are never 0xffffffff. So filling
55158 PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
55188 ** This function is invoked once for each page that has already been
55190 ** Parameter iPg is the page number of said page. The pCtx argument
55193 ** If page iPg is present in the cache, and has no outstanding references,
55195 ** references, the page content is reloaded from the database. If the
55242 ** + Discard the cached page (if refcount==0), or
55243 ** + Reload page content from the database (if refcount>0).
55263 ** The list of pages passed into this routine is always sorted by page number.
55264 ** Hence, if page 1 appears anywhere on the list, it will be the first page.
55279 /* Verify that the page list is in accending order */
55288 ** any pages with page numbers greater than nTruncate into the WAL file.
55360 ** in pages (assuming the page size currently stored in Pager.pageSize).
55382 ** WAL sub-system, determine the page count based on the size of
55384 ** integer multiple of the page-size, round up the result.
55480 ** Throughout the rollback process, each time a page is rolled back, the
55482 ** implementation below). This is used to ensure that a page is only
55490 ** (or transaction). No page with a page-number greater than this value
55530 ** There might be records in the main journal that have a page number
55814 ** Change the page size used by the Pager object. The new page size
55823 ** * the new page size (value of *pPageSize) is valid (a power
55826 ** * there are no outstanding page references, and
55831 ** then the pager object page size is set to *pPageSize.
55833 ** If the page size is changed, then this function uses sqlite3PagerMalloc()
55835 ** fails, SQLITE_NOMEM is returned and the page size remains unchanged.
55838 ** If the page size is not changed, either because one of the enumerated
55841 ** then *pPageSize is set to the old, retained page size before returning.
55852 ** there is at least one outstanding page reference, this function
55904 ** Return a pointer to the "temporary page" buffer held internally
55906 ** entire content of a database page. This buffer is used internally
55916 ** Attempt to set the maximum database page count if mxPage is positive.
55918 ** maximum page count below the current size of the database.
55920 ** Regardless of mxPage, return the current maximum page count.
55997 ** However, if the file is between 1 and <page-size> bytes in size, then
55998 ** this is considered a 1 page file.
56042 ** following is true for all dirty pages currently in the page-cache:
56044 ** a) The page number is less than or equal to the size of the
56047 ** b) if the page content were written at this time, it would not
56052 ** dirty page were to be discarded from the cache via the pagerStress()
56053 ** routine, pagerStress() would not write the current page content to
56056 ** content of the page. However, since this content is not present in either
56129 ** Obtain a reference to a memory mapped page object for page number pgno.
56131 ** If successful, set *ppPage to point to the new page reference
56141 void *pData, /* xFetch()'d data for this page */
56142 PgHdr **ppPage /* OUT: Acquired page object */
56144 PgHdr *p; /* Memory mapped page to return */
56179 ** Release a reference to page pPg. pPg must have been returned by an
56230 ** Shutdown the page cache. Free all memory and close all files.
56234 ** and their memory is freed. Any attempt to use a page associated
56235 ** with this page cache after this function returns will likely
56302 ** Return the page number for page pPg.
56310 ** Increment the reference count for page pPg.
56348 ** page currently held in memory before returning SQLITE_OK. If an IO
56480 ** a page is skipped if it meets either of the following criteria:
56482 ** * The page number is greater than Pager.dbSize, or
56483 ** * The PGHDR_DONT_WRITE flag is set on the page.
56485 ** If writing out a page causes the database file to grow, Pager.dbFileSize
56486 ** is updated accordingly. If page 1 is written out, then the value cached
56528 /* If there are dirty pages in the page cache with page numbers greater
56533 ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
56545 /* Write out the page data. */
56548 /* If page 1 was just written, update Pager.dbFileVers to match
56550 ** page caused the database file to grow, update dbFileSize.
56563 PAGERTRACE(("STORE %d page %d hash(%08x)\n",
56568 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno));
56601 ** Append a record of the current state of page pPg to the sub-journal.
56633 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
56659 ** database). The second argument is a reference to a page that is
56660 ** currently dirty but has no outstanding references. The page
56668 ** If successful, sqlite3PcacheMakeClean() is called on the page and
56670 ** page clean, the IO error code is returned. If the page cannot be
56711 /* Write a single frame for this page to the log. */
56732 /* Write the contents of the page out to the database file. */
56739 /* Mark the page as clean. */
56741 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
56781 ** along with each page reference. This space is available to the user
56782 ** via the sqlite3PagerGetExtra() API. When a new page is allocated, the
56804 int nExtra, /* Extra bytes append to each in-memory page */
56825 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
57024 ** choose a default page size in case we have to create the
57025 ** database file. The default page size is the maximum of:
57029 ** + The largest page size that can be written atomically.
57066 ** In this case we accept the default page size and delay actually
57325 ** the contents of the page cache and rolling back any open journal
57455 ** to be in ERROR state when there are zero outstanding page
57557 ** The page getter methods each try to acquire a reference to a
57558 ** page with page number pgno. If the requested reference is
57568 ** If the requested page is already in the cache, it is returned.
57569 ** Otherwise, a new page object is allocated and populated with data
57571 ** choose not to allocate a new page object and may reuse an existing
57574 ** The extra data appended to a page is always initialized to zeros the
57575 ** first time a page is loaded into memory. If the page requested is
57577 ** data is left as it was when the page object was last used.
57579 ** If the database image is smaller than the requested page or if
57581 ** requested page is not already stored in the cache, then no
57583 ** page is initialized to all zeros.
57586 ** the contents of the page. This occurs in two scenarios:
57588 ** a) When reading a free-list leaf page from the database, and
57591 ** a new page into the cache to be filled with the data read
57598 ** savepoints are set. This means if the page is made writable at any
57606 ** to find a page in the in-memory cache first. If the page is not already
57616 DbPage **ppPage, /* Write a pointer to the page here */
57648 ** the page. Return without further ado. */
57654 /* The pager cache has created a new page. Its content needs to
57657 ** (*) obsolete. Was: maximum page number is 2^31
57658 ** (2) Never try to fetch the locking page
57676 ** page that does not need to be journaled. Nevertheless, be sure
57714 /* The page getter for when memory-mapped I/O is enabled */
57718 DbPage **ppPage, /* Write a pointer to the page here */
57725 /* It is acceptable to use a read-only (mmap) page for any page except
57726 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
57783 /* The page getter method for when the pager is an error state */
57787 DbPage **ppPage, /* Write a pointer to the page here */
57798 /* Dispatch all page fetch requests to the appropriate getter method.
57803 DbPage **ppPage, /* Write a pointer to the page here */
57810 ** Acquire a page if it is already in the in-memory cache. Do
57811 ** not read the page from disk. Return a pointer to the page,
57812 ** or 0 if the page is not in cache.
57816 ** in the page if the page is not already in cache. This routine
57817 ** returns NULL if the page is not in cache or if a disk I/O error
57832 ** Release a page reference.
57835 ** used if we know that the page being released is not the last page.
57837 ** to routines can be used to release any page other than BtShared.pPage1.
58026 ** file as well as into the page cache. Which would be incorrect in
58046 ** Write page pPg onto the end of the rollback journal.
58055 /* We should never write to the journal file the page that
58065 ** page in the block above, set the need-sync flag for the page.
58067 ** playback_one_page() will think that the page needs to be restored
58083 PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
58099 ** Mark a single data page as writeable. The page is written into the
58100 ** main journal or sub-journal as required. If the page is written into
58126 ** This is done before calling sqlite3PcacheMakeDirty() on the page.
58138 /* Mark the page that is about to be modified as dirty. */
58141 /* If a rollback journal is in use, them make sure the page that is about
58142 ** to change is in the rollback journal, or if the page is a new page off
58159 PAGERTRACE(("APPEND %d page %d needSync=%d\n",
58165 /* The PGHDR_DIRTY bit is set above when the page was added to the dirty-list
58166 ** and before writing the page into the rollback journal. Wait until now,
58167 ** after the page has been successfully journalled, before setting the
58168 ** PGHDR_WRITEABLE bit that indicates that the page can be safely modified.
58172 /* If the statement journal is open and the page is not in it,
58173 ** then write the page into the statement journal.
58188 ** is larger than the page size. SQLite makes the (reasonable) assumption that
58193 ** Usually, the sector size is less than or equal to the page size, in which
58195 ** exceptional case where the page size is smaller than the sector size.
58200 Pgno pg1; /* First page of the sector pPg is located on. */
58203 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
58215 /* This trick assumes that both the page-size and sector-size are
58217 ** of the first page of the sector pPg is located on.
58278 ** Mark a data page as writeable. This routine must be called before
58279 ** making changes to a page. The caller must check the return value
58280 ** of this function and be careful not to change any page data unless
58310 ** Return TRUE if the page given in the argument was previously passed
58312 ** to change the content of the page.
58322 ** write the information on page pPg back to the disk, even though
58323 ** that page might be marked as dirty. This happens, for example, when
58324 ** the page has been added as a leaf of the freelist and so its
58328 ** on the given page is unused. The pager marks the page as clean so
58334 ** This optimization cannot be used with a temp-file, as the page may
58336 ** memory pressure forces page pPg out of the cache, the data does need
58343 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
58359 ** To avoid excess churning of page 1, the update only happens once.
58364 ** sqlite3PagerWrite() on page 1, then modifying the contents of the
58365 ** page data. In this case the file will be updated when the current
58371 ** by writing an updated version of page 1 using a call to the
58401 PgHdr *pPgHdr; /* Reference to page 1 */
58405 /* Open page 1 of the file for writing. */
58409 /* If page one was fetched successfully, and this function is not
58410 ** operating in direct-mode, make page 1 writable. When not in
58411 ** direct mode, page 1 is always held in cache and hence the PagerGet()
58422 /* If running in direct mode, write the contents of page 1 to the file. */
58444 /* Release the page reference. */
58561 /* Must have at least one page for the WAL commit flag.
58597 ** blocks of size page-size, and
58599 ** * Exactly one page has been modified and store in the journal file.
58626 ** following call will modify the in-memory representation of page 1
58627 ** to include the updated change counter and then write page 1
58662 ** Because the change-counter page was just modified, unless the
58711 ** last page in the db image moved to the free-list. In this case the
58712 ** last page is never written out to disk, leaving the database file
58894 ** Return the number of references to the specified page.
59180 ** Move the page pPg to location pgno in the file.
59182 ** There must be no references to the page previously located at
59183 ** pgno (which we call pPgOld) though that page is allowed to be
59184 ** in cache. If the page previously located at pgno is not already
59187 ** References to the page pPg remain valid. Updating any
59189 ** allocated along with the page) is the responsibility of the caller.
59193 ** has been removed (CREATE INDEX needs to move a page when a statement
59196 ** If the fourth argument, isCommit, is non-zero, then this page is being
59198 ** is being committed. In this case, it is guaranteed that the database page
59205 PgHdr *pPgOld; /* The page being overwritten. */
59208 Pgno origPgno; /* The original page number */
59217 ** the page we are moving from.
59225 /* If the page being moved is dirty and has not been saved by the latest
59226 ** savepoint, then save the current contents of the page into the
59230 ** <journal page X, then modify it in memory>
59232 ** <Move page X to location Y>
59235 ** If page X were not written to the sub-journal here, it would not
59249 PAGERTRACE(("MOVE %d page %d (needSync=%d) moves to %d\n",
59253 /* If the journal needs to be sync()ed before page pPg->pgno can
59257 ** the journal needs to be sync()ed before database page pPg->pgno
59267 /* If the cache contains a page with page-number pgno, remove it
59269 ** page pgno before the 'move' operation, it needs to be retained
59270 ** for the page moved there.
59283 ** need to rollback later. Just move the page out of the way. */
59294 /* For an in-memory database, make sure the original page continues
59296 ** as the original page since it has already been allocated.
59305 ** sync()ed before any data is written to database file page needSyncPgno.
59306 ** Currently, no such page exists in the page-cache and the
59308 ** loading the page into the pager-cache and setting the PGHDR_NEED_SYNC
59311 ** If the attempt to load the page into the page-cache fails, (due
59313 ** array. Otherwise, if the page is loaded and written again in
59337 ** The page handle passed as the first argument refers to a dirty page
59338 ** with a page number other than iNew. This function changes the page's
59339 ** page number to iNew and sets the value of the PgHdr.flags field to
59349 ** Return a pointer to the data for the specified page.
59358 ** allocated along with the specified page.
59845 ** frames, return the size in bytes of the page images stored within the
59877 ** Each frame records the revised content of a single page from the
59897 ** 8: Database page size. Example: 1024
59905 ** frame consists of a 24-byte frame-header followed by a <page-size> bytes
59906 ** of page data. The frame-header is six big-endian 32-bit unsigned
59960 ** To read a page from the database (call it page number P), a reader
59961 ** first checks the WAL to see if it contains page P. If so, then the
59962 ** last valid instance of page P that is a followed by a commit frame
59964 ** contains no copies of page P that are valid and which are a commit
59965 ** frame or are followed by a commit frame, then page P is read from
59978 ** because frames for page P can appear anywhere within the WAL, the
59979 ** reader has to scan the entire WAL looking for page P frames. If the
59983 ** search for frames of a particular page.
60007 ** a page number P and a maximum frame index M, return the index of the
60008 ** last frame in the wal before frame M for page P in the WAL, or return
60009 ** NULL if there are no frames for page P in the WAL prior to M.
60024 ** Each index block contains two sections, a page-mapping that contains the
60025 ** database page number associated with each wal frame, and a hash-table
60026 ** that allows readers to query an index block for a specific page number.
60027 ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
60028 ** for the first index block) 32-bit page numbers. The first entry in the
60029 ** first index-block contains the database page number corresponding to the
60035 ** complement of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE) page-numbers,
60037 ** allocated size of the page-mapping array - the page-mapping array merely
60040 ** Even without using the hash table, the last frame for page P
60041 ** can be found by scanning the page-mapping sections of each index block
60045 ** holding the content for that page.
60049 ** hash table for each page number in the mapping section, so the hash
60059 ** To look for page P in the hash table, first compute a hash iKey on
60072 ** no hash slot such that aHash[i]==p) then page P is not in the
60075 ** page P.
60078 ** first index block, looking for entries corresponding to page P. On
60080 ** examined in order to either find the last entry for page P, or to
60173 ** Or it can be 1 to represent a 65536-byte page. The latter case was
60182 u16 szPage; /* Database page size in bytes. 1==64K */
60286 ** assuming a database page size of szPage bytes. The offset returned
60306 u32 szPage; /* Database page size */
60348 ** Each page of the wal-index mapping contains a hash-table made up of
60355 ** all frames in the WAL in database page order. Where two or more frames
60356 ** correspond to the same database page, the iterator visits only the
60374 u32 *aPgno; /* Array of page numbers. */
60377 } aSegment[1]; /* One for every 32KB page in the wal-index */
60382 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
60393 ** The block of page numbers associated with the first hash-table in a
60395 ** hash-table on each aligned 32KB page of the wal-index.
60405 ** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
60415 ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
60420 int iPage, /* The page we seek */
60421 volatile u32 **ppPage /* Write the page pointer here */
60440 /* Request a pointer to the required page from the VFS */
60467 int iPage, /* The page we seek */
60468 volatile u32 **ppPage /* Write the page pointer here */
60609 u32 iPage, /* Database page number for frame */
60611 u8 *aData, /* Pointer to page data */
60640 u32 *piPage, /* OUT: Database page number for frame */
60642 u8 *aData, /* Pointer to page data (for checksum) */
60657 /* A frame is only valid if the page number is creater than zero.
60679 /* If we reach this point, the frame is valid. Return the page number
60752 ** Compute a hash on a page number. The resulting hash value must land
60767 ** of a page hash table in the wal-index. This becomes the return value
60773 volatile u32 *aPgno; /* aPgno[1] is the page of first frame indexed */
60778 ** Return pointers to the hash table and page number array stored on
60779 ** page iHash of the wal-index. The wal-index is broken into 32KB pages
60788 ** Finally, set pLoc->aPgno so that pLoc->aPgno[1] is the page number of the
60815 ** Return the number of the wal-index page that contains the hash-table
60816 ** and page-number array that contain entries corresponding to WAL frame
60833 ** Return the page number associated with frame iFrame in this WAL.
60869 /* Obtain pointers to the hash-table and page-number array containing
60871 ** that the page said hash-table and array reside on is already mapped.(1)
60914 ** Set an entry in the wal-index that will map database page number
60924 ** page number array and hash table entry.
61048 u32 iPg; /* Current 32KB wal-index page */
61057 /* If the database page size is not a power of two, or is greater than
61118 u32 pgno; /* Database page number for frame */
61336 ** Find the smallest page number out of all pages held in the WAL that
61339 ** that page was last written into the WAL. Write into *piPage the page
61342 ** Return 0 on success. If there are no pages in the WAL with a page
61347 u32 *piPage, /* OUT: The page number of the next page */
61348 u32 *piFrame /* OUT: Wal frame index of next page */
61351 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
61721 ** Return the page-size in bytes used by the database.
61765 ** by active readers. This routine will never overwrite a database page
61801 int szPage; /* Database page-size */
61803 u32 iDbpage = 0; /* Next database page to write */
61806 u32 mxPage; /* Max database page to write */
61873 ** maximum size of the pending-byte page (65536 bytes), then
62080 /* The first page of the wal-index must be mapped at this point. */
62150 /* Ensure that page 0 of the wal-index (the page that contains the
62180 /* If the first page of the wal-index has been mapped, try to read the
62262 ** contents of the page cache before proceeding. Or, if it returns
62339 ** reading the database file only. However, the page cache cannot
62380 u32 pgno; /* Database page number for frame */
62428 ** to the caller that the local page cache is obsolete and needs to be
62447 ** access any database page that is modified by a WAL frame up to and
62483 ** paged out or take a page-fault that is time-consuming to resolve,
62524 ** must be zeroed before the requested page is returned.
62652 ** a version of page X that lies before pWal->minFrame (call that version
62654 ** page later in the wal file. But if version B happens to like past
62679 ** comparing their content to the corresponding page with the database
62683 ** This is only really safe if the file-system is such that any page
62688 ** page.
62849 ** is the same database page. */
62881 ** Search the wal file for page pgno. If found, set *piRead to the frame that
62882 ** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
62890 Pgno pgno, /* Database page number to read data for */
62894 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
62901 /* If the "last page" field of the wal-index header snapshot is 0, then
62912 /* Search the hash table or tables for an entry matching page number
62996 u8 *pOut /* Buffer to write page data to */
63118 /* This call cannot fail. Unless the page for which the page number
63121 ** (if (a) is false) or simply expels the page from the cache (if (b)
63125 ** are no outstanding references to any page other than page 1. And
63126 ** page 1 is never written to the log until the transaction is
63246 int szPage; /* Size of one page */
63284 PgHdr *pPage, /* The page of the frame to be written */
63295 /* Write the page data */
63309 const int szPage = pWal->szPage;/* Database page size */
63359 int szPage, /* Database page-size in bytes */
63369 int nExtra = 0; /* Number of extra copies of last page */
63460 /* Check if this page has already been written into the wal file by
63893 ** read-lock. This function returns the database page-size if it is known,
63949 ** The basic idea is that each page of the file contains N database
63956 ** All of the keys on the page that Ptr(0) points to have values less
63957 ** than Key(0). All of the keys on page Ptr(1) and its subpages have
63966 ** BTrees. Each BTree is identified by the index of its root page. The
63969 ** page. If the payload is larger than the preset amount then surplus
63972 ** page has a small header which contains the Ptr(N) pointer and other
63977 ** The file is divided into pages. The first page is called page 1,
63978 ** the second is page 2, and so forth. A page number of zero indicates
63979 ** "no such page". The page size can be any power of 2 between 512 and 65536.
63980 ** Each page can be either a btree page, a freelist page, an overflow
63981 ** page, or a pointer-map page.
63983 ** The first page is always a btree page. The first 100 bytes of the first
63984 ** page contain a special header (the "file header") that describes the file.
63992 ** 20 1 Bytes of unused space at the end of each page
63998 ** 32 4 First freelist page
64004 ** 48 4 Size of page cache
64005 ** 52 4 Largest root-page (auto/incr_vacuum)
64021 ** space in a page that can be consumed by a single cell for standard
64024 ** on one page. Thus the default max embedded payload fraction is 64.
64027 ** payload is spilled to overflow pages. Once an overflow page is allocated,
64038 ** file header that occurs before the page header.
64043 ** | page header | 8 bytes for leaves. 12 bytes for interior nodes
64056 ** The page headers looks like this:
64061 ** 3 2 number of cells on this page
64066 ** The flags define the format of this btree page. The leaf flag means that
64067 ** this page has no children. The zerodata flag means that this page carries
64072 ** The cell pointer array begins on the first byte after the page header.
64074 ** offsets from the beginning of the page to the cell content in the cell
64077 ** be easily added without having to defragment the page.
64079 ** Cell content is stored at the very end of the page and grows toward the
64080 ** beginning of the page.
64089 ** in the page header at offset 7.
64096 ** the end of the page. Pointers to the cells are in the cell pointer array
64097 ** that immediately follows the page header. Cells is not necessarily
64126 ** 4 First page of the overflow chain. Omitted if no overflow
64128 ** Overflow pages form a linked list. Each page except the last is completely
64129 ** filled with data (pagesize - 4 bytes). The last page can have as little
64133 ** 4 Page number of next overflow page
64137 ** file header points to the first in a linked list of trunk page. Each trunk
64138 ** page points to multiple leaf pages. The content of a leaf page is
64139 ** unspecified. A trunk page looks like this:
64142 ** 4 Page number of next trunk page
64143 ** 4 Number of leaf pointers on this page
64149 /* The following value is the maximum cell size assuming a maximum page
64154 /* The maximum number of cells on a single page of the database. This
64156 ** plus 2 bytes for the index to the cell in the page header). Such
64184 ** first byte of on-disk image of every BTree page.
64193 ** page that has been loaded into memory. The information in this object
64194 ** is derived from the raw on-disk page content.
64196 ** As each database page is loaded into memory, the pager allocats an
64198 ** "extra" information associated with each page of the pager.)
64208 Pgno pgno; /* Page number for this page */
64209 /* Only the first 8 bytes (above) are zeroed by pager.c when a new page
64211 u8 leaf; /* True if a leaf page */
64212 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
64219 int nFree; /* Number of free bytes on the page. -1 for unknown */
64220 u16 nCell; /* Number of cells on this page, local and ovfl */
64221 u16 maskPage; /* Mask for page offset */
64225 BtShared *pBt; /* Pointer to BtShared that this page is part of */
64226 u8 *aData; /* Pointer to disk image of the page data */
64230 DbPage *pDbPage; /* Pager page handle */
64238 ** is opened on the table with root page BtShared.iTable. Locks are removed
64244 Pgno iTable; /* Root page of table */
64290 BtLock lock; /* Object used to lock page 1 */
64355 Pager *pPager; /* The page cache */
64358 MemPage *pPage1; /* First page of the database */
64367 u8 nReserveWanted; /* Desired number of extra bytes per page */
64373 u32 pageSize; /* Total number of bytes on a page */
64374 u32 usableSize; /* Number of usable bytes on each page */
64407 ** based on information extract from the raw disk page.
64414 u16 nSize; /* Size of the cell content on the main b-tree page */
64462 Pgno *aOverflow; /* Cache of overflow page locations */
64472 Pgno pgnoRoot; /* The root page of this tree */
64473 i8 iPage; /* Index of current page in apPage */
64478 MemPage *pPage; /* Current page */
64479 MemPage *apPage[BTCURSOR_MAX_DEPTH-1]; /* Stack of parents of current page */
64530 ** The database page the PENDING_BYTE occupies. This page is never used.
64536 ** database page. The first argument to each is the number of usable
64537 ** bytes on each page of the database (often 1024). The second is the
64538 ** page number to look up in the pointer map.
64540 ** PTRMAP_PAGENO returns the database page number of the pointer-map
64541 ** page that stores the required pointer. PTRMAP_PTROFFSET returns
64544 ** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
64546 ** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
64554 ** The pointer map is a lookup table that identifies the parent page for
64555 ** each child page in the database file. The parent page is the page that
64556 ** contains a pointer to the child. Every page in the database contains
64557 ** 0 or 1 parent pages. (In this context 'database page' refers
64558 ** to any page that is not part of the pointer map itself.) Each pointer map
64559 ** entry consists of a single byte 'type' and a 4 byte parent page number.
64563 ** position in the file to another as part of autovacuum. When a page
64565 ** new location. The pointer map is used to locate the parent page quickly.
64567 ** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
64570 ** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
64573 ** PTRMAP_OVERFLOW1: The database page is the first page in a list of
64574 ** overflow pages. The page number identifies the page that
64575 ** contains the cell with a pointer to this overflow page.
64577 ** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
64578 ** overflow pages. The page-number identifies the previous
64579 ** page in the overflow page list.
64581 ** PTRMAP_BTREE: The database page is a non-root btree page. The page number
64582 ** identifies the parent page in the btree.
64616 ** The aRef[] array is allocated so that there is 1 bit for each page in
64617 ** the database. As the integrity-check proceeds, for each page used in
64626 u8 *aPgRef; /* 1 bit per page in the db (see above) */
64996 ** from the header of a btree page. If the page size is 65536 and the page
65005 #define BTALLOC_ANY 0 /* Allocate any page */
65006 #define BTALLOC_EXACT 1 /* Allocate exact page if possible */
65007 #define BTALLOC_LE 2 /* Allocate any page <= the parameter */
65089 ** with the page number and filename associated with the (MemPage*).
65095 zMsg = sqlite3_mprintf("database corruption page %d of %s",
65117 ** table with root page iRoot. Return 1 if it does and 0 if not.
65119 ** For example, when writing to a table with root-page iRoot via
65125 ** caller should have first obtained a lock specifying the root page of
65131 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
65132 ** hold a write-lock on the schema table (root page 1). This is also
65137 Pgno iRoot, /* Root page of b-tree */
65164 /* Figure out the root-page that the lock should be held on. For table
65165 ** b-trees, this is just the root page of the b-tree being read or
65166 ** written. For index b-trees, it is the root page of the associated
65175 /* Two or more indexes share the same root page. There must
65188 /* Search for the required lock. Either a write-lock on root-page iTab, a
65220 ** rooted at page iRoot, one should call:
65240 ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
65300 ** Add a lock on the table with root-page iTable to the shared-btree used
65474 ** Invalidate the overflow page-list cache for all cursors opened
65493 ** cursors open on any row within the table with root-page pgnoRoot.
65526 ** when a page that previously contained data becomes a free-list leaf
65527 ** page.
65533 ** 1) When all data is deleted from a page and the page becomes
65534 ** a free-list leaf page, the page is not written to the database
65536 ** such a page is not even journalled (as it will not be modified,
65539 ** 2) When a free-list leaf page is reused, its content is not read
65545 ** a page is moved to the free-list and then reused within the same
65546 ** transaction, a problem comes up. If the page is not journalled when
65552 ** The solution is the BtShared.pHasContent bitvec. Whenever a page is
65553 ** moved to become a free-list leaf page, the corresponding bit is
65554 ** set in the bitvec. Whenever a leaf page is extracted from the free-list,
65577 ** This function is called when a free-list leaf page is removed from the
65579 ** page from the pager layer with the 'no-content' flag set. True otherwise.
65695 ** the table with root-page iRoot. "Saving the cursor position" means that
65706 ** If pExpect!=NULL and if no other cursors are found on the same root-page,
65921 ** Given a page number of a regular database page, return the page
65922 ** number for the pointer-map page that contains the entry for the
65923 ** input page number.
65925 ** Return 0 (not a valid page) for pgno==1 since there is
65926 ** no pointer map associated with page 1. The integrity_check logic
65946 ** This routine updates the pointer map entry for page number 'key'
65947 ** so that it maps to type 'eType' and parent page number 'pgno'.
65954 DbPage *pDbPage; /* The pointer map page */
65956 Pgno iPtrmap; /* The pointer map page number */
65957 int offset; /* Offset in pointer map page */
65963 /* The super-journal page number must never be used as a pointer map page */
65979 ** If that byte is set, it means this page is also being used
65980 ** as a btree page. */
66008 ** This routine retrieves the pointer map entry for page 'key', writing
66009 ** the type and parent page number to *pEType and *pPgno respectively.
66013 DbPage *pDbPage; /* The pointer map page */
66014 int iPtrmap; /* Pointer map page index */
66015 u8 *pPtrmap; /* Pointer map page data */
66050 ** Given a btree page and a cell index (0 means the first cell on
66051 ** the page, 1 means the second cell, and so forth) return a pointer
66068 ** on a single B-tree page. Make necessary adjustments to the CellInfo
66076 /* If the payload will not fit completely on the local page, we have
66104 ** page pPage, return the number of bytes of payload stored locally.
66210 ** on the local page. No overflow is required.
66247 ** on the local page. No overflow is required.
66269 ** data area of the btree-page. The return number includes the cell
66270 ** data header and the local payload, but not any overflow page or
66357 ** The cell pCell is currently part of page pSrc but will ultimately be part
66359 ** pointer to an overflow page, insert an entry into the pointer-map for
66360 ** the overflow page that will be valid after pCell has been moved to pPage.
66382 ** Defragment the page given. This routine reorganizes cells within the
66383 ** page so that there are no free-blocks on the free-block list.
66386 ** present in the page after this routine returns.
66389 ** b-tree page so that there are no freeblocks or fragment bytes, all
66391 ** cells are packed tightly at the end of the page.
66396 int hdr; /* Offset to the page header */
66398 int usableSize; /* Number of usable bytes on a page */
66401 int nCell; /* Number of cells on the page */
66402 unsigned char *data; /* The page data */
66426 ** reconstruct the entire page. */
66516 ** Search the free-list on page pPg for space to store a cell nByte bytes in
66530 const int hdr = pPg->hdrOffset; /* Offset to page header */
66548 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
66553 ** fragmented bytes within the page. */
66557 /* This slot extends off the end of the usable part of the page */
66578 /* The free slot chain extends off the end of the page */
66585 ** Allocate nByte bytes of space from within the B-Tree page passed
66615 /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size
66617 ** then the cell content offset of an empty page wants to be 65536.
66670 ** is no way that the allocation can extend off the end of the page.
66690 ** at the end of the page. So do additional corruption checks inside this
66749 ** pointer in the page header) then check to see if iStart should be
66789 ** Decode the flags byte (the first byte of the header) for a page
66811 /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
66812 ** interior table b-tree page. */
66814 /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
66815 ** leaf table b-tree page. */
66829 /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
66830 ** interior index b-tree page. */
66832 /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
66833 ** leaf index b-tree page. */
66841 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
66850 ** Compute the amount of freespace on the page. In other words, fill
66855 u8 hdr; /* Offset to beginning of page header */
66857 int usableSize; /* Amount of usable space on each page */
66858 int nFree; /* Number of unused bytes on the page */
66882 /* Compute the total free space on the page
66884 ** start of the first freeblock on the page, or is zero if there are no
66891 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
66898 /* Freeblock off the end of the page */
66912 /* Last freeblock extends past page end */
66920 ** of the page, then the page must be corrupted. This check also
66922 ** area, according to the page header, lies within the page.
66942 int usableSize; /* Maximum usable space on the page */
66970 ** Return SQLITE_OK on success. If we see that the page does
66971 ** not contain a well-formed database page, then return
66973 ** guarantee that the page is well-formed. It only shows that
66991 ** the b-tree page type. */
67003 ** number of cells on the page. */
67006 /* To many cells for a single page. The page must be corrupt */
67010 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
67011 ** possible for a root page of a table that contains no rows) then the
67012 ** offset to the cell content area will equal the page size minus the
67026 ** Set up a raw page so that it looks like a database page holding
67080 ** Get a page from the pager. Initialize the MemPage.pBt and
67084 ** about the content of the page at this time. So do not go to the disk
67086 ** If in the future we call sqlite3PagerWrite() on this page, that
67092 Pgno pgno, /* Number of the page to fetch */
67093 MemPage **ppPage, /* Return the page in this parameter */
67108 ** Retrieve a page from the pager cache. If the requested page is not
67135 ** Get a page from the pager and initialize it.
67137 ** If pCur!=0 then the page is being fetched as part of a moveToChild()
67138 ** call. Do additional sanity checking on the page in this case.
67141 ** The page is fetched as read-write unless pCur is not NULL and is
67149 Pgno pgno, /* Number of the page to get */
67150 MemPage **ppPage, /* Write the page pointer here */
67151 BtCursor *pCur, /* Cursor to receive the page, or NULL */
67152 int bReadOnly /* True for a read-only page */
67180 /* If obtaining a child page for a cursor, we must verify that the page is
67181 ** compatible with the root page. */
67230 ** Get an unused page.
67234 ** * If the page is already in use for some other purpose, immediately
67240 Pgno pgno, /* Number of the page to fetch */
67241 MemPage **ppPage, /* Return the page in this parameter */
67262 ** the transaction, for each page restored this routine is called.
67265 ** page to agree with the restored data.
67275 /* pPage might not be a btree page; it might be an overflow page
67276 ** or ptrmap page or a free page. In those cases, the following
67279 ** btreeInitPage() be called on every btree page so we make
67280 ** the call for every page that comes in for re-initing. */
67329 u8 nReserve; /* Byte of unused space on each page */
67486 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
67659 ** inserting them into a leaf page (function fillInCell()). If
67664 ** it into a database page. This is not actually a problem, but it
67827 ** Change the default pages size and the number of reserved bytes per page.
67828 ** Or, if the page size has already been fixed, return SQLITE_READONLY
67831 ** The page size must be a power of 2 between 512 and 65536. If the page
67832 ** size supplied does not meet this constraint then the page size is not
67838 ** at the beginning of a page.
67841 ** bytes per page is left unchanged.
67843 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
67876 ** Return the currently defined page size
67901 ** Return the number of bytes of space at the end of every page that
67920 ** Set the maximum page count for a database if mxPage is positive.
67922 ** Regardless of the value of mxPage, return the maximum page count.
67943 ** freelist leaf pages are not written back to the database. Thus in-page
68107 ** required as the version of page 1 currently in the page1 buffer
68138 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
68142 /* EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
68154 ** each page to reserve for extensions.
68161 /* After reading the first page of the database assuming a page size
68162 ** of BtShared.pageSize, we have discovered that the page-size is
68165 ** again with the correct page-size.
68180 ** be less than 480. In other words, if the page size is 512, then the
68195 ** cells can will fit on one page. We assume a 10-byte page header.
68201 ** 4-byte overflow page pointer
68204 ** page pointer.
68253 ** this routine unrefs the first page of the database file which
68272 ** into a new empty database by initializing the first page of
68315 ** Initialize the first page of the database file (creating a database
68316 ** consisting of a single page and no schema objects). Return SQLITE_OK
68421 ** page 1. So if some other shared-cache client already has a write-lock
68422 ** on page 1, the transaction cannot be opened. */
68444 ** reading page 1 it discovers that the page-size of the database
68446 ** pBt->pageSize to the page-size of the file on disk.
68505 ** re-read the database size from page 1 if a savepoint or transaction
68539 ** Set the pointer-map entries for all children of page pPage. Also, if
68545 int nCell; /* Number of cells in page pPage */
68575 ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
68579 ** PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child
68580 ** page of pPage.
68582 ** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow
68583 ** page pointed to by one of the cells on pPage.
68585 ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
68586 ** overflow page in the list.
68592 /* The pointer is always the first 4 bytes of the page in this case. */
68641 ** Move the open database page pDbPage to location iFreePage in the
68645 ** the journal needs to be sync()ed before database page pDbPage->pgno
68647 ** page.
68651 MemPage *pDbPage, /* Open page to move */
68653 Pgno iPtrPage, /* Pointer map 'page-no' entry for pDbPage */
68657 MemPage *pPtrPage; /* The page that contains a pointer to pDbPage */
68668 /* Move page iDbPage from its current location to page number iFreePage */
68669 TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n",
68677 /* If pDbPage was a btree-page, then it may have child pages and/or cells
68681 ** If pDbPage is an overflow page, then the first 4 bytes may store a
68682 ** pointer to a subsequent overflow page. If this is the case, then
68683 ** the pointer map needs to be updated for the subsequent overflow page.
68700 /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
68733 ** that the last page of the file currently in use is no longer in use.
68769 /* Remove the page from the files free-list. This is not required
68784 Pgno iFreePg; /* Index of free page to move pLastPg to */
68794 /* If bCommit is zero, this loop runs exactly once and page pLastPg
68795 ** is swapped with the first free page pulled off the free list.
68798 ** looping until a free-page located within the first nFin pages
68840 int nEntry; /* Number of entries on one ptrmap page */
68918 Pgno iFree; /* The next page to be freed */
68923 /* It is not possible to create a database for which the final page
68924 ** is either a pointer-map page or the pending-byte page. If one
69226 ** call btreeGetPage() on page 1 again to make
69321 ** Create a new cursor for the BTree whose root is on the page
69355 ** No checking is done to make sure that page iTable really is the
69356 ** root page of a b-tree. If it is not, then the cursor acquired
69364 Pgno iTable, /* Root page of table to open */
69429 Pgno iTable, /* Root page of table to open */
69442 Pgno iTable, /* Root page of table to open */
69643 ** Given the page number of an overflow page in the database (parameter
69644 ** ovfl), this function finds the page number of the next page in the
69646 ** pointer-map data instead of reading the content of page ovfl to do so.
69650 ** The page number of the next overflow page in the linked list is
69651 ** written to *pPgnoNext. If page ovfl is the last page in its linked
69655 ** to page number pOvfl was obtained, then *ppPage is set to point to that
69663 Pgno ovfl, /* Current overflow page number */
69665 Pgno *pPgnoNext /* OUT: Next overflow page number */
69675 /* Try to find the next page in the overflow list using the
69676 ** autovacuum pointer-map pages. Guess that the next page in
69677 ** the overflow list is page number (ovfl+1). If that guess turns
69678 ** out to be wrong, fall back to loading the data of page
69679 ** number ovfl to determine the next page number.
69719 ** Copy data from a buffer to a page, or from a page to a buffer.
69721 ** pPayload is a pointer to data stored on database page pDbPage.
69730 void *pPayload, /* Pointer to page data */
69733 int eOp, /* 0 -> copy from page, 1 -> copy to page */
69737 /* Copy data from buffer to page (a write operation) */
69744 /* Copy data from page to buffer (a read operation) */
69761 ** The content being read or written might appear on the main page
69766 ** the overflow page-list cache array (BtCursor.aOverflow).
69770 ** Once an overflow page-list cache has been allocated, it must be
69773 ** mode, the following events may invalidate an overflow page-list cache.
69777 ** * Creating a table (may require moving an overflow page).
69789 MemPage *pPage = pCur->pPage; /* Btree page of current entry */
69815 /* Check if data must be read/written to/from the btree page itself. */
69831 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
69838 ** The aOverflow[] array is sized at one entry for each overflow page
69839 ** in the overflow chain. The page number of the first overflow page is
69860 /* If the overflow page-list cache has been allocated and the
69861 ** entry for the first required overflow page is valid, skip
69873 /* If required, populate the overflow page-list cache. */
69881 /* The only reason to read this page is to obtain the page
69882 ** number for the next page in the overflow chain. The page
69884 ** page-list cache, if any, then fall back to the getOverflowPage()
69896 /* Need to read this page properly. It contains some of the
69908 ** 2) data is required from the start of this overflow page, and
69909 ** 3) there are no dirty pages in the page-cache
69911 ** 5) the page is not in the WAL file
69915 ** output buffer, bypassing the page-cache altogether. This speeds
70028 ** and data to fit on the local page and for there to be no overflow
70035 ** page of the database. The data might change or move the next time
70053 /* There is too little space on the page for the expected amount
70066 ** b-tree page. Write the number of available bytes into *pAmt.
70083 ** Move the cursor down to a new child page. The newPgno argument is the
70084 ** page number of the child page to move to.
70086 ** This function returns SQLITE_CORRUPT if the page-header flags field of
70087 ** the new child page does not match the flags field of the parent (i.e.
70088 ** if an intkey page appears to be the parent of a non-intkey page, or
70112 ** Page pParent is an internal (non-leaf) tree page. This function
70113 ** asserts that page number iChild is the left-child if the iIdx'th
70114 ** cell in page pParent. Or, if iIdx is equal to the total number of
70115 ** cells in pParent, that page number iChild is the right-child of
70116 ** the page.
70133 ** Move the cursor up to the parent page.
70136 ** to the page we are coming from. If we are coming from the
70137 ** right-most child page then pCur->idx is set to one more than
70161 ** Move the cursor to point to the root page of its b-tree structure.
70163 ** If the table has a virtual root page, then the cursor is moved to point
70164 ** to the virtual root page instead of the actual root page. A table has a
70165 ** virtual root page when the actual root page contains no cells and a
70166 ** single child page. This can only happen with the table rooted at page 1.
70171 ** (or virtual root) page and the cursor state is set to CURSOR_VALID.
70174 ** page-header flags indicate that the [virtual] root-page is the expected
70175 ** kind of b-tree page (i.e. if when opening the cursor the caller did not
70231 ** if the root page was already loaded when this function was called (i.e.
70233 ** in such a way that page pRoot is linked into a second b-tree table
70285 ** page to which it is currently pointing. Notice the difference
70288 ** finds the right-most entry beneath the *page*.
70386 ** left pointing at a leaf page which would hold the entry if it
70495 /* pPage->nCell must be greater than zero. If this is the root-page
70497 ** not run. If this is not the root-page, then the moveToChild() routine
70499 ** be the right kind (index or table) of b-tree page. Otherwise
70548 /* The maximum supported page-size is 65536 bytes. This means that
70550 ** page is less than 16384 bytes and may be stored as a 2-byte
70553 ** stored entirely within the b-tree page by inspecting the first
70560 ** b-tree page. */
70567 ** fits entirely on the main b-tree page. */
70706 ** to the next cell on the current page. The (slower) btreeNext() helper
70707 ** routine is called when it is necessary to move to a different page or
70752 ** the page while cursor pCur is holding a reference to it. Which can
70754 ** page into more than one b-tree structure.
70816 ** to the previous cell on the current page. The (slower) btreePrevious()
70817 ** helper routine is called when it is necessary to move to a different page
70892 ** Allocate a new page from the database file.
70894 ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
70895 ** has already been called on the new page.) The new page has also
70897 ** sqlite3PagerUnref() on the new page when it is done.
70903 ** locate a page close to the page number "nearby". This can be used in an
70907 ** If the eMode parameter is BTALLOC_EXACT and the nearby page exists
70909 ** eMode is BTALLOC_LT then the page returned will be less than or equal
70910 ** to nearby if any such page exists. If eMode is BTALLOC_ANY then there
70911 ** are no restrictions on which page is returned.
70915 MemPage **ppPage, /* Store pointer to the allocated page here */
70916 Pgno *pPgno, /* Store the page number here */
70917 Pgno nearby, /* Search for a page near this one */
70946 ** shows that the page 'nearby' is somewhere on the free-list, then
70947 ** the entire-list will be searched for that page.
70967 ** first free-list trunk page. iPrevTrunk is initially 1.
70974 ** is not true. Otherwise, it runs once for each trunk-page on the
70975 ** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT)
70976 ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
70981 /* EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
70982 ** is the page number of the next freelist trunk page in the list or
70983 ** zero if this is the last freelist trunk page. */
70987 ** stores the page number of the first page of the freelist, or zero if
71003 /* EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
71004 ** is the number of leaf page pointers to follow. */
71008 ** So extract the trunk page itself and use it as the newly
71009 ** allocated page */
71028 /* The list is being searched and this trunk page is the page
71049 /* The trunk page is required by the caller but it contains
71051 ** page in this case.
71155 /* There are no pages on the freelist, so append a new page to the
71162 ** steps, then the page we are about to allocate may contain content
71165 ** the current page content before overwriting it.
71168 ** content for any page that really does lie past the end of the database
71182 /* If *pPgno refers to a pointer-map page, allocate two new pages
71183 ** at the end of the file instead of one. The first allocated page
71184 ** becomes a new pointer-map page, the second is used by the caller.
71187 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
71224 ** This function is used to add page iPage to the database file free-list.
71225 ** It is assumed that the page is not already a part of the free-list.
71229 ** corresponding to page iPage handy, it may pass it as the second value.
71236 MemPage *pTrunk = 0; /* Free-list trunk page */
71237 Pgno iTrunk = 0; /* Page number of free-list trunk page */
71238 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
71257 /* Increment the free page count on pPage1 */
71276 ** to indicate that the page is free.
71285 ** trunk page in the free-list is full, then this page will become a
71286 ** new free-list trunk page. Otherwise, it will become a leaf of the
71287 ** first trunk page in the current free-list. This block tests if it
71288 ** is possible to add the page as a new free-list leaf.
71291 u32 nLeaf; /* Initial number of leaf cells on trunk page */
71310 /* In this case there is room on the trunk page to insert the page
71313 ** Note that the trunk page is not really full until it contains
71325 ** avoid using the last six entries in the freelist trunk page array in
71338 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
71344 ** the page being freed as a leaf page of the first trunk in the free-list.
71346 ** first trunk in the free-list is full. Either way, the page being freed
71347 ** will become the new first trunk page in the free-list.
71359 TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, iTrunk));
71380 MemPage *pPage, /* The page that contains the Cell */
71398 /* Cell extends past end of page */
71413 /* 0 is not a legal page number and page 1 cannot be an
71414 ** overflow page. Therefore if ovflPgno<2 or past the end of the
71427 ** to an overflow page belonging to a cell that is being deleted/updated.
71428 ** So if there exists more than one reference to this page, then it
71429 ** must not really be an overflow page and the database must be corrupt.
71431 ** freePage2() may zero the page contents if secure-delete mode is
71432 ** enabled. If this 'overflow' page happens to be a page that the
71451 ** Create the byte sequence used to represent a cell on page pPage
71463 MemPage *pPage, /* The page that contains the cell */
71505 /* This is the common case where everything fits on the btree page
71541 ** pPrior Where to write the pgno of the first overflow page
71588 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
71600 ** overflow page is being allocated, add an entry to the pointer-map
71601 ** for that page now.
71603 ** If this is the first overflow page, then write a partial entry
71657 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
71698 ** If the cell content will fit on the page, then put it there. If it
71710 int i, /* New cell becomes the i-th cell of the page */
71719 u8 *data; /* The content of the whole page */
71749 ** only occur when inserting divider cells into the parent page during
71773 ** a btree page has a value of 3 or less, the pCell value might point
71775 ** the source page. Make sure this does not cause problems by not
71791 /* The cell may contain a pointer to an overflow page. If so, write
71792 ** the entry for the overflow page into the pointer map.
71803 ** of the page that participate in the balancing operation. NB is the
71804 ** total number of pages that participate, including the target page and
71825 ** page plus up to three child pages. There are a total of nCell cells.
71860 ** For an index btree, the apEnd[] array holds pointer to the end of page
71878 ** Sometimes when deleting, a child page can have zero cells. In those
71886 MemPage *pRef; /* Reference page */
71928 ** Array apCell[] contains pointers to nCell b-tree page cells. The
71930 ** replaces the current contents of page pPg with the contents of the cell
71935 ** such cells before overwriting the page data.
71941 CellArray *pCArray, /* Content to be added to page pPg */
71943 int nCell, /* Final number of cells on page */
71944 MemPage *pPg /* The page to be reconstructed */
72009 ** This function attempts to add the cells stored in the array to page pPg.
72010 ** If it cannot (because the page needs to be defragmented before the cells
72015 ** (part of page pPg) to populate. After cell apCell[0] is written to the
72016 ** page body, a 16-bit offset is written to pCellptr. And so on, for each
72021 ** content area on page pPg. If the size of the content area is extended,
72026 ** end of the space required by this page for the cell-pointer area (for
72041 u8 *aData = pPg->aData; /* Complete page */
72046 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
72092 ** The cell-pointers and other fields of the page are not updated.
72142 ** pCArray contains pointers to and sizes of all cells in the page being
72143 ** balanced. The current page, pPg, has pPg->nCell cells starting with
72144 ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
72154 MemPage *pPg, /* Edit this page */
72155 int iOld, /* Index of first cell currently on page */
72156 int iNew, /* Index of new first cell on page */
72157 int nNew, /* Final number of cells on page */
72175 /* Remove cells from the start and end of the page */
72192 /* Add cells to the start of the page */
72223 /* Append cells to the end of the page */
72251 /* Unable to edit this page. Rebuild it from scratch instead. */
72265 ** a new page to the right-hand side and put the one new entry in
72266 ** that page. This leaves the right side of the tree somewhat
72268 ** at the end soon afterwards so the nearly empty page will quickly
72271 ** pPage is the leaf page which is the right-most page in the tree.
72273 ** which is also the right-most entry on the page.
72277 ** byte page number followed by a variable length integer. In other
72283 MemPage *pNew; /* Newly allocated page */
72295 /* Allocate a new page. This page will become the right-sibling of
72296 ** pPage. Make the parent page writable, so that the new divider cell
72326 ** with entries for the new page, and any pointer from the
72327 ** cell on the page to an overflow page. If either of these
72329 ** of the parent page are still manipulated by thh code below.
72330 ** That is Ok, at this point the parent page is guaranteed to
72332 ** rollback, undoing any changes made to the parent page.
72342 ** consists of a 4-byte page number (the page number of pPage) and
72366 /* Set the right-child pointer of pParent to point to the new page. */
72369 /* Release the reference to the new page. */
72421 ** on page pFrom to page pTo. If page pFrom was not a leaf page, then
72422 ** the pointer-map entries for each child page are updated so that the
72423 ** parent page stored in the pointer map is page pTo. If pFrom contained
72424 ** any cells with overflow page pointers, then the corresponding pointer
72425 ** map entries are also updated so that the parent page is page pTo.
72430 ** Before returning, page pTo is reinitialized using btreeInitPage().
72451 /* Copy the b-tree node content from page pFrom to page pTo. */
72456 /* Reinitialize page pTo so that the contents of the MemPage structure
72459 ** page pFrom.
72480 ** (hereafter "the page") and up to 2 siblings so that all pages have about the
72482 ** page are used in the balancing, though both siblings might come from one
72483 ** side if the page is the first or last child of its parent. If the page
72484 ** has fewer than 2 siblings (something which can only happen if the page
72485 ** is a root page or a child of a root page) then all available siblings
72488 ** The number of siblings of the page might be increased or decreased by
72491 ** Note that when this routine is called, some of the cells on the page
72493 ** if the page is overfull. This routine ensures that all cells allocated
72494 ** to the page and its siblings fit into MemPage.aData[] before returning.
72496 ** In the course of balancing the page and its siblings, cells may be
72497 ** inserted into or removed from the parent page (pParent). Doing so
72498 ** may cause the parent page to become overfull or underfull. If this
72507 ** buffer big enough to hold one page. If while inserting cells into the parent
72508 ** page (pParent) the parent page becomes overfull, this buffer is
72510 ** a maximum of four divider cells into the parent page, and the maximum
72512 ** of the page-size, the aOvflSpace[] buffer is guaranteed to be large
72519 MemPage *pParent, /* Parent page of siblings being balanced */
72520 int iParentIdx, /* Index of "the page" in pParent */
72521 u8 *aOvflSpace, /* page-size bytes of space for parent ovfl */
72522 int isRoot, /* True if pParent is a root-page */
72543 int cntNew[NB+2]; /* Index in b.paCell[] of cell after i-th page */
72545 int szNew[NB+2]; /* Combined size of cells placed on i-th page */
72547 Pgno pgno; /* Temp var to store a page number in */
72548 u8 abDone[NB+2]; /* True after i'th new page is populated */
72580 ** This loop also drops the divider cells from the parent page. This
72582 ** overflow cells in the parent page, since if any existed they will
72633 /* Drop the cell from the parent page. apDiv[i] still points to
72732 ** offset section of the btree page will be overwritten and we will no
72780 /* The right pointer of the child page pOld becomes the left
72801 ** size of all cells on the i-th page and cntNew[] which is the index
72802 ** in b.apCell[] of the cell that divides page i from page i+1.
72808 ** szNew[i]: Spaced used on the i-th sibling page.
72810 ** the right of the i-th sibling page.
72923 ** (2) pPage is a virtual root page. A virtual root page is when
72924 ** the real root page is page 1 and we are the only child of
72925 ** that page.
72958 /* Set the pointer-map entry for the new sibling page. */
72969 ** Reassign page numbers so that the new pages are in ascending order.
72990 ** page number. */
72998 int iBest = 0; /* aPgno[] index of page number to use */
73032 ** of the right-most new sibling page is set to the value that was
73033 ** originally in the same field of the right-most old sibling page. */
73045 ** entry associated with the first page in the overflow chain, and
73047 ** b) if the sibling pages are not leaves, the child page associated
73076 /* Cell pCell is destined for new sibling page pNew. Originally, it
73077 ** was either part of sibling page iOld (possibly an overflow cell),
73078 ** or else the divider cell to the left of sibling page iOld. So,
73079 ** if sibling page iOld had the same page number as pNew, and if
73080 ** pCell really was a part of sibling page iOld (not a divider or
73116 ** the sibling-page assembled above only.
73151 ** is important, as this code needs to avoid disrupting any page from which
73155 ** then it is not safe to update page apNew[iPg] until after
73159 ** then it is not safe to update page apNew[iPg] until after
73162 ** If neither of the above apply, the page is safe to update.
73216 /* The root page of the b-tree now contains no cells. The only sibling
73217 ** page is the right-child of the parent. Copy the contents of the
73218 ** child page into the parent, decreasing the overall height of the
73226 ** It is critical that the child page be defragmented before being
73227 ** copied into the parent, because if the parent is page 1 then it will
73243 ** sibling page. All other pointer map entries have already been taken
73289 ** This function is called when the root page of a b-tree structure is
73292 ** A new child page is allocated and the contents of the current root
73293 ** page, including overflow cells, are copied into the child. The root
73294 ** page is then overwritten to make it an empty page with the right-child
73295 ** pointer pointing to the new page.
73298 ** that the new child-page now contains pointers to are updated. The
73300 ** page is also updated.
73303 ** page and SQLITE_OK is returned. In this case the caller is required
73309 MemPage *pChild = 0; /* Pointer to a new child page */
73310 Pgno pgnoChild = 0; /* Page number of the new child page */
73316 /* Make pRoot, the root page of the b-tree, writable. Allocate a new
73317 ** page that will become the new right-child of pPage. Copy the contents
73318 ** of the node stored on pRoot into the new child page.
73379 ** The page that pCur currently points to has just been modified in
73406 /* The root page of the b-tree is overfull. In this case call the
73407 ** balance_deeper() function to create a new child for the root-page
73408 ** and copy the current contents of the root-page to it. The
73409 ** next iteration of the do-loop will balance the child page.
73464 ** will balance the parent page to correct this.
73466 ** If the parent page becomes overfull, the overflow cell or cells
73471 ** different page). Once this subsequent call to balance_nonroot()
73474 ** copied either into the body of a database page or into the new
73497 /* The next iteration of the do-loop balances the parent page. */
73563 Pgno ovflPgno; /* Next overflow page to write */
73564 u32 ovflPageSize; /* Size to write on overflow page */
73792 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
73872 ** back to the root page as balance() used to invalidate the contents
74098 /* If the page containing the entry to delete is not a leaf page, move
74103 ** sub-tree headed by the child page of the cell being deleted. This makes
74124 /* Make the page containing the entry to be deleted writable. Then free any
74126 ** itself from within the page. */
74133 /* If the cell deleted was not located on a leaf page, then the cursor
74135 ** by the child-page of the cell that was just deleted from an internal
74167 /* Balance the tree. If the entry deleted was located on a leaf page,
74168 ** then the cursor still points to that page. In this case the first
74172 ** Otherwise, if the entry deleted was on an internal node page, then
74173 ** pCur is pointing to the leaf page from which a cell was removed to
74218 ** Create a new BTree table. Write into *piTable the page
74219 ** number for the root page of the new table.
74233 int ptfFlags; /* Page-type flage for the root page of new table */
74246 Pgno pgnoMove; /* Move a page here to make room for the root-page */
74247 MemPage *pPageMove; /* The page to move to. */
74250 ** to make room for the new tables root page. In case this page turns
74251 ** out to be an overflow page, delete all overflow page-map caches
74257 ** root page of the new table should go. meta[3] is the largest root-page
74258 ** created so far, so the new root-page is (meta[3]+1).
74266 /* The new root-page may not be allocated on a pointer-map page, or the
74267 ** PENDING_BYTE page.
74275 /* Allocate a page. The page that currently resides at pgnoRoot will
74276 ** be moved to the allocated page (unless the allocated page happens
74285 /* pgnoRoot is the page that will be used for the root-page of
74288 ** by extending the file), the current page at position pgnoMove
74296 ** corresponding to page pgnoRoot. */
74303 /* Move the page currently at pgnoRoot to pgnoMove. */
74321 /* Obtain the page at pgnoRoot */
74338 /* Update the pointer-map and meta-data with the new root-page number. */
74345 /* When the new root page was allocated, page 1 was made writable in
74382 ** Erase the given database page and all its children. Return
74383 ** the page to the freelist.
74388 int freePageFlag, /* Deallocate page if true */
74441 ** the page number of the root of the table. After this routine returns,
74442 ** the root page is empty, but still exists.
74483 ** page 1) is never added to the freelist.
74488 ** If AUTOVACUUM is enabled and the page at iTable is not the last
74489 ** root page in the database file, then the last root page
74491 ** iTable and that last slot formerly occupied by the last root page
74495 ** page number that used to be the last root page in the file before
74496 ** the move. If no page gets moved, *piMoved is set to 0.
74497 ** The last root page is recorded in meta[3] and the value of
74531 /* If the table being dropped is the table with the largest root-page
74532 ** number in the database, put the root page on the free list.
74540 /* The table being dropped does not have the largest root-page
74541 ** number in the database. So move the page that does into the
74542 ** gap left by the deleted root-page.
74565 /* Set the new 'max-root-page' value in the database header. This
74567 ** be a root-page number, less one again if that is the
74687 ** page in the B-Tree structure (not including overflow pages).
74691 MemPage *pPage; /* Current page of the b-tree */
74693 /* If this is a leaf page or the tree is not an int-key tree, then
74694 ** this page contains countable entries. Increment the entry counter
74704 ** the next page in the tree that has not yet been visited. The
74706 ** of the page, or to the number of cells in the page if the next page
74781 ** corresponds to page iPg is already set.
74789 ** Set the bit in the IntegrityCk.aPgRef[] array that corresponds to page iPg.
74798 ** Add 1 to the reference count for page iPage. If this is the second
74799 ** reference to the page, add an error message to pCheck->zErrMsg.
74800 ** Return 1 if there are 2 or more references to the page and 0 if
74801 ** if this is the first reference to the page.
74803 ** Also check that the page number is in bounds.
74807 checkAppendMsg(pCheck, "invalid page number %d", iPage);
74811 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
74821 ** Check that the entry in the pointer-map for page iChild maps to
74822 ** page iParent, pointer type ptrType. If not, append an error message
74827 Pgno iChild, /* Child page number */
74829 Pgno iParent /* Expected pointer map parent page number */
74851 ** Check the integrity of the freelist or of an overflow page list.
74856 int isFreeList, /* True for a freelist. False for overflow page list */
74857 Pgno iPage, /* Page number for first page in the list */
74869 checkAppendMsg(pCheck, "failed to get page %d", iPage);
74882 "freelist leaf count too big on page %d", iPage);
74900 ** page in this overflow list, check that the pointer-map entry for
74901 ** the following page matches iPage.
74939 ** entry represents the span of a cell or freeblock on a btree page.
74974 ** Do various sanity checks on a single page of a tree. Return
74981 ** but combine to completely cover the page.
74989 Pgno iPage, /* Page number of the page to check */
74993 MemPage *pPage = 0; /* The page being analyzed */
74998 int nFrag; /* Number of fragmented bytes on the page */
74999 int hdr; /* Offset to the page header */
75010 u32 usableSize; /* Usable size of the page */
75019 /* Check that the page exists
75029 "unable to get the page. error code=%d", rc);
75052 pCheck->zPfx = "On tree page %u cell %d: ";
75057 ** number of cells on the page. */
75061 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
75062 ** immediately follows the b-tree page header. */
75068 /* Analyze the right-child page of internal pages */
75072 pCheck->zPfx = "On page %u at right child: ";
75104 checkAppendMsg(pCheck, "Extends off end of page");
75115 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
75121 Pgno pgnoOvfl; /* First page of the overflow chain */
75134 /* Check sanity of left child page for internal pages */
75144 checkAppendMsg(pCheck, "Child page depth differs");
75154 /* Check for complete coverage of the page
75173 ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
75175 ** freeblocks on the page.
75185 ** big-endian integer which is the offset in the b-tree page of the next
75199 ** There is an implied first entry the covers the page header, the cell
75213 "Multiple uses for byte %u of page %u", x>>16, iPage);
75222 ** is stored in the fifth field of the b-tree page header.
75228 "Fragmentation of %d bytes reported as %d on page %u",
75246 ** an array of pages numbers were each page number is the root page of
75261 ** and the checks to make sure every page is referenced are also skipped,
75372 /* Make sure every page in the file is referenced
75390 checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
75531 ** Obtain a lock on the table whose root page is iTab. The
75582 ** version of the b-tree page modified by the accessPayload call below.
75671 ** Return the size of the header added to each page by this module.
75722 Pgno iNext; /* Page number of the next source page to copy */
75751 ** the page cache associated with the source database. The mutex
75805 ** Attempt to set the page size of the destination to match the page size
75919 ** page iSrcPg from the source database. Copy this data into the
75924 Pgno iSrcPg, /* Source database page to backup */
75925 const u8 *zSrcData, /* Source database page data */
75943 ** page sizes of the source and destination differ.
75949 /* This loop runs once for each destination page spanned by the source
75950 ** page. For each iteration, variable iOff is set to the byte offset
75951 ** of the destination page.
75964 /* Copy the data from the source page into the destination page.
75967 ** of the page 'extra' space to invalidate the Btree layers
75968 ** cached parse of the page). MemPage.isInit is marked
76019 int pgszSrc = 0; /* Source page size */
76020 int pgszDest = 0; /* Destination page size */
76059 ** try to set its page size to the same as the source database. This
76061 ** not possible to create a database file that uses one page size by
76076 ** and the page sizes are different between source and destination */
76090 const Pgno iSrcPg = p->iNext; /* Source page number */
76092 DbPage *pSrcPg; /* Source page object */
76135 ** database. The complication here is that the destination page
76136 ** size may be different to the source page size.
76138 ** If the source page size is smaller than the destination page size,
76142 ** destination file that lie beyond the nDestTruncate page mark are
76160 /* If the source page-size is smaller than the destination page-size,
76166 ** pending-byte page in the source database may need to be
76349 ** This function is called after the contents of page iPage of the
76350 ** source database have been modified. If page iPage has already been
76369 /* The backup process p has already copied page iPage. But now it
77673 u32 available = 0; /* Number of bytes available on the local btree page */
88611 assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */
88650 ** than a few bytes. Even if the record occurs at the end of the page
88651 ** content area, the "page header" comes after the page content and so
88752 ** page - where the content is not on an overflow page */
89168 ** every btree page of the table. But if P3 is non-zero, an estimate
89639 ** Open a read-only cursor for the database table whose root page is
89690 ** page is P2 (or whose root page is held in register P2 if the
89712 ** as the root page, not the value of P2 itself.
89808 ** SQLite used to check if the root-page flags were sane at this point
89938 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
91360 ** into the database page. That means that the content of the output
92108 ** Delete an entire database table or index whose root page in the database
92115 ** If AUTOVACUUM is enabled then it is possible that another root page
92116 ** might be moved into the newly deleted root page in order to keep all
92118 ** value of the root page that moved - its value before the move occurred -
92119 ** is stored in register P2. If no page movement was required (because the
92126 ** updating existing cursors when a root page is moved in an AUTOVACUUM
92168 ** Delete all contents of the database table or index whose root page
92238 ** The root page number of the new b-tree is stored in register P2.
92420 ** The root page numbers of all tables in the database are integers
93359 ** P2 contains the root-page of the table to lock.
93795 ** Try to set the maximum page count for database P1 to the value in P3.
93796 ** Do not let the maximum page count fall below the current page count and
93797 ** do not change the maximum page count value if P3==0.
93799 ** Store the maximum page count after the change in register P2.
94834 ** page-cache of the main database. Specifically, the threshold is set to
95068 int pgsz; /* Main database page size */
95157 ** size. But I/O is more efficient if it occurs in page-sized blocks where
95158 ** each block is aligned on a page boundary. This object caches writes to
95159 ** the PMA so that aligned, page-size blocks are written.
96548 ** than (page-size * cache-size), or
96551 ** than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
98112 ** journal data to roll back changes made to the internal page-cache
111613 Pgno iTab; /* The root page of the table to be locked */
111621 ** The table to be locked has root page iTab and is found in database iDb.
111631 Pgno iTab, /* Root page number of the table to be locked */
112808 ** The root page number of the new table is left in reg pParse->regRoot.
112809 ** The rowid and root page number values are needed by the code that
113819 /* The root page of the PRIMARY KEY is the table root page */
113995 ** So do not write to the disk again. Extract the root page number
113996 ** for the table from the db->init.newTnum field. (The page number
113999 ** If the root page number is 1, that means this is the sqlite_schema
114119 ** statement to populate the new table. The root-page number for the
114490 ** used by SQLite when the btree layer moves a table root page. The
114491 ** root-page of a table or index in database iDb has changed from iFrom
114531 ** Write code to erase the table with root-page iTable from database iDb.
114533 ** if a root-page of another table is moved by the btree-layer whilst
114544 ** is non-zero, then it is the root page number of a table moved to
114563 ** in case a root-page belonging to another table is moved by the btree layer
114570 ** largest root-page number. This guarantees that none of the root-pages
114578 ** and root page 5 happened to be the largest root-page number in the
114579 ** database, then root page 5 would be moved to page 4 by the
114581 ** a free-list page.
115006 ** root page number of the index. If memRootPage is negative, then
115008 ** the root page number of the index is taken from pIndex->tnum.
115017 Pgno tnum; /* Root page of index */
128039 ** page cache size. The value returned is the maximum number of
128040 ** pages in the page cache. The second form sets both the current
128041 ** page cache size value and the persistent page cache size value
128091 ** database page size in bytes. The second form sets the
128092 ** database page size value. The value can only be set if
128102 /* Malloc may fail when setting the page-size, as there is an internal
128373 ** page cache size. The second form sets the local
128374 ** page cache size value. If N is positive then that is the
128397 ** page cache spill size. The second form turns cache spill on
128407 ** cache_size pages, no spilling occurs until the page count exceeds
129130 int *aRoot; /* Array of root page numbers of all btrees */
130195 ** of pIndex has the same root page number, and if it does, return true.
130228 ** argv[3] = root page number for table or index. 0 for trigger or view.
130306 ** to do here is record the root page number for that index.
130410 ** meta[2] Size of the page cache.
138159 Pgno iRoot = pTab->tnum; /* Root page of scanned b-tree */
141658 ** original database is required. Every page of the database is written
141660 ** Two writes per page are required in step (3) because the original
141727 int nRes; /* Bytes of reserved space at the end of each page */
141811 ** to ensure that we do not try to change the page-size on a WAL database.
141818 /* Do not attempt to change the page size for a WAL database */
141903 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
141915 ** we already have page 1 loaded into cache and marked dirty. */
164573 ** the size of each page cache line (sz), and the number of cache lines
164583 ** that integer the number of extra bytes per page required for each page
164605 ** object. This object specifies the interface to a custom page cache
164613 ** object. SQLite copies of the current page cache implementation into
167696 sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno);
168242 ** or off. "tnum" is the root page of the b-tree to which the imposter
170750 ** Store the current database page-size in bytes in p->nPgsz.
171520 /* Figure out the page-size for the database. This is required in order to
171903 int isFirstTerm = 1; /* True when processing first term on page */
174918 ** of data that will fit on a single leaf page of an intkey table in
182462 int nReq; /* Number of bytes required on leaf page */
183933 sqlite3_int64 nLeafData; /* Bytes of leaf page data so far */
184881 Blob root = {0,0,0}; /* New root page image */
191249 ** child page.
192110 ** an internal node, then the 64-bit integer is a child page number.
193378 RtreeNode **ppLeaf /* OUT: Selected leaf page */
194835 ** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
194836 ** This ensures that each node is stored on a single database page. If the
194837 ** database page-size is so large that more than RTREE_MAXCELLS entries
195284 ** Argument pCell points to an array of coordinates stored on an rtree page.
195290 ** the array of coordinates on the parent page that bound the page
195360 int nCell; /* Number of cells on page */
198494 ** The problem is that in order to update a b-tree, the leaf page (at least)
198506 ** and all but guarantees each modified leaf page is loaded and stored
198999 ** sqlite3rbu_step() will copy a page of data from the *-wal file into
199262 int iTnum; /* Root page of current object */
199313 ** file should be copied to page iDbPage of the database file.
200143 ** is set to the root page number of the primary key index before
201018 int tnum = pIter->iPkTnum; /* Root page of PK index */
201942 ** The checksum is store in the first page of xShmMap memory as an 8-byte
201963 ** (wal frame -> db page) copy operations required to checkpoint the
201995 ** do not perform any IO. Instead, the frame/page combinations that
202009 ** array populated with a set of (frame -> page) mappings. Because the
202086 ** Called when a page of data is written to offset iOff of the database
202087 ** file while the rbu handle is in capture mode. Record the page number
202088 ** of the page being written in the aFrame[] array.
202465 ** throw an SQLITE_SCHEMA exception. The only database page the
202466 ** statement reads is page 1, which is guaranteed to be in the cache.
202710 ** However, if the sector-size is larger than the page-size, and the
202713 ** then the database page written here may be damaged. Work around
202714 ** this by checkpointing frames until the next page in the aFrame[]
203019 ** page 1 of the database file. */
203338 ** 1. Whenever the first page of a main database file is read or
203384 ** Instead the frame and page numbers that would be read and written
203567 /* If this is being called to read the first page of the target
203569 ** contents of the first page if it does not yet exist. Otherwise,
203581 rbuPutU32(&aBuf[52], iRoot); /* largest root page number */
203583 rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
203685 ** pretend that it has at least one page. Otherwise, SQLite will not
203846 ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
204072 ** in wal mode, even if the first page of the database file has
204318 ** Additional information is available on the "dbstat.html" page of the
204330 ** root-node of the b-tree structure to each page. The value of the
204333 ** The value of the path for the left-most child page of the root of
204336 ** The next to left-most child of the root page is
204337 ** '/001', and so on, each sibling page identified by a 3-digit hex
204344 ** the left-most cell of the 450th child of the root page are identified
204347 ** '/1c2/000+000000' // First page in overflow chain
204348 ** '/1c2/000+000001' // Second page in overflow chain
204349 ** '/1c2/000+000002' // Third page in overflow chain
204353 ** sort-order than its child page:
204360 " path TEXT," /* 1 Path to page from root (NULL for agg) */
204361 " pageno INTEGER," /* 2 Page number (page count for aggregates) */
204363 " ncell INTEGER," /* 4 Cells on page (0 for overflow) */
204364 " payload INTEGER," /* 5 Bytes of payload on this page */
204365 " unused INTEGER," /* 6 Bytes of unused space on this page */
204367 " pgoffset INTEGER," /* 8 Offset of page in file (NULL for agg) */
204368 " pgsize INTEGER," /* 9 Size of the page (sum for aggregate) */
204380 /* Size information for a single cell within a btree page */
204385 u32 *aOvfl; /* Array of overflow page numbers */
204386 int nLastOvfl; /* Bytes of payload on final overflow page */
204390 /* Size information for a single btree page */
204396 char *zPath; /* Path to this page */
204400 int nCell; /* Number of cells on page */
204401 int nUnused; /* Number of unused bytes on page */
204403 u32 iRightChildPg; /* Right-child page number (or 0) */
204404 int nMxPayload; /* Largest payload of any cell on the page */
204415 StatPage aPage[32]; /* Pages in path to current page */
204647 ** For a single cell on a btree page, compute the number of bytes of
204648 ** content (payload) stored on that page. That is to say, compute the
204652 int nUsable, /* Usable bytes per page */
204674 ** cells found on the page currently under analysis.
204717 int nUsable; /* Usable bytes per page */
204798 /* If connected to a ZIPVFS backend, find the page size and
204807 /* Not ZIPVFS: The default page size and offset */
204815 ** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
204966 ** next page. The loop will exit via the return at label-statNext-done
205184 ** value must be a BLOB which is the correct page size, otherwise the
205197 int pgno; /* Current page number */
205198 int mxPgno; /* Last page to visit on this scan */
205202 int szPage; /* Size of each page in bytes */
205491 zErr = "bad page number";
205498 zErr = "bad page value";
211827 ** field that occurs at the start of each leaf page (see fts5_index.c). */
211964 int pgsz; /* Approximate page size used in %_data */
215256 /* Maximum allowed page size */
219837 ** * all segment b-tree leaf data is stored in fixed size page records
219844 ** records that contain a copy of the first rowid on each page spanned by
219898 ** + first leaf page number (often 1, always greater than 0)
219899 ** + final leaf page number
219914 ** on the leaf page, is:
219955 ** Each leaf page begins with a 4-byte header containing 2 16-bit
219958 ** * The byte offset of the first rowid on the page, if it exists
219961 ** * The byte offset of the start of the page footer. If the page
219963 ** size of the leaf page in bytes.
219965 ** The page footer consists of a single varint for each term located
219966 ** on the page. Each varint is the byte offset of the current term
219967 ** within the page, delta-compressed against the previous value. In
219973 ** term/doclist data fits on a single leaf page. If this is not the case,
219976 ** + if the first rowid on a page occurs before the first term, it
219981 ** + the first term on each page is stored in the same way as the
219990 ** a single leaf record only. The format of each doclist index leaf page
219994 ** 0x01: Clear if leaf is also the root page, otherwise set.
219996 ** * Page number of fts index leaf page. As a varint.
219998 ** * First rowid on page indicated by previous field. As a varint.
220000 ** * A list of varints, one for each subsequent termless page. A
220001 ** positive delta if the termless page contains at least one rowid,
220007 ** 0x01: Clear for root page, otherwise set.
220009 ** * Page number of first child page. As a varint.
220011 ** * Copy of first rowid on page indicated by previous field. As a varint.
220014 ** child page.
220032 ** the leaf page number to the FTS5_SEGMENT_ROWID macro. Leaves are numbered
220038 #define FTS5_DATA_PAGE_B 31 /* Max page number of 2147483648 */
220079 int szLeaf; /* Size of leaf without page-index */
220133 int pgnoFirst; /* First leaf page number in segment */
220134 int pgnoLast; /* Last leaf page number in segment */
220153 int pgno; /* Page number for this page */
220156 Fts5Buffer pgidx; /* Buffer containing page-index */
220157 Fts5Buffer term; /* Buffer containing previous term on page */
220160 int pgno; /* Page number for this page */
220162 i64 iPrev; /* Previous rowid value written to page */
220163 Fts5Buffer buf; /* Buffer containing page data */
220170 u8 bFirstRowidInPage; /* True if next rowid is first in page */
220198 ** Current leaf page number within segment.
220205 ** is the last thing on the leaf page.
220208 ** Buffer containing current leaf page data. Set to NULL at EOF.
220211 ** Leaf page number containing the last term read from the segment. And
220229 ** For each rowid on the page corresponding to the current term, the
220231 ** start of the "position-list-size" field within the page.
220239 int iLeafPgno; /* Current leaf page number */
220241 Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */
220247 /* The page and offset from which the current term was read. The offset
220271 ** leaf page.
220282 ** page. This macro evaluates to true if the leaf contains no terms, or
220348 Fts5Data *pData; /* Data for current page of this level */
220354 int iLeafPgno; /* Page number of current leaf page */
221081 ** doclist-index page is reached, return non-zero.
221147 ** When this function is called pIter->iLeafPgno is the page number the
221166 /* Advance each level to the last entry on the last page */
221279 int iLeafPg /* Leaf page number to load dlidx for */
221330 ** Load the next leaf page into the segment iterator.
221334 Fts5SegIter *pIter /* Iterator to advance to next page */
221543 ** the position-list size field for the first relevant rowid on the page.
221547 ** relevant rowid on the page and, if necessary, initializes the
221619 ** thing on the page - i.e. the first rowid is on the following page.
221715 /* Next entry is on the next page */
221724 /* Next entry is on the current page */
221788 /* Search for the end of the position list within the current page. */
221796 /* The next entry is on the current page. */
221835 /* Next entry is not on the current page */
221930 ** term may not be stored on the current page. So search forward to
221936 /* The last rowid in the doclist may not be on the current page. Search
221937 ** forward to find the page containing the last rowid. */
221957 ** lies on the page currently indicated by the iterator. In this case
221959 ** field associated with the first relevant rowid on the page.
221961 ** Or, if pLast is non-NULL, then it is the page that contains the last
221963 ** first rowid on this page.
221988 ** page. If the current term is the last term on the page, load the
221999 /* Check if the current doclist ends on this page. If it does, return
222014 ** function searches the leaf page for a term matching (pTerm/nTerm).
222016 ** If the specified term is found on the page, then the iterator is left
222023 ** current page.
222188 /* This block sets stack variable iPg to the leaf page number that may
222468 ** Move the seg-iter so that it points to the first rowid on page iLeafPgno.
223032 /* All data is stored on the current page. Populate the output
223033 ** variables to point into the body of the page object. */
223057 ** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
223125 /* All data is stored on the current page. Populate the output
223126 ** variables to point into the body of the page object. */
223525 ** last term on leaf page (pWriter->iBtPage) is completed.
223532 ** Fts5SegWriter.btterm currently contains the first term on page iBtPage.
223555 ** This is called once for each leaf page except the first that contains
223566 int nTerm, const u8 *pTerm /* First term on new page */
223576 ** This function is called when flushing a leaf page that contains no
223583 /* If there were no rowids on the leaf page either and the doclist-index
223605 ** Rowid iRowid has just been appended to the current leaf page. It is the
223606 ** first on the page. This function appends an appropriate entry to the current
223622 /* The current doclist-index page is full. Write it to disk and push
223624 ** doclist-index leaf page) up into the next level of the b-tree
223681 /* No term was written to this page. */
223685 /* Append the pgidx to the page buffer. Set the szLeaf header field. */
223689 /* Write the page out to disk */
223693 /* Initialize the next page. */
223729 /* If the current leaf page is full, flush it to disk. */
223778 ** to the page. */
223808 /* If this is to be the first rowid written to the page, set the
223809 ** rowid-pointer in the page-header. Also append a value to the dlidx
223922 /* Initialize the 4-byte leaf-page header to 0x00. */
223948 ** Set both the first and last page-numbers to 0 to indicate that the
223953 int iOff = pSeg->iTermLeafOffset; /* Offset on new first leaf page */
223964 ** a single page has been assigned to more than one segment. In
223980 /* Set up the new page-index array */
224125 /* Flush the last leaf page to disk. Set the output segment b-tree height
224126 ** and last leaf page number at the same time. */
224305 int pgnoLast = 0; /* Last leaf page number in segment */
224317 Fts5Buffer *pBuf; /* Buffer in which to assemble leaf page */
224363 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
225841 ** is also a rowid pointer within the leaf page header, it points to a
225898 /* Check that the leaf page indicated by the iterator really does
225930 /* Page iter.iLeaf must now be the rightmost leaf-page in the segment */
226297 Fts5Buffer term; /* Current term read from page */
226345 Fts5Buffer term; /* Current term read from page */
226370 /* Decode the position list tail at the start of the page */
226384 /* Decode any more doclist data that appears on the page before the
226394 int bFirst = (iPgidxOff==szLeaf); /* True for first term on page */