MySQL 9.0.0
Source Code Documentation
page0cur.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 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/page0cur.h
29 The page cursor
30
31 Created 10/4/1994 Heikki Tuuri
32 *************************************************************************/
33
34#ifndef page0cur_h
35#define page0cur_h
36
37#include "univ.i"
38
39#include "buf0types.h"
40#include "data0data.h"
41#include "gis0type.h"
42#include "mtr0mtr.h"
43#include "page0page.h"
44#include "rem0rec.h"
45#include "rem0wrec.h"
46
47#define PAGE_CUR_ADAPT
48
49#ifdef UNIV_DEBUG
50/** Gets pointer to the page frame where the cursor is positioned.
51 @return page */
53 page_cur_t *cur); /*!< in: page cursor */
54/** Gets pointer to the buffer block where the cursor is positioned.
55 @return page */
57 page_cur_t *cur); /*!< in: page cursor */
58/** Gets pointer to the page frame where the cursor is positioned.
59 @return page */
61 page_cur_t *cur); /*!< in: page cursor */
62/** Gets the record where the cursor is positioned.
63 @return record */
64static inline rec_t *page_cur_get_rec(page_cur_t *cur); /*!< in: page cursor */
65#else /* UNIV_DEBUG */
66#define page_cur_get_page(cur) page_align((cur)->rec)
67#define page_cur_get_block(cur) (cur)->block
68#define page_cur_get_page_zip(cur) buf_block_get_page_zip((cur)->block)
69#define page_cur_get_rec(cur) (cur)->rec
70#endif /* UNIV_DEBUG */
71
72/** Sets the cursor object to point before the first user record on the page.
73@param[in] block index page
74@param[in] cur cursor */
75static inline void page_cur_set_before_first(const buf_block_t *block,
76 page_cur_t *cur);
77
78/** Sets the cursor object to point after the last user record on the page.
79@param[in] block index page
80@param[in] cur cursor */
81static inline void page_cur_set_after_last(const buf_block_t *block,
82 page_cur_t *cur);
83
84/** Returns true if the cursor is before first user record on page.
85 @return true if at start */
86static inline bool page_cur_is_before_first(
87 const page_cur_t *cur); /*!< in: cursor */
88/** Returns true if the cursor is after last user record.
89 @return true if at end */
90static inline bool page_cur_is_after_last(
91 const page_cur_t *cur); /*!< in: cursor */
92
93/** Positions the cursor on the given record.
94@param[in] rec record on a page
95@param[in] block buffer block containing the record
96@param[out] cur page cursor */
97static inline void page_cur_position(const rec_t *rec, const buf_block_t *block,
98 page_cur_t *cur);
99
100/** Moves the cursor to the next record on page. */
101static inline void page_cur_move_to_next(
102 page_cur_t *cur); /*!< in/out: cursor; must not be after last */
103/** Moves the cursor to the previous record on page. */
104static inline void page_cur_move_to_prev(
105 page_cur_t *cur); /*!< in/out: cursor; not before first */
106#ifndef UNIV_HOTBACKUP
107/** Inserts a record next to page cursor. Returns pointer to inserted record if
108succeed, i.e., enough space available, NULL otherwise. The cursor stays at the
109same logical position, but the physical position may change if it is pointing to
110a compressed page that was reorganized.
111
112IMPORTANT: The caller will have to update IBUF_BITMAP_FREE if this is a
113compressed leaf page in a secondary index. This has to be done either within the
114same mini-transaction, or by invoking ibuf_reset_free_bits() before
115mtr_commit().
116
117@param[in,out] cursor Page cursor.
118@param[in] tuple Pointer to a data tuple
119@param[in] index Index descriptor.
120@param[in] offsets Offsets on *rec.
121@param[in,out] heap Pointer to memory heap, or to nullptr.
122@param[in] mtr Mini-transaction handle, or nullptr.
123@return pointer to record if succeed, NULL otherwise */
124[[nodiscard]] static inline rec_t *page_cur_tuple_insert(
125 page_cur_t *cursor, const dtuple_t *tuple, dict_index_t *index,
126 ulint **offsets, mem_heap_t **heap, mtr_t *mtr);
127#endif /* !UNIV_HOTBACKUP */
128
129/** Inserts a record next to page cursor. Returns pointer to inserted record
130if succeed, i.e., enough space available, NULL otherwise. The cursor stays at
131the same logical position, but the physical position may change if it is
132pointing to a compressed page that was reorganized.
133
134IMPORTANT: The caller will have to update IBUF_BITMAP_FREE if this is a
135compressed leaf page in a secondary index.
136This has to be done either within the same mini-transaction, or by invoking
137ibuf_reset_free_bits() before mtr_commit().
138
139@param[in,out] cursor A page cursor
140@param[in] rec record To insert
141@param[in] index Record descriptor
142@param[in,out] offsets rec_get_offsets(rec, index)
143@param[in] mtr Mini-transaction handle, or NULL
144@return pointer to record if succeed, NULL otherwise */
145static inline rec_t *page_cur_rec_insert(page_cur_t *cursor, const rec_t *rec,
146 dict_index_t *index, ulint *offsets,
147 mtr_t *mtr);
148
149/** Inserts a record next to page cursor on an uncompressed page.
150 Returns pointer to inserted record if succeed, i.e., enough
151 space available, NULL otherwise. The cursor stays at the same position.
152 @return pointer to record if succeed, NULL otherwise */
153[[nodiscard]] rec_t *page_cur_insert_rec_low(
154 rec_t *current_rec, /*!< in: pointer to current record after
155 which the new record is inserted */
156 dict_index_t *index, /*!< in: record descriptor */
157 const rec_t *rec, /*!< in: pointer to a physical record */
158 ulint *offsets, /*!< in/out: rec_get_offsets(rec, index) */
159 mtr_t *mtr); /*!< in: mini-transaction handle, or NULL */
160
161/** Inserts a record next to page cursor on an uncompressed page.
162@param[in] current_rec Pointer to current record after which
163 the new record is inserted.
164@param[in] index Record descriptor
165@param[in] tuple Pointer to a data tuple
166@param[in] mtr Mini-transaction handle, or NULL
167@param[in] rec_size The size of new record
168
169@return pointer to record if succeed, NULL otherwise */
171 const dtuple_t *tuple, mtr_t *mtr,
172 ulint rec_size);
173
174/** Inserts a record next to page cursor on a compressed and uncompressed
175 page. Returns pointer to inserted record if succeed, i.e.,
176 enough space available, NULL otherwise.
177 The cursor stays at the same position.
178
179 IMPORTANT: The caller will have to update IBUF_BITMAP_FREE
180 if this is a compressed leaf page in a secondary index.
181 This has to be done either within the same mini-transaction,
182 or by invoking ibuf_reset_free_bits() before mtr_commit().
183
184 @return pointer to record if succeed, NULL otherwise */
185[[nodiscard]] rec_t *page_cur_insert_rec_zip(
186 page_cur_t *cursor, /*!< in/out: page cursor */
187 dict_index_t *index, /*!< in: record descriptor */
188 const rec_t *rec, /*!< in: pointer to a physical record */
189 ulint *offsets, /*!< in/out: rec_get_offsets(rec, index) */
190 mtr_t *mtr); /*!< in: mini-transaction handle, or NULL */
191/** Copies records from page to a newly created page, from a given record
192 onward, including that record. Infimum and supremum records are not copied.
193
194 IMPORTANT: The caller will have to update IBUF_BITMAP_FREE
195 if this is a compressed leaf page in a secondary index.
196 This has to be done either within the same mini-transaction,
197 or by invoking ibuf_reset_free_bits() before mtr_commit(). */
199 page_t *new_page, /*!< in/out: index page to copy to */
200 rec_t *rec, /*!< in: first record to copy */
201 dict_index_t *index, /*!< in: record descriptor */
202 mtr_t *mtr); /*!< in: mtr */
203/** Deletes a record at the page cursor. The cursor is moved to the
204 next record after the deleted one. */
206 page_cur_t *cursor, /*!< in/out: a page cursor */
207 const dict_index_t *index, /*!< in: record descriptor */
208 const ulint *offsets, /*!< in: rec_get_offsets(
209 cursor->rec, index) */
210 mtr_t *mtr); /*!< in: mini-transaction handle */
211#ifndef UNIV_HOTBACKUP
212/** Search the right position for a page cursor.
213@param[in] block buffer block
214@param[in] index index tree
215@param[in] tuple data tuple
216@param[in] mode PAGE_CUR_L, PAGE_CUR_LE, PAGE_CUR_G, or PAGE_CUR_GE
217@param[out] cursor page cursor
218@return number of matched fields on the left */
219static inline ulint page_cur_search(const buf_block_t *block,
220 const dict_index_t *index,
221 const dtuple_t *tuple, page_cur_mode_t mode,
222 page_cur_t *cursor);
223
224/** Search the right position for a page cursor.
225@param[in] block buffer block
226@param[in] index index tree
227@param[in] tuple data tuple
228@param[out] cursor page cursor
229@return number of matched fields on the left */
230static inline ulint page_cur_search(const buf_block_t *block,
231 const dict_index_t *index,
232 const dtuple_t *tuple, page_cur_t *cursor);
233#endif /* !UNIV_HOTBACKUP */
234
235/** Searches the right position for a page cursor.
236@param[in] block Buffer block
237@param[in] index Record descriptor
238@param[in] tuple Data tuple
239@param[in] mode PAGE_CUR_L, PAGE_CUR_LE, PAGE_CUR_G, or PAGE_CUR_GE
240@param[in,out] iup_matched_fields Already matched fields in upper limit record
241@param[in,out] ilow_matched_fields Already matched fields in lower limit record
242@param[out] cursor Page cursor
243@param[in,out] rtr_info Rtree search stack */
245 const dict_index_t *index,
246 const dtuple_t *tuple, page_cur_mode_t mode,
247 ulint *iup_matched_fields,
248
249 ulint *ilow_matched_fields,
250
251 page_cur_t *cursor, rtr_info_t *rtr_info);
252
253/** Search the right position for a page cursor.
254@param[in] block buffer block
255@param[in] index index tree
256@param[in] tuple key to be searched for
257@param[in] mode search mode
258@param[in,out] iup_matched_fields already matched fields in the
259upper limit record
260@param[in,out] iup_matched_bytes already matched bytes in the
261first partially matched field in the upper limit record
262@param[in,out] ilow_matched_fields already matched fields in the
263lower limit record
264@param[in,out] ilow_matched_bytes already matched bytes in the
265first partially matched field in the lower limit record
266@param[out] cursor page cursor */
268 const buf_block_t *block, const dict_index_t *index, const dtuple_t *tuple,
269 page_cur_mode_t mode, ulint *iup_matched_fields, ulint *iup_matched_bytes,
270 ulint *ilow_matched_fields, ulint *ilow_matched_bytes, page_cur_t *cursor);
271/** Positions a page cursor on a randomly chosen user record on a page. If there
272 are no user records, sets the cursor on the infimum record. */
273void page_cur_open_on_rnd_user_rec(buf_block_t *block, /*!< in: page */
274 page_cur_t *cursor); /*!< out: page cursor */
275/** Parses a log record of a record insert on a page.
276 @return end of log record or NULL */
277const byte *page_cur_parse_insert_rec(
278 bool is_short, /*!< in: true if short inserts */
279 const byte *ptr, /*!< in: buffer */
280 const byte *end_ptr, /*!< in: buffer end */
281 buf_block_t *block, /*!< in: page or NULL */
282 dict_index_t *index, /*!< in: record descriptor */
283 mtr_t *mtr); /*!< in: mtr or NULL */
284/** Parses a log record of copying a record list end to a new created page.
285 @return end of log record or NULL */
287 const byte *ptr, /*!< in: buffer */
288 const byte *end_ptr, /*!< in: buffer end */
289 buf_block_t *block, /*!< in: page or NULL */
290 dict_index_t *index, /*!< in: record descriptor */
291 mtr_t *mtr); /*!< in: mtr or NULL */
292/** Parses log record of a record delete on a page.
293 @return pointer to record end or NULL */
294const byte *page_cur_parse_delete_rec(
295 const byte *ptr, /*!< in: buffer */
296 const byte *end_ptr, /*!< in: buffer end */
297 buf_block_t *block, /*!< in: page or NULL */
298 dict_index_t *index, /*!< in: record descriptor */
299 mtr_t *mtr); /*!< in: mtr or NULL */
300/** Removes the record from a leaf page. This function does not log
301any changes. It is used by the IMPORT tablespace functions.
302@return true if success, i.e., the page did not become too empty
303@param[in] index The index that the record belongs to.
304@param[in,out] pcur Page cursor on record to delete.
305@param[in] offsets Offsets for record. */
306bool page_delete_rec(const dict_index_t *index, page_cur_t *pcur,
307 const ulint *offsets);
308
309/** Index page cursor */
310
312 /** Index the cursor is on. */
313 const dict_index_t *index{nullptr};
314
315 /** pointer to a record on page */
316 rec_t *rec{nullptr};
317
318 /** Current offsets of the record. */
319 ulint *offsets{nullptr};
320
321 /** Pointer to the current block containing rec. */
323};
324
325#include "page0cur.ic"
326
327#endif
The database buffer pool global types for the directory.
SQL data field and tuple.
R-tree header file.
Mini-transaction buffer.
mode
Definition: file_handle.h:61
static bool page_cur_is_after_last(const page_cur_t *cur)
Returns true if the cursor is after last user record.
static page_zip_des_t * page_cur_get_page_zip(page_cur_t *cur)
Gets pointer to the page frame where the cursor is positioned.
static rec_t * page_cur_tuple_insert(page_cur_t *cursor, const dtuple_t *tuple, dict_index_t *index, ulint **offsets, mem_heap_t **heap, mtr_t *mtr)
Inserts a record next to page cursor.
void page_cur_search_with_match_bytes(const buf_block_t *block, const dict_index_t *index, const dtuple_t *tuple, page_cur_mode_t mode, ulint *iup_matched_fields, ulint *iup_matched_bytes, ulint *ilow_matched_fields, ulint *ilow_matched_bytes, page_cur_t *cursor)
Search the right position for a page cursor.
Definition: page0cur.cc:614
rec_t * page_cur_insert_rec_low(rec_t *current_rec, dict_index_t *index, const rec_t *rec, ulint *offsets, mtr_t *mtr)
Inserts a record next to page cursor on an uncompressed page.
Definition: page0cur.cc:1225
rec_t * page_cur_direct_insert_rec_low(rec_t *current_rec, dict_index_t *index, const dtuple_t *tuple, mtr_t *mtr, ulint rec_size)
Inserts a record next to page cursor on an uncompressed page.
Definition: page0cur.cc:1415
static void page_cur_set_after_last(const buf_block_t *block, page_cur_t *cur)
Sets the cursor object to point after the last user record on the page.
static rec_t * page_cur_rec_insert(page_cur_t *cursor, const rec_t *rec, dict_index_t *index, ulint *offsets, mtr_t *mtr)
Inserts a record next to page cursor.
static void page_cur_move_to_prev(page_cur_t *cur)
Moves the cursor to the previous record on page.
static rec_t * page_cur_get_rec(page_cur_t *cur)
Gets the record where the cursor is positioned.
void page_cur_open_on_rnd_user_rec(buf_block_t *block, page_cur_t *cursor)
Positions a page cursor on a randomly chosen user record on a page.
Definition: page0cur.cc:834
static void page_cur_position(const rec_t *rec, const buf_block_t *block, page_cur_t *cur)
Positions the cursor on the given record.
void page_cur_delete_rec(page_cur_t *cursor, const dict_index_t *index, const ulint *offsets, mtr_t *mtr)
Deletes a record at the page cursor.
Definition: page0cur.cc:2303
const byte * page_parse_copy_rec_list_to_created_page(const byte *ptr, const byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Parses a log record of copying a record list end to a new created page.
Definition: page0cur.cc:2009
static void page_cur_set_before_first(const buf_block_t *block, page_cur_t *cur)
Sets the cursor object to point before the first user record on the page.
static buf_block_t * page_cur_get_block(page_cur_t *cur)
Gets pointer to the buffer block where the cursor is positioned.
void page_cur_search_with_match(const buf_block_t *block, const dict_index_t *index, const dtuple_t *tuple, page_cur_mode_t mode, ulint *iup_matched_fields, ulint *ilow_matched_fields, page_cur_t *cursor, rtr_info_t *rtr_info)
Searches the right position for a page cursor.
Definition: page0cur.cc:328
rec_t * page_cur_insert_rec_zip(page_cur_t *cursor, dict_index_t *index, const rec_t *rec, ulint *offsets, mtr_t *mtr)
Inserts a record next to page cursor on a compressed and uncompressed page.
Definition: page0cur.cc:1593
bool page_delete_rec(const dict_index_t *index, page_cur_t *pcur, const ulint *offsets)
Removes the record from a leaf page.
Definition: page0page.cc:2557
static void page_cur_move_to_next(page_cur_t *cur)
Moves the cursor to the next record on page.
const byte * page_cur_parse_insert_rec(bool is_short, const byte *ptr, const byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Parses a log record of a record insert on a page.
Definition: page0cur.cc:1051
static ulint page_cur_search(const buf_block_t *block, const dict_index_t *index, const dtuple_t *tuple, page_cur_mode_t mode, page_cur_t *cursor)
Search the right position for a page cursor.
void page_copy_rec_list_end_to_created_page(page_t *new_page, rec_t *rec, dict_index_t *index, mtr_t *mtr)
Copies records from page to a newly created page, from a given record onward, including that record.
Definition: page0cur.cc:2065
static bool page_cur_is_before_first(const page_cur_t *cur)
Returns true if the cursor is before first user record on page.
static page_t * page_cur_get_page(page_cur_t *cur)
Gets pointer to the page frame where the cursor is positioned.
const byte * page_cur_parse_delete_rec(const byte *ptr, const byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Parses log record of a record delete on a page.
Definition: page0cur.cc:2256
The page cursor.
Index page routines.
page_cur_mode_t
Definition: page0types.h:176
byte page_t
Type of the index page.
Definition: page0types.h:152
Record manager.
byte rec_t
Definition: rem0types.h:41
Record manager wrapper declaration.
The buffer control block structure.
Definition: buf0buf.h:1747
Data structure for an index.
Definition: dict0mem.h:1046
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:684
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
Index page cursor.
Definition: page0cur.h:311
const dict_index_t * index
Index the cursor is on.
Definition: page0cur.h:313
buf_block_t * block
Pointer to the current block containing rec.
Definition: page0cur.h:322
ulint * offsets
Current offsets of the record.
Definition: page0cur.h:319
rec_t * rec
pointer to a record on page
Definition: page0cur.h:316
Compressed page descriptor.
Definition: page0types.h:201
Vectors holding the matching internal pages/nodes and leaf records.
Definition: gis0type.h:109
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:406