MySQL 8.0.31
Source Code Documentation
page0page.ic File Reference

Index page routines. More...

#include "mach0data.h"
#include "log0recv.h"
#include "rem0cmp.h"
#include "mtr0log.h"
#include "page0zip.h"

Functions

static page_tpage_align (const void *ptr)
 Gets the start of a page. More...
 
static ulint page_offset (const void *ptr)
 Gets the offset within a page. More...
 
static trx_id_t page_get_max_trx_id (const page_t *page)
 Returns the max trx id field value. More...
 
static void page_update_max_trx_id (buf_block_t *block, page_zip_des_t *page_zip, trx_id_t trx_id, mtr_t *mtr)
 Sets the max trx id field value if trx_id is bigger than the previous value. More...
 
static node_seq_t page_get_ssn_id (const page_t *page)
 Returns the RTREE SPLIT SEQUENCE NUMBER (FIL_RTREE_SPLIT_SEQ_NUM). More...
 
static void page_set_ssn_id (buf_block_t *block, page_zip_des_t *page_zip, node_seq_t ssn_id, mtr_t *mtr)
 Sets the RTREE SPLIT SEQUENCE NUMBER field value. More...
 
static void page_header_set_field (page_t *page, page_zip_des_t *page_zip, ulint field, ulint val)
 Sets the given header field. More...
 
static ulint page_header_get_offs (const page_t *page, ulint field)
 
static void page_header_set_ptr (page_t *page, page_zip_des_t *page_zip, ulint field, const byte *ptr)
 Sets the pointer stored in the given header field. More...
 
static void page_header_reset_last_insert (page_t *page, page_zip_des_t *page_zip, mtr_t *mtr)
 Resets the last insert info field in the page header. More...
 
static bool page_is_comp (const page_t *page)
 Determine whether the page is in new-style compact format. More...
 
static bool page_rec_is_comp (const rec_t *rec)
 true if the record is on a page in compact format. More...
 
static ulint page_rec_get_heap_no (const rec_t *rec)
 Returns the heap number of a record. More...
 
static bool page_is_leaf (const page_t *page)
 Determine whether the page is a B-tree leaf. More...
 
static bool page_is_empty (const page_t *page)
 Determine whether the page is empty. More...
 
static bool page_is_root (const page_t *page)
 Determine whether a page is an index root page. More...
 
static bool page_has_garbage (const page_t *page)
 Determine whether the page contains garbage. More...
 
static ulint page_get_infimum_offset (const page_t *page)
 Gets the offset of the first record on the page. More...
 
static ulint page_get_supremum_offset (const page_t *page)
 Gets the offset of the last record on the page. More...
 
static bool page_rec_is_user_rec_low (ulint offset)
 true if the record is a user record on the page. More...
 
static bool page_rec_is_supremum_low (ulint offset)
 true if the record is the supremum record on a page. More...
 
static bool page_rec_is_infimum_low (ulint offset)
 true if the record is the infimum record on a page. More...
 
static bool page_rec_is_user_rec (const rec_t *rec)
 true if the record is a user record on the page. More...
 
static bool page_rec_is_supremum (const rec_t *rec)
 true if the record is the supremum record on a page. More...
 
static bool page_rec_is_infimum (const rec_t *rec)
 true if the record is the infimum record on a page. More...
 
static bool page_rec_is_first (const rec_t *rec, const page_t *page)
 
static bool page_rec_is_second (const rec_t *rec, const page_t *page)
 
static bool page_rec_is_last (const rec_t *rec, const page_t *page)
 
static bool page_rec_distance_is_at_most (const rec_t *left_rec, const rec_t *right_rec, ulint val)
 
static bool page_rec_is_second_last (const rec_t *rec, const page_t *page)
 
static rec_tpage_rec_get_nth (page_t *page, ulint nth)
 Returns the nth record of the record list. More...
 
static rec_tpage_get_middle_rec (page_t *page)
 Returns the middle record of the records on the page. More...
 
static page_no_t page_get_page_no (const page_t *page)
 Gets the page number. More...
 
static space_id_t page_get_space_id (const page_t *page)
 Gets the tablespace identifier. More...
 
