MySQL  8.0.19
Source Code Documentation
page0types.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2019, Oracle and/or its affiliates. All Rights Reserved.
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 
48 typedef byte page_header_t;
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. */
188  PAGE_CUR_WITHIN = 9,
189  PAGE_CUR_DISJOINT = 10,
194 };
195 
196 /** Compressed page descriptor */
197 struct page_zip_des_t {
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 */
218 struct page_zip_stat_t {
219  /** Number of page compressions */
220  ulint compressed;
221  /** Number of successful page compressions */
222  ulint compressed_ok;
223  /** Number of page decompressions */
224  ulint decompressed;
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. */
260  page_zip_des_t *page_zip, /*!< in/out: compressed page */
261  const byte *rec, /*!< in: record on the uncompressed page */
262  ulint flag); /*!< in: the owned flag (nonzero=TRUE) */
263 
264 /** Shift the dense page directory when a record is deleted.
265 @param[in,out] page_zip compressed page
266 @param[in] rec deleted record
267 @param[in] index index of rec
268 @param[in] offsets rec_get_offsets(rec)
269 @param[in] free previous start of the free list */
270 void page_zip_dir_delete(page_zip_des_t *page_zip, byte *rec,
271  dict_index_t *index, const ulint *offsets,
272  const byte *free);
273 
274 /** Add a slot to the dense page directory. */
276  page_zip_des_t *page_zip, /*!< in/out: compressed page */
277  bool is_clustered); /*!< in: nonzero for clustered index,
278  zero for others */
279 #endif
PAGE_CUR_CONTAIN
@ PAGE_CUR_CONTAIN
Definition: page0types.h:171
dict0types.h
page_zip_stat_t::decompressed
ulint decompressed
Number of page decompressions.
Definition: page0types.h:209
page_t
#define page_t
Eliminates a name collision on HP-UX.
Definition: page0types.h:131
page_zip_des_t::data
page_zip_t * data
compressed page data
Definition: page0types.h:183
PAGE_ZIP_SSIZE_MAX
#define PAGE_ZIP_SSIZE_MAX
Maximum compressed page shift size.
Definition: page0types.h:148
PAGE_CUR_INTERSECT
@ PAGE_CUR_INTERSECT
Definition: page0types.h:172
PAGE_CUR_G
@ PAGE_CUR_G
Definition: page0types.h:160
page_zip_stat_t::compressed_ok
ulint compressed_ok
Number of successful page compressions.
Definition: page0types.h:207
PAGE_CUR_GE
@ PAGE_CUR_GE
Definition: page0types.h:161
page_cur_mode_t
page_cur_mode_t
Definition: page0types.h:158
page_zip_des_t::m_nonempty
unsigned m_nonempty
TRUE if the modification log is not empty.
Definition: page0types.h:191
page_zip_rec_set_owned
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:2246
dict_index_t
Data structure for an index.
Definition: dict0mem.h:869
PAGE_ZIP_SSIZE_BITS
#define PAGE_ZIP_SSIZE_BITS
Number of bits needed for representing different compressed page sizes.
Definition: page0types.h:145
page_cur_t
Index page cursor.
Definition: page0cur.h:315
page_zip_stat
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
free
#define free(A)
Definition: fts0ast.h:42
PAGE_CUR_RTREE_GET_FATHER
@ PAGE_CUR_RTREE_GET_FATHER
Definition: page0types.h:178
page_zip_stat_t::compressed
ulint compressed
Number of page compressions.
Definition: page0types.h:205
PAGE_CUR_UNSUPP
@ PAGE_CUR_UNSUPP
Definition: page0types.h:159
PAGE_CUR_WITHIN
@ PAGE_CUR_WITHIN
Definition: page0types.h:173
page_zip_des_t
Compressed page descriptor.
Definition: page0types.h:182
page_zip_dir_add_slot
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:2419
page_zip_stat_t
Compression statistics for a given page size.
Definition: page0types.h:203
PAGE_CUR_L
@ PAGE_CUR_L
Definition: page0types.h:162
page_zip_stat_t::page_zip_stat_t
page_zip_stat_t()
Definition: page0types.h:214
page_zip_stat_per_index
page_zip_stat_per_index_t page_zip_stat_per_index
Statistics on compression, indexed by dict_index_t::id.
Definition: page0zip.cc:82
page_zip_rec_set_deleted
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:2226
PAGE_CUR_DISJOINT
@ PAGE_CUR_DISJOINT
Definition: page0types.h:174
page_zip_des_t::n_blobs
unsigned n_blobs
number of externally stored columns on the page; the maximum is 744 on a 16 KiB page
Definition: page0types.h:193
page_zip_des_t::m_start
unsigned m_start
start offset of modification log
Definition: page0types.h:186
PAGE_HEAP_NO_USER_LOW
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:121
page_zip_des_t::ssize
unsigned ssize
0 or compressed page shift size; the size in bytes is (UNIV_ZIP_SIZE_MIN >> 1) << ssize.
Definition: page0types.h:196
page_zip_t
byte page_zip_t
Compressed index page.
Definition: page0types.h:135
ut0new.h
page_zip_stat_t::decompressed_usec
ib_uint64_t decompressed_usec
Duration of page decompressions in microseconds.
Definition: page0types.h:213
page_zip_dir_delete
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.
page_zip_des_t::m_external
bool m_external
Allocated externally, not from the buffer pool.
Definition: page0types.h:187
PAGE_CUR_MBR_EQUAL
@ PAGE_CUR_MBR_EQUAL
Definition: page0types.h:175
page_zip_stat_per_index_t
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:228
page_zip_des_t::m_end
unsigned m_end
end offset of modification log
Definition: page0types.h:190
PAGE_CUR_RTREE_LOCATE
@ PAGE_CUR_RTREE_LOCATE
Definition: page0types.h:177
page_zip_stat_t::compressed_usec
ib_uint64_t compressed_usec
Duration of page compressions in microseconds.
Definition: page0types.h:211
PAGE_HEAP_NO_INFIMUM
constexpr ulint PAGE_HEAP_NO_INFIMUM
Page infimum.
Definition: page0types.h:115
PAGE_HEAP_NO_SUPREMUM
constexpr ulint PAGE_HEAP_NO_SUPREMUM
Page supremum.
Definition: page0types.h:117
PAGE_CUR_RTREE_INSERT
@ PAGE_CUR_RTREE_INSERT
Definition: page0types.h:176
ut_allocator
Allocator class for allocating memory from inside std::* containers.
Definition: ut0new.h:567
page_header_t
byte page_header_t
Definition: page0types.h:48
index
char * index(const char *, int c)
Definition: mysql.cc:2875
mtr0types.h
PAGE_CUR_LE
@ PAGE_CUR_LE
Definition: page0types.h:163
flag
static int flag
Definition: hp_test1.cc:39