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