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