Debian Codegraph @

storage/innobase/include/page0types.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 1994, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 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
48 Index page header starts at the first offset left free by the FIL-module */
49
50 typedef byte page_header_t;
51
52 /** index page header starts at this offset */
53 constexpr uint32_t PAGE_HEADER = FSEG_PAGE_DATA;
54
55 /*-----------------------------*/
56 /** number of slots in page directory */
57 constexpr uint32_t PAGE_N_DIR_SLOTS = 0;
58 /** pointer to record heap top */
59 constexpr uint32_t PAGE_HEAP_TOP = 2;
60 /** number of records in the heap, bit 15=flag: new-style compact page format */
61 constexpr uint32_t PAGE_N_HEAP = 4;
62 /** pointer to start of page free record list */
63 constexpr uint32_t PAGE_FREE = 6;
64 /** number of bytes in deleted records */
65 constexpr 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 */
68 constexpr uint32_t PAGE_LAST_INSERT = 10;
69 /** last insert direction: PAGE_LEFT, ... */
70 constexpr uint32_t PAGE_DIRECTION = 12;
71 /** number of consecutive inserts to the same direction */
72 constexpr uint32_t PAGE_N_DIRECTION = 14;
73 /** number of user records on the page */
74 constexpr uint32_t PAGE_N_RECS = 16;
75 /** highest id of a trx which may have modified a record on the page; trx_id_t;
76 defined only in secondary indexes and in the insert buffer tree */
77 constexpr uint32_t PAGE_MAX_TRX_ID = 18;
78 /** end of private data structure of the page header which are set in a page
79 create */
80 constexpr uint32_t PAGE_HEADER_PRIV_END = 26;
81 /*----*/
82 /** level of the node in an index tree; the leaf level is the level 0.
83 This field should not be written to after page creation. */
84 constexpr uint32_t PAGE_LEVEL = 26;
85 /** index id where the page belongs. This field should not be written to after
86 page creation. */
87 constexpr 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 */
90 constexpr uint32_t PAGE_BTR_SEG_LEAF = 36;
91 constexpr uint32_t PAGE_BTR_IBUF_FREE_LIST = PAGE_BTR_SEG_LEAF;
92 constexpr uint32_t PAGE_BTR_IBUF_FREE_LIST_NODE = PAGE_BTR_SEG_LEAF;
93 /* in the place of PAGE_BTR_SEG_LEAF and _TOP
94 there is a free list base node if the page is
95 the root page of an ibuf tree, and at the same
96 place is the free list node if the page is in
97 a free list */
98 constexpr uint32_t PAGE_BTR_SEG_TOP = 36 + FSEG_HEADER_SIZE;
99 /* file segment header for the non-leaf pages
100 in a B-tree: defined only on the root page of
101 a B-tree, but not in the root of an ibuf
102 tree */
103 /*----*/
104 /** start of data on the page */
105 constexpr uint32_t PAGE_DATA = PAGE_HEADER + 36 + 2 * FSEG_HEADER_SIZE;
106
107 /** offset of the page infimum record on an
108 old-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
112 old-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 */
131 constexpr ulint PAGE_HEAP_NO_INFIMUM = 0;
132 /** Page supremum */
133 constexpr ulint PAGE_HEAP_NO_SUPREMUM = 1;
134
135 /** First user record in creation (insertion) order, not necessarily collation
136 order; this record may have been deleted */
137 constexpr ulint PAGE_HEAP_NO_USER_LOW = 2;
138
139 /* Directions of cursor movement */
140
141 enum cursor_direction_t : uint8_t {
142 PAGE_LEFT = 1,
143 PAGE_RIGHT = 2,
144 PAGE_SAME_REC = 3,
145 PAGE_SAME_PAGE = 4,
146 PAGE_NO_DIRECTION = 5
147 };
148
149 /** Eliminates a name collision on HP-UX */
150 #define page_t ib_page_t
151 /** Type of the index page */
152 typedef byte page_t;
153 /** Index page cursor */
154 struct page_cur_t;
155
156 /** Compressed index page */
157 typedef byte page_zip_t;
158
159 /* The following definitions would better belong to page0zip.h,
160 but we cannot include page0zip.h from rem0rec.ic, because
161 page0*.h includes rem0rec.h and may include rem0rec.ic. */
162
163 /** Number of bits needed for representing different compressed page sizes */
164 constexpr uint8_t PAGE_ZIP_SSIZE_BITS = 3;
165
166 /** Maximum compressed page shift size */
167 constexpr uint32_t PAGE_ZIP_SSIZE_MAX =
168 UNIV_ZIP_SIZE_SHIFT_MAX - UNIV_ZIP_SIZE_SHIFT_MIN + 1;
169
170 /* Make sure there are enough bits available to store the maximum zip
171 ssize, which is the number of shifts from 512. */
172 static_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! */
176 enum page_cur_mode_t {
177 PAGE_CUR_UNSUPP = 0,
178 PAGE_CUR_G = 1,
179 PAGE_CUR_GE = 2,
180 PAGE_CUR_L = 3,
181 PAGE_CUR_LE = 4,
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. */
189 PAGE_CUR_CONTAIN = 7,
190 PAGE_CUR_INTERSECT = 8,
191 PAGE_CUR_WITHIN = 9,
192 PAGE_CUR_DISJOINT = 10,
193 PAGE_CUR_MBR_EQUAL = 11,
194 PAGE_CUR_RTREE_INSERT = 12,
195 PAGE_CUR_RTREE_LOCATE = 13,
196 PAGE_CUR_RTREE_GET_FATHER = 14
197 };
198
199 /** Compressed page descriptor */
200 struct page_zip_des_t {
201 /** Compressed page data */
202 page_zip_t *data;
203
204 #ifdef UNIV_DEBUG
205 /** Start offset of modification log */
206 uint16_t m_start;
207 /** Allocated externally, not from the buffer pool */
208 bool m_external;
209 #endif /* UNIV_DEBUG */
210
211 /** End offset of modification log */
212 uint16_t m_end;
213
214 /** Number of externally stored columns on the page; the maximum is 744
215 on a 16 KiB page */
216 uint16_t n_blobs;
217
218 /** true if the modification log is not empty. */
219 bool m_nonempty;
220
221 /** 0 or compressed page shift size; the size in bytes is:
222 (UNIV_ZIP_SIZE_MIN * >> 1) << ssize. */
223 uint8_t ssize;
224 };
225
226 /** Compression statistics for a given page size */
227 struct page_zip_stat_t {
228 /** Number of page compressions */
229 ulint compressed;
230 /** Number of successful page compressions */
231 ulint compressed_ok;
232 /** Number of page decompressions */
233 ulint decompressed;
234 /** Duration of page compressions */
235 std::chrono::microseconds compress_time;
236 /** Duration of page decompressions */
237 std::chrono::microseconds decompress_time;
238 page_zip_stat_t()
239 : /* Initialize members to 0 so that when we do
240 stlmap[key].compressed++ and element with "key" does not
241 exist it gets inserted with zeroed members. */
242 compressed(0),
243 compressed_ok(0),
244 decompressed(0),
245 compress_time{},
246 decompress_time{} {}
247 };
248
249 /** Compression statistics types */
250 typedef std::map<index_id_t, page_zip_stat_t, std::less<index_id_t>,
251 ut::allocator<std::pair<const index_id_t, page_zip_stat_t>>>
252 page_zip_stat_per_index_t;
253
254 /** Statistics on compression, indexed by page_zip_des_t::ssize - 1 */
255 extern page_zip_stat_t page_zip_stat[PAGE_ZIP_SSIZE_MAX];
256 /** Statistics on compression, indexed by dict_index_t::id */
257 extern page_zip_stat_per_index_t page_zip_stat_per_index;
258
259 /** Write the "deleted" flag of a record on a compressed page. The flag must
260 already have been written on the uncompressed page. */
261 void page_zip_rec_set_deleted(
262 page_zip_des_t *page_zip, /*!< in/out: compressed page */
263 const byte *rec, /*!< in: record on the uncompressed page */
264 bool flag); /*!< in: the deleted flag (nonzero=true) */
265
266 /** Write the "owned" flag of a record on a compressed page. The n_owned field
267 must already have been written on the uncompressed page.
268 @param[in,out] page_zip Compressed page
269 @param[in] rec Record on the uncompressed page
270 @param[in] flag The owned flag (nonzero=true) */
271 void page_zip_rec_set_owned(page_zip_des_t *page_zip, const byte *rec,
272 ulint flag);
273
274 /** Shift the dense page directory when a record is deleted.
275 @param[in,out] page_zip compressed page
276 @param[in] rec deleted record
277 @param[in] index index of rec
278 @param[in] offsets rec_get_offsets(rec)
279 @param[in] free previous start of the free list */
280 void page_zip_dir_delete(page_zip_des_t *page_zip, byte *rec,
281 dict_index_t *index, const ulint *offsets,
282 const byte *free);
283
284 /** Add a slot to the dense page directory.
285 @param[in,out] page_zip Compressed page
286 @param[in] is_clustered Nonzero for clustered index, zero for others */
287 void page_zip_dir_add_slot(page_zip_des_t *page_zip, bool is_clustered);
288
289 #endif