static page_id_t page_get_page_id (const page_t *page)
 
static ulint page_get_n_recs (const page_t *page)
 Gets the number of user records on page (infimum and supremum records are not user records). More...
 
static ulint page_dir_get_n_slots (const page_t *page)
 Gets the number of dir slots in directory. More...
 
static void page_dir_set_n_slots (page_t *page, page_zip_des_t *page_zip, ulint n_slots)
 Sets the number of dir slots in directory. More...
 
static void page_dir_set_n_heap (page_t *page, page_zip_des_t *page_zip, ulint n_heap)
 Sets the number of records in the heap. More...
 
static page_dir_slot_tpage_dir_get_nth_slot (const page_t *page, ulint n)
 Gets pointer to nth directory slot. More...
 
static bool page_rec_check (const rec_t *rec)
 Used to check the consistency of a record on a page. More...
 
static const rec_tpage_dir_slot_get_rec (const page_dir_slot_t *slot)
 Gets the record pointed to by a directory slot. More...
 
static void page_dir_slot_set_rec (page_dir_slot_t *slot, rec_t *rec)
 This is used to set the record offset in a directory slot. More...
 
static ulint page_dir_slot_get_n_owned (const page_dir_slot_t *slot)
 Gets the number of records owned by a directory slot. More...
 
static void page_dir_slot_set_n_owned (page_dir_slot_t *slot, page_zip_des_t *page_zip, ulint n)
 This is used to set the owned records field of a directory slot. More...
 
static ulint page_dir_calc_reserved_space (ulint n_recs)
 Calculates the space reserved for directory slots of a given number of records. More...
 
static const rec_tpage_rec_get_next_low (const rec_t *rec, ulint comp)
 Gets the pointer to the next record on the page. More...
 
static rec_tpage_rec_get_next (rec_t *rec)
 Gets the pointer to the next record on the page. More...
 
static const rec_tpage_rec_get_next_const (const rec_t *rec)
 Gets the pointer to the next record on the page. More...
 
static const rec_tpage_rec_get_next_non_del_marked (const rec_t *rec)
 Gets the pointer to the next non delete-marked record on the page. More...
 
static void page_rec_set_next (rec_t *rec, const rec_t *next)
 Sets the pointer to the next record on the page. More...
 
static const rec_tpage_rec_get_prev_const (const rec_t *rec)
 Gets the pointer to the previous record. More...
 
static rec_tpage_rec_get_prev (rec_t *rec)
 Gets the pointer to the previous record. More...
 
static rec_tpage_rec_find_owner_rec (rec_t *rec)
 Looks for the record which owns the given record. More...
 
static ulint page_rec_get_base_extra_size (const rec_t *rec)
 Returns the base extra size of a physical record. More...
 
static ulint page_get_data_size (const page_t *page)
 Returns the sum of the sizes of the records in the record list, excluding the infimum and supremum records. More...
 
static void page_mem_alloc_free (page_t *page, page_zip_des_t *page_zip, rec_t *next_rec, ulint need)
 Allocates a block of memory from the free list of an index page. More...
 
static ulint page_get_free_space_of_empty (bool comp)
 Calculates free space if a page is emptied. More...
 
static ulint page_get_max_insert_size (const page_t *page, ulint n_recs)
 Each user record on a page, and also the deleted user records in the heap takes its size plus the fraction of the dir cell size / PAGE_DIR_SLOT_MIN_N_OWNED bytes for it. More...
 
static ulint page_get_max_insert_size_after_reorganize (const page_t *page, ulint n_recs)
 Returns the maximum combined size of records which can be inserted on top of the record heap if a page is first reorganized. More...
 
static void page_mem_free (page_t *page, page_zip_des_t *page_zip, rec_t *rec, const dict_index_t *index, const ulint *offsets)
 Puts a record to free list. More...
 
ulong page_size_validate (ulong page_size)
 Check that a page_size is correct for InnoDB. More...
 

Detailed Description

Index page routines.

Created 2/2/1994 Heikki Tuuri

Function Documentation

◆ page_align()

