MySQL 8.4.0
Source Code Documentation
page0size.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2013, 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/page0size.h
29 A class describing a page size.
30
31 Created Nov 14, 2013 Vasil Dimov
32 *******************************************************/
33
34#ifndef page0size_t
35#define page0size_t
36
37#include "fsp0types.h"
38
39constexpr size_t FIELD_REF_SIZE = 20;
40
41/** A BLOB field reference full of zero, for use in assertions and
42tests.Initially, BLOB field references are set to zero, in
43dtuple_convert_big_rec(). */
44extern const byte field_ref_zero[FIELD_REF_SIZE];
45
46constexpr size_t PAGE_SIZE_T_SIZE_BITS = 17;
47
48/** Page size descriptor. Contains the physical and logical page size, as well
49as whether the page is compressed or not. */
51 public:
52 /** Constructor from (physical, logical, is_compressed).
53 @param[in] physical physical (on-disk/zipped) page size
54 @param[in] logical logical (in-memory/unzipped) page size
55 @param[in] is_compressed whether the page is compressed */
56 page_size_t(uint32_t physical, uint32_t logical, bool is_compressed) {
57 if (physical == 0) {
59 }
60 if (logical == 0) {
62 }
63
64 m_physical = static_cast<unsigned>(physical);
65 m_logical = static_cast<unsigned>(logical);
66 m_is_compressed = static_cast<unsigned>(is_compressed);
67
70
73
77 }
78
79 /** Constructor from (fsp_flags).
80 @param[in] fsp_flags filespace flags */
81 explicit page_size_t(uint32_t fsp_flags) {
82 uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags);
83
84 /* If the logical page size is zero in fsp_flags, then use the
85 legacy 16k page size. */
86 ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize;
87
88 /* Convert from a 'log2 minus 9' to a page size in bytes. */
89 const ulint size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
90
93
95
96 ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags);
97
98 /* If the fsp_flags have zero in the zip_ssize field, then
99 it means that the tablespace does not have compressed pages
100 and the physical page size is the same as the logical page
101 size. */
102 if (ssize == 0) {
103 m_is_compressed = false;
105 } else {
106 m_is_compressed = true;
107
108 /* Convert from a 'log2 minus 9' to a page size
109 in bytes. */
110 const ulint phy = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
111
112 ut_ad(phy <= UNIV_ZIP_SIZE_MAX);
113 ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS));
114
115 m_physical = phy;
116 }
117 }
118
119 /** Retrieve the physical page size (on-disk).
120 @return physical page size in bytes */
121 inline size_t physical() const {
122 ut_ad(m_physical > 0);
123
124 return (m_physical);
125 }
126
127 /** Retrieve the logical page size (in-memory).
128 @return logical page size in bytes */
129 inline size_t logical() const {
130 ut_ad(m_logical > 0);
131 return (m_logical);
132 }
133
135 page_no_t size = 0;
136 switch (m_physical) {
137 case 4096:
138 size = 256;
139 break;
140 case 8192:
141 size = 128;
142 break;
143 case 16384:
144 case 32768:
145 case 65536:
146 size = 64;
147 break;
148 default:
149 ut_d(ut_error);
150 }
151 return (size);
152 }
153
154 size_t extents_per_xdes() const { return (m_physical / extent_size()); }
155
156 /** Check whether the page is compressed on disk.
157 @return true if compressed */
158 inline bool is_compressed() const { return (m_is_compressed); }
159
160 /** Copy the values from a given page_size_t object.
161 @param[in] src page size object whose values to fetch */
162 inline void copy_from(const page_size_t &src) {
163 m_physical = src.physical();
164 m_logical = src.logical();
166 }
167
168 /** Check if a given page_size_t object is equal to the current one.
169 @param[in] a page_size_t object to compare
170 @return true if equal */
171 inline bool equals_to(const page_size_t &a) const {
172 return (a.physical() == m_physical && a.logical() == m_logical &&
173 a.is_compressed() == (bool)m_is_compressed);
174 }
175
176 inline void set_flag(uint32_t fsp_flags) {
177 uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags);
178
179 /* If the logical page size is zero in fsp_flags, then
180 use the legacy 16k page size. */
181 ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize;
182
183 /* Convert from a 'log2 minus 9' to a page size in bytes. */
184 const uint32_t size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
185
188
189 m_logical = size;
190
191 ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags);
192
193 /* If the fsp_flags have zero in the zip_ssize field,
194 then it means that the tablespace does not have
195 compressed pages and the physical page size is the same
196 as the logical page size. */
197 if (ssize == 0) {
198 m_is_compressed = false;
200 } else {
201 m_is_compressed = true;
202
203 /* Convert from a 'log2 minus 9' to a page size
204 in bytes. */
205 const ulint phy = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
206
207 ut_ad(phy <= UNIV_ZIP_SIZE_MAX);
208 ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS));
209
210 m_physical = phy;
211 }
212 }
213
214 page_size_t &operator=(const page_size_t &) = default;
215 page_size_t(const page_size_t &) = default;
216
217 private:
218 /* For non compressed tablespaces, physical page size is equal to
219 the logical page size and the data is stored in buf_page_t::frame
220 (and is also always equal to univ_page_size (--innodb-page-size=)).
221
222 For compressed tablespaces, physical page size is the compressed
223 page size as stored on disk and in buf_page_t::zip::data. The logical
224 page size is the uncompressed page size in memory - the size of
225 buf_page_t::frame (currently also always equal to univ_page_size
226 (--innodb-page-size=)). */
227
228 /** Physical page size. */
230
231 /** Logical page size. */
233
234 /** Flag designating whether the physical page is compressed, which is
235 true IFF the whole tablespace where the page belongs is compressed. */
236 unsigned m_is_compressed : 1;
237};
238
239/* Overloading the global output operator to conveniently print an object
240of type the page_size_t.
241@param[in,out] out the output stream
242@param[in] obj an object of type page_size_t to be printed
243@retval the output stream */
244inline std::ostream &operator<<(std::ostream &out, const page_size_t &obj) {
245 out << "[page size: physical=" << obj.physical()
246 << ", logical=" << obj.logical() << ", compressed=" << obj.is_compressed()
247 << "]";
248 return (out);
249}
250
252
253#endif /* page0size_t */
uint32_t page_no_t
Page number.
Definition: api0api.h:45
Page size descriptor.
Definition: page0size.h:50
page_no_t extent_size() const
Definition: page0size.h:134
bool equals_to(const page_size_t &a) const
Check if a given page_size_t object is equal to the current one.
Definition: page0size.h:171
page_size_t(uint32_t fsp_flags)
Constructor from (fsp_flags).
Definition: page0size.h:81
void set_flag(uint32_t fsp_flags)
Definition: page0size.h:176
bool is_compressed() const
Check whether the page is compressed on disk.
Definition: page0size.h:158
unsigned m_physical
Physical page size.
Definition: page0size.h:229
unsigned m_is_compressed
Flag designating whether the physical page is compressed, which is true IFF the whole tablespace wher...
Definition: page0size.h:236
page_size_t(uint32_t physical, uint32_t logical, bool is_compressed)
Constructor from (physical, logical, is_compressed).
Definition: page0size.h:56
void copy_from(const page_size_t &src)
Copy the values from a given page_size_t object.
Definition: page0size.h:162
page_size_t & operator=(const page_size_t &)=default
size_t logical() const
Retrieve the logical page size (in-memory).
Definition: page0size.h:129
size_t extents_per_xdes() const
Definition: page0size.h:154
unsigned m_logical
Logical page size.
Definition: page0size.h:232
page_size_t(const page_size_t &)=default
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:121
constexpr uint32_t FSP_FLAGS_GET_PAGE_SSIZE(uint32_t flags)
Return the value of the PAGE_SSIZE field.
Definition: fsp0types.h:335
constexpr uint32_t FSP_FLAGS_GET_ZIP_SSIZE(uint32_t flags)
Return the value of the ZIP_SSIZE field.
Definition: fsp0types.h:327
size_t size(const char *const c)
Definition: base64.h:46
constexpr size_t PAGE_SIZE_T_SIZE_BITS
Definition: page0size.h:46
std::ostream & operator<<(std::ostream &out, const page_size_t &obj)
Definition: page0size.h:244
page_size_t univ_page_size
constexpr size_t FIELD_REF_SIZE
Definition: page0size.h:39
const byte field_ref_zero[FIELD_REF_SIZE]
A BLOB field reference full of zero, for use in assertions and tests.Initially, BLOB field references...
Definition: page0zip.cc:42
constexpr uint32_t UNIV_ZIP_SIZE_MAX
Largest compressed page size.
Definition: univ.i:333
constexpr uint32_t UNIV_PAGE_SIZE_ORIG
Original 16k page size for InnoDB tablespaces.
Definition: univ.i:327
constexpr uint32_t UNIV_PAGE_SSIZE_ORIG
Original 16k InnoDB Page Size as an ssize (log2 - 9)
Definition: univ.i:318
unsigned long int ulint
Definition: univ.i:406
constexpr size_t UNIV_PAGE_SIZE_MAX
Maximum page size InnoDB currently supports.
Definition: univ.i:323
constexpr uint32_t UNIV_ZIP_SIZE_MIN
Smallest compressed page size.
Definition: univ.i:330
#define ut_error
Abort execution.
Definition: ut0dbg.h:101
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:107
#define ut_is_2pow(n)
Determines if a number is zero or a power of two.
Definition: ut0ut.h:203