MySQL 26.7.0
Source Code Documentation
page0size.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2013, 2026, 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
85 use the 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 uint32_t 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,
99 then it means that the tablespace does not have
100 compressed pages and the physical page size is the same
101 as the logical page 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 if (m_physical > m_logical) {
118#ifdef UNIV_NO_ERR_MSGS
120#else
121 ib::fatal(UT_LOCATION_HERE, ER_IB_INVALID_PAGE_SIZE, ulong{m_physical},
122 ulong{m_logical}, ulong{fsp_flags});
123#endif
124 }
125 }
126
127 /** Retrieve the physical page size (on-disk).
128 @return physical page size in bytes */
129 inline size_t physical() const {
130 ut_ad(m_physical > 0);
131
132 return (m_physical);
133 }
134
135 /** Retrieve the logical page size (in-memory).
136 @return logical page size in bytes */
137 inline size_t logical() const {
138 ut_ad(m_logical > 0);
139 return (m_logical);
140 }
141
143 page_no_t size = 0;
144 switch (m_physical) {
145 case 4096:
146 size = 256;
147 break;
148 case 8192:
149 size = 128;
150 break;
151 case 16384:
152 case 32768:
153 case 65536:
154 size = 64;
155 break;
156 default:
157 ut_d(ut_error);
158 }
159 return (size);
160 }
161
162 size_t extents_per_xdes() const { return (m_physical / extent_size()); }
163
164 /** Check whether the page is compressed on disk.
165 @return true if compressed */
166 inline bool is_compressed() const { return (m_is_compressed); }
167
168 /** Copy the values from a given page_size_t object.
169 @param[in] src page size object whose values to fetch */
170 inline void copy_from(const page_size_t &src) {
171 m_physical = src.physical();
172 m_logical = src.logical();
174 }
175
176 /** Check if a given page_size_t object is equal to the current one.
177 @param[in] a page_size_t object to compare
178 @return true if equal */
179 inline bool equals_to(const page_size_t &a) const {
180 return (a.physical() == m_physical && a.logical() == m_logical &&
181 a.is_compressed() == (bool)m_is_compressed);
182 }
183
184 page_size_t &operator=(const page_size_t &) = default;
185 page_size_t(const page_size_t &) = default;
186
187 private:
188 /* For non compressed tablespaces, physical page size is equal to
189 the logical page size and the data is stored in buf_page_t::frame
190 (and is also always equal to univ_page_size (--innodb-page-size=)).
191
192 For compressed tablespaces, physical page size is the compressed
193 page size as stored on disk and in buf_page_t::zip::data. The logical
194 page size is the uncompressed page size in memory - the size of
195 buf_page_t::frame (currently also always equal to univ_page_size
196 (--innodb-page-size=)). */
197
198 /** Physical page size. */
200
201 /** Logical page size. */
203
204 /** Flag designating whether the physical page is compressed, which is
205 true IFF the whole tablespace where the page belongs is compressed. */
206 unsigned m_is_compressed : 1;
207};
208
209/* Overloading the global output operator to conveniently print an object
210of type the page_size_t.
211@param[in,out] out the output stream
212@param[in] obj an object of type page_size_t to be printed
213@retval the output stream */
214inline std::ostream &operator<<(std::ostream &out, const page_size_t &obj) {
215 out << "[page size: physical=" << obj.physical()
216 << ", logical=" << obj.logical() << ", compressed=" << obj.is_compressed()
217 << "]";
218 return (out);
219}
220
222
223#endif /* page0size_t */
uint32_t page_no_t
Page number.
Definition: api0api.h:47
The class fatal is used to emit an error message and stop the server by crashing it.
Definition: ut0log.h:247
Page size descriptor.
Definition: page0size.h:50
page_no_t extent_size() const
Definition: page0size.h:142
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:179
page_size_t(uint32_t fsp_flags)
Constructor from (fsp_flags).
Definition: page0size.h:81
bool is_compressed() const
Check whether the page is compressed on disk.
Definition: page0size.h:166
unsigned m_physical
Physical page size.
Definition: page0size.h:199
unsigned m_is_compressed
Flag designating whether the physical page is compressed, which is true IFF the whole tablespace wher...
Definition: page0size.h:206
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:170
page_size_t & operator=(const page_size_t &)=default
size_t logical() const
Retrieve the logical page size (in-memory).
Definition: page0size.h:137
size_t extents_per_xdes() const
Definition: page0size.h:162
unsigned m_logical
Logical page size.
Definition: page0size.h:202
page_size_t(const page_size_t &)=default
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:129
constexpr uint32_t FSP_FLAGS_GET_PAGE_SSIZE(uint32_t flags)
Return the value of the PAGE_SSIZE field.
Definition: fsp0types.h:352
constexpr uint32_t FSP_FLAGS_GET_ZIP_SSIZE(uint32_t flags)
Return the value of the ZIP_SSIZE field.
Definition: fsp0types.h:344
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:214
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:330
constexpr uint32_t UNIV_PAGE_SIZE_ORIG
Original 16k page size for InnoDB tablespaces.
Definition: univ.i:324
constexpr uint32_t UNIV_PAGE_SSIZE_ORIG
Original 16k InnoDB Page Size as an ssize (log2 - 9)
Definition: univ.i:315
unsigned long int ulint
Definition: univ.i:403
constexpr size_t UNIV_PAGE_SIZE_MAX
Maximum page size InnoDB currently supports.
Definition: univ.i:320
constexpr uint32_t UNIV_ZIP_SIZE_MIN
Smallest compressed page size.
Definition: univ.i:327
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_error
Abort execution.
Definition: ut0dbg.h:105
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:111
#define ut_is_2pow(n)
Determines if a number is zero or a power of two.
Definition: ut0ut.h:200