static page_t * page_align ( const void *  ptr)
inlinestatic

Gets the start of a page.

Returns
start of the page
Parameters
ptrin: pointer to page frame

◆ page_dir_calc_reserved_space()

static ulint page_dir_calc_reserved_space ( ulint  n_recs)
inlinestatic

Calculates the space reserved for directory slots of a given number of records.

The exact value is a fraction number n * PAGE_DIR_SLOT_SIZE / PAGE_DIR_SLOT_MIN_N_OWNED, and it is rounded upwards to an integer.

Parameters
n_recsin: number of records

◆ page_dir_get_n_slots()

static ulint page_dir_get_n_slots ( const page_t page)
inlinestatic

Gets the number of dir slots in directory.

Returns
number of slots
Parameters
pagein: index page

◆ page_dir_get_nth_slot()

static page_dir_slot_t * page_dir_get_nth_slot ( const page_t page,
ulint  n 
)
inlinestatic

Gets pointer to nth directory slot.

Returns
pointer to dir slot
Parameters
pagein: index page
nin: position

◆ page_dir_set_n_heap()

static void page_dir_set_n_heap ( page_t page,
page_zip_des_t page_zip,
ulint  n_heap 
)
inlinestatic

Sets the number of records in the heap.

Parameters
pagein/out: index page
page_zipin/out: compressed page whose uncompressed part will be updated, or NULL. Note that the size of the dense page directory in the compressed page trailer is n_heap * PAGE_ZIP_DIR_SLOT_SIZE.
n_heapin: number of records

◆ page_dir_set_n_slots()

static void page_dir_set_n_slots ( page_t page,
page_zip_des_t page_zip,
ulint  n_slots 
)
inlinestatic

Sets the number of dir slots in directory.

Parameters
pagein/out: page
page_zipin/out: compressed page whose uncompressed part will be updated, or NULL
n_slotsin: number of slots

◆ page_dir_slot_get_n_owned()

static ulint page_dir_slot_get_n_owned ( const page_dir_slot_t slot)
inlinestatic

Gets the number of records owned by a directory slot.

Returns
number of records
Parameters
slotin: page directory slot

◆ page_dir_slot_get_rec()

static const rec_t * page_dir_slot_get_rec ( const page_dir_slot_t slot)
inlinestatic

Gets the record pointed to by a directory slot.

Returns
pointer to record
Parameters
slotin: directory slot

◆ page_dir_slot_set_n_owned()

static void page_dir_slot_set_n_owned ( page_dir_slot_t slot,
page_zip_des_t page_zip,
ulint  n 
)
inlinestatic

This is used to set the owned records field of a directory slot.

Parameters
slotin/out: directory slot
page_zipin/out: compressed page, or NULL
nin: number of records owned by the slot

◆ page_dir_slot_set_rec()

static void page_dir_slot_set_rec ( page_dir_slot_t slot,
rec_t rec 
)
inlinestatic

This is used to set the record offset in a directory slot.

Parameters
slotin: directory slot
recin: record on the page

◆ page_get_data_size()

static ulint page_get_data_size ( const page_t page)
inlinestatic

Returns the sum of the sizes of the records in the record list, excluding the infimum and supremum records.

Returns
data in bytes
Parameters
pagein: index page

◆ page_get_free_space_of_empty()

static ulint page_get_free_space_of_empty ( bool  comp)
inlinestatic

Calculates free space if a page is emptied.

Returns
free space
Parameters
compin: nonzero=compact page layout

◆ page_get_infimum_offset()

static ulint page_get_infimum_offset ( const page_t page)
inlinestatic

Gets the offset of the first record on the page.

Returns
offset of the first record in record list, relative from page
Parameters
pagein: page which must have record(s)

◆ page_get_max_insert_size()

static ulint page_get_max_insert_size ( const page_t page,
ulint  n_recs 
)
inlinestatic

Each user record on a page, and also the deleted user records in the heap takes its size plus the fraction of the dir cell size / PAGE_DIR_SLOT_MIN_N_OWNED bytes for it.

