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