Debian Codegraph @

storage/innobase/include/btr0cur.ic

raw
1 /*****************************************************************************
2
3 Copyright (c) 1994, 2026, 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 designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/btr0cur.ic
29 The index tree cursor
30
31 Created 10/16/1994 Heikki Tuuri
32 *******************************************************/
33
34 #ifndef UNIV_HOTBACKUP
35 #endif /* !UNIV_HOTBACKUP */
36 #include "btr0btr.h"
37
38 #ifdef UNIV_DEBUG
39 #define LIMIT_OPTIMISTIC_INSERT_DEBUG(NREC, CODE) \
40 if (btr_cur_limit_optimistic_insert_debug > 1 && \
41 (NREC) >= (ulint)btr_cur_limit_optimistic_insert_debug) { \
42 CODE; \
43 }
44 #else
45 #define LIMIT_OPTIMISTIC_INSERT_DEBUG(NREC, CODE)
46 #endif /* UNIV_DEBUG */
47
48 #ifdef UNIV_DEBUG
49 /** Returns the page cursor component of a tree cursor.
50 @return pointer to page cursor component */
51 static inline page_cur_t *btr_cur_get_page_cur(
52 const btr_cur_t *cursor) /*!< in: tree cursor */
53 {
54 return (&((btr_cur_t *)cursor)->page_cur);
55 }
56
57 /** Returns the buffer block on which the tree cursor is positioned.
58 @return pointer to buffer block */
59 static inline buf_block_t *btr_cur_get_block(
60 const btr_cur_t *cursor) /*!< in: tree cursor */
61 {
62 return (page_cur_get_block(btr_cur_get_page_cur(cursor)));
63 }
64
65 /** Returns the record pointer of a tree cursor.
66 @return pointer to record */
67 static inline rec_t *btr_cur_get_rec(
68 const btr_cur_t *cursor) /*!< in: tree cursor */
69 {
70 return (page_cur_get_rec(btr_cur_get_page_cur(cursor)));
71 }
72 #endif /* UNIV_DEBUG */
73
74 /** Returns the compressed page on which the tree cursor is positioned.
75 @return pointer to compressed page, or NULL if the page is not compressed */
76 static inline page_zip_des_t *btr_cur_get_page_zip(
77 btr_cur_t *cursor) /*!< in: tree cursor */
78 {
79 return (buf_block_get_page_zip(btr_cur_get_block(cursor)));
80 }
81
82 /** Returns the page of a tree cursor.
83 @return pointer to page */
84 static inline page_t *btr_cur_get_page(
85 btr_cur_t *cursor) /*!< in: tree cursor */
86 {
87 return (page_align(page_cur_get_rec(&(cursor->page_cur))));
88 }
89
90 /** Positions a tree cursor at a given record. */
91 static inline void btr_cur_position(
92 dict_index_t *index, /*!< in: index */
93 rec_t *rec, /*!< in: record in tree */
94 buf_block_t *block, /*!< in: buffer block of rec */
95 btr_cur_t *cursor) /*!< out: cursor */
96 {
97 ut_ad(page_align(rec) == block->frame);
98
99 page_cur_position(rec, block, btr_cur_get_page_cur(cursor));
100
101 cursor->index = index;
102 }
103
104 /** Checks if compressing an index page where a btr cursor is placed makes
105 sense.
106 @return true if compression is recommended */
107 static inline bool btr_cur_compress_recommendation(
108 btr_cur_t *cursor, /*!< in: btr cursor */
109 mtr_t *mtr) /*!< in: mtr */
110 {
111 const page_t *page;
112
113 ut_ad(mtr_is_block_fix(mtr, btr_cur_get_block(cursor), MTR_MEMO_PAGE_X_FIX,
114 cursor->index->table));
115
116 page = btr_cur_get_page(cursor);
117
118 LIMIT_OPTIMISTIC_INSERT_DEBUG(page_get_n_recs(page) * 2, return false);
119
120 if ((page_get_data_size(page) < BTR_CUR_PAGE_COMPRESS_LIMIT(cursor->index)) ||
121 ((btr_page_get_next(page, mtr) == FIL_NULL) &&
122 (btr_page_get_prev(page, mtr) == FIL_NULL))) {
123 /* The page fillfactor has dropped below a predefined
124 minimum value OR the level in the B-tree contains just
125 one page: we recommend compression if this is not the
126 root page. */
127
128 return (dict_index_get_page(cursor->index) != page_get_page_no(page));
129 }
130
131 return false;
132 }
133
134 /** Checks if the record on which the cursor is placed can be deleted without
135 making tree compression necessary (or, recommended).
136 @return true if can be deleted without recommended compression */
137 static inline bool btr_cur_can_delete_without_compress(
138 btr_cur_t *cursor, /*!< in: btr cursor */
139 ulint rec_size, /*!< in: rec_get_size(btr_cur_get_rec(cursor))*/
140 mtr_t *mtr) /*!< in: mtr */
141 {
142 page_t *page;
143
144 ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor), MTR_MEMO_PAGE_X_FIX));
145
146 page = btr_cur_get_page(cursor);
147
148 if ((page_get_data_size(page) - rec_size <
149 BTR_CUR_PAGE_COMPRESS_LIMIT(cursor->index)) ||
150 ((btr_page_get_next(page, mtr) == FIL_NULL) &&
151 (btr_page_get_prev(page, mtr) == FIL_NULL)) ||
152 (page_get_n_recs(page) < 2)) {
153 /* The page fillfactor will drop below a predefined
154 minimum value, OR the level in the B-tree contains just
155 one page, OR the page will become empty: we recommend
156 compression if this is not the root page. */
157
158 return (dict_index_get_page(cursor->index) == page_get_page_no(page));
159 }
160
161 return true;
162 }
163
164 static inline void btr_rec_set_deleted_flag(rec_t *rec,
165 page_zip_des_t *page_zip,
166 bool flag) {
167 if (page_rec_is_comp(rec)) {
168 rec_set_deleted_flag_new(rec, page_zip, flag);
169 } else {
170 ut_ad(!page_zip);
171 rec_set_deleted_flag_old(rec, flag);
172 }
173 }