If the sum of these exceeds the value of page_get_free_space_of_empty, the insert is impossible, otherwise it is allowed. This function returns the maximum combined size of records which can be inserted on top of the record heap.

Returns
maximum combined size for inserted records
Parameters
pagein: index page
n_recsin: number of records

◆ page_get_max_insert_size_after_reorganize()

static ulint page_get_max_insert_size_after_reorganize ( const page_t page,
ulint  n_recs 
)
inlinestatic

Returns the maximum combined size of records which can be inserted on top of the record heap if a page is first reorganized.

Returns
maximum combined size for inserted records
Parameters
pagein: index page
n_recsin: number of records

◆ page_get_max_trx_id()

static trx_id_t page_get_max_trx_id ( const page_t page)
inlinestatic

Returns the max trx id field value.

Parameters
pagein: page

◆ page_get_middle_rec()

static rec_t * page_get_middle_rec ( page_t page)
inlinestatic

Returns the middle record of the records on the page.

If there is an even number of records in the list, returns the first record of the upper half-list.

Returns
middle record
Parameters
pagein: page

◆ page_get_n_recs()

static ulint page_get_n_recs ( const page_t page)
inlinestatic

Gets the number of user records on page (infimum and supremum records are not user records).

Returns
number of user records
Parameters
pagein: index page

◆ page_get_page_id()

static page_id_t page_get_page_id ( const page_t page)
inlinestatic

◆ page_get_page_no()

static page_no_t page_get_page_no ( const page_t page)
inlinestatic

Gets the page number.

Returns
page number
Parameters
pagein: page

◆ page_get_space_id()

static space_id_t page_get_space_id ( const page_t page)
inlinestatic

Gets the tablespace identifier.

Returns
space id
Parameters
pagein: page

◆ page_get_ssn_id()

static node_seq_t page_get_ssn_id ( const page_t page)
inlinestatic

Returns the RTREE SPLIT SEQUENCE NUMBER (FIL_RTREE_SPLIT_SEQ_NUM).

Parameters
[in]pagepage
Returns
SPLIT SEQUENCE NUMBER

◆ page_get_supremum_offset()

static ulint page_get_supremum_offset ( const page_t page)
inlinestatic

Gets the offset of the last record on the page.

Returns
offset of the last record in record list, relative from page
Parameters
pagein: page which must have record(s)

◆ page_has_garbage()

static bool page_has_garbage ( const page_t page)
inlinestatic

Determine whether the page contains garbage.

Returns
true if the page contains garbage (PAGE_GARBAGE is not 0)
Parameters
pagein: page

◆ page_header_get_offs()

static ulint page_header_get_offs ( const page_t page,
ulint  field 
)
inlinestatic

◆ page_header_reset_last_insert()

static void page_header_reset_last_insert ( page_t page,
page_zip_des_t page_zip,
mtr_t mtr 
)
inlinestatic

Resets the last insert info field in the page header.

Writes to mlog about this operation.

Parameters
pagein/out: page
page_zipin/out: compressed page whose uncompressed part will be updated, or NULL
mtrin: mtr

◆ page_header_set_field()

static void page_header_set_field ( page_t page,
page_zip_des_t page_zip,
ulint  field,
ulint  val 
)
inlinestatic

Sets the given header field.

Parameters
pagein/out: page
page_zipin/out: compressed page whose uncompressed part will be updated, or NULL
fieldin: PAGE_N_DIR_SLOTS, ...
valin: value

◆ page_header_set_ptr()

static void page_header_set_ptr ( page_t page,
page_zip_des_t page_zip,
ulint  field,
const byte ptr 
)
inlinestatic

Sets the pointer stored in the given header field.

Parameters
pagein: page
page_zipin/out: compressed page whose uncompressed part will be updated, or NULL
fieldin: PAGE_FREE, ...
ptrin: pointer or NULL

◆ page_is_comp()

static bool page_is_comp ( const page_t page)
inlinestatic

Determine whether the page is in new-style compact format.

Returns
nonzero if the page is in compact format, zero if it is in old-style format
Parameters
pagein: index page

◆ page_is_empty()

static bool page_is_empty ( const page_t page)
inlinestatic

Determine whether the page is empty.

Returns
true if the page is empty (PAGE_N_RECS = 0)
Parameters
pagein: page

◆ page_is_leaf()

static bool page_is_leaf ( const page_t page)
inlinestatic

Determine whether the page is a B-tree leaf.

Returns
true if the page is a B-tree leaf (PAGE_LEVEL = 0)
Parameters
pagein: page

◆ page_is_root()

static bool page_is_root ( const page_t page)
inlinestatic

Determine whether a page is an index root page.

Parameters
[in]pagepage frame
Returns
true if the page is a root page of an index

◆ page_mem_alloc_free()

static void page_mem_alloc_free ( page_t page,
page_zip_des_t page_zip,
rec_t next_rec,
ulint  need 
)
inlinestatic

Allocates a block of memory from the free list of an index page.

Parameters
pagein/out: index page
page_zipin/out: compressed page with enough space available for inserting the record, or NULL
next_recin: pointer to the new head of the free record list
needin: number of bytes allocated

◆ page_mem_free()

static void page_mem_free ( page_t page,
page_zip_des_t page_zip,
rec_t rec,
const dict_index_t index,
const ulint offsets 
)
inlinestatic

Puts a record to free list.

Parameters
pagein/out: index page
page_zipin/out: compressed page, or NULL
recin: pointer to the (origin of) record
indexin: index of rec
offsetsin: array returned by rec_get_offsets()

◆ page_offset()

static ulint page_offset ( const void *  ptr)
inlinestatic

Gets the offset within a page.

Returns
offset from the start of the page
Parameters
ptrin: pointer to page frame

◆ page_rec_check()

static bool page_rec_check ( const rec_t rec)
inlinestatic

Used to check the consistency of a record on a page.

Returns
true if succeed
Parameters
recin: record

◆ page_rec_distance_is_at_most()

static bool page_rec_distance_is_at_most ( const rec_t left_rec,
const rec_t right_rec,
ulint  val 
)
inlinestatic

◆ page_rec_find_owner_rec()

static rec_t * page_rec_find_owner_rec ( rec_t rec)
inlinestatic

Looks for the record which owns the given record.

Returns
the owner record
Parameters
recin: the physical record

◆ page_rec_get_base_extra_size()

static ulint page_rec_get_base_extra_size ( const rec_t rec)
inlinestatic

Returns the base extra size of a physical record.

This is the size of the fixed header, independent of the record size.

Returns
REC_N_NEW_EXTRA_BYTES or REC_N_OLD_EXTRA_BYTES
Parameters
recin: physical record

◆ page_rec_get_heap_no()

static ulint page_rec_get_heap_no ( const rec_t rec)
inlinestatic

Returns the heap number of a record.

Returns
heap number
Parameters
recin: the physical record

◆ page_rec_get_next()

static rec_t * page_rec_get_next ( rec_t rec)
inlinestatic

Gets the pointer to the next record on the page.

Returns
pointer to next record
Parameters
recin: pointer to record

◆ page_rec_get_next_const()

static const rec_t * page_rec_get_next_const ( const rec_t rec)
inlinestatic

Gets the pointer to the next record on the page.

Returns
pointer to next record
Parameters
recin: pointer to record

◆ page_rec_get_next_low()

static const rec_t * page_rec_get_next_low ( const rec_t rec,
ulint  comp 
)
inlinestatic

Gets the pointer to the next record on the page.

Returns
pointer to next record
Parameters
recin: pointer to record
compin: nonzero=compact page layout

◆ page_rec_get_next_non_del_marked()

static const rec_t * page_rec_get_next_non_del_marked ( const rec_t rec)
inlinestatic

Gets the pointer to the next non delete-marked record on the page.

If all subsequent records are delete-marked, then this function will return the supremum record.

Returns
pointer to next non delete-marked record or pointer to supremum
Parameters
recin: pointer to record

◆ page_rec_get_nth()

static rec_t * page_rec_get_nth ( page_t page,
ulint  nth 
)
inlinestatic

Returns the nth record of the record list.

This is the inverse function of page_rec_get_n_recs_before().

Returns
nth record
Parameters
pagein: page
nthin: nth record

◆ page_rec_get_prev()

static rec_t * page_rec_get_prev ( rec_t rec)
inlinestatic

Gets the pointer to the previous record.

Returns
pointer to previous record
Parameters
recin: pointer to record, must not be page infimum

◆ page_rec_get_prev_const()

static const rec_t * page_rec_get_prev_const ( const rec_t rec)
inlinestatic

Gets the pointer to the previous record.

Returns
pointer to previous record
Parameters
recin: pointer to record, must not be page infimum

◆ page_rec_is_comp()

static bool page_rec_is_comp ( const rec_t rec)
inlinestatic

true if the record is on a page in compact format.

Returns
nonzero if in compact format
Parameters
recin: record

◆ page_rec_is_first()

static bool page_rec_is_first ( const rec_t rec,
const page_t page 
)
inlinestatic

◆ page_rec_is_infimum()

static bool page_rec_is_infimum ( const rec_t rec)
inlinestatic

true if the record is the infimum record on a page.

Returns
true if the infimum record
Parameters
recin: record

◆ page_rec_is_infimum_low()

static bool page_rec_is_infimum_low ( ulint  offset)
inlinestatic

true if the record is the infimum record on a page.

Returns
true if the infimum record
Parameters
offsetin: record offset on page

◆ page_rec_is_last()

static bool page_rec_is_last ( const rec_t rec,
const page_t page 
)
inlinestatic

◆ page_rec_is_second()

static bool page_rec_is_second ( const rec_t rec,
const page_t page 
)
inlinestatic

◆ page_rec_is_second_last()

static bool page_rec_is_second_last ( const rec_t rec,
const page_t page 
)
inlinestatic

◆ page_rec_is_supremum()

static bool page_rec_is_supremum ( const rec_t rec)
inlinestatic

true if the record is the supremum record on a page.

Returns
true if the supremum record
Parameters
recin: record

◆ page_rec_is_supremum_low()

static bool page_rec_is_supremum_low ( ulint  offset)
inlinestatic

true if the record is the supremum record on a page.

Returns
true if the supremum record
Parameters
offsetin: record offset on page

◆ page_rec_is_user_rec()

static bool page_rec_is_user_rec ( const rec_t rec)
inlinestatic

true if the record is a user record on the page.

Returns
true if a user record
Parameters
recin: record

◆ page_rec_is_user_rec_low()

static bool page_rec_is_user_rec_low ( ulint  offset)
inlinestatic

true if the record is a user record on the page.

Returns
true if a user record
Parameters
offsetin: record offset on page

◆ page_rec_set_next()

static void page_rec_set_next ( rec_t rec,
const rec_t next 
)
inlinestatic

Sets the pointer to the next record on the page.

Parameters
recin: pointer to record, must not be page supremum
nextin: pointer to next record, must not be page infimum

◆ page_set_ssn_id()

static void page_set_ssn_id ( buf_block_t block,
page_zip_des_t page_zip,
node_seq_t  ssn_id,
mtr_t mtr 
)
inlinestatic

Sets the RTREE SPLIT SEQUENCE NUMBER field value.

Parameters
[in,out]blockPage
[in,out]page_zipCompressed page whose uncompressed part will be updated, or NULL
[in]ssn_idTransaction id
[in,out]mtrMini-transaction

◆ page_size_validate()

ulong page_size_validate ( ulong  page_size)
inline

Check that a page_size is correct for InnoDB.

If correct, set the associated page_size_shift which is the power of 2 for this page size.

Parameters
[in]page_sizePage Size to evaluate
Returns
an associated page_size_shift if valid, 0 if invalid.

◆ page_update_max_trx_id()

static void page_update_max_trx_id ( buf_block_t block,
page_zip_des_t page_zip,
trx_id_t  trx_id,
mtr_t mtr 
)
inlinestatic

Sets the max trx id field value if trx_id is bigger than the previous value.

Parameters
blockin/out: page
page_zipin/out: compressed page whose uncompressed part will be updated, or NULL
trx_idin: transaction id
mtrin/out: mini-transaction