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