MySQL 8.2.0
Source Code Documentation
page0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2023, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/page0types.h
28 Index page routines
29
30 Created 2/2/1994 Heikki Tuuri
31 *******************************************************/
32
33#ifndef page0types_h
34#define page0types_h
35
36#include "dict0types.h"
37#include "fsp0types.h"
38#include "mtr0types.h"
39#include "univ.i"
40#include "ut0new.h"
41
42#include <map>
43
44/* PAGE HEADER
45 ===========
46
47Index page header starts at the first offset left free by the FIL-module */
48
49typedef byte page_header_t;
50
51/** index page header starts at this offset */
52constexpr uint32_t PAGE_HEADER = FSEG_PAGE_DATA;
53
54/*-----------------------------*/
55/** number of slots in page directory */
56constexpr uint32_t PAGE_N_DIR_SLOTS = 0;
57/** pointer to record heap top */
58constexpr uint32_t PAGE_HEAP_TOP = 2;
59/** number of records in the heap, bit 15=flag: new-style compact page format */
60constexpr uint32_t PAGE_N_HEAP = 4;
61/** pointer to start of page free record list */
62constexpr uint32_t PAGE_FREE = 6;
63/** number of bytes in deleted records */
64constexpr uint32_t PAGE_GARBAGE = 8;
65/** pointer to the last inserted record, or NULL if this info has been reset by
66 a delete, for example */
67constexpr uint32_t PAGE_LAST_INSERT = 10;
68/** last insert direction: PAGE_LEFT, ... */
69constexpr uint32_t PAGE_DIRECTION = 12;
70/** number of consecutive inserts to the same direction */
71constexpr uint32_t PAGE_N_DIRECTION = 14;
72/** number of user records on the page */
73constexpr uint32_t PAGE_N_RECS = 16;
74/** highest id of a trx which may have modified a record on the page; trx_id_t;
75defined only in secondary indexes and in the insert buffer tree */
76constexpr uint32_t PAGE_MAX_TRX_ID = 18;
77/** end of private data structure of the page header which are set in a page
78create */
79constexpr uint32_t PAGE_HEADER_PRIV_END = 26;
80/*----*/
81/** level of the node in an index tree; the leaf level is the level 0.
82This field should not be written to after page creation. */
83constexpr uint32_t PAGE_LEVEL = 26;
84/** index id where the page belongs. This field should not be written to after
85 page creation. */
86constexpr uint32_t PAGE_INDEX_ID = 28;
87/** file segment header for the leaf pages in a B-tree: defined only on the root
88 page of a B-tree, but not in the root of an ibuf tree */
89constexpr uint32_t PAGE_BTR_SEG_LEAF = 36;
92/* in the place of PAGE_BTR_SEG_LEAF and _TOP
93there is a free list base node if the page is
94the root page of an ibuf tree, and at the same
95place is the free list node if the page is in
96a free list */
97constexpr uint32_t PAGE_BTR_SEG_TOP = 36 + FSEG_HEADER_SIZE;
98/* file segment header for the non-leaf pages
99in a B-tree: defined only on the root page of
100a B-tree, but not in the root of an ibuf
101tree */
102/*----*/
103/** start of data on the page */
104constexpr uint32_t PAGE_DATA = PAGE_HEADER + 36 + 2 * FSEG_HEADER_SIZE;
105
106/** offset of the page infimum record on an
107old-style page */
108#define PAGE_OLD_INFIMUM (PAGE_DATA + 1 + REC_N_OLD_EXTRA_BYTES)
109
110/** offset of the page supremum record on an
111old-style page */
112#define PAGE_OLD_SUPREMUM (PAGE_DATA + 2 + 2 * REC_N_OLD_EXTRA_BYTES + 8)
113
114/** offset of the page supremum record end on an old-style page */
115#define PAGE_OLD_SUPREMUM_END (PAGE_OLD_SUPREMUM + 9)
116
117/** offset of the page infimum record on a new-style compact page */
118#define PAGE_NEW_INFIMUM (PAGE_DATA + REC_N_NEW_EXTRA_BYTES)
119
120/** offset of the page supremum record on a new-style compact page */
121#define PAGE_NEW_SUPREMUM (PAGE_DATA + 2 * REC_N_NEW_EXTRA_BYTES + 8)
122
123/** offset of the page supremum record end on a new-style compact page */
124#define PAGE_NEW_SUPREMUM_END (PAGE_NEW_SUPREMUM + 8)
125
126/*-----------------------------*/
127
128/* Heap numbers */
129/** Page infimum */
131/** Page supremum */
133
134/** First user record in creation (insertion) order, not necessarily collation
135order; this record may have been deleted */
137
138/* Directions of cursor movement */
139
140enum cursor_direction_t : uint8_t {
147
148/** Eliminates a name collision on HP-UX */
149#define page_t ib_page_t
150/** Type of the index page */
151typedef byte page_t;
152/** Index page cursor */
153struct page_cur_t;
154
155/** Compressed index page */
156typedef byte page_zip_t;
157
158/* The following definitions would better belong to page0zip.h,
159but we cannot include page0zip.h from rem0rec.ic, because
160page0*.h includes rem0rec.h and may include rem0rec.ic. */
161
162/** Number of bits needed for representing different compressed page sizes */
163constexpr uint8_t PAGE_ZIP_SSIZE_BITS = 3;
164
165/** Maximum compressed page shift size */
166constexpr uint32_t PAGE_ZIP_SSIZE_MAX =
168
169/* Make sure there are enough bits available to store the maximum zip
170ssize, which is the number of shifts from 512. */
171static_assert(PAGE_ZIP_SSIZE_MAX < (1 << PAGE_ZIP_SSIZE_BITS),
172 "PAGE_ZIP_SSIZE_MAX >= (1 << PAGE_ZIP_SSIZE_BITS)");
173
174/* Page cursor search modes; the values must be in this order! */
181
182 /* PAGE_CUR_LE_OR_EXTENDS = 5,*/ /* This is a search mode used in
183 "column LIKE 'abc%' ORDER BY column DESC";
184 we have to find strings which are <= 'abc' or
185 which extend it */
186
187 /* These search mode is for search R-tree index. */
197
198/** Compressed page descriptor */
200 /** Compressed page data */
202
203#ifdef UNIV_DEBUG
204 /** Start offset of modification log */
205 uint16_t m_start;
206 /** Allocated externally, not from the buffer pool */
208#endif /* UNIV_DEBUG */
209
210 /** End offset of modification log */
211 uint16_t m_end;
212
213 /** Number of externally stored columns on the page; the maximum is 744
214 on a 16 KiB page */
215 uint16_t n_blobs;
216
217 /** true if the modification log is not empty. */
219
220 /** 0 or compressed page shift size; the size in bytes is:
221 (UNIV_ZIP_SIZE_MIN * >> 1) << ssize. */
222 uint8_t ssize;
223};
224
225/** Compression statistics for a given page size */
227 /** Number of page compressions */
229 /** Number of successful page compressions */
231 /** Number of page decompressions */
233 /** Duration of page compressions */
234 std::chrono::microseconds compress_time;
235 /** Duration of page decompressions */
236 std::chrono::microseconds decompress_time;
238 : /* Initialize members to 0 so that when we do
239 stlmap[key].compressed++ and element with "key" does not
240 exist it gets inserted with zeroed members. */
241 compressed(0),
242 compressed_ok(0),
243 decompressed(0),
245 decompress_time{} {}
246};
247
248/** Compression statistics types */
249typedef std::map<index_id_t, page_zip_stat_t, std::less<index_id_t>,
252
253/** Statistics on compression, indexed by page_zip_des_t::ssize - 1 */
255/** Statistics on compression, indexed by dict_index_t::id */
257
258/** Write the "deleted" flag of a record on a compressed page. The flag must
259 already have been written on the uncompressed page. */
261 page_zip_des_t *page_zip, /*!< in/out: compressed page */
262 const byte *rec, /*!< in: record on the uncompressed page */
263 bool flag); /*!< in: the deleted flag (nonzero=true) */
264
265/** Write the "owned" flag of a record on a compressed page. The n_owned field
266 must already have been written on the uncompressed page.
267@param[in,out] page_zip Compressed page
268@param[in] rec Record on the uncompressed page
269@param[in] flag The owned flag (nonzero=true) */
270void page_zip_rec_set_owned(page_zip_des_t *page_zip, const byte *rec,
271 ulint flag);
272
273/** Shift the dense page directory when a record is deleted.
274@param[in,out] page_zip compressed page
275@param[in] rec deleted record
276@param[in] index index of rec
277@param[in] offsets rec_get_offsets(rec)
278@param[in] free previous start of the free list */
279void page_zip_dir_delete(page_zip_des_t *page_zip, byte *rec,
280 dict_index_t *index, const ulint *offsets,
281 const byte *free);
282
283/** Add a slot to the dense page directory.
284@param[in,out] page_zip Compressed page
285@param[in] is_clustered Nonzero for clustered index, zero for others */
286void page_zip_dir_add_slot(page_zip_des_t *page_zip, bool is_clustered);
287
288#endif
Allocator that allows std::* containers to manage their memory through ut::malloc* and ut::free libra...
Definition: ut0new.h:2180
Data dictionary global types.
constexpr uint32_t FSEG_PAGE_DATA
On a page of any file segment, data may be put starting from this offset.
Definition: fsp0types.h:78
constexpr uint32_t FSEG_HEADER_SIZE
Length of the file system header, in bytes.
Definition: fsp0types.h:93
static int flag
Definition: hp_test1.cc:39
#define free(A)
Definition: lexyy.cc:915
Mini-transaction buffer global types.
constexpr uint32_t PAGE_HEADER
index page header starts at this offset
Definition: page0types.h:52
page_zip_stat_t page_zip_stat[PAGE_ZIP_SSIZE_MAX]
Statistics on compression, indexed by page_zip_des_t::ssize - 1.
Definition: page0zip.cc:74
cursor_direction_t
Definition: page0types.h:140
@ PAGE_SAME_PAGE
Definition: page0types.h:144
@ PAGE_LEFT
Definition: page0types.h:141
@ PAGE_RIGHT
Definition: page0types.h:142
@ PAGE_SAME_REC
Definition: page0types.h:143
@ PAGE_NO_DIRECTION
Definition: page0types.h:145
page_cur_mode_t
Definition: page0types.h:175
@ PAGE_CUR_LE
Definition: page0types.h:180
@ PAGE_CUR_G
Definition: page0types.h:177
@ PAGE_CUR_UNSUPP
Definition: page0types.h:176
@ PAGE_CUR_CONTAIN
Definition: page0types.h:188
@ PAGE_CUR_INTERSECT
Definition: page0types.h:189
@ PAGE_CUR_MBR_EQUAL
Definition: page0types.h:192
@ PAGE_CUR_RTREE_LOCATE
Definition: page0types.h:194
@ PAGE_CUR_WITHIN
Definition: page0types.h:190
@ PAGE_CUR_L
Definition: page0types.h:179
@ PAGE_CUR_RTREE_GET_FATHER
Definition: page0types.h:195
@ PAGE_CUR_GE
Definition: page0types.h:178
@ PAGE_CUR_RTREE_INSERT
Definition: page0types.h:193
@ PAGE_CUR_DISJOINT
Definition: page0types.h:191
void page_zip_rec_set_owned(page_zip_des_t *page_zip, const byte *rec, ulint flag)
Write the "owned" flag of a record on a compressed page.
Definition: page0zip.cc:2242
constexpr uint32_t PAGE_DATA
start of data on the page
Definition: page0types.h:104
constexpr uint8_t PAGE_ZIP_SSIZE_BITS
Number of bits needed for representing different compressed page sizes.
Definition: page0types.h:163
constexpr uint32_t PAGE_N_DIRECTION
number of consecutive inserts to the same direction
Definition: page0types.h:71
constexpr uint32_t PAGE_INDEX_ID
index id where the page belongs.
Definition: page0types.h:86
constexpr uint32_t PAGE_N_RECS
number of user records on the page
Definition: page0types.h:73
constexpr uint32_t PAGE_GARBAGE
number of bytes in deleted records
Definition: page0types.h:64
constexpr uint32_t PAGE_BTR_IBUF_FREE_LIST_NODE
Definition: page0types.h:91
constexpr uint32_t PAGE_MAX_TRX_ID
highest id of a trx which may have modified a record on the page; trx_id_t; defined only in secondary...
Definition: page0types.h:76
constexpr ulint PAGE_HEAP_NO_INFIMUM
Page infimum.
Definition: page0types.h:130
byte page_header_t
Definition: page0types.h:49
constexpr ulint PAGE_HEAP_NO_SUPREMUM
Page supremum.
Definition: page0types.h:132
constexpr uint32_t PAGE_BTR_SEG_LEAF
file segment header for the leaf pages in a B-tree: defined only on the root page of a B-tree,...
Definition: page0types.h:89
constexpr uint32_t PAGE_ZIP_SSIZE_MAX
Maximum compressed page shift size.
Definition: page0types.h:166
std::map< index_id_t, page_zip_stat_t, std::less< index_id_t >, ut::allocator< std::pair< const index_id_t, page_zip_stat_t > > > page_zip_stat_per_index_t
Compression statistics types.
Definition: page0types.h:251
constexpr uint32_t PAGE_LAST_INSERT
pointer to the last inserted record, or NULL if this info has been reset by a delete,...
Definition: page0types.h:67
constexpr uint32_t PAGE_N_HEAP
number of records in the heap, bit 15=flag: new-style compact page format
Definition: page0types.h:60
constexpr uint32_t PAGE_DIRECTION
last insert direction: PAGE_LEFT, ...
Definition: page0types.h:69
void page_zip_rec_set_deleted(page_zip_des_t *page_zip, const byte *rec, bool flag)
Write the "deleted" flag of a record on a compressed page.
Definition: page0zip.cc:2219
constexpr uint32_t PAGE_FREE
pointer to start of page free record list
Definition: page0types.h:62
void page_zip_dir_delete(page_zip_des_t *page_zip, byte *rec, dict_index_t *index, const ulint *offsets, const byte *free)
Shift the dense page directory when a record is deleted.
constexpr uint32_t PAGE_LEVEL
level of the node in an index tree; the leaf level is the level 0.
Definition: page0types.h:83
constexpr uint32_t PAGE_HEAP_TOP
pointer to record heap top
Definition: page0types.h:58
constexpr uint32_t PAGE_HEADER_PRIV_END
end of private data structure of the page header which are set in a page create
Definition: page0types.h:79
void page_zip_dir_add_slot(page_zip_des_t *page_zip, bool is_clustered)
Add a slot to the dense page directory.
Definition: page0zip.cc:2414
constexpr uint32_t PAGE_BTR_SEG_TOP
Definition: page0types.h:97
constexpr uint32_t PAGE_BTR_IBUF_FREE_LIST
Definition: page0types.h:90
constexpr uint32_t PAGE_N_DIR_SLOTS
number of slots in page directory
Definition: page0types.h:56
byte page_zip_t
Compressed index page.
Definition: page0types.h:153
constexpr ulint PAGE_HEAP_NO_USER_LOW
First user record in creation (insertion) order, not necessarily collation order; this record may hav...
Definition: page0types.h:136
#define page_t
Eliminates a name collision on HP-UX.
Definition: page0types.h:149
page_zip_stat_per_index_t page_zip_stat_per_index
Statistics on compression, indexed by dict_index_t::id.
Definition: page0zip.cc:82
Data structure for an index.
Definition: dict0mem.h:1045
Index page cursor.
Definition: page0cur.h:310
Compressed page descriptor.
Definition: page0types.h:199
uint16_t m_start
Start offset of modification log.
Definition: page0types.h:205
uint16_t n_blobs
Number of externally stored columns on the page; the maximum is 744 on a 16 KiB page.
Definition: page0types.h:215
uint8_t ssize
0 or compressed page shift size; the size in bytes is: (UNIV_ZIP_SIZE_MIN * >> 1) << ssize.
Definition: page0types.h:222
bool m_nonempty
true if the modification log is not empty.
Definition: page0types.h:218
uint16_t m_end
End offset of modification log.
Definition: page0types.h:211
page_zip_t * data
Compressed page data.
Definition: page0types.h:201
bool m_external
Allocated externally, not from the buffer pool.
Definition: page0types.h:207
Compression statistics for a given page size.
Definition: page0types.h:226
ulint compressed_ok
Number of successful page compressions.
Definition: page0types.h:230
ulint decompressed
Number of page decompressions.
Definition: page0types.h:232
std::chrono::microseconds decompress_time
Duration of page decompressions.
Definition: page0types.h:236
ulint compressed
Number of page compressions.
Definition: page0types.h:228
std::chrono::microseconds compress_time
Duration of page compressions.
Definition: page0types.h:234
page_zip_stat_t()
Definition: page0types.h:237
Version control for database, common definitions, and include files.
constexpr uint32_t UNIV_ZIP_SIZE_SHIFT_MIN
log2 of smallest compressed page size (1<<10 == 1024 bytes) Note: This must never change!
Definition: univ.i:297
unsigned long int ulint
Definition: univ.i:405
constexpr uint32_t UNIV_ZIP_SIZE_SHIFT_MAX
log2 of largest compressed page size (1<<14 == 16384 bytes).
Definition: univ.i:305
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...