Debian Codegraph @

storage/innobase/btr/btr0btr.cc

raw symbols SCIP
1 /*****************************************************************************
2
3 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2012, Facebook Inc.
5 Copyright (c) 2014, 2023, MariaDB Corporation.
6
7 This program is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free Software
9 Foundation; version 2 of the License.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
18
19 *****************************************************************************/
20
21 /**************************************************//**
22 @file btr/btr0btr.cc
23 The B-tree
24
25 Created 6/2/1994 Heikki Tuuri
26 *******************************************************/
27
28 #include "btr0btr.h"cxx . . $ `<file>/storage/innobase/include/btr0btr.h`/
29
30 #include "page0page.h"cxx . . $ `<file>/storage/innobase/include/page0page.h`/
31 #include "page0zip.h"cxx . . $ `<file>/storage/innobase/include/page0zip.h`/
32 #include "gis0rtree.h"cxx . . $ `<file>/storage/innobase/include/gis0rtree.h`/
33
34 #include "btr0cur.h"cxx . . $ `<file>/storage/innobase/include/btr0cur.h`/
35 #include "btr0sea.h"cxx . . $ `<file>/storage/innobase/include/btr0sea.h`/
36 #include "btr0pcur.h"cxx . . $ `<file>/storage/innobase/include/btr0pcur.h`/
37 #include "rem0cmp.h"cxx . . $ `<file>/storage/innobase/include/rem0cmp.h`/
38 #include "lock0lock.h"cxx . . $ `<file>/storage/innobase/include/lock0lock.h`/
39 #include "trx0trx.h"cxx . . $ `<file>/storage/innobase/include/trx0trx.h`/
40 #include "srv0mon.h"cxx . . $ `<file>/storage/innobase/include/srv0mon.h`/
41 #include "que0que.h"cxx . . $ `<file>/storage/innobase/include/que0que.h`/
42 #include "gis0geo.h"cxx . . $ `<file>/storage/innobase/include/gis0geo.h`/
43 #include "dict0boot.h"cxx . . $ `<file>/storage/innobase/include/dict0boot.h`/
44 #include "row0sel.h"cxx . . $ `<file>/storage/innobase/include/row0sel.h`/ /* row_search_max_autoinc() */
45 #include "log.h"cxx . . $ `<file>/sql/log.h`/
46
47 /**************************************************************//**
48 Checks if the page in the cursor can be merged with given page.
49 If necessary, re-organize the merge_page.
50 @return true if possible to merge. */
51 static
52 bool
53 btr_can_merge_with_pagecxx . . $ btr_can_merge_with_page(68fe3ccd9ccd8e70).(
54 /*====================*/
55 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor on the page to merge */
56 uint32_tcxx . . $ uint32_t# page_no, /*!< in: a sibling page */
57 buf_block_tcxx . . $ buf_block_t#** merge_block, /*!< out: the merge block */
58 mtr_tcxx . . $ mtr_t#* mtr); /*!< in: mini-transaction */
59
60 /*
61 Latching strategy of the InnoDB B-tree
62 --------------------------------------
63
64 Node pointer page latches acquisition is protected by index->lock latch.
65
66 Before MariaDB 10.2.2, all node pointer pages were protected by index->lock
67 either in S (shared) or X (exclusive) mode and block->lock was not acquired on
68 node pointer pages.
69
70 After MariaDB 10.2.2, block->lock S-latch or X-latch is used to protect
71 node pointer pages and obtaiment of node pointer page latches is protected by
72 index->lock.
73
74 (0) Definition: B-tree level.
75
76 (0.1) The leaf pages of the B-tree are at level 0.
77
78 (0.2) The parent of a page at level L has level L+1. (The level of the
79 root page is equal to the tree height.)
80
81 (0.3) The B-tree lock (index->lock) is the parent of the root page and
82 has a level = tree height + 1.
83
84 Index->lock has 3 possible locking modes:
85
86 (1) S-latch:
87
88 (1.1) All latches for pages must be obtained in descending order of tree level.
89
90 (1.2) Before obtaining the first node pointer page latch at a given B-tree
91 level, parent latch must be held (at level +1 ).
92
93 (1.3) If a node pointer page is already latched at the same level
94 we can only obtain latch to its right sibling page latch at the same level.
95
96 (1.4) Release of the node pointer page latches must be done in
97 child-to-parent order. (Prevents deadlocks when obtained index->lock
98 in SX mode).
99
100 (1.4.1) Level L node pointer page latch can be released only when
101 no latches at children level i.e. level < L are hold.
102
103 (1.4.2) All latches from node pointer pages must be released so
104 that no latches are obtained between.
105
106 (1.5) [implied by (1.1), (1.2)] Root page latch must be first node pointer
107 latch obtained.
108
109 (2) SX-latch:
110
111 In this case rules (1.2) and (1.3) from S-latch case are relaxed and
112 merged into (2.2) and rule (1.4) is removed. Thus, latch acquisition
113 can be skipped at some tree levels and latches can be obtained in
114 a less restricted order.
115
116 (2.1) [identical to (1.1)]: All latches for pages must be obtained in descending
117 order of tree level.
118
119 (2.2) When a node pointer latch at level L is obtained,
120 the left sibling page latch in the same level or some ancestor
121 page latch (at level > L) must be hold.
122
123 (2.3) [implied by (2.1), (2.2)] The first node pointer page latch obtained can
124 be any node pointer page.
125
126 (3) X-latch:
127
128 Node pointer latches can be obtained in any order.
129
130 NOTE: New rules after MariaDB 10.2.2 does not affect the latching rules of leaf pages:
131
132 index->lock S-latch is needed in read for the node pointer traversal. When the leaf
133 level is reached, index-lock can be released (and with the MariaDB 10.2.2 changes, all
134 node pointer latches). Left to right index travelsal in leaf page level can be safely done
135 by obtaining right sibling leaf page latch and then releasing the old page latch.
136
137 Single leaf page modifications (BTR_MODIFY_LEAF) are protected by index->lock
138 S-latch.
139
140 B-tree operations involving page splits or merges (BTR_MODIFY_TREE) and page
141 allocations are protected by index->lock X-latch.
142
143 Node pointers
144 -------------
145 Leaf pages of a B-tree contain the index records stored in the
146 tree. On levels n > 0 we store 'node pointers' to pages on level
147 n - 1. For each page there is exactly one node pointer stored:
148 thus the our tree is an ordinary B-tree, not a B-link tree.
149
150 A node pointer contains a prefix P of an index record. The prefix
151 is long enough so that it determines an index record uniquely.
152 The file page number of the child page is added as the last
153 field. To the child page we can store node pointers or index records
154 which are >= P in the alphabetical order, but < P1 if there is
155 a next node pointer on the level, and P1 is its prefix.
156
157 If a node pointer with a prefix P points to a non-leaf child,
158 then the leftmost record in the child must have the same
159 prefix P. If it points to a leaf node, the child is not required
160 to contain any record with a prefix equal to P. The leaf case
161 is decided this way to allow arbitrary deletions in a leaf node
162 without touching upper levels of the tree.
163
164 We have predefined a special minimum record which we
165 define as the smallest record in any alphabetical order.
166 A minimum record is denoted by setting a bit in the record
167 header. A minimum record acts as the prefix of a node pointer
168 which points to a leftmost node on any level of the tree.
169
170 File page allocation
171 --------------------
172 In the root node of a B-tree there are two file segment headers.
173 The leaf pages of a tree are allocated from one file segment, to
174 make them consecutive on disk if possible. From the other file segment
175 we allocate pages for the non-leaf levels of the tree.
176 */
177
178 /** Check a file segment header within a B-tree root page.
179 @param offset file segment header offset
180 @param block B-tree root page
181 @param space tablespace
182 @return whether the segment header is valid */
183 bool btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(ulintcxx . . $ ulint# offset, const buf_block_tcxx . . $ buf_block_t# &block,
184 const fil_space_tcxx . . $ fil_space_t# &space)
185 {
186 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block.page.id().space() == space.id);
187 const uint16_tcxx . . $ uint16_t# hdr= mach_read_from_2cxx . . $ mach_read_from_2(469dcb4e54b221a8).(offset + FSEG_HDR_OFFSETcxx . . $ `storage/innobase/include/fsp0types.h:88:9`! +
188 block.pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
189 if (FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! <= hdr && hdr <= srv_page_sizecxx . . $ srv_page_size. - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`! &&
190 mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(block.pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + offset + FSEG_HDR_SPACEcxx . . $ `storage/innobase/include/fsp0types.h:86:9`!) == space.idcxx . . $ fil_space_t#id.)
191 return true;
192 sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Index root page " UINT32PFcxx . . $ `storage/innobase/include/univ.i:312:10`! " in %s is corrupted "
193 "at " ULINTPFcxx . . $ `storage/innobase/include/univ.i:290:9`!,
194 block.pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(),
195 UT_LIST_GET_FIRSTcxx . . $ `storage/innobase/include/ut0lst.h:421:9`!(space.chain)->namecxx . . $ fil_node_t#name., offset);
196 return false;
197 }
198
199 /** Report a read failure if it is a decryption failure.
200 @param err error code
201 @param index the index that is being accessed */
202 ATTRIBUTE_COLDcxx . . $ `include/my_compiler.h:166:10`! void btr_read_failedcxx . . $ btr_read_failed(5cd27334cb9550f7).(dberr_tcxx . . $ dberr_t# err, const dict_index_tcxx . . $ dict_index_t# &index)
203 {
204 if (err == DB_DECRYPTION_FAILEDcxx . . $ DB_DECRYPTION_FAILED.)
205 innodb_decryption_failedcxx . . $ innodb_decryption_failed(2ca3359e2fe53efa).(nullptr, index.tablecxx . . $ dict_index_t#table.);
206 }
207
208 /** Get an index page and declare its latching order level.
209 @param index index tree
210 @param page page number
211 @param latch_mode latch mode
212 @param mtr mini-transaction
213 @param err error code
214 @param first set if this is a first-time access to the page
215 @return block */
216 buf_block_tcxx . . $ buf_block_t# *btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(const dict_index_tcxx . . $ dict_index_t# &index, uint32_tcxx . . $ uint32_t# page,
217 rw_lock_type_tcxx . . $ rw_lock_type_t# latch_mode, mtr_tcxx . . $ mtr_t# *mtr,
218 dberr_tcxx . . $ dberr_t# *err, bool *first
219 #if defined(UNIV_DEBUG) || !defined(DBUG_OFFcxx . . $ `<built-in>:492:9`!)
220 , ulint page_get_mode
221 /*!< BUF_GET or BUF_GET_POSSIBLY_FREED */
222 #endif /* defined(UNIV_DEBUG) || !defined(DBUG_OFF) */
223 )
224 {
225 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(latch_mode != RW_NO_LATCH);
226 dberr_tcxx . . $ dberr_t# local_err;
227 if (!err)
228 err= &local_err;
229 buf_block_tcxx . . $ buf_block_t# *block=
230 buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).{index.tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.->idcxx . . $ fil_space_t#id., page},
231 index.tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(), latch_mode, nullptr,
232 #if defined(UNIV_DEBUG) || !defined(DBUG_OFFcxx . . $ `<built-in>:492:9`!)
233 page_get_mode,
234 #else
235 BUF_GETcxx . . $ `storage/innobase/include/buf0buf.h:53:9`!,
236 #endif /* defined(UNIV_DEBUG) || !defined(DBUG_OFF) */
237 mtr, err);
238 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!block == (*err != DB_SUCCESS));
239
240 if (UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(block != nullptr))
241 {
242 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, &index);
243 if (!!page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) != index.tablecxx . . $ dict_index_t#table.->not_redundantcxx . . $ dict_table_t#not_redundant(50ce9a9e25b4a850).() ||
244 btr_page_get_index_idcxx . . $ btr_page_get_index_id(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) != index.idcxx . . $ dict_index_t#id. ||
245 !fil_page_index_page_checkcxx . . $ `storage/innobase/include/fil0fil.h:1357:9`!(block->page.frame) ||
246 index.is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).() !=
247 (fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) == FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.))
248 {
249 *err= DB_PAGE_CORRUPTEDcxx . . $ DB_PAGE_CORRUPTED.;
250 block= nullptr;
251 }
252 else if (!buf_page_make_young_if_neededcxx . . $ buf_page_make_young_if_needed(12ea16e51c748147).(&block->pagecxx . . $ buf_block_t#page.) && first)
253 *first= true;
254 }
255 else
256 btr_read_failedcxx . . $ btr_read_failed(5cd27334cb9550f7).(*err, index);
257
258 return block;
259 }
260
261 /**************************************************************//**
262 Gets the root node of a tree and x- or s-latches it.
263 @return root page, x- or s-latched */
264 buf_block_tcxx . . $ buf_block_t#*
265 btr_root_block_getcxx . . $ btr_root_block_get(4bcbd40788d58e0a).(
266 /*===============*/
267 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index tree */
268 rw_lock_type_tcxx . . $ rw_lock_type_t# mode, /*!< in: either RW_S_LATCH
269 or RW_X_LATCH */
270 mtr_tcxx . . $ mtr_t#* mtr, /*!< in: mtr */
271 dberr_tcxx . . $ dberr_t#* err) /*!< out: error code */
272 {
273 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mode != RW_NO_LATCH);
274
275 if (!index->tablecxx . . $ dict_index_t#table. || !index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.)
276 {
277 *err= DB_TABLESPACE_NOT_FOUNDcxx . . $ DB_TABLESPACE_NOT_FOUND.;
278 return nullptr;
279 }
280
281 buf_block_tcxx . . $ buf_block_t# *block;
282 #ifndef BTR_CUR_ADAPTcxx . . $ `<built-in>:480:9`!
283 static constexpr buf_block_t *guess= nullptr;
284 #else
285 buf_block_tcxx . . $ buf_block_t# *&guess= index->search_infocxx . . $ dict_index_t#search_info..root_guesscxx . . $ dict_index_t#ahi#root_guess.;
286 guess=
287 #endif
288 block=
289 buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).({cxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.->idcxx . . $ fil_space_t#id., index->pagecxx . . $ dict_index_t#page.},
290 index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(), mode, guess, BUF_GETcxx . . $ `storage/innobase/include/buf0buf.h:53:9`!,
291 mtr, err);
292 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!block == (*err != DB_SUCCESS));
293
294 if (UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(block != nullptr))
295 {
296 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, index);
297 if (!!page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) !=
298 index->tablecxx . . $ dict_index_t#table.->not_redundantcxx . . $ dict_table_t#not_redundant(50ce9a9e25b4a850).() ||
299 btr_page_get_index_idcxx . . $ btr_page_get_index_id(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) != index->idcxx . . $ dict_index_t#id. ||
300 !fil_page_index_page_checkcxx . . $ `storage/innobase/include/fil0fil.h:1357:9`!(block->page.frame) ||
301 index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).() !=
302 (fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) == FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.))
303 {
304 *err= DB_PAGE_CORRUPTEDcxx . . $ DB_PAGE_CORRUPTED.;
305 block= nullptr;
306 }
307 else if (!btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!,
308 *block, *index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.) ||
309 !btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!,
310 *block, *index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.))
311 {
312 *err= DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
313 block= nullptr;
314 }
315 else
316 buf_page_make_young_if_neededcxx . . $ buf_page_make_young_if_needed(12ea16e51c748147).(&block->pagecxx . . $ buf_block_t#page.);
317 }
318 else
319 btr_read_failedcxx . . $ btr_read_failed(5cd27334cb9550f7).(*err, *index);
320
321 return block;
322 }
323
324 /**************************************************************//**
325 Gets the root node of a tree and sx-latches it for segment access.
326 @return root page, sx-latched */
327 static
328 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!*
329 btr_root_getcxx . . $ btr_root_get(a67aff4a3674617f).(
330 /*=========*/
331 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index tree */
332 mtr_tcxx . . $ mtr_t#* mtr, /*!< in: mtr */
333 dberr_tcxx . . $ dberr_t#* err) /*!< out: error code */
334 {
335 /* Intended to be used for accessing file segment lists.
336 Concurrent read of other data is allowed. */
337 if (buf_block_tcxx . . $ buf_block_t# *root= btr_root_block_getcxx . . $ btr_root_block_get(4bcbd40788d58e0a).(index, RW_SX_LATCHcxx . . $ RW_SX_LATCH., mtr, err))
338 return root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.;
339 return nullptr;
340 }
341
342 /**************************************************************//**
343 Checks a file segment header within a B-tree root page and updates
344 the segment header space id.
345 @return TRUE if valid */
346 static
347 bool
348 btr_root_fseg_adjust_on_importcxx . . $ btr_root_fseg_adjust_on_import(30fbe675e7e47abd).(
349 /*===========================*/
350 fseg_header_tcxx . . $ fseg_header_t#* seg_header, /*!< in/out: segment header */
351 page_zip_des_tcxx . . $ page_zip_des_t#* page_zip, /*!< in/out: compressed page,
352 or NULL */
353 ulintcxx . . $ ulint# space) /*!< in: tablespace identifier */
354 {
355 ulintcxx . . $ ulint# offset = mach_read_from_2cxx . . $ mach_read_from_2(469dcb4e54b221a8).(seg_header + FSEG_HDR_OFFSETcxx . . $ `storage/innobase/include/fsp0types.h:88:9`!);
356
357 if (offset < FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`!
358 || offset > srv_page_sizecxx . . $ srv_page_size. - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!) {
359 return false;
360 }
361
362 seg_header += FSEG_HDR_SPACEcxx . . $ `storage/innobase/include/fsp0types.h:86:9`!;
363
364 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(seg_header, space);
365 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(page_zip)) {
366 memcpy(page_zip->datacxx . . $ page_zip_des_t#data. + page_offsetcxx . . $ page_offset(70c5808fd903031e).(seg_header), seg_header,
367 4);
368 }
369
370 return true;
371 }
372
373 /**************************************************************//**
374 Checks and adjusts the root node of a tree during IMPORT TABLESPACE.
375 @param trx transaction
376 @param index index tree
377 @return error code */
378 dberr_tcxx . . $ dberr_t# btr_root_adjust_on_importcxx . . $ btr_root_adjust_on_import(49a8b0f1bcb516ba).(trx_tcxx . . $ trx_t# *trx, const dict_index_tcxx . . $ dict_index_t# *index)
379 {
380 dberr_tcxx . . $ dberr_t# err;
381 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{trx};
382 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page;
383 page_zip_des_tcxx . . $ page_zip_des_t#* page_zip;
384 dict_table_tcxx . . $ dict_table_t#* table = index->tablecxx . . $ dict_index_t#table.;
385
386 DBUG_EXECUTE_IFcxx . . $ `include/my_dbug.h:172:9`!("ib_import_trigger_corruption_3",
387 return(DB_CORRUPTION););
388
389 mtr_startcxx . . $ `storage/innobase/include/mtr0mtr.h:35:9`!(&mtr);
390
391 mtr_set_log_modecxx . . $ `storage/innobase/include/mtr0mtr.h:42:9`!(&mtr, MTR_LOG_NO_REDO);
392
393 buf_block_tcxx . . $ buf_block_t#* block = buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(
394 page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).(table->spacecxx . . $ dict_table_t#space.->idcxx . . $ fil_space_t#id., index->pagecxx . . $ dict_index_t#page.),
395 table->spacecxx . . $ dict_table_t#space.->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(), RW_X_LATCHcxx . . $ RW_X_LATCH., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, BUF_GETcxx . . $ `storage/innobase/include/buf0buf.h:53:9`!,
396 &mtr, &err);
397 if (!block) {
398 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(err != DB_SUCCESS);
399 goto func_exit;
400 }
401
402 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, index);
403 page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
404 page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block);
405
406 if (!fil_page_index_page_checkcxx . . $ `storage/innobase/include/fil0fil.h:1357:9`!(page) || page_has_siblingscxx . . $ page_has_siblings(190063cf6fb4afb1).(page)) {
407 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
408
409 } else if (dict_index_is_clustcxx . . $ `storage/innobase/include/dict0dict.h:617:9`!(index)) {
410 bool page_is_compact_format;
411
412 page_is_compact_format = page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page) > 0;
413
414 /* Check if the page format and table format agree. */
415 if (page_is_compact_format != dict_table_is_compcxx . . $ `storage/innobase/include/dict0dict.h:776:9`!(table)) {
416 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
417 } else {
418 /* Check that the table flags and the tablespace
419 flags match. */
420 uint32_tcxx . . $ uint32_t# tf = dict_tf_to_fsp_flagscxx . . $ dict_tf_to_fsp_flags(2141b656ce2cc063).(table->flagscxx . . $ dict_table_t#flags.);
421 uint32_tcxx . . $ uint32_t# sf = table->spacecxx . . $ dict_table_t#space.->flagscxx . . $ fil_space_t#flags.;
422 sf &= ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!;
423 tf &= ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!;
424 if (fil_space_tcxx . . $ fil_space_t#::is_flags_equalcxx . . $ fil_space_t#is_flags_equal(d92a6f4903462276).(tf, sf)
425 || fil_space_tcxx . . $ fil_space_t#::is_flags_equalcxx . . $ fil_space_t#is_flags_equal(d92a6f4903462276).(sf, tf)) {
426 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_system.mutex);
427 table->spacecxx . . $ dict_table_t#space.->flagscxx . . $ fil_space_t#flags. = (table->spacecxx . . $ dict_table_t#space.->flagscxx . . $ fil_space_t#flags.
428 & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!)
429 | (tf & FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!);
430 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_system.mutex);
431 err = DB_SUCCESScxx . . $ DB_SUCCESS.;
432 } else {
433 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
434 }
435 }
436 } else {
437 err = DB_SUCCESScxx . . $ DB_SUCCESS.;
438 }
439
440 /* Check and adjust the file segment headers, if all OK so far. */
441 if (err == DB_SUCCESScxx . . $ DB_SUCCESS.
442 && (!btr_root_fseg_adjust_on_importcxx . . $ btr_root_fseg_adjust_on_import(30fbe675e7e47abd).(
443 FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!
444 + page, page_zip, table->space_idcxx . . $ dict_table_t#space_id.)
445 || !btr_root_fseg_adjust_on_importcxx . . $ btr_root_fseg_adjust_on_import(30fbe675e7e47abd).(
446 FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!
447 + page, page_zip, table->space_idcxx . . $ dict_table_t#space_id.))) {
448
449 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
450 }
451
452 func_exit:
453 mtr_commitcxx . . $ `storage/innobase/include/mtr0mtr.h:38:9`!(&mtr);
454
455 return(err);
456 }
457
458 /**************************************************************//**
459 Creates a new index page (not the root, and also not
460 used in page reorganization). @see btr_page_empty(). */
461 void
462 btr_page_createcxx . . $ btr_page_create(403ca5985fa24f33).(
463 /*============*/
464 buf_block_tcxx . . $ buf_block_t#* block, /*!< in/out: page to be created */
465 page_zip_des_tcxx . . $ page_zip_des_t#* page_zip,/*!< in/out: compressed page, or NULL */
466 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
467 ulintcxx . . $ ulint# level, /*!< in: the B-tree level of the page */
468 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
469 {
470 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
471 bytecxx . . $ byte# *index_id= my_assume_alignedcxx . . $ my_assume_aligned(5eb18401b0825ee).<2>(PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_INDEX_IDcxx . . $ `storage/innobase/include/page0page.h:109:9`! +
472 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
473
474 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(page_zip))
475 {
476 mach_write_to_8cxx . . $ mach_write_to_8(5500c4293b1bbef0).(index_id, index->idcxx . . $ dict_index_t#id.);
477 page_create_zipcxx . . $ page_create_zip(992652f8f3e48cc9).(block, index, level, 0, mtr);
478 }
479 else
480 {
481 page_createcxx . . $ page_create(529cd47aa3b34ebe).(block, mtr, dict_table_is_compcxx . . $ `storage/innobase/include/dict0dict.h:776:9`!(index->table));
482 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).())
483 {
484 static_assert(((FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX. & 0xff00) | bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.)) ==
485 FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE., "compatibility");
486 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<1>(*block, FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + 1 + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
487 bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.));
488 if (mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + FIL_RTREE_SPLIT_SEQ_NUMcxx . . $ `storage/innobase/include/fil0fil.h:1239:9`!))
489 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(block, FIL_RTREE_SPLIT_SEQ_NUMcxx . . $ `storage/innobase/include/fil0fil.h:1239:9`!, 8, 0);
490 }
491 /* Set the level of the new index page */
492 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*block,
493 my_assume_alignedcxx . . $ my_assume_aligned(5eb18401b0825ee).<2>(PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! +
494 PAGE_LEVELcxx . . $ `storage/innobase/include/page0page.h:106:9`! +
495 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.),
496 level);
497 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<8,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*block, index_id, index->idcxx . . $ dict_index_t#id.);
498 }
499 }
500
501 buf_block_tcxx . . $ buf_block_t# *
502 mtr_tcxx . . $ mtr_t#::get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(const page_id_tcxx . . $ page_id_t# id, mtr_memo_type_tcxx . . $ mtr_memo_type_t# type) const
503 {
504 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(is_active());
505 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type == MTR_MEMO_PAGE_X_FIX || type == MTR_MEMO_PAGE_SX_FIX ||
506 type == MTR_MEMO_PAGE_S_FIX);
507 for (ulintcxx . . $ ulint# i= 0; i < m_memocxx . . $ mtr_t#m_memo..sizecxx . . $ small_vector_base#size(c9b1e749b64d5edc).(); i++)
508 {
509 const mtr_memo_slot_tcxx . . $ mtr_memo_slot_t# &slot= m_memocxx . . $ mtr_t#m_memo.[cxx . . $ small_vector#`operator[]`(c65000e556194d6f).i];
510 const auto slot_type= mtr_memo_type_tcxx . . $ mtr_memo_type_t#(slot.typecxx . . $ mtr_memo_slot_t#type. & ~MTR_MEMO_MODIFYcxx . . $ MTR_MEMO_MODIFY.);
511 if (slot_type == MTR_MEMO_PAGE_X_FIXcxx . . $ MTR_MEMO_PAGE_X_FIX. || slot_type == type)
512 {
513 buf_block_tcxx . . $ buf_block_t# *block= static_cast<buf_block_tcxx . . $ buf_block_t#*>(slot.objectcxx . . $ mtr_memo_slot_t#object.);
514 if (block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).() ==cxx . . $ page_id_t#`operator==`(d789d526a826a185). id)
515 return block;
516 }
517 }
518 return nullptr;
519 }
520
521 /** Fetch an index root page that was already latched in the
522 mini-transaction. */
523 static buf_block_tcxx . . $ buf_block_t# *btr_get_latched_rootcxx . . $ btr_get_latched_root(7433449132ea960e).(const dict_index_tcxx . . $ dict_index_t# &index, mtr_tcxx . . $ mtr_t# *mtr)
524 {
525 return mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).{index.tablecxx . . $ dict_index_t#table.->space_idcxx . . $ dict_table_t#space_id., index.pagecxx . . $ dict_index_t#page.},
526 MTR_MEMO_PAGE_SX_FIXcxx . . $ MTR_MEMO_PAGE_SX_FIX.);
527 }
528
529 /** Fetch an index page that should have been already latched in the
530 mini-transaction. */
531 static buf_block_tcxx . . $ buf_block_t# *
532 btr_block_regetcxx . . $ btr_block_reget(795d7a25592e446a).(mtr_tcxx . . $ mtr_t# *mtr, const dict_index_tcxx . . $ dict_index_t# &index,
533 const page_id_tcxx . . $ page_id_t# id, dberr_tcxx . . $ dberr_t# *err)
534 {
535 if (buf_block_tcxx . . $ buf_block_t# *block= mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(id, MTR_MEMO_PAGE_X_FIXcxx . . $ MTR_MEMO_PAGE_X_FIX.))
536 {
537 *err= DB_SUCCESScxx . . $ DB_SUCCESS.;
538 return block;
539 }
540
541 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&index.lock, MTR_MEMO_X_LOCK));
542 return btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(index, id.page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(), RW_X_LATCHcxx . . $ RW_X_LATCH., mtr, err);
543 }
544
545 static MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull, warn_unused_result))
546 /** Acquire a latch on the index root page for allocating or freeing pages.
547 @param index index tree
548 @param mtr mini-transaction
549 @param err error code
550 @return root page
551 @retval nullptr if an error occurred */
552 buf_block_tcxx . . $ buf_block_t# *btr_root_block_sxcxx . . $ btr_root_block_sx(b54933fda0d862ae).(dict_index_tcxx . . $ dict_index_t# *index, mtr_tcxx . . $ mtr_t# *mtr, dberr_tcxx . . $ dberr_t# *err)
553 {
554 buf_block_tcxx . . $ buf_block_t# *root=
555 mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).{index->tablecxx . . $ dict_index_t#table.->space_idcxx . . $ dict_table_t#space_id., index->pagecxx . . $ dict_index_t#page.},
556 MTR_MEMO_PAGE_SX_FIXcxx . . $ MTR_MEMO_PAGE_SX_FIX.);
557 if (!root)
558 {
559 root= btr_root_block_getcxx . . $ btr_root_block_get(4bcbd40788d58e0a).(index, RW_SX_LATCHcxx . . $ RW_SX_LATCH., mtr, err);
560 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!root))
561 return root;
562 }
563 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
564 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(else if (dict_index_t *index= root->index))
565 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->freed());
566 #endif
567 return root;
568 }
569
570 /**************************************************************//**
571 Allocates a new file page to be used in an index tree. NOTE: we assume
572 that the caller has made the reservation for free extents!
573 @retval NULL if no page could be allocated */
574 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull, warn_unused_result))
575 buf_block_tcxx . . $ buf_block_t#*
576 btr_page_alloccxx . . $ btr_page_alloc(97e5958ce206bff9).(
577 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
578 uint32_tcxx . . $ uint32_t# hint_page_no, /*!< in: hint of a good page */
579 bytecxx . . $ byte# file_direction, /*!< in: direction where a possible
580 page split is made */
581 ulintcxx . . $ ulint# level, /*!< in: level where the page is placed
582 in the tree */
583 mtr_tcxx . . $ mtr_t#* mtr, /*!< in/out: mini-transaction
584 for the allocation */
585 mtr_tcxx . . $ mtr_t#* init_mtr, /*!< in/out: mtr or another
586 mini-transaction in which the
587 page should be initialized. */
588 dberr_tcxx . . $ dberr_t#* err) /*!< out: error code */
589 {
590 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(level < BTR_MAX_NODE_LEVEL);
591
592 buf_block_tcxx . . $ buf_block_t# *root= btr_root_block_sxcxx . . $ btr_root_block_sx(b54933fda0d862ae).(index, mtr, err);
593 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!root))
594 return root;
595 fseg_header_tcxx . . $ fseg_header_t# *seg_header= root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. +
596 (level ? PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`! : PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!);
597 return fseg_alloc_free_page_generalcxx . . $ fseg_alloc_free_page_general(deb8b3a5a4fea0d7).(seg_header, hint_page_no, file_direction,
598 true, mtr, init_mtr, err);
599 }
600
601 /** Free an index page.
602 @param[in,out] index index tree
603 @param[in,out] block block to be freed
604 @param[in,out] mtr mini-transaction
605 @param[in] blob whether this is freeing a BLOB page
606 @param[in] latched whether index->table->space->x_lock() was called
607 @return error code */
608 dberr_tcxx . . $ dberr_t# btr_page_freecxx . . $ btr_page_free(afbef3f3f4a891ab).(dict_index_tcxx . . $ dict_index_t#* index, buf_block_tcxx . . $ buf_block_t#* block, mtr_tcxx . . $ mtr_t#* mtr,
609 bool blob, bool space_latched)
610 {
611 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
612 #if defined BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`! && defined UNIV_DEBUG
613 if (btr_search_check_marked_free_index(block))
614 {
615 ut_ad(!blob);
616 ut_ad(page_is_leaf(block->page.frame));
617 }
618 #endif
619 const uint32_tcxx . . $ uint32_t# page{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()};
620 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->table->space_id == block->page.id().space());
621 /* The root page is freed by btr_free_root(). */
622 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page != index->page);
623 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->is_named_space(index->table->space));
624
625 /* The page gets invalid for optimistic searches: increment the frame
626 modify clock */
627 buf_block_modify_clock_inccxx . . $ buf_block_modify_clock_inc(25904839e76d08c3).(block);
628
629 /* TODO: Discard any operations for block from mtr->m_log.
630 The page will be freed, so previous changes to it by this
631 mini-transaction should not matter. */
632
633 fil_space_tcxx . . $ fil_space_t# *space= index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.;
634 dberr_tcxx . . $ dberr_t# err;
635
636 if (buf_block_tcxx . . $ buf_block_t# *root= btr_root_block_sxcxx . . $ btr_root_block_sx(b54933fda0d862ae).(index, mtr, &err))
637 {
638 err= fseg_free_pagecxx . . $ fseg_free_page(cc834b1a651b3ff8).(&root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[blob ||
639 page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.)
640 ? PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!
641 : PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!],
642 space, page, mtr, space_latched);
643 if (err == DB_SUCCESScxx . . $ DB_SUCCESS.)
644 buf_page_freecxx . . $ buf_page_free(f7ea9b970d942d4).(space, page, mtr);
645 }
646
647 /* The page was marked free in the allocation bitmap, but it
648 should remain exclusively latched until mtr_t::commit() or until it
649 is explicitly freed from the mini-transaction. */
650 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
651 return err;
652 }
653
654 /** Set the child page number in a node pointer record.
655 @param[in,out] block non-leaf index page
656 @param[in,out] rec node pointer record in the page
657 @param[in] offsets rec_get_offsets(rec)
658 @param[in] page_no child page number
659 @param[in,out] mtr mini-transaction
660 Sets the child node file address in a node pointer. */
661 inline void btr_node_ptr_set_child_page_nocxx . . $ btr_node_ptr_set_child_page_no(74c562001a057f5).(buf_block_tcxx . . $ buf_block_t# *block,
662 rec_tcxx . . $ rec_t# *rec, const rec_offscxx . . $ rec_offs# *offsets,
663 ulintcxx . . $ ulint# page_no, mtr_tcxx . . $ mtr_t# *mtr)
664 {
665 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_offs_validate(rec, NULL, offsets));
666 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_rec_is_leaf(rec));
667 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!rec_offs_comp(offsets) || rec_get_node_ptr_flag(rec));
668
669 const ulintcxx . . $ ulint# offs= rec_offs_data_sizecxx . . $ rec_offs_data_size(6fce5c29061b60f9).(offsets);
670 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_offs_nth_size(offsets, rec_offs_n_fields(offsets) - 1) ==
671 REC_NODE_PTR_SIZE);
672
673 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(block->page.zip.data))
674 page_zip_write_node_ptrcxx . . $ page_zip_write_node_ptr(d81176b668f225a).(block, rec, offs, page_no, mtr);
675 else
676 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<4>(*block, rec + offs - REC_NODE_PTR_SIZEcxx . . $ `storage/innobase/include/rem0rec.h:62:9`!, page_no);
677 }
678
679 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull(1,2,3,4),warn_unused_result))
680 /************************************************************//**
681 Returns the child page of a node pointer and sx-latches it.
682 @return child page, sx-latched */
683 static
684 buf_block_tcxx . . $ buf_block_t#*
685 btr_node_ptr_get_childcxx . . $ btr_node_ptr_get_child(809ad4b01f04a0a4).(
686 /*===================*/
687 const rec_tcxx . . $ rec_t#* node_ptr,/*!< in: node pointer */
688 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
689 const rec_offscxx . . $ rec_offs#* offsets,/*!< in: array returned by rec_get_offsets() */
690 mtr_tcxx . . $ mtr_t#* mtr, /*!< in: mtr */
691 dberr_tcxx . . $ dberr_t#* err = nullptr) /*!< out: error code */
692 {
693 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_offs_validate(node_ptr, index, offsets));
694 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->table->space_id
695 == page_get_space_id(page_align(node_ptr)));
696
697 return btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(
698 *index, btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(node_ptr, offsets),
699 RW_SX_LATCHcxx . . $ RW_SX_LATCH., mtr, err);
700 }
701
702 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull(2,3,4), warn_unused_result))
703 /************************************************************//**
704 Returns the upper level node pointer to a page. It is assumed that mtr holds
705 an sx-latch on the tree.
706 @return rec_get_offsets() of the node pointer record */
707 static
708 rec_offscxx . . $ rec_offs#*
709 btr_page_get_father_node_ptr_for_validatecxx . . $ btr_page_get_father_node_ptr_for_validate(fbc97b7d2f73ee90).(
710 rec_offscxx . . $ rec_offs#* offsets,/*!< in: work area for the return value */
711 mem_heap_tcxx . . $ mem_heap_t#* heap, /*!< in: memory heap to use */
712 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor pointing to user record,
713 out: cursor on node pointer record,
714 its page x-latched */
715 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
716 {
717 const uint32_tcxx . . $ uint32_t# page_no = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor)->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).();
718 dict_index_tcxx . . $ dict_index_t#* index = btr_cur_get_indexcxx . . $ `storage/innobase/include/btr0cur.h:82:9`!(cursor);
719 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_spatial(index));
720 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains(index->lock, MTR_MEMO_X_LOCK));
721 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(dict_index_get_page(index) != page_no);
722
723 const auto level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor));
724
725 const rec_tcxx . . $ rec_t#* user_rec = btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor);
726 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(page_rec_is_user_rec(user_rec));
727
728 if (btr_cur_search_to_nth_levelcxx . . $ btr_cur_search_to_nth_level(59eb7917f67212e).(level + 1,
729 dict_index_build_node_ptrcxx . . $ dict_index_build_node_ptr(21b5a4827c82add7).(index,
730 user_rec, 0,
731 heap, level),
732 RW_S_LATCHcxx . . $ RW_S_LATCH.,
733 cursor, mtr) != DB_SUCCESScxx . . $ DB_SUCCESS.) {
734 return nullptr;
735 }
736
737 const rec_tcxx . . $ rec_t#* node_ptr = btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor);
738
739 offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(node_ptr, index, offsets, 0,
740 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
741
742 if (btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(node_ptr, offsets) != page_no) {
743 offsets = nullptr;
744 }
745
746 return(offsets);
747 }
748
749 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull(2,3,4), warn_unused_result))
750 /** Return the node pointer to a page.
751 @param offsets work area for the return value
752 @param heap memory heap
753 @param cursor in: child page; out: node pointer to it
754 @param mtr mini-transaction
755 @return rec_get_offsets() of the node pointer record
756 @retval nullptr if the parent page had not been latched in mtr */
757 static rec_offscxx . . $ rec_offs# *btr_page_get_parentcxx . . $ btr_page_get_parent(fbc97b7d2f73ee90).(rec_offscxx . . $ rec_offs# *offsets, mem_heap_tcxx . . $ mem_heap_t# *heap,
758 btr_cur_tcxx . . $ btr_cur_t# *cursor, mtr_tcxx . . $ mtr_t# *mtr)
759 {
760 const uint32_tcxx . . $ uint32_t# page_no= cursor->blockcxx . . $ btr_cur_t#block(1f66ca64e72a94a3).()->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).();
761 const dict_index_tcxx . . $ dict_index_t# *index= cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).();
762 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->is_spatial());
763 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->page != page_no);
764
765 uint32_tcxx . . $ uint32_t# p= index->pagecxx . . $ dict_index_t#page.;
766 auto level= btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(cursor->blockcxx . . $ btr_cur_t#block(1f66ca64e72a94a3).()->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
767 const dtuple_tcxx . . $ dtuple_t# *tuple=
768 dict_index_build_node_ptrcxx . . $ dict_index_build_node_ptr(21b5a4827c82add7).(index, btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor), 0, heap, level);
769 level++;
770
771 ulintcxx . . $ ulint# i;
772 for (i= 0; i < mtr->get_savepointcxx . . $ mtr_t#get_savepoint(fe4d2d262d4164a8).(); i++)
773 if (buf_block_tcxx . . $ buf_block_t# *block= mtr->block_at_savepointcxx . . $ mtr_t#block_at_savepoint(af74c280cb0dfd96).(i))
774 if (block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() == p)
775 {
776 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block->page.lock.have_u_or_x() ||
777 (!block->page.lock.have_s() && index->lock.have_x()));
778 uint16_tcxx . . $ uint16_t# up_match= 0, low_match= 0;
779 cursor->page_curcxx . . $ btr_cur_t#page_cur..blockcxx . . $ page_cur_t#block.= block;
780 if (page_cur_search_with_matchcxx . . $ page_cur_search_with_match(2a162131057c114d).(tuple, PAGE_CUR_LEcxx . . $ PAGE_CUR_LE., &up_match,
781 &low_match, &cursor->page_curcxx . . $ btr_cur_t#page_cur.,
782 nullptr))
783 return nullptr;
784 offsets= rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(cursor->page_cur.rec, index, offsets, 0,
785 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
786 p= btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(cursor->page_curcxx . . $ btr_cur_t#page_cur..reccxx . . $ page_cur_t#rec., offsets);
787 if (p != page_no)
788 {
789 if (btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) == level)
790 return nullptr;
791 i= 0; // MDEV-29835 FIXME: require all pages to be latched in order!
792 continue;
793 }
794 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block->page.lock.have_u_or_x());
795 if (block->pagecxx . . $ buf_block_t#page..lockcxx . . $ buf_page_t#lock..have_u_not_xcxx . . $ sux_lock#have_u_not_x(50ce9a9e25b4a850).())
796 {
797 /* btr_cur_t::search_leaf(BTR_MODIFY_TREE) only U-latches the
798 root page initially. */
799 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block->page.id().page_no() == index->page);
800 block->pagecxx . . $ buf_block_t#page..lockcxx . . $ buf_page_t#lock..u_x_upgradecxx . . $ sux_lock#u_x_upgrade(49f6e7a06ebc5aa8).();
801 mtr->page_lock_upgradecxx . . $ mtr_t#page_lock_upgrade(f445c7a177d29c95).(*block);
802 }
803 return offsets;
804 }
805
806 return nullptr;
807 }
808
809 /************************************************************//**
810 Returns the upper level node pointer to a page. It is assumed that mtr holds
811 an x-latch on the tree.
812 @return rec_get_offsets() of the node pointer record
813 @retval nullptr on corruption */
814 static
815 rec_offscxx . . $ rec_offs#*
816 btr_page_get_father_blockcxx . . $ btr_page_get_father_block(931ebee81e95307a).(
817 /*======================*/
818 rec_offscxx . . $ rec_offs#* offsets,/*!< in: work area for the return value */
819 mem_heap_tcxx . . $ mem_heap_t#* heap, /*!< in: memory heap to use */
820 mtr_tcxx . . $ mtr_t#* mtr, /*!< in: mtr */
821 btr_cur_tcxx . . $ btr_cur_t#* cursor) /*!< out: cursor on node pointer record,
822 its page x-latched */
823 noexcept
824 {
825 const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *page= btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
826 const rec_tcxx . . $ rec_t# *rec= page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page)
827 ? page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, page + PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`!)
828 : page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, page + PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`!);
829 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!rec))
830 return nullptr;
831 cursor->page_curcxx . . $ btr_cur_t#page_cur..reccxx . . $ page_cur_t#rec.= const_cast<rec_tcxx . . $ rec_t#*>(rec);
832 return btr_page_get_parentcxx . . $ btr_page_get_parent(fbc97b7d2f73ee90).(offsets, heap, cursor, mtr);
833 }
834
835 /** Seek to the parent page of a B-tree page.
836 @param mtr mini-transaction
837 @param cursor cursor pointing to the x-latched parent page
838 @return whether the cursor was successfully positioned */
839 bool btr_page_get_fathercxx . . $ btr_page_get_father(ef799a93ae7a666b).(mtr_tcxx . . $ mtr_t# *mtr, btr_cur_tcxx . . $ btr_cur_t# *cursor) noexcept
840 {
841 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *page= btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
842 const rec_tcxx . . $ rec_t# *rec= page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page)
843 ? page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, page + PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`!)
844 : page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, page + PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`!);
845 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!rec))
846 return false;
847 cursor->page_curcxx . . $ btr_cur_t#page_cur..reccxx . . $ page_cur_t#rec.= const_cast<rec_tcxx . . $ rec_t#*>(rec);
848 mem_heap_tcxx . . $ mem_heap_t# *heap= mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(100);
849 const bool got= btr_page_get_parentcxx . . $ btr_page_get_parent(fbc97b7d2f73ee90).(nullptr, heap, cursor, mtr);
850 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
851 return got;
852 }
853
854 #ifdef UNIV_DEBUG
855 /** PAGE_INDEX_ID value for freed index B-trees */
856 constexpr index_id_t BTR_FREED_INDEX_ID = 0;
857 #endif
858
859 /** Free a B-tree root page. btr_free_but_not_root() must already
860 have been called.
861 @param block index root page
862 @param space tablespace
863 @param mtr mini-transaction */
864 static void btr_free_rootcxx . . $ btr_free_root(3835fffe11e158f4).(buf_block_tcxx . . $ buf_block_t# *block, const fil_space_tcxx . . $ fil_space_t# &space,
865 mtr_tcxx . . $ mtr_t# *mtr)
866 {
867 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX |
868 MTR_MEMO_PAGE_SX_FIX));
869 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->is_named_space(&space));
870
871 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
872
873 if (btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!, *block, space))
874 {
875 /* Free the entire segment in small steps. */
876 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(mtr->freeing_tree());
877 while (!fseg_free_stepcxx . . $ fseg_free_step(8fc797f7c0e1ec22).(block, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!, mtr));
878 }
879 }
880
881 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((warn_unused_result))
882 /** Prepare to free a B-tree.
883 @param[in] page_id page id
884 @param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
885 @param[in] index_id PAGE_INDEX_ID contents
886 @param[in,out] mtr mini-transaction
887 @return root block, to invoke btr_free_but_not_root() and btr_free_root()
888 @retval NULL if the page is no longer a matching B-tree page */
889 static
890 buf_block_tcxx . . $ buf_block_t# *btr_free_root_checkcxx . . $ btr_free_root_check(6f8a7de2d425683d).(const page_id_tcxx . . $ page_id_t# page_id, ulintcxx . . $ ulint# zip_size,
891 index_id_tcxx . . $ index_id_t# index_id, mtr_tcxx . . $ mtr_t# *mtr)
892 {
893 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_id.space() != SRV_TMP_SPACE_ID);
894 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index_id != BTR_FREED_INDEX_ID);
895
896 buf_block_tcxx . . $ buf_block_t# *block= buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(page_id, zip_size, RW_X_LATCHcxx . . $ RW_X_LATCH.,
897 nullptr, BUF_GET_POSSIBLY_FREEDcxx . . $ `storage/innobase/include/buf0buf.h:58:9`!, mtr);
898
899 if (block)
900 {
901 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block,reinterpret_cast<dict_index_tcxx . . $ dict_index_t#*>(-1));
902 if (fil_page_index_page_checkcxx . . $ `storage/innobase/include/fil0fil.h:1357:9`!(block->page.frame) &&
903 index_id == btr_page_get_index_idcxx . . $ btr_page_get_index_id(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.))
904 /* This should be a root page. It should not be possible to
905 reassign the same index_id for some other index in the
906 tablespace. */
907 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(block->page.frame));
908 else
909 block= nullptr;
910 }
911
912 return block;
913 }
914
915 /** Initialize the root page of the b-tree
916 @param[in,out] block root block
917 @param[in] index_id index id
918 @param[in] index index of root page
919 @param[in,out] mtr mini-transaction */
920 static void btr_root_page_initcxx . . $ btr_root_page_init(1036b703ec1e0377).(buf_block_tcxx . . $ buf_block_t# *block, index_id_tcxx . . $ index_id_t# index_id,
921 dict_index_tcxx . . $ dict_index_t# *index, mtr_tcxx . . $ mtr_t# *mtr)
922 {
923 constexpr uint16_tcxx . . $ uint16_t# field= PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_INDEX_IDcxx . . $ `storage/innobase/include/page0page.h:109:9`!;
924 bytecxx . . $ byte# *page_index_id= my_assume_alignedcxx . . $ my_assume_aligned(5eb18401b0825ee).<2>(field + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
925
926 /* Create a new index page on the allocated segment page */
927 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(block->page.zip.data))
928 {
929 mach_write_to_8cxx . . $ mach_write_to_8(5500c4293b1bbef0).(page_index_id, index_id);
930 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(block->page.zip.data));
931 page_create_zipcxx . . $ page_create_zip(992652f8f3e48cc9).(block, index, 0, 0, mtr);
932 }
933 else
934 {
935 page_createcxx . . $ page_create(529cd47aa3b34ebe).(block, mtr, index && index->tablecxx . . $ dict_index_t#table.->not_redundantcxx . . $ dict_table_t#not_redundant(50ce9a9e25b4a850).());
936 if (index && index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).())
937 {
938 static_assert(((FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX. & 0xff00) | bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.)) ==
939 FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE., "compatibility");
940 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<1>(*block, FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + 1 + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
941 bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.));
942 if (mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + FIL_RTREE_SPLIT_SEQ_NUMcxx . . $ `storage/innobase/include/fil0fil.h:1239:9`!))
943 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(block, FIL_RTREE_SPLIT_SEQ_NUMcxx . . $ `storage/innobase/include/fil0fil.h:1239:9`!, 8, 0);
944 }
945 /* Set the level of the new index page */
946 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(
947 *block, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_LEVELcxx . . $ `storage/innobase/include/page0page.h:106:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 0U);
948 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<8,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*block, page_index_id, index_id);
949 }
950 }
951
952 /** Create the root node for a new index tree.
953 @param[in] type type of the index
954 @param[in] index_id index id
955 @param[in,out] space tablespace where created
956 @param[in] index index, or NULL to create a system table
957 @param[in,out] mtr mini-transaction
958 @param[out] err error code
959 @return page number of the created root
960 @retval FIL_NULL if did not succeed */
961 uint32_tcxx . . $ uint32_t#
962 btr_createcxx . . $ btr_create(3d74a30862055473).(
963 ulintcxx . . $ ulint# type,
964 fil_space_tcxx . . $ fil_space_t#* space,
965 index_id_tcxx . . $ index_id_t# index_id,
966 dict_index_tcxx . . $ dict_index_t#* index,
967 mtr_tcxx . . $ mtr_t#* mtr,
968 dberr_tcxx . . $ dberr_t#* err)
969 {
970 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->is_named_space(space));
971 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index_id != BTR_FREED_INDEX_ID);
972 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index || space == fil_system.sys_space);
973
974 /* Create the two new segments for the index tree;
975 the segment headers are put on the allocated root page */
976
977 buf_block_tcxx . . $ buf_block_t# *block = fseg_createcxx . . $ fseg_create(8bc949c6f95c6eb1).(space, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!,
978 mtr, err);
979
980 if (!block) {
981 return FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!;
982 }
983
984 if (!fseg_createcxx . . $ fseg_create(8bc949c6f95c6eb1).(space, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!, mtr,
985 err, false, block)) {
986 /* Not enough space for new segment, free root
987 segment before return. */
988 btr_free_rootcxx . . $ btr_free_root(3835fffe11e158f4).(block, *space, mtr);
989 return FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!;
990 }
991
992 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(block->page.frame));
993
994 btr_root_page_initcxx . . $ btr_root_page_init(1036b703ec1e0377).(block, index_id, index, mtr);
995
996 /* In the following assertion we test that two records of maximum
997 allowed size fit on the root page: this fact is needed to ensure
998 correctness of split algorithms */
999
1000 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_get_max_insert_size(block->page.frame, 2)
1001 > 2 * BTR_PAGE_MAX_REC_SIZE);
1002
1003 return(block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).());
1004 }
1005
1006 /** Free a B-tree except the root page. The root page MUST be freed after
1007 this by calling btr_free_root.
1008 @param[in,out] block root page
1009 @param[in] outer_mtr surrounding mini-transaction */
1010 static
1011 void
1012 btr_free_but_not_rootcxx . . $ btr_free_but_not_root(ef523e46611fa9e).(
1013 buf_block_tcxx . . $ buf_block_t#* block,
1014 const mtr_tcxx . . $ mtr_t#& outer_mtr
1015 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
1016 ,bool ahi=false
1017 #endif
1018 )
1019 {
1020 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{outer_mtr.trxcxx . . $ mtr_t#trx.};
1021
1022 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(fil_page_index_page_check(block->page.frame));
1023 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(block->page.frame));
1024 leaf_loop:
1025 mtr_startcxx . . $ `storage/innobase/include/mtr0mtr.h:35:9`!(&mtr);
1026 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(mtr.freeing_tree());
1027 mtr_set_log_modecxx . . $ `storage/innobase/include/mtr0mtr.h:42:9`!(&mtr, outer_mtr.get_log_mode());
1028 fil_space_tcxx . . $ fil_space_t# *space = mtr.set_named_space_idcxx . . $ mtr_t#set_named_space_id(1e56389d70b9001).(block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().spacecxx . . $ page_id_t#space(d22c8608b6eae7b5).());
1029
1030 if (!btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!,
1031 *block, *space)
1032 || !btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!,
1033 *block, *space)) {
1034 mtr_commitcxx . . $ `storage/innobase/include/mtr0mtr.h:38:9`!(&mtr);
1035 return;
1036 }
1037
1038 /* NOTE: page hash indexes are dropped when a page is freed inside
1039 fsp0fsp. */
1040
1041 bool finished = fseg_free_stepcxx . . $ fseg_free_step(8fc797f7c0e1ec22).(block, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!,
1042 &mtr
1043 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
1044 , ahi
1045 #endif /* BTR_CUR_HASH_ADAPT */
1046 );
1047 mtr_commitcxx . . $ `storage/innobase/include/mtr0mtr.h:38:9`!(&mtr);
1048
1049 if (!finished) {
1050
1051 goto leaf_loop;
1052 }
1053 top_loop:
1054 mtr_startcxx . . $ `storage/innobase/include/mtr0mtr.h:35:9`!(&mtr);
1055 mtr_set_log_modecxx . . $ `storage/innobase/include/mtr0mtr.h:42:9`!(&mtr, outer_mtr.get_log_mode());
1056 space = mtr.set_named_space_idcxx . . $ mtr_t#set_named_space_id(1e56389d70b9001).(block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().spacecxx . . $ page_id_t#space(d22c8608b6eae7b5).());
1057
1058 finished = !btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!,
1059 *block, *space)
1060 || fseg_free_step_not_headercxx . . $ fseg_free_step_not_header(8fc797f7c0e1ec22).(block,
1061 PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!,
1062 &mtr
1063 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
1064 ,ahi
1065 #endif /* BTR_CUR_HASH_ADAPT */
1066 );
1067 mtr_commitcxx . . $ `storage/innobase/include/mtr0mtr.h:38:9`!(&mtr);
1068
1069 if (!finished) {
1070 goto top_loop;
1071 }
1072 }
1073
1074 /** Clear the index tree and reinitialize the root page, in the
1075 rollback of TRX_UNDO_EMPTY. The BTR_SEG_LEAF is freed and reinitialized.
1076 @param thr query thread
1077 @return error code */
1078 dberr_tcxx . . $ dberr_t# dict_index_tcxx . . $ dict_index_t#::clearcxx . . $ dict_index_t#clear(d87fbd865449b31e).(que_thr_tcxx . . $ que_thr_t# *thr)
1079 {
1080 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{thr_get_trxcxx . . $ thr_get_trx(bce191eb970ff2ca).(thr)};
1081 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1082 if (tablecxx . . $ dict_index_t#table.->is_temporarycxx . . $ dict_table_t#is_temporary(50ce9a9e25b4a850).())
1083 mtr.set_log_modecxx . . $ mtr_t#set_log_mode(9fa4fa4ef91bef56).(MTR_LOG_NO_REDOcxx . . $ MTR_LOG_NO_REDO.);
1084 else
1085 set_modifiedcxx . . $ dict_index_t#set_modified(6ecce9205e900009).(mtr);
1086 mtr_sx_lock_indexcxx . . $ `storage/innobase/include/mtr0mtr.h:47:10`!(this, &mtr);
1087
1088 dberr_tcxx . . $ dberr_t# err;
1089 buf_block_tcxx . . $ buf_block_t# *root_block;
1090 #ifndef BTR_CUR_ADAPTcxx . . $ `<built-in>:480:9`!
1091 static constexpr buf_block_t *guess= nullptr;
1092 #else
1093 buf_block_tcxx . . $ buf_block_t# *&guess= search_infocxx . . $ dict_index_t#search_info..root_guesscxx . . $ dict_index_t#ahi#root_guess.;
1094 guess=
1095 #endif
1096 root_block= buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).({cxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).tablecxx . . $ dict_index_t#table.->space_idcxx . . $ dict_table_t#space_id., pagecxx . . $ dict_index_t#page.},
1097 tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(),
1098 RW_X_LATCHcxx . . $ RW_X_LATCH., guess, BUF_GETcxx . . $ `storage/innobase/include/buf0buf.h:53:9`!, &mtr, &err);
1099 if (root_block)
1100 {
1101 btr_free_but_not_rootcxx . . $ btr_free_but_not_root(ef523e46611fa9e).(root_block, mtr
1102 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
1103 ,any_ahi_pagescxx . . $ dict_index_t#any_ahi_pages(3482b152b9333168).()
1104 #endif
1105 );
1106 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(root_block, nullptr);
1107 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
1108 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!any_ahi_pages());
1109 #endif
1110 mtr.memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(root_block, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!,
1111 FSEG_HEADER_SIZEcxx . . $ `storage/innobase/include/fsp0types.h:90:9`!, 0);
1112 if (fseg_createcxx . . $ fseg_create(8bc949c6f95c6eb1).(tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space., PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!, &mtr,
1113 &err, false, root_block))
1114 btr_root_page_initcxx . . $ btr_root_page_init(1036b703ec1e0377).(root_block, idcxx . . $ dict_index_t#id., this, &mtr);
1115 }
1116
1117 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1118 return err;
1119 }
1120
1121 /** Free a persistent index tree if it exists.
1122 @param[in,out] space tablespce
1123 @param[in] page root page number
1124 @param[in] index_id PAGE_INDEX_ID contents
1125 @param[in,out] mtr mini-transaction */
1126 void btr_free_if_existscxx . . $ btr_free_if_exists(71d53d38fa6670fa).(fil_space_tcxx . . $ fil_space_t# *space, uint32_tcxx . . $ uint32_t# page,
1127 index_id_tcxx . . $ index_id_t# index_id, mtr_tcxx . . $ mtr_t# *mtr)
1128 {
1129 if (buf_block_tcxx . . $ buf_block_t# *root= btr_free_root_checkcxx . . $ btr_free_root_check(6f8a7de2d425683d).(page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).(space->idcxx . . $ fil_space_t#id., page),
1130 space->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(),
1131 index_id, mtr))
1132 {
1133 btr_free_but_not_rootcxx . . $ btr_free_but_not_root(ef523e46611fa9e).(root, *mtr);
1134 mtr->set_named_spacecxx . . $ mtr_t#set_named_space(932cf7f430860204).(space);
1135 btr_free_rootcxx . . $ btr_free_root(3835fffe11e158f4).(root, *space, mtr);
1136 }
1137 }
1138
1139 /** Drop a temporary table
1140 @param trx transaction
1141 @param table temporary table */
1142 void btr_drop_temporary_tablecxx . . $ btr_drop_temporary_table(87051a9661da353e).(trx_tcxx . . $ trx_t# *trx, const dict_table_tcxx . . $ dict_table_t# &table)
1143 {
1144 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(table.is_temporary());
1145 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(table.space == fil_system.temp_space);
1146 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{trx};
1147 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1148 for (const dict_index_tcxx . . $ dict_index_t# *index= table.indexescxx . . $ dict_table_t#indexes..startcxx . . $ ut_list_base#start.; index;
1149 index= dict_table_get_next_indexcxx . . $ `storage/innobase/include/dict0dict.h:614:10`!(index))
1150 {
1151 #ifndef BTR_CUR_ADAPTcxx . . $ `<built-in>:480:9`!
1152 static constexpr buf_block_t *guess= nullptr;
1153 #else
1154 buf_block_tcxx . . $ buf_block_t# *guess= index->search_infocxx . . $ dict_index_t#search_info..root_guesscxx . . $ dict_index_t#ahi#root_guess.;
1155 #endif
1156 if (buf_block_tcxx . . $ buf_block_t# *block= buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).({cxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).SRV_TMP_SPACE_IDcxx . . $ SRV_TMP_SPACE_ID., index->pagecxx . . $ dict_index_t#page.},
1157 0, RW_X_LATCHcxx . . $ RW_X_LATCH., guess, BUF_GETcxx . . $ `storage/innobase/include/buf0buf.h:53:9`!,
1158 &mtr, nullptr))
1159 {
1160 mtr.set_log_modecxx . . $ mtr_t#set_log_mode(9fa4fa4ef91bef56).(MTR_LOG_NO_REDOcxx . . $ MTR_LOG_NO_REDO.);
1161 btr_free_but_not_rootcxx . . $ btr_free_but_not_root(ef523e46611fa9e).(block, mtr);
1162 btr_free_rootcxx . . $ btr_free_root(3835fffe11e158f4).(block, *fil_systemcxx . . $ fil_system..temp_spacecxx . . $ fil_system_t#temp_space., &mtr);
1163 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1164 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1165 }
1166 }
1167 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1168 }
1169
1170 /** Read the last used AUTO_INCREMENT value from PAGE_ROOT_AUTO_INC.
1171 @param[in,out] index clustered index
1172 @return the last used AUTO_INCREMENT value
1173 @retval 0 on error or if no AUTO_INCREMENT value was used yet */
1174 ib_uint64_tcxx . . $ ib_uint64_t#
1175 btr_read_autoinccxx . . $ btr_read_autoinc(2e6d4b3eeae69f8c).(dict_index_tcxx . . $ dict_index_t#* index)
1176 {
1177 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->is_primary());
1178 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->table->persistent_autoinc);
1179 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->table->is_temporary());
1180 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{nullptr};
1181 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1182 dberr_tcxx . . $ dberr_t# err;
1183 uint64_tcxx . . $ uint64_t# autoinc;
1184 if (buf_block_tcxx . . $ buf_block_t# *root= btr_root_block_getcxx . . $ btr_root_block_get(4bcbd40788d58e0a).(index, RW_S_LATCHcxx . . $ RW_S_LATCH., &mtr, &err))
1185 autoinc= page_get_autoinccxx . . $ page_get_autoinc(b191ace3c5bffbd9).(root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1186 else
1187 autoinc= 0;
1188 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1189 return autoinc;
1190 }
1191
1192 dict_index_tcxx . . $ dict_index_t# *dict_table_tcxx . . $ dict_table_t#::get_indexcxx . . $ dict_table_t#get_index(6c1e1d65197260de).(const dict_col_tcxx . . $ dict_col_t# &col) const
1193 {
1194 dict_index_tcxx . . $ dict_index_t# *index= dict_table_get_first_indexcxx . . $ `storage/innobase/include/dict0dict.h:612:10`!(this);
1195
1196 while (index && (index->fieldscxx . . $ dict_index_t#fields.[0].colcxx . . $ dict_field_t#col. != &col || index->is_corruptedcxx . . $ dict_index_t#is_corrupted(50ce9a9e25b4a850).()))
1197 index= dict_table_get_next_indexcxx . . $ `storage/innobase/include/dict0dict.h:614:10`!(index);
1198
1199 return index;
1200 }
1201
1202 /** Read the last used AUTO_INCREMENT value from PAGE_ROOT_AUTO_INC,
1203 or fall back to MAX(auto_increment_column).
1204 @param table table containing an AUTO_INCREMENT column
1205 @param col_no index of the AUTO_INCREMENT column
1206 @param mysql_version TABLE_SHARE::mysql_version
1207 @param max the maximum value of the AUTO_INCREMENT column
1208 @return the AUTO_INCREMENT value
1209 @retval 0 on error or if no AUTO_INCREMENT value was used yet */
1210 uint64_tcxx . . $ uint64_t# btr_read_autoinc_with_fallbackcxx . . $ btr_read_autoinc_with_fallback(f4407c6203fb1f86).(const dict_table_tcxx . . $ dict_table_t# *table,
1211 unsigned col_no, ulong mysql_version,
1212 uint64_tcxx . . $ uint64_t# max)
1213 {
1214 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(table->persistent_autoinc);
1215 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!table->is_temporary());
1216
1217 uint64_tcxx . . $ uint64_t# autoinc= 0;
1218 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{nullptr};
1219 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1220 const dict_index_tcxx . . $ dict_index_t# *const first_index= dict_table_get_first_indexcxx . . $ `storage/innobase/include/dict0dict.h:612:10`!(table);
1221
1222 if (buf_block_tcxx . . $ buf_block_t# *block=
1223 buf_page_getcxx . . $ `storage/innobase/include/buf0buf.h:149:10`!(page_id_t(table->space_id, first_index->page),
1224 table->space->zip_size(), RW_SX_LATCH, &mtr))
1225 {
1226 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, first_index);
1227 autoinc= page_get_autoinccxx . . $ page_get_autoinc(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1228
1229 if (autoinc > 0 && autoinc <= max && mysql_version >= 100210);
1230 else if (dict_index_tcxx . . $ dict_index_t# *index=
1231 table->get_indexcxx . . $ dict_table_t#get_index(6c1e1d65197260de).(*dict_table_get_nth_colcxx . . $ `storage/innobase/include/dict0dict.h:737:9`!(table, col_no)))
1232 {
1233 /* Read MAX(autoinc_col), in case this table had originally been
1234 created before MariaDB 10.2.4 introduced persistent AUTO_INCREMENT
1235 and MariaDB 10.2.10 fixed MDEV-12123, and there could be a garbage
1236 value in the PAGE_ROOT_AUTO_INC field. */
1237 const uint64_tcxx . . $ uint64_t# max_autoinc= row_search_max_autoinccxx . . $ row_search_max_autoinc(96978c6ee2276cc3).(index);
1238 const bool need_adjust{autoinc > max || autoinc < max_autoinc};
1239 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(max_autoinc <= max);
1240
1241 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(need_adjust) && !high_level_read_onlycxx . . $ high_level_read_only. && !opt_readonlycxx . . $ opt_readonly.)
1242 {
1243 sql_print_informationcxx . . $ sql_print_information(326aeb464d16410c).("InnoDB: Resetting PAGE_ROOT_AUTO_INC from "
1244 UINT64PFcxx . . $ `storage/innobase/include/univ.i:322:9`! " to " UINT64PFcxx . . $ `storage/innobase/include/univ.i:322:9`!
1245 " on table %.*sQ.%sQ (created with version %lu)",
1246 autoinc, max_autoinc,
1247 int(table->namecxx . . $ dict_table_t#name..dblencxx . . $ table_name_t#dblen(c9b1e749b64d5edc).()), table->namecxx . . $ dict_table_t#name..m_namecxx . . $ table_name_t#m_name.,
1248 table->namecxx . . $ dict_table_t#name..basenamecxx . . $ table_name_t#basename(ba32b354807b2b81).(), mysql_version);
1249 autoinc= max_autoinc;
1250 index->set_modifiedcxx . . $ dict_index_t#set_modified(6ecce9205e900009).(mtr);
1251 page_set_autoinccxx . . $ page_set_autoinc(a8d2f9a12d05e3b9).(block, max_autoinc, &mtr, true);
1252 }
1253 }
1254 }
1255
1256 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1257 return autoinc;
1258 }
1259
1260 /** Write the next available AUTO_INCREMENT value to PAGE_ROOT_AUTO_INC.
1261 @param[in,out] trx transaction
1262 @param[in,out] index clustered index
1263 @param[in] autoinc the AUTO_INCREMENT value
1264 @param[in] reset whether to reset the AUTO_INCREMENT
1265 to a possibly smaller value than currently
1266 exists in the page */
1267 void btr_write_autoinccxx . . $ btr_write_autoinc(b2007400f7d5da6b).(trx_tcxx . . $ trx_t# *trx, dict_index_tcxx . . $ dict_index_t# *index, uint64_tcxx . . $ uint64_t# autoinc,
1268 bool reset)
1269 {
1270 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->is_primary());
1271 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->table->persistent_autoinc);
1272 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->table->is_temporary());
1273
1274 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{trx};
1275 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1276 fil_space_tcxx . . $ fil_space_t# *space= index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.;
1277 if (buf_block_tcxx . . $ buf_block_t# *root= buf_page_getcxx . . $ `storage/innobase/include/buf0buf.h:149:10`!(page_id_t(space->id, index->page),
1278 space->zip_size(), RW_SX_LATCH, &mtr))
1279 {
1280 #ifdef BTR_CUR_HASH_ADAPTcxx . . $ `<built-in>:481:9`!
1281 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(if (dict_index_t *ri= root->index)) ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(ri == index);
1282 #endif /* BTR_CUR_HASH_ADAPT */
1283 buf_page_make_young_if_neededcxx . . $ buf_page_make_young_if_needed(12ea16e51c748147).(&root->pagecxx . . $ buf_block_t#page.);
1284 mtr.set_named_spacecxx . . $ mtr_t#set_named_space(932cf7f430860204).(space);
1285 page_set_autoinccxx . . $ page_set_autoinc(a8d2f9a12d05e3b9).(root, autoinc, &mtr, reset);
1286 }
1287
1288 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1289 }
1290
1291 /** Reorganize an index page.
1292 @param cursor index page cursor
1293 @param mtr mini-transaction */
1294 static dberr_tcxx . . $ dberr_t# btr_page_reorganize_lowcxx . . $ btr_page_reorganize_low(e4b2ea64c1f14b9e).(page_cur_tcxx . . $ page_cur_t# *cursor, mtr_tcxx . . $ mtr_t# *mtr)
1295 {
1296 buf_block_tcxx . . $ buf_block_t# *const block= cursor->blockcxx . . $ page_cur_t#block.;
1297
1298 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
1299 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!is_buf_block_get_page_zip(block));
1300 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(fil_page_index_page_check(block->page.frame));
1301 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->index->is_dummy ||
1302 block->page.id().space() == cursor->index->table->space->id);
1303 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->index->is_dummy ||
1304 block->page.id().page_no() != cursor->index->page ||
1305 !page_has_siblings(block->page.frame));
1306
1307 /* Save the cursor position. */
1308 const ulintcxx . . $ ulint# pos= page_rec_get_n_recs_beforecxx . . $ page_rec_get_n_recs_before(b191ace3c5bffbd9).(cursor->reccxx . . $ page_cur_t#rec.);
1309
1310 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(pos == ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!))
1311 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
1312
1313 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
1314
1315 buf_block_tcxx . . $ buf_block_t# *old= buf_block_alloccxx . . $ `storage/innobase/include/buf0lru.h:92:9`!();
1316 /* Copy the old page to temporary space */
1317 memcpy_alignedcxx . . $ memcpy_aligned(cc817cb175f282d).<UNIV_PAGE_SIZE_MINcxx . . $ `storage/innobase/include/univ.i:212:9`!>(old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1318 srv_page_sizecxx . . $ srv_page_size.);
1319
1320 const mtr_log_tcxx . . $ mtr_log_t# log_mode= mtr->set_log_modecxx . . $ mtr_t#set_log_mode(9fa4fa4ef91bef56).(MTR_LOG_NO_REDOcxx . . $ MTR_LOG_NO_REDO.);
1321
1322 page_createcxx . . $ page_create(529cd47aa3b34ebe).(block, mtr, cursor->indexcxx . . $ page_cur_t#index.->tablecxx . . $ dict_index_t#table.->not_redundantcxx . . $ dict_table_t#not_redundant(50ce9a9e25b4a850).());
1323 if (cursor->indexcxx . . $ page_cur_t#index.->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).())
1324 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + 1]= bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.);
1325
1326 static_assert(((FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX. & 0xff00) | bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.)) ==
1327 FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE., "compatibility");
1328
1329 /* Copy the records from the temporary space to the recreated page;
1330 do not copy the lock bits yet */
1331
1332 dberr_tcxx . . $ dberr_t# err=
1333 page_copy_rec_list_end_no_lockscxx . . $ page_copy_rec_list_end_no_locks(86dac29eba89661f).(block, old,
1334 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(old->page.frame),
1335 cursor->indexcxx . . $ page_cur_t#index., mtr);
1336 mtr->set_log_modecxx . . $ mtr_t#set_log_mode(9fa4fa4ef91bef56).(log_mode);
1337
1338 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(err != DB_SUCCESS))
1339 return err;
1340
1341 /* Copy the PAGE_MAX_TRX_ID or PAGE_ROOT_AUTO_INC. */
1342 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_get_max_trx_id(block->page.frame));
1343 memcpy_alignedcxx . . $ memcpy_aligned(cc817cb175f282d).<8>(PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`! + PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1344 PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`! + PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 8);
1345 #ifdef UNIV_DEBUG
1346 if (page_get_max_trx_id(block->page.frame))
1347 /* PAGE_MAX_TRX_ID must be zero on non-leaf pages other than
1348 clustered index root pages. */
1349 ut_ad(!cursor->index->is_primary()
1350 ? page_is_leaf(block->page.frame)
1351 : block->page.id().page_no() == cursor->index->page);
1352 else
1353 /* PAGE_MAX_TRX_ID is unused in clustered index pages (other than
1354 the root where it is repurposed as PAGE_ROOT_AUTO_INC), non-leaf
1355 pages, and in temporary tables. It was always zero-initialized in
1356 page_create(). PAGE_MAX_TRX_ID must be nonzero on secondary index
1357 leaf pages. */
1358 ut_ad(cursor->index->table->is_temporary() ||
1359 !page_is_leaf(block->page.frame) ||
1360 cursor->index->is_primary());
1361 #endif
1362
1363 const uint16_tcxx . . $ uint16_t# data_size1= page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1364 const uint16_tcxx . . $ uint16_t# data_size2= page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1365 const ulintcxx . . $ ulint# max1=
1366 page_get_max_insert_size_after_reorganizecxx . . $ page_get_max_insert_size_after_reorganize(4adc7973d4c4f159).(old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 1);
1367 const ulintcxx . . $ ulint# max2=
1368 page_get_max_insert_size_after_reorganizecxx . . $ page_get_max_insert_size_after_reorganize(4adc7973d4c4f159).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 1);
1369
1370 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(data_size1 != data_size2 || max1 != max2))
1371 {
1372 sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Page old data size %u new data size %u"
1373 ", page old max ins size %zu new max ins size %zu",
1374 data_size1, data_size2, max1, max2);
1375 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
1376 }
1377
1378 /* Restore the cursor position. */
1379 if (!pos)
1380 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->rec == page_get_infimum_rec(block->page.frame));
1381 else if (!(cursor->reccxx . . $ page_cur_t#rec.= page_rec_get_nthcxx . . $ page_rec_get_nth(7ccb9c26b1180419).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., pos)))
1382 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
1383
1384 if (block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() != cursor->indexcxx . . $ page_cur_t#index.->pagecxx . . $ dict_index_t#page. ||
1385 fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.) != FIL_PAGE_TYPE_INSTANTcxx . . $ FIL_PAGE_TYPE_INSTANT.)
1386 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(old->page.frame, block->page.frame, PAGE_HEADER));
1387 else if (!cursor->indexcxx . . $ page_cur_t#index.->is_instantcxx . . $ dict_index_t#is_instant(50ce9a9e25b4a850).())
1388 {
1389 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(old->page.frame, block->page.frame, FIL_PAGE_TYPE));
1390 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(old->page.frame + FIL_PAGE_TYPE + 2,
1391 block->page.frame + FIL_PAGE_TYPE + 2,
1392 PAGE_HEADER - FIL_PAGE_TYPE - 2));
1393 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2,mtr_tcxx . . $ mtr_t#::FORCEDcxx . . $ mtr_t#FORCED.>(*block, FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1394 FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX.);
1395 }
1396 else
1397 {
1398 /* Preserve the PAGE_INSTANT information. */
1399 memcpy_alignedcxx . . $ memcpy_aligned(cc817cb175f282d).<2>(FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1400 FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 2);
1401 memcpy_alignedcxx . . $ memcpy_aligned(cc817cb175f282d).<2>(PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_INSTANTcxx . . $ `storage/innobase/include/page0page.h:88:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1402 PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_INSTANTcxx . . $ `storage/innobase/include/page0page.h:88:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 2);
1403 if (!cursor->indexcxx . . $ page_cur_t#index.->tablecxx . . $ dict_index_t#table.->instantcxx . . $ dict_table_t#instant.);
1404 else if (page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.))
1405 {
1406 memcpy(PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1407 PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 8);
1408 memcpy(PAGE_NEW_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:144:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1409 PAGE_NEW_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:144:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 8);
1410 }
1411 else
1412 {
1413 memcpy(PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1414 PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 8);
1415 memcpy(PAGE_OLD_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:135:9`! + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1416 PAGE_OLD_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:135:9`! + old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 8);
1417 }
1418
1419 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(old->page.frame, block->page.frame, PAGE_HEADER));
1420 }
1421
1422 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(old->page.frame + PAGE_MAX_TRX_ID + PAGE_HEADER,
1423 block->page.frame + PAGE_MAX_TRX_ID + PAGE_HEADER,
1424 PAGE_DATA - (PAGE_MAX_TRX_ID + PAGE_HEADER)));
1425
1426 if (!cursor->indexcxx . . $ page_cur_t#index.->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).());
1427 else if (cursor->indexcxx . . $ page_cur_t#index.->pagecxx . . $ dict_index_t#page. == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!)
1428 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->index->is_dummy);
1429 else
1430 lock_move_reorganize_pagecxx . . $ lock_move_reorganize_page(71e7023f76cd449a).(block, old);
1431
1432 /* Write log for the changes, if needed. */
1433 if (log_mode == MTR_LOG_ALLcxx . . $ MTR_LOG_ALL.)
1434 {
1435 /* Check and log the changes in the page header. */
1436 ulintcxx . . $ ulint# a, e;
1437 for (a= PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`!, e= PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`! + PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`!; a < e; a++)
1438 {
1439 if (old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1440 continue;
1441 while (--e, old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e]);
1442 e++;
1443 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(a < e);
1444 /* Write log for the changed page header fields. */
1445 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, e - a);
1446 break;
1447 }
1448
1449 const uint16_tcxx . . $ uint16_t# top= page_header_get_offscxx . . $ page_header_get_offs(cbdda48327e67104).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., PAGE_HEAP_TOPcxx . . $ `storage/innobase/include/page0page.h:52:9`!);
1450
1451 if (page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.))
1452 {
1453 /* info_bits=0, n_owned=1, heap_no=0, status */
1454 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(PAGE_NEW_INFIMUM - REC_N_NEW_EXTRA_BYTES +
1455 block->page.frame,
1456 PAGE_NEW_INFIMUM - REC_N_NEW_EXTRA_BYTES +
1457 old->page.frame, 3));
1458 /* If the 'next' pointer of the infimum record has changed, log it. */
1459 a= PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`! - 2;
1460 e= a + 2;
1461 if (block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] == old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1462 a++;
1463 if (--e, block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e] != old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e])
1464 e++;
1465 if (ulintcxx . . $ ulint# len= e - a)
1466 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, len);
1467 /* The infimum record itself must not change. */
1468 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(PAGE_NEW_INFIMUM + block->page.frame,
1469 PAGE_NEW_INFIMUM + old->page.frame, 8));
1470 /* Log any change of the n_owned of the supremum record. */
1471 a= PAGE_NEW_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:144:9`! - REC_N_NEW_EXTRA_BYTEScxx . . $ `storage/innobase/include/rem0rec.h:46:9`!;
1472 if (block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] != old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1473 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, 1);
1474 /* The rest of the supremum record must not change. */
1475 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(&block->page.frame[a + 1], &old->page.frame[a + 1],
1476 PAGE_NEW_SUPREMUM_END - PAGE_NEW_SUPREMUM +
1477 REC_N_NEW_EXTRA_BYTES - 1));
1478
1479 /* Log the differences in the payload. */
1480 for (a= PAGE_NEW_SUPREMUM_ENDcxx . . $ `storage/innobase/include/page0page.h:147:9`!, e= top; a < e; a++)
1481 {
1482 if (old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1483 continue;
1484 while (--e, old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e]);
1485 e++;
1486 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(a < e);
1487 /* TODO: write MEMMOVE records to minimize this further! */
1488 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, e - a);
1489 break;
1490 }
1491 }
1492 else
1493 {
1494 /* info_bits=0, n_owned=1, heap_no=0, number of fields, 1-byte format */
1495 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(PAGE_OLD_INFIMUM - REC_N_OLD_EXTRA_BYTES +
1496 block->page.frame,
1497 PAGE_OLD_INFIMUM - REC_N_OLD_EXTRA_BYTES +
1498 old->page.frame, 4));
1499 /* If the 'next' pointer of the infimum record has changed, log it. */
1500 a= PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`! - 2;
1501 e= a + 2;
1502 if (block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] == old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1503 a++;
1504 if (--e, block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e] != old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e])
1505 e++;
1506 if (ulintcxx . . $ ulint# len= e - a)
1507 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, len);
1508 /* The infimum record itself must not change. */
1509 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(PAGE_OLD_INFIMUM + block->page.frame,
1510 PAGE_OLD_INFIMUM + old->page.frame, 8));
1511 /* Log any change of the n_owned of the supremum record. */
1512 a= PAGE_OLD_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:135:9`! - REC_N_OLD_EXTRA_BYTEScxx . . $ `storage/innobase/include/rem0rec.h:43:9`!;
1513 if (block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] != old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1514 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, 1);
1515 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(&block->page.frame[a + 1], &old->page.frame[a + 1],
1516 PAGE_OLD_SUPREMUM_END - PAGE_OLD_SUPREMUM +
1517 REC_N_OLD_EXTRA_BYTES - 1));
1518
1519 /* Log the differences in the payload. */
1520 for (a= PAGE_OLD_SUPREMUM_ENDcxx . . $ `storage/innobase/include/page0page.h:138:9`!, e= top; a < e; a++)
1521 {
1522 if (old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1523 continue;
1524 while (--e, old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e]);
1525 e++;
1526 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(a < e);
1527 /* TODO: write MEMMOVE records to minimize this further! */
1528 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, e - a);
1529 break;
1530 }
1531 }
1532
1533 e= srv_page_sizecxx . . $ srv_page_size. - PAGE_DIRcxx . . $ `storage/innobase/include/page0page.h:178:9`!;
1534 a= e - PAGE_DIR_SLOT_SIZEcxx . . $ PAGE_DIR_SLOT_SIZE. * page_dir_get_n_slotscxx . . $ page_dir_get_n_slots(469dcb4e54b221a8).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1535
1536 /* Zero out the payload area. */
1537 mtr->memsetcxx . . $ mtr_t#memset(a63e36b03de8061).(*block, top, a - top, 0);
1538
1539 /* Log changes to the page directory. */
1540 for (; a < e; a++)
1541 {
1542 if (old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[a])
1543 continue;
1544 while (--e, old->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e] == block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[e]);
1545 e++;
1546 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(a < e);
1547 /* Write log for the changed page directory slots. */
1548 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, a, e - a);
1549 break;
1550 }
1551 }
1552
1553 buf_block_freecxx . . $ `storage/innobase/include/buf0buf.h:148:10`!(old);
1554
1555 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_INDEX_REORG_ATTEMPTS);
1556 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_INDEX_REORG_SUCCESSFUL);
1557 return DB_SUCCESScxx . . $ DB_SUCCESS.;
1558 }
1559
1560 /** Reorganize an index page.
1561 @return error code
1562 @retval DB_FAIL if reorganizing a ROW_FORMAT=COMPRESSED page failed */
1563 dberr_tcxx . . $ dberr_t#
1564 btr_page_reorganize_blockcxx . . $ btr_page_reorganize_block(b7f2450dfd4d62c3).(
1565 ulintcxx . . $ ulint# z_level,/*!< in: compression level to be used
1566 if dealing with compressed page */
1567 buf_block_tcxx . . $ buf_block_t#* block, /*!< in/out: B-tree page */
1568 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: the index tree of the page */
1569 mtr_tcxx . . $ mtr_t#* mtr) /*!< in/out: mini-transaction */
1570 {
1571 if (buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block))
1572 return page_zip_reorganizecxx . . $ page_zip_reorganize(253bcb2463e440be).(block, index, z_level, mtr, true);
1573 page_cur_tcxx . . $ page_cur_t# cur;
1574 page_cur_set_before_firstcxx . . $ page_cur_set_before_first(34f1922d808032bb).(block, &cur);
1575 cur.indexcxx . . $ page_cur_t#index.= index;
1576 return btr_page_reorganize_lowcxx . . $ btr_page_reorganize_low(e4b2ea64c1f14b9e).(&cur, mtr);
1577 }
1578
1579 /** Reorganize an index page.
1580 @param cursor page cursor
1581 @param mtr mini-transaction
1582 @return error code
1583 @retval DB_FAIL if reorganizing a ROW_FORMAT=COMPRESSED page failed */
1584 dberr_tcxx . . $ dberr_t# btr_page_reorganizecxx . . $ btr_page_reorganize(e4b2ea64c1f14b9e).(page_cur_tcxx . . $ page_cur_t# *cursor, mtr_tcxx . . $ mtr_t# *mtr)
1585 {
1586 if (!buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(cursor->block))
1587 return btr_page_reorganize_lowcxx . . $ btr_page_reorganize_low(e4b2ea64c1f14b9e).(cursor, mtr);
1588
1589 ulintcxx . . $ ulint# pos= page_rec_get_n_recs_beforecxx . . $ page_rec_get_n_recs_before(b191ace3c5bffbd9).(cursor->reccxx . . $ page_cur_t#rec.);
1590 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(pos == ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!))
1591 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
1592
1593 dberr_tcxx . . $ dberr_t# err= page_zip_reorganizecxx . . $ page_zip_reorganize(253bcb2463e440be).(cursor->blockcxx . . $ page_cur_t#block., cursor->indexcxx . . $ page_cur_t#index.,
1594 page_zip_levelcxx . . $ page_zip_level., mtr, true);
1595 if (err == DB_FAILcxx . . $ DB_FAIL.);
1596 else if (!pos)
1597 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->rec == page_get_infimum_rec(cursor->block->page.frame));
1598 else if (!(cursor->reccxx . . $ page_cur_t#rec.= page_rec_get_nthcxx . . $ page_rec_get_nth(7ccb9c26b1180419).(cursor->blockcxx . . $ page_cur_t#block.->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., pos)))
1599 err= DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
1600
1601 return err;
1602 }
1603
1604 /** Empty an index page (possibly the root page). @see btr_page_create().
1605 @param[in,out] block page to be emptied
1606 @param[in,out] page_zip compressed page frame, or NULL
1607 @param[in] index index of the page
1608 @param[in] level B-tree level of the page (0=leaf)
1609 @param[in,out] mtr mini-transaction */
1610 void
1611 btr_page_emptycxx . . $ btr_page_empty(403ca5985fa24f33).(
1612 buf_block_tcxx . . $ buf_block_t#* block,
1613 page_zip_des_tcxx . . $ page_zip_des_t#* page_zip,
1614 dict_index_tcxx . . $ dict_index_t#* index,
1615 ulintcxx . . $ ulint# level,
1616 mtr_tcxx . . $ mtr_t#* mtr)
1617 {
1618 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
1619 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_zip == buf_block_get_page_zip(block));
1620 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->is_dummy);
1621 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->table->space->id == block->page.id().space());
1622 #ifdef UNIV_ZIP_DEBUG
1623 ut_a(!page_zip
1624 || page_zip_validate(page_zip, block->page.frame, index));
1625 #endif /* UNIV_ZIP_DEBUG */
1626
1627 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
1628
1629 /* Recreate the page: note that global data on page (possible
1630 segment headers, next page-field, etc.) is preserved intact */
1631
1632 /* Preserve PAGE_ROOT_AUTO_INC when creating a clustered index
1633 root page. */
1634 const ib_uint64_tcxx . . $ ib_uint64_t# autoinc
1635 = dict_index_is_clustcxx . . $ `storage/innobase/include/dict0dict.h:617:9`!(index)
1636 && index->pagecxx . . $ dict_index_t#page. == block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()
1637 ? page_get_autoinccxx . . $ page_get_autoinc(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.)
1638 : 0;
1639
1640 if (page_zip) {
1641 page_create_zipcxx . . $ page_create_zip(992652f8f3e48cc9).(block, index, level, autoinc, mtr);
1642 } else {
1643 page_createcxx . . $ page_create(529cd47aa3b34ebe).(block, mtr, index->tablecxx . . $ dict_index_t#table.->not_redundantcxx . . $ dict_table_t#not_redundant(50ce9a9e25b4a850).());
1644 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
1645 static_assert(((FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX. & 0xff00)
1646 | bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.))
1647 == FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE., "compatibility");
1648 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<1>(*block, FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`! + 1
1649 + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1650 bytecxx . . $ byte#(FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.));
1651 if (mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.
1652 + FIL_RTREE_SPLIT_SEQ_NUMcxx . . $ `storage/innobase/include/fil0fil.h:1239:9`!)) {
1653 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(block, FIL_RTREE_SPLIT_SEQ_NUMcxx . . $ `storage/innobase/include/fil0fil.h:1239:9`!,
1654 8, 0);
1655 }
1656 }
1657 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*block, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_LEVELcxx . . $ `storage/innobase/include/page0page.h:106:9`!
1658 + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., level);
1659 if (autoinc) {
1660 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<8>(*block, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`!
1661 + block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., autoinc);
1662 }
1663 }
1664 }
1665
1666 /** Write instant ALTER TABLE metadata to a root page.
1667 @param[in,out] root clustered index root page
1668 @param[in] index clustered index with instant ALTER TABLE
1669 @param[in,out] mtr mini-transaction */
1670 void btr_set_instantcxx . . $ btr_set_instant(c781c825a451f33b).(buf_block_tcxx . . $ buf_block_t#* root, const dict_index_tcxx . . $ dict_index_t#& index, mtr_tcxx . . $ mtr_t#* mtr)
1671 {
1672 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index.n_core_fields > 0);
1673 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index.n_core_fields < REC_MAX_N_FIELDS);
1674 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index.is_instant());
1675 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(fil_page_get_type(root->page.frame) == FIL_PAGE_TYPE_INSTANT
1676 || fil_page_get_type(root->page.frame) == FIL_PAGE_INDEX);
1677 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(root->page.frame));
1678 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(root->page.id().page_no() == index.page);
1679
1680 rec_tcxx . . $ rec_t#* infimum = page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(root->page.frame);
1681 rec_tcxx . . $ rec_t#* supremum = page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(root->page.frame);
1682 bytecxx . . $ byte#* page_type = root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`!;
1683 uint16_tcxx . . $ uint16_t# i = page_header_get_fieldcxx . . $ page_header_get_field(cbdda48327e67104).(root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., PAGE_INSTANTcxx . . $ `storage/innobase/include/page0page.h:88:9`!);
1684
1685 switch (mach_read_from_2cxx . . $ mach_read_from_2(469dcb4e54b221a8).(page_type)) {
1686 case FIL_PAGE_TYPE_INSTANTcxx . . $ FIL_PAGE_TYPE_INSTANT.:
1687 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_get_instant(root->page.frame)
1688 == index.n_core_fields);
1689 if (memcmp(infimum, "infimum", 8)
1690 || memcmp(supremum, "supremum", 8)) {
1691 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index.table->instant);
1692 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(infimum, field_ref_zero, 8));
1693 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(supremum, field_ref_zero, 7));
1694 /* The n_core_null_bytes only matters for
1695 ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC tables. */
1696 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(supremum[7] == index.n_core_null_bytes
1697 || !index.table->not_redundant());
1698 return;
1699 }
1700 break;
1701 default:
1702 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!("wrong page type" == 0);
1703 /* fall through */
1704 case FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX.:
1705 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_is_comp(root->page.frame)
1706 || !page_get_instant(root->page.frame));
1707 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(infimum, "infimum", 8));
1708 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(supremum, "supremum", 8));
1709 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2>(*root, page_type, FIL_PAGE_TYPE_INSTANTcxx . . $ FIL_PAGE_TYPE_INSTANT.);
1710 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(i <= PAGE_NO_DIRECTION);
1711 i |= static_cast<uint16_tcxx . . $ uint16_t#>(index.n_core_fieldscxx . . $ dict_index_t#n_core_fields. << 3);
1712 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2>(*root, PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_INSTANTcxx . . $ `storage/innobase/include/page0page.h:88:9`!
1713 + root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., i);
1714 break;
1715 }
1716
1717 if (index.tablecxx . . $ dict_index_t#table.->instantcxx . . $ dict_table_t#instant.) {
1718 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(root, infimum - root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 8, 0);
1719 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(root, supremum - root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., 7, 0);
1720 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<1,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*root, &supremum[7],
1721 index.n_core_null_bytescxx . . $ dict_index_t#n_core_null_bytes.);
1722 }
1723 }
1724
1725 /** Reset the table to the canonical format on ROLLBACK of instant ALTER TABLE.
1726 @param[in] index clustered index with instant ALTER TABLE
1727 @param[in] all whether to reset FIL_PAGE_TYPE as well
1728 @param[in,out] mtr mini-transaction */
1729 ATTRIBUTE_COLDcxx . . $ `include/my_compiler.h:166:10`!
1730 void btr_reset_instantcxx . . $ btr_reset_instant(65307ff9370f19d4).(const dict_index_tcxx . . $ dict_index_t# &index, bool all, mtr_tcxx . . $ mtr_t# *mtr)
1731 {
1732 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index.table->is_temporary());
1733 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index.is_primary());
1734 buf_block_tcxx . . $ buf_block_t# *root= btr_get_latched_rootcxx . . $ btr_get_latched_root(7433449132ea960e).(index, mtr);
1735 bytecxx . . $ byte# *page_type= root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`!;
1736 if (all)
1737 {
1738 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mach_read_from_2(page_type) == FIL_PAGE_TYPE_INSTANT ||
1739 mach_read_from_2(page_type) == FIL_PAGE_INDEX);
1740 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*root, page_type, FIL_PAGE_INDEXcxx . . $ FIL_PAGE_INDEX.);
1741 bytecxx . . $ byte# *instant= PAGE_INSTANTcxx . . $ `storage/innobase/include/page0page.h:88:9`! + PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.;
1742 mtr->writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<2,mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*root, instant,
1743 page_ptr_get_directioncxx . . $ page_ptr_get_direction(f3688bc2ee54ea05).(instant + 1));
1744 }
1745 else
1746 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mach_read_from_2(page_type) == FIL_PAGE_TYPE_INSTANT);
1747 static const bytecxx . . $ byte# supremuminfimum[8 + 8] = "supremuminfimum";
1748 uint16_tcxx . . $ uint16_t# infimum, supremum;
1749 if (page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.))
1750 {
1751 infimum= PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`!;
1752 supremum= PAGE_NEW_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:144:9`!;
1753 }
1754 else
1755 {
1756 infimum= PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`!;
1757 supremum= PAGE_OLD_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:135:9`!;
1758 }
1759 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(&root->page.frame[infimum], supremuminfimum + 8, 8) ==
1760 !memcmp(&root->page.frame[supremum], supremuminfimum, 8));
1761 mtr->memcpycxx . . $ mtr_t#memcpy(cacdda589782ca45).<mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*root, &root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[infimum],
1762 supremuminfimum + 8, 8);
1763 mtr->memcpycxx . . $ mtr_t#memcpy(cacdda589782ca45).<mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*root, &root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.[supremum],
1764 supremuminfimum, 8);
1765 }
1766
1767 /*************************************************************//**
1768 Makes tree one level higher by splitting the root, and inserts
1769 the tuple. It is assumed that mtr contains an x-latch on the tree.
1770 NOTE that the operation of this function must always succeed,
1771 we cannot reverse it: therefore enough free disk space must be
1772 guaranteed to be available before this function is called.
1773 @return inserted record */
1774 rec_tcxx . . $ rec_t#*
1775 btr_root_raise_and_insertcxx . . $ btr_root_raise_and_insert(705431d322c9a50a).(
1776 /*======================*/
1777 ulintcxx . . $ ulint# flags, /*!< in: undo logging and locking flags */
1778 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor at which to insert: must be
1779 on the root page; when the function returns,
1780 the cursor is positioned on the predecessor
1781 of the inserted record */
1782 rec_offscxx . . $ rec_offs#** offsets,/*!< out: offsets on inserted record */
1783 mem_heap_tcxx . . $ mem_heap_t#** heap, /*!< in/out: pointer to memory heap, or NULL */
1784 const dtuple_tcxx . . $ dtuple_t#* tuple, /*!< in: tuple to insert */
1785 ulintcxx . . $ ulint# n_ext, /*!< in: number of externally stored columns */
1786 mtr_tcxx . . $ mtr_t#* mtr, /*!< in: mtr */
1787 dberr_tcxx . . $ dberr_t#* err) /*!< out: error code */
1788 {
1789 dict_index_tcxx . . $ dict_index_t#* index;
1790 dtuple_tcxx . . $ dtuple_t#* node_ptr;
1791 ulintcxx . . $ ulint# level;
1792 rec_tcxx . . $ rec_t#* node_ptr_rec;
1793 page_cur_tcxx . . $ page_cur_t#* page_cursor;
1794 page_zip_des_tcxx . . $ page_zip_des_t#* root_page_zip;
1795 page_zip_des_tcxx . . $ page_zip_des_t#* new_page_zip;
1796 buf_block_tcxx . . $ buf_block_t#* root;
1797 buf_block_tcxx . . $ buf_block_t#* new_block;
1798
1799 root = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor);
1800 root_page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(root);
1801 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_is_empty(root->page.frame));
1802 index = btr_cur_get_indexcxx . . $ `storage/innobase/include/btr0cur.h:82:9`!(cursor);
1803 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->n_core_null_bytes <= UT_BITS_IN_BYTES(index->n_nullable));
1804 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->is_spatial());
1805 #ifdef UNIV_ZIP_DEBUG
1806 ut_a(!root_page_zip
1807 || page_zip_validate(root_page_zip, root->page.frame, index));
1808 #endif /* UNIV_ZIP_DEBUG */
1809 const page_id_tcxx . . $ page_id_t# root_id{root->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
1810
1811 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&index->lock, MTR_MEMO_X_LOCK
1812 | MTR_MEMO_SX_LOCK));
1813 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(root, MTR_MEMO_PAGE_X_FIX));
1814
1815 if (index->pagecxx . . $ dict_index_t#page. != root_id.page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()) {
1816 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!("corrupted root page number" == 0);
1817 return nullptr;
1818 }
1819
1820 if (!btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_LEAFcxx . . $ `storage/innobase/include/page0page.h:113:9`!,
1821 *root, *index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.)
1822 || !btr_root_fseg_validatecxx . . $ btr_root_fseg_validate(8aef732a94764f22).(FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`! + PAGE_BTR_SEG_TOPcxx . . $ `storage/innobase/include/page0page.h:123:9`!,
1823 *root, *index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.)) {
1824 return nullptr;
1825 }
1826
1827 /* Allocate a new page to the tree. Root splitting is done by first
1828 moving the root records to the new page, emptying the root, putting
1829 a node pointer to the new page, and then splitting the new page. */
1830
1831 level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1832
1833 new_block = btr_page_alloccxx . . $ btr_page_alloc(97e5958ce206bff9).(index, 0, FSP_NO_DIRcxx . . $ `storage/innobase/include/fsp0types.h:55:9`!, level, mtr, mtr, err);
1834
1835 if (!new_block) {
1836 return nullptr;
1837 }
1838
1839 new_page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(new_block);
1840 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(!new_page_zip == !root_page_zip);
1841 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(!new_page_zip
1842 || page_zip_get_size(new_page_zip)
1843 == page_zip_get_size(root_page_zip));
1844
1845 btr_page_createcxx . . $ btr_page_create(403ca5985fa24f33).(new_block, new_page_zip, index, level, mtr);
1846 if (page_has_siblingscxx . . $ page_has_siblings(190063cf6fb4afb1).(new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.)) {
1847 compile_time_assertcxx . . $ `include/my_global.h:377:9`!(FIL_PAGE_NEXTcxx . . $ `storage/innobase/include/fil0fil.h:1203:9`! == FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`! + 4);
1848 compile_time_assertcxx . . $ `include/my_global.h:377:9`!(FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`! == 0xffffffff);
1849 static_assert(FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`! % 8 == 0, "alignment");
1850 memset_alignedcxx . . $ memset_aligned(d1de1e4fb215f1c6).<8>(new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!,
1851 0xff, 8);
1852 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(new_block, FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!, 8, 0xff);
1853 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(new_page_zip)) {
1854 memset_alignedcxx . . $ memset_aligned(d1de1e4fb215f1c6).<8>(new_page_zip->datacxx . . $ page_zip_des_t#data. + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!,
1855 0xff, 8);
1856 }
1857 }
1858
1859 /* Copy the records from root to the new page one by one. */
1860 if (0
1861 #ifdef UNIV_ZIP_COPY
1862 || new_page_zip
1863 #endif /* UNIV_ZIP_COPY */
1864 || !page_copy_rec_list_endcxx . . $ page_copy_rec_list_end(49a7688bb655da1e).(new_block, root,
1865 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(root->page.frame),
1866 index, mtr, err)) {
1867 switch (*err) {
1868 case DB_SUCCESScxx . . $ DB_SUCCESS.:
1869 break;
1870 case DB_FAILcxx . . $ DB_FAIL.:
1871 *err = DB_SUCCESScxx . . $ DB_SUCCESS.;
1872 break;
1873 default:
1874 return nullptr;
1875 }
1876
1877 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(new_page_zip);
1878
1879 /* Copy the page byte for byte. */
1880 page_zip_copy_recscxx . . $ page_zip_copy_recs(10c35386c1dea7d4).(new_block, root_page_zip,
1881 root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., index, mtr);
1882
1883 /* Update the lock table and possible hash index. */
1884 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
1885 lock_move_rec_list_endcxx . . $ lock_move_rec_list_end(8f3f6be5e6bf9974).(
1886 new_block, root,
1887 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(root->page.frame));
1888 }
1889
1890 btr_search_move_or_delete_hash_entriescxx . . $ btr_search_move_or_delete_hash_entries(da6997965f563264).(new_block, root);
1891 }
1892
1893 constexpr uint16_tcxx . . $ uint16_t# max_trx_id = PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`!;
1894 if (!index->is_primarycxx . . $ dict_index_t#is_primary(50ce9a9e25b4a850).()) {
1895 /* In secondary indexes,
1896 PAGE_MAX_TRX_ID can be reset on the root page, because
1897 the field only matters on leaf pages, and the root no
1898 longer is a leaf page. (Older versions of InnoDB did
1899 set PAGE_MAX_TRX_ID on all secondary index pages.) */
1900 bytecxx . . $ byte#* p = my_assume_alignedcxx . . $ my_assume_aligned(5eb18401b0825ee).<8>(
1901 PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`! + root->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1902 if (mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(p)) {
1903 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(root, max_trx_id, 8, 0);
1904 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(root->page.zip.data)) {
1905 memset_alignedcxx . . $ memset_aligned(d1de1e4fb215f1c6).<8>(max_trx_id
1906 + root->pagecxx . . $ buf_block_t#page..zipcxx . . $ buf_page_t#zip..datacxx . . $ page_zip_des_t#data., 0, 8);
1907 }
1908 }
1909 } else {
1910 /* PAGE_ROOT_AUTO_INC is only present in the clustered index
1911 root page; on other clustered index pages, we want to reserve
1912 the field PAGE_MAX_TRX_ID for future use. */
1913 bytecxx . . $ byte#* p = my_assume_alignedcxx . . $ my_assume_aligned(5eb18401b0825ee).<8>(
1914 PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_MAX_TRX_IDcxx . . $ `storage/innobase/include/page0page.h:100:9`! + new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
1915 if (mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(p)) {
1916 mtr->memsetcxx . . $ mtr_t#memset(514fd140d769d0f8).(new_block, max_trx_id, 8, 0);
1917 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(new_block->page.zip.data)) {
1918 memset_alignedcxx . . $ memset_aligned(d1de1e4fb215f1c6).<8>(max_trx_id
1919 + new_block->pagecxx . . $ buf_block_t#page..zipcxx . . $ buf_page_t#zip..datacxx . . $ page_zip_des_t#data.,
1920 0, 8);
1921 }
1922 }
1923 }
1924
1925 /* If this is a pessimistic insert which is actually done to
1926 perform a pessimistic update then we have stored the lock
1927 information of the record to be inserted on the infimum of the
1928 root page: we cannot discard the lock structs on the root page */
1929
1930 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
1931 lock_update_root_raisecxx . . $ lock_update_root_raise(a59c6f65a779987b).(*new_block, root_id);
1932 }
1933
1934 /* Create a memory heap where the node pointer is stored */
1935 if (!*heap) {
1936 *heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(1000);
1937 }
1938
1939 const uint32_tcxx . . $ uint32_t# new_page_no = new_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).();
1940 const rec_tcxx . . $ rec_t#* rec= page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.)
1941 ? page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1942 new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.
1943 + PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`!)
1944 : page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
1945 new_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.
1946 + PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`!);
1947 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec); /* We just created the page. */
1948
1949 /* Build the node pointer (= node key and page address) for the
1950 child */
1951 node_ptr = dict_index_build_node_ptrcxx . . $ dict_index_build_node_ptr(21b5a4827c82add7).(index, rec, new_page_no, *heap,
1952 level);
1953 /* The node pointer must be marked as the predefined minimum record,
1954 as there is no lower alphabetical limit to records in the leftmost
1955 node of a level: */
1956 dtuple_set_info_bitscxx . . $ dtuple_set_info_bits(5c57e6daa93fddc1).(node_ptr,
1957 dtuple_get_info_bitscxx . . $ dtuple_get_info_bits(b99d8fb98adb3238).(node_ptr)
1958 | REC_INFO_MIN_REC_FLAGcxx . . $ `storage/innobase/include/data0type.h:504:9`!);
1959
1960 /* Rebuild the root page to get free space */
1961 btr_page_emptycxx . . $ btr_page_empty(403ca5985fa24f33).(root, root_page_zip, index, level + 1, mtr);
1962 /* btr_page_empty() is supposed to zero-initialize the field. */
1963 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_get_instant(root->page.frame));
1964
1965 if (index->is_instantcxx . . $ dict_index_t#is_instant(50ce9a9e25b4a850).()) {
1966 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!root_page_zip);
1967 btr_set_instantcxx . . $ btr_set_instant(c781c825a451f33b).(root, *index, mtr);
1968 }
1969
1970 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(root->page.frame));
1971
1972 page_cursor = btr_cur_get_page_curcxx . . $ `storage/innobase/include/btr0cur.h:62:9`!(cursor);
1973
1974 /* Insert node pointer to the root */
1975
1976 page_cur_set_before_firstcxx . . $ page_cur_set_before_first(34f1922d808032bb).(root, page_cursor);
1977
1978 node_ptr_rec = page_cur_tuple_insertcxx . . $ page_cur_tuple_insert(20b71dd453d7ef65).(page_cursor, node_ptr,
1979 offsets, heap, 0, mtr);
1980
1981 /* The root page should only contain the node pointer
1982 to new_block at this point. Thus, the data should fit. */
1983 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(node_ptr_rec);
1984
1985 page_cursor->blockcxx . . $ page_cur_t#block. = new_block;
1986 page_cursor->indexcxx . . $ page_cur_t#index. = index;
1987
1988 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(dtuple_check_typed(tuple));
1989 /* Reposition the cursor to the child node */
1990 uint16_tcxx . . $ uint16_t# low_match = 0, up_match = 0;
1991
1992 if (page_cur_search_with_matchcxx . . $ page_cur_search_with_match(2a162131057c114d).(tuple, PAGE_CUR_LEcxx . . $ PAGE_CUR_LE.,
1993 &up_match, &low_match,
1994 page_cursor, nullptr)) {
1995 *err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
1996 return nullptr;
1997 }
1998
1999 /* Split the child and insert tuple */
2000 return btr_page_split_and_insertcxx . . $ btr_page_split_and_insert(705431d322c9a50a).(flags, cursor, offsets, heap,
2001 tuple, n_ext, mtr, err);
2002 }
2003
2004 /** Decide if the page should be split at the convergence point of inserts
2005 converging to the left.
2006 @param cursor insert position
2007 @return the first record to be moved to the right half page
2008 @retval nullptr if no split is recommended */
2009 rec_tcxx . . $ rec_t# *btr_page_get_split_rec_to_leftcxx . . $ btr_page_get_split_rec_to_left(15754bd857ff87f9).(const btr_cur_tcxx . . $ btr_cur_t# *cursor) noexcept
2010 {
2011 const rec_tcxx . . $ rec_t# *split_rec= btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor);
2012 const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *page= btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
2013 const rec_tcxx . . $ rec_t# *const last= page + page_header_get_offscxx . . $ page_header_get_offs(cbdda48327e67104).(page, PAGE_LAST_INSERTcxx . . $ `storage/innobase/include/page0page.h:57:9`!);
2014
2015 if (page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page))
2016 {
2017 if (last != page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, split_rec))
2018 return nullptr;
2019 /* The metadata record must be present in the leftmost leaf page
2020 of the clustered index, if and only if index->is_instant().
2021 However, during innobase_instant_try(), index->is_instant() would
2022 already hold when row_ins_clust_index_entry_low() is being invoked
2023 to insert the the metadata record. So, we can only assert that
2024 when the metadata record exists, index->is_instant() must hold. */
2025 const rec_tcxx . . $ rec_t# *const infimum= page + PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`!;
2026 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_is_leaf(page) || page_has_prev(page) ||
2027 cursor->index()->is_instant() ||
2028 !(rec_get_info_bits(page_rec_next_get<true>(page, infimum), true) &
2029 REC_INFO_MIN_REC_FLAG));
2030 /* If the convergence is in the middle of a page, include also the
2031 record immediately before the new insert to the upper page.
2032 Otherwise, we could repeatedly move from page to page lots of
2033 records smaller than the convergence point. */
2034 if (split_rec == infimum ||
2035 split_rec == page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, infimum))
2036 split_rec= page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, split_rec);
2037 }
2038 else
2039 {
2040 if (last != page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, split_rec))
2041 return nullptr;
2042 const rec_tcxx . . $ rec_t# *const infimum= page + PAGE_OLD_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:132:9`!;
2043 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_is_leaf(page) || page_has_prev(page) ||
2044 cursor->index()->is_instant() ||
2045 !(rec_get_info_bits(page_rec_next_get<false>(page, infimum), false) &
2046 REC_INFO_MIN_REC_FLAG));
2047 if (split_rec == infimum ||
2048 split_rec == page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, infimum))
2049 split_rec= page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, split_rec);
2050 }
2051
2052 return const_cast<rec_tcxx . . $ rec_t#*>(split_rec);
2053 }
2054
2055 /** Decide if the page should be split at the convergence point of inserts
2056 converging to the right.
2057 @param cursor insert position
2058 @param split_rec if split recommended, the first record on the right
2059 half page, or nullptr if the to-be-inserted record should be first
2060 @return whether split is recommended */
2061 bool
2062 btr_page_get_split_rec_to_rightcxx . . $ btr_page_get_split_rec_to_right(f07a715fb6186f94).(const btr_cur_tcxx . . $ btr_cur_t# *cursor, rec_tcxx . . $ rec_t# **split_rec)
2063 noexcept
2064 {
2065 const rec_tcxx . . $ rec_t# *insert_point= btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor);
2066 const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *page= btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
2067
2068 /* We use eager heuristics: if the new insert would be right after
2069 the previous insert on the same page, we assume that there is a
2070 pattern of sequential inserts here. */
2071 if (page + page_header_get_offscxx . . $ page_header_get_offs(cbdda48327e67104).(page, PAGE_LAST_INSERTcxx . . $ `storage/innobase/include/page0page.h:57:9`!) != insert_point)
2072 return false;
2073
2074 if (page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page))
2075 {
2076 const rec_tcxx . . $ rec_t# *const supremum= page + PAGE_NEW_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:144:9`!;
2077 insert_point= page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, insert_point);
2078 if (!insert_point);
2079 else if (insert_point == supremum)
2080 insert_point= nullptr;
2081 else
2082 {
2083 insert_point= page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<true>(page, insert_point);
2084 if (insert_point == supremum)
2085 insert_point= nullptr;
2086 /* If there are >= 2 user records up from the insert point,
2087 split all but 1 off. We want to keep one because then sequential
2088 inserts can do the necessary checks of the right search position
2089 just by looking at the records on this page. */
2090 }
2091 }
2092 else
2093 {
2094 const rec_tcxx . . $ rec_t# *const supremum= page + PAGE_OLD_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:135:9`!;
2095 insert_point= page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, insert_point);
2096 if (!insert_point);
2097 else if (insert_point == supremum)
2098 insert_point= nullptr;
2099 else
2100 {
2101 insert_point= page_rec_next_getcxx . . $ page_rec_next_get(f5cba2a7e3e0d594).<false>(page, insert_point);
2102 if (insert_point == supremum)
2103 insert_point= nullptr;
2104 }
2105 }
2106
2107 *split_rec= const_cast<rec_tcxx . . $ rec_t#*>(insert_point);
2108 return true;
2109 }
2110
2111 /*************************************************************//**
2112 Calculates a split record such that the tuple will certainly fit on
2113 its half-page when the split is performed. We assume in this function
2114 only that the cursor page has at least one user record.
2115 @return split record, or NULL if tuple will be the first record on
2116 the lower or upper half-page (determined by btr_page_tuple_smaller()) */
2117 static
2118 rec_tcxx . . $ rec_t#*
2119 btr_page_get_split_reccxx . . $ btr_page_get_split_rec(2234a0cda457d5f2).(
2120 /*===================*/
2121 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor at which insert should be made */
2122 const dtuple_tcxx . . $ dtuple_t#* tuple, /*!< in: tuple to insert */
2123 ulintcxx . . $ ulint# n_ext) /*!< in: number of externally stored columns */
2124 {
2125 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page;
2126 page_zip_des_tcxx . . $ page_zip_des_t#* page_zip;
2127 ulintcxx . . $ ulint# insert_size;
2128 ulintcxx . . $ ulint# free_space;
2129 ulintcxx . . $ ulint# total_data;
2130 ulintcxx . . $ ulint# total_n_recs;
2131 ulintcxx . . $ ulint# total_space;
2132 ulintcxx . . $ ulint# incl_data;
2133 rec_tcxx . . $ rec_t#* ins_rec;
2134 rec_tcxx . . $ rec_t#* rec;
2135 rec_tcxx . . $ rec_t#* next_rec;
2136 ulintcxx . . $ ulint# n;
2137 mem_heap_tcxx . . $ mem_heap_t#* heap;
2138 rec_offscxx . . $ rec_offs#* offsets;
2139
2140 page = btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
2141
2142 insert_size = rec_get_converted_sizecxx . . $ rec_get_converted_size(65a2a1c1835c6045).(cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), tuple, n_ext);
2143 free_space = page_get_free_space_of_emptycxx . . $ page_get_free_space_of_empty(ecdaa1632f49f591).(page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page));
2144
2145 page_zip = btr_cur_get_page_zipcxx . . $ btr_cur_get_page_zip(25879e64d517f276).(cursor);
2146 if (page_zip) {
2147 /* Estimate the free space of an empty compressed page. */
2148 ulintcxx . . $ ulint# free_space_zip = page_zip_empty_sizecxx . . $ page_zip_empty_size(80bad76eed2d2579).(
2149 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->n_fieldscxx . . $ dict_index_t#n_fields.,
2150 page_zip_get_sizecxx . . $ page_zip_get_size(a3b1d3a3537f7de).(page_zip));
2151
2152 if (free_space > (ulintcxx . . $ ulint#) free_space_zip) {
2153 free_space = (ulintcxx . . $ ulint#) free_space_zip;
2154 }
2155 }
2156
2157 /* free_space is now the free space of a created new page */
2158
2159 total_data = page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(page) + insert_size;
2160 total_n_recs = ulintcxx . . $ ulint#(page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(page)) + 1;
2161 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(total_n_recs >= 2);
2162 total_space = total_data + page_dir_calc_reserved_spacecxx . . $ page_dir_calc_reserved_space(ecdaa1632f49f591).(total_n_recs);
2163
2164 n = 0;
2165 incl_data = 0;
2166 ins_rec = btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor);
2167 rec = page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page);
2168
2169 heap = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2170 offsets = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2171
2172 /* We start to include records to the left half, and when the
2173 space reserved by them exceeds half of total_space, then if
2174 the included records fit on the left page, they will be put there
2175 if something was left over also for the right page,
2176 otherwise the last included record will be the first on the right
2177 half page */
2178
2179 do {
2180 /* Decide the next record to include */
2181 if (rec == ins_rec) {
2182 rec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; /* NULL denotes that tuple is
2183 now included */
2184 } else if (rec == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
2185 rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(ins_rec);
2186 } else {
2187 rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(rec);
2188 }
2189
2190 if (rec == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
2191 /* Include tuple */
2192 incl_data += insert_size;
2193 } else {
2194 offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(rec, cursor->index(),
2195 offsets, page_is_leaf(page)
2196 ? cursor->index()
2197 ->n_core_fields
2198 : 0,
2199 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
2200 incl_data += rec_offs_sizecxx . . $ rec_offs_size(6fce5c29061b60f9).(offsets);
2201 }
2202
2203 n++;
2204 } while (incl_data + page_dir_calc_reserved_spacecxx . . $ page_dir_calc_reserved_space(ecdaa1632f49f591).(n)
2205 < total_space / 2);
2206
2207 if (incl_data + page_dir_calc_reserved_spacecxx . . $ page_dir_calc_reserved_space(ecdaa1632f49f591).(n) <= free_space) {
2208 /* The next record will be the first on
2209 the right half page if it is not the
2210 supremum record of page */
2211
2212 if (rec == ins_rec) {
2213 rec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2214
2215 goto func_exit;
2216 } else if (rec == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
2217 next_rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(ins_rec);
2218 } else {
2219 next_rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(rec);
2220 }
2221 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(next_rec);
2222 if (!page_rec_is_supremumcxx . . $ page_rec_is_supremum(190063cf6fb4afb1).(next_rec)) {
2223 rec = next_rec;
2224 }
2225 }
2226
2227 func_exit:
2228 if (heap) {
2229 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
2230 }
2231 return(rec);
2232 }
2233
2234 #ifdef UNIV_DEBUG
2235 /*************************************************************//**
2236 Returns TRUE if the insert fits on the appropriate half-page with the
2237 chosen split_rec.
2238 @return true if fits */
2239 static MY_ATTRIBUTE((nonnull(1,3,4,6), warn_unused_result))
2240 bool
2241 btr_page_insert_fits(
2242 /*=================*/
2243 btr_cur_t* cursor, /*!< in: cursor at which insert
2244 should be made */
2245 const rec_t* split_rec,/*!< in: suggestion for first record
2246 on upper half-page, or NULL if
2247 tuple to be inserted should be first */
2248 rec_offs** offsets,/*!< in: rec_get_offsets(
2249 split_rec, cursor->index()); out: garbage */
2250 const dtuple_t* tuple, /*!< in: tuple to insert */
2251 ulint n_ext, /*!< in: number of externally stored columns */
2252 mem_heap_t** heap) /*!< in: temporary memory heap */
2253 {
2254 page_t* page;
2255 ulint insert_size;
2256 ulint free_space;
2257 ulint total_data;
2258 ulint total_n_recs;
2259 const rec_t* rec;
2260 const rec_t* end_rec;
2261
2262 page = btr_cur_get_page(cursor);
2263
2264 ut_ad(!split_rec
2265 || !page_is_comp(page) == !rec_offs_comp(*offsets));
2266 ut_ad(!split_rec
2267 || rec_offs_validate(split_rec, cursor->index(), *offsets));
2268
2269 insert_size = rec_get_converted_size(cursor->index(), tuple, n_ext);
2270 free_space = page_get_free_space_of_empty(page_is_comp(page));
2271
2272 /* free_space is now the free space of a created new page */
2273
2274 total_data = page_get_data_size(page) + insert_size;
2275 total_n_recs = ulint(page_get_n_recs(page)) + 1;
2276
2277 /* We determine which records (from rec to end_rec, not including
2278 end_rec) will end up on the other half page from tuple when it is
2279 inserted. */
2280
2281 if (!(end_rec = split_rec)) {
2282 end_rec = page_rec_get_next(btr_cur_get_rec(cursor));
2283 } else if (cmp_dtuple_rec(tuple, split_rec, cursor->index(),
2284 *offsets) < 0) {
2285 rec = split_rec;
2286 end_rec = page_get_supremum_rec(page);
2287 goto got_rec;
2288 }
2289
2290 if (!(rec = page_rec_get_next(page_get_infimum_rec(page)))) {
2291 return false;
2292 }
2293
2294 got_rec:
2295 if (total_data + page_dir_calc_reserved_space(total_n_recs)
2296 <= free_space) {
2297
2298 /* Ok, there will be enough available space on the
2299 half page where the tuple is inserted */
2300
2301 return(true);
2302 }
2303
2304 while (rec != end_rec) {
2305 /* In this loop we calculate the amount of reserved
2306 space after rec is removed from page. */
2307
2308 *offsets = rec_get_offsets(rec, cursor->index(), *offsets,
2309 page_is_leaf(page)
2310 ? cursor->index()->n_core_fields
2311 : 0,
2312 ULINT_UNDEFINED, heap);
2313
2314 total_data -= rec_offs_size(*offsets);
2315 total_n_recs--;
2316
2317 if (total_data + page_dir_calc_reserved_space(total_n_recs)
2318 <= free_space) {
2319
2320 /* Ok, there will be enough available space on the
2321 half page where the tuple is inserted */
2322
2323 return(true);
2324 }
2325
2326 if (!(rec = page_rec_get_next_const(rec))) {
2327 break;
2328 }
2329 }
2330
2331 return(false);
2332 }
2333 #endif
2334
2335 /*******************************************************//**
2336 Inserts a data tuple to a tree on a non-leaf level. It is assumed
2337 that mtr holds an x-latch on the tree. */
2338 dberr_tcxx . . $ dberr_t#
2339 btr_insert_on_non_leaf_levelcxx . . $ btr_insert_on_non_leaf_level(3adb5c2757e97672).(
2340 ulintcxx . . $ ulint# flags, /*!< in: undo logging and locking flags */
2341 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
2342 ulintcxx . . $ ulint# level, /*!< in: level, must be > 0 */
2343 dtuple_tcxx . . $ dtuple_t#* tuple, /*!< in: the record to be inserted */
2344 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
2345 {
2346 big_rec_tcxx . . $ big_rec_t#* dummy_big_rec;
2347 btr_cur_tcxx . . $ btr_cur_t# cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
2348 rec_tcxx . . $ rec_t#* rec;
2349 mem_heap_tcxx . . $ mem_heap_t#* heap = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2350 rec_offscxx . . $ rec_offs# offsets_[REC_OFFS_NORMAL_SIZEcxx . . $ REC_OFFS_NORMAL_SIZE.];
2351 rec_offscxx . . $ rec_offs#* offsets = offsets_;
2352 rec_offs_initcxx . . $ `storage/innobase/include/rem0rec.h:844:9`!(offsets_);
2353 rtr_info_tcxx . . $ rtr_info_t# rtr_info;
2354
2355 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(level > 0);
2356
2357 flags |= BTR_NO_LOCKING_FLAGcxx . . $ BTR_NO_LOCKING_FLAG. | BTR_KEEP_SYS_FLAGcxx . . $ BTR_KEEP_SYS_FLAG.
2358 | BTR_NO_UNDO_LOG_FLAGcxx . . $ BTR_NO_UNDO_LOG_FLAG.;
2359 cursor.page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index;
2360
2361 dberr_tcxx . . $ dberr_t# err;
2362
2363 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
2364 /* For spatial index, initialize structures to track
2365 its parents etc. */
2366 rtr_init_rtr_infocxx . . $ rtr_init_rtr_info(8b8a56c3073d5c77).(&rtr_info, false, &cursor, index, false);
2367
2368 rtr_info_update_btrcxx . . $ rtr_info_update_btr(c964833cb5753363).(&cursor, &rtr_info);
2369 err = rtr_search_to_nth_levelcxx . . $ rtr_search_to_nth_level(3ce8038bbdc9ae12).(&cursor, nullptr, tuple,
2370 BTR_CONT_MODIFY_TREEcxx . . $ BTR_CONT_MODIFY_TREE., mtr,
2371 PAGE_CUR_RTREE_INSERTcxx . . $ PAGE_CUR_RTREE_INSERT., level);
2372 } else {
2373 err = btr_cur_search_to_nth_levelcxx . . $ btr_cur_search_to_nth_level(59eb7917f67212e).(level, tuple, RW_X_LATCHcxx . . $ RW_X_LATCH.,
2374 &cursor, mtr);
2375 }
2376
2377 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor.flag == BTR_CUR_BINARY);
2378 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_cur_get_block(&cursor)
2379 != mtr->at_savepoint(mtr->get_savepoint() - 1)
2380 || index->is_spatial()
2381 || mtr->memo_contains(index->lock, MTR_MEMO_X_LOCK));
2382
2383 if (UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(err == DB_SUCCESS)) {
2384 err = btr_cur_optimistic_insertcxx . . $ btr_cur_optimistic_insert(608ae1f6b838559e).(flags,
2385 &cursor, &offsets, &heap,
2386 tuple, &rec,
2387 &dummy_big_rec, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, mtr);
2388 }
2389
2390 if (err == DB_FAILcxx . . $ DB_FAIL.) {
2391 err = btr_cur_pessimistic_insertcxx . . $ btr_cur_pessimistic_insert(608ae1f6b838559e).(flags,
2392 &cursor, &offsets, &heap,
2393 tuple, &rec,
2394 &dummy_big_rec, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, mtr);
2395 }
2396
2397 if (UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(heap)) {
2398 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
2399 }
2400
2401 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
2402 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor.rtr_info);
2403
2404 rtr_clean_rtr_infocxx . . $ rtr_clean_rtr_info(297f4d0a6e845a99).(&rtr_info, true);
2405 }
2406
2407 return err;
2408 }
2409
2410 static_assert(FIL_PAGE_OFFSETcxx . . $ `storage/innobase/include/fil0fil.h:1195:9`! % 4 == 0, "alignment");
2411 static_assert(FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`! % 4 == 0, "alignment");
2412 static_assert(FIL_PAGE_NEXTcxx . . $ `storage/innobase/include/fil0fil.h:1203:9`! % 4 == 0, "alignment");
2413
2414 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull,warn_unused_result))
2415 /**************************************************************//**
2416 Attaches the halves of an index page on the appropriate level in an
2417 index tree. */
2418 static
2419 dberr_tcxx . . $ dberr_t#
2420 btr_attach_half_pagescxx . . $ btr_attach_half_pages(93bef5c7986f0682).(
2421 /*==================*/
2422 ulintcxx . . $ ulint# flags, /*!< in: undo logging and
2423 locking flags */
2424 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: the index tree */
2425 buf_block_tcxx . . $ buf_block_t#* block, /*!< in/out: page to be split */
2426 const rec_tcxx . . $ rec_t#* split_rec, /*!< in: first record on upper
2427 half page */
2428 buf_block_tcxx . . $ buf_block_t#* new_block, /*!< in/out: the new half page */
2429 ulintcxx . . $ ulint# direction, /*!< in: FSP_UP or FSP_DOWN */
2430 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
2431 {
2432 dtuple_tcxx . . $ dtuple_t#* node_ptr_upper;
2433 mem_heap_tcxx . . $ mem_heap_t#* heap;
2434 buf_block_tcxx . . $ buf_block_t#* prev_block = nullptr;
2435 buf_block_tcxx . . $ buf_block_t#* next_block = nullptr;
2436 buf_block_tcxx . . $ buf_block_t#* lower_block;
2437 buf_block_tcxx . . $ buf_block_t#* upper_block;
2438
2439 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
2440 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(new_block, MTR_MEMO_PAGE_X_FIX));
2441
2442 /* Create a memory heap where the data tuple is stored */
2443 heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(1024);
2444
2445 /* Based on split direction, decide upper and lower pages */
2446 if (direction == FSP_DOWNcxx . . $ `storage/innobase/include/fsp0types.h:54:9`!) {
2447
2448 btr_cur_tcxx . . $ btr_cur_t# cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
2449 rec_offscxx . . $ rec_offs#* offsets;
2450
2451 lower_block = new_block;
2452 upper_block = block;
2453
2454 cursor.page_curcxx . . $ btr_cur_t#page_cur..blockcxx . . $ page_cur_t#block. = block;
2455 cursor.page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index;
2456
2457 /* Look up the index for the node pointer to page */
2458 offsets = btr_page_get_father_blockcxx . . $ btr_page_get_father_block(931ebee81e95307a).(nullptr, heap, mtr,
2459 &cursor);
2460
2461 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!offsets)) {
2462 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
2463 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
2464 }
2465
2466 /* Replace the address of the old child node (= page) with the
2467 address of the new lower half */
2468
2469 btr_node_ptr_set_child_page_nocxx . . $ btr_node_ptr_set_child_page_no(74c562001a057f5).(
2470 btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&cursor),
2471 btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&cursor),
2472 offsets, lower_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(), mtr);
2473 mem_heap_emptycxx . . $ mem_heap_empty(5231cf397463bfab).(heap);
2474 } else {
2475 lower_block = block;
2476 upper_block = new_block;
2477 }
2478
2479 /* Get the level of the split pages */
2480 const ulintcxx . . $ ulint# level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
2481 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(level == btr_page_get_level(new_block->page.frame));
2482 page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
2483
2484 /* Get the previous and next pages of page */
2485 const uint32_tcxx . . $ uint32_t# prev_page_no = btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
2486 const uint32_tcxx . . $ uint32_t# next_page_no = btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
2487
2488 /* for consistency, both blocks should be locked, before change */
2489 if (prev_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`! && direction == FSP_DOWNcxx . . $ `storage/innobase/include/fsp0types.h:54:9`!) {
2490 id.set_page_nocxx . . $ page_id_t#set_page_no(6bab9b75950d6f3).(prev_page_no);
2491 prev_block = mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(id, MTR_MEMO_PAGE_X_FIXcxx . . $ MTR_MEMO_PAGE_X_FIX.);
2492 #if 1 /* MDEV-29835 FIXME: acquire page latches upfront */
2493 if (!prev_block) {
2494 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains(index->lock,
2495 MTR_MEMO_X_LOCK));
2496 prev_block = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*index, prev_page_no,
2497 RW_X_LATCHcxx . . $ RW_X_LATCH., mtr);
2498 }
2499 #endif
2500 }
2501 if (next_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`! && direction != FSP_DOWNcxx . . $ `storage/innobase/include/fsp0types.h:54:9`!) {
2502 id.set_page_nocxx . . $ page_id_t#set_page_no(6bab9b75950d6f3).(next_page_no);
2503 next_block = mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(id, MTR_MEMO_PAGE_X_FIXcxx . . $ MTR_MEMO_PAGE_X_FIX.);
2504 #if 1 /* MDEV-29835 FIXME: acquire page latches upfront */
2505 if (!next_block) {
2506 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains(index->lock,
2507 MTR_MEMO_X_LOCK));
2508 next_block = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*index, next_page_no,
2509 RW_X_LATCHcxx . . $ RW_X_LATCH., mtr);
2510 }
2511 #endif
2512 }
2513
2514 /* Build the node pointer (= node key and page address) for the upper
2515 half */
2516
2517 node_ptr_upper = dict_index_build_node_ptrcxx . . $ dict_index_build_node_ptr(21b5a4827c82add7).(
2518 index, split_rec, upper_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(),
2519 heap, level);
2520
2521 /* Insert it next to the pointer to the lower half. Note that this
2522 may generate recursion leading to a split on the higher level. */
2523
2524 dberr_tcxx . . $ dberr_t# err = btr_insert_on_non_leaf_levelcxx . . $ btr_insert_on_non_leaf_level(3adb5c2757e97672).(
2525 flags, index, level + 1, node_ptr_upper, mtr);
2526
2527 /* Free the memory heap */
2528 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
2529
2530 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(err != DB_SUCCESS)) {
2531 return err;
2532 }
2533
2534 /* Update page links of the level */
2535
2536 if (prev_block) {
2537 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(memcmp_aligned<4>(prev_block->page.frame
2538 + FIL_PAGE_NEXTcxx . . $ `storage/innobase/include/fil0fil.h:1203:9`!,
2539 block->page.frame
2540 + FIL_PAGE_OFFSETcxx . . $ `storage/innobase/include/fil0fil.h:1195:9`!,
2541 4))) {
2542 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
2543 }
2544 btr_page_set_nextcxx . . $ btr_page_set_next(3cf5e6fa100ccb2d).(prev_block, lower_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(),
2545 mtr);
2546 }
2547
2548 if (next_block) {
2549 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(memcmp_aligned<4>(next_block->page.frame
2550 + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!,
2551 block->page.frame
2552 + FIL_PAGE_OFFSETcxx . . $ `storage/innobase/include/fil0fil.h:1195:9`!,
2553 4))) {
2554 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
2555 }
2556 btr_page_set_prevcxx . . $ btr_page_set_prev(3cf5e6fa100ccb2d).(next_block, upper_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(),
2557 mtr);
2558 }
2559
2560 if (direction == FSP_DOWNcxx . . $ `storage/innobase/include/fsp0types.h:54:9`!) {
2561 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lower_block == new_block);
2562 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_page_get_next(upper_block->page.frame)
2563 == next_page_no);
2564 btr_page_set_prevcxx . . $ btr_page_set_prev(3cf5e6fa100ccb2d).(lower_block, prev_page_no, mtr);
2565 } else {
2566 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(upper_block == new_block);
2567 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_page_get_prev(lower_block->page.frame)
2568 == prev_page_no);
2569 btr_page_set_nextcxx . . $ btr_page_set_next(3cf5e6fa100ccb2d).(upper_block, next_page_no, mtr);
2570 }
2571
2572 btr_page_set_prevcxx . . $ btr_page_set_prev(3cf5e6fa100ccb2d).(upper_block, lower_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(), mtr);
2573 btr_page_set_nextcxx . . $ btr_page_set_next(3cf5e6fa100ccb2d).(lower_block, upper_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(), mtr);
2574
2575 return DB_SUCCESScxx . . $ DB_SUCCESS.;
2576 }
2577
2578 /*************************************************************//**
2579 Determine if a tuple is smaller than any record on the page.
2580 @return TRUE if smaller */
2581 static MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull, warn_unused_result))
2582 bool
2583 btr_page_tuple_smallercxx . . $ btr_page_tuple_smaller(80ecf9b349e94119).(
2584 /*===================*/
2585 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: b-tree cursor */
2586 const dtuple_tcxx . . $ dtuple_t#* tuple, /*!< in: tuple to consider */
2587 rec_offscxx . . $ rec_offs#** offsets,/*!< in/out: temporary storage */
2588 ulintcxx . . $ ulint# n_uniq, /*!< in: number of unique fields
2589 in the index page records */
2590 mem_heap_tcxx . . $ mem_heap_t#** heap) /*!< in/out: heap for offsets */
2591 {
2592 buf_block_tcxx . . $ buf_block_t#* block;
2593 const rec_tcxx . . $ rec_t#* first_rec;
2594 page_cur_tcxx . . $ page_cur_t# pcur;
2595
2596 /* Read the first user record in the page. */
2597 block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor);
2598 page_cur_set_before_firstcxx . . $ page_cur_set_before_first(34f1922d808032bb).(block, &pcur);
2599 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!(first_rec = page_cur_move_to_next(&pcur)))) {
2600 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!("corrupted page" == 0);
2601 return false;
2602 }
2603
2604 *offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(first_rec, cursor->index(), *offsets,
2605 page_is_leaf(block->page.frame)
2606 ? cursor->index()->n_core_fields : 0,
2607 n_uniq, heap);
2608
2609 return cmp_dtuple_reccxx . . $ cmp_dtuple_rec(fc19edad24dfa402).(tuple, first_rec, cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), *offsets) < 0;
2610 }
2611
2612 /** Insert the tuple into the right sibling page, if the cursor is at the end
2613 of a page.
2614 @param[in] flags undo logging and locking flags
2615 @param[in,out] cursor cursor at which to insert; when the function succeeds,
2616 the cursor is positioned before the insert point.
2617 @param[out] offsets offsets on inserted record
2618 @param[in,out] heap memory heap for allocating offsets
2619 @param[in] tuple tuple to insert
2620 @param[in] n_ext number of externally stored columns
2621 @param[in,out] mtr mini-transaction
2622 @return inserted record (first record on the right sibling page);
2623 the cursor will be positioned on the page infimum
2624 @retval NULL if the operation was not performed */
2625 static
2626 rec_tcxx . . $ rec_t#*
2627 btr_insert_into_right_siblingcxx . . $ btr_insert_into_right_sibling(b3626e1bbaba8d22).(
2628 ulintcxx . . $ ulint# flags,
2629 btr_cur_tcxx . . $ btr_cur_t#* cursor,
2630 rec_offscxx . . $ rec_offs#** offsets,
2631 mem_heap_tcxx . . $ mem_heap_t#* heap,
2632 const dtuple_tcxx . . $ dtuple_t#* tuple,
2633 ulintcxx . . $ ulint# n_ext,
2634 mtr_tcxx . . $ mtr_t#* mtr)
2635 {
2636 buf_block_tcxx . . $ buf_block_t#* block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor);
2637 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
2638 const uint32_tcxx . . $ uint32_t# next_page_no = btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(page);
2639
2640 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&cursor->index()->lock,
2641 MTR_MEMO_X_LOCK | MTR_MEMO_SX_LOCK));
2642 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
2643 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(heap);
2644 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(dtuple_check_typed(tuple));
2645
2646 if (next_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`! || !page_rec_is_supremumcxx . . $ page_rec_is_supremum(190063cf6fb4afb1).(
2647 page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor)))) {
2648
2649 return nullptr;
2650 }
2651
2652 page_cur_tcxx . . $ page_cur_t# next_page_cursor;
2653 buf_block_tcxx . . $ buf_block_t#* next_block;
2654 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* next_page;
2655 btr_cur_tcxx . . $ btr_cur_t# next_father_cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
2656 rec_tcxx . . $ rec_t#* rec = nullptr;
2657
2658 next_block = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), next_page_no, RW_X_LATCHcxx . . $ RW_X_LATCH.,
2659 mtr);
2660 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!next_block)) {
2661 return nullptr;
2662 }
2663 next_page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(next_block);
2664 const bool is_leaf = page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(next_page);
2665
2666 next_page_cursor.indexcxx . . $ page_cur_t#index. = cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).();
2667 next_page_cursor.blockcxx . . $ page_cur_t#block. = next_block;
2668 next_father_cursor.page_curcxx . . $ btr_cur_t#page_cur. =cxx . . $ page_cur_t#`operator=`(396f7cf79b87c113). next_page_cursor;
2669
2670 if (!btr_page_get_fathercxx . . $ btr_page_get_father(ef799a93ae7a666b).(mtr, &next_father_cursor)) {
2671 return nullptr;
2672 }
2673
2674 uint16_tcxx . . $ uint16_t# up_match = 0, low_match = 0;
2675
2676 if (page_cur_search_with_matchcxx . . $ page_cur_search_with_match(2a162131057c114d).(tuple,
2677 PAGE_CUR_LEcxx . . $ PAGE_CUR_LE., &up_match, &low_match,
2678 &next_page_cursor, nullptr)) {
2679 return nullptr;
2680 }
2681
2682 /* Extends gap lock for the next page */
2683 if (is_leaf && cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
2684 lock_update_node_pointercxx . . $ lock_update_node_pointer(71e7023f76cd449a).(block, next_block);
2685 }
2686
2687 rec = page_cur_tuple_insertcxx . . $ page_cur_tuple_insert(20b71dd453d7ef65).(&next_page_cursor, tuple, offsets, &heap,
2688 n_ext, mtr);
2689
2690 if (!rec) {
2691 return nullptr;
2692 }
2693
2694 iboolcxx . . $ `storage/innobase/include/univ.i:355:9`! compressed;
2695 dberr_tcxx . . $ dberr_t# err;
2696 ulintcxx . . $ ulint# level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(next_page);
2697
2698 /* adjust cursor position */
2699 *btr_cur_get_page_curcxx . . $ `storage/innobase/include/btr0cur.h:62:9`!(cursor) =cxx . . $ page_cur_t#`operator=`(396f7cf79b87c113). next_page_cursor;
2700
2701 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_cur_get_rec(cursor) == page_get_infimum_rec(next_page));
2702 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_rec_get_next(page_get_infimum_rec(next_page)) == rec);
2703
2704 /* We have to change the parent node pointer */
2705
2706 compressed = btr_cur_pessimistic_deletecxx . . $ btr_cur_pessimistic_delete(8e234601f90ce98f).(
2707 &err, TRUEcxx . . $ `include/my_global.h:476:9`!, &next_father_cursor,
2708 BTR_CREATE_FLAGcxx . . $ BTR_CREATE_FLAG., false, mtr);
2709
2710 if (err != DB_SUCCESScxx . . $ DB_SUCCESS.) {
2711 return nullptr;
2712 }
2713
2714 if (!compressed) {
2715 btr_cur_compress_if_usefulcxx . . $ btr_cur_compress_if_useful(c0ed7dbe459c1b6c).(&next_father_cursor, false, mtr);
2716 }
2717
2718 dtuple_tcxx . . $ dtuple_t#* node_ptr = dict_index_build_node_ptrcxx . . $ dict_index_build_node_ptr(21b5a4827c82add7).(
2719 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), rec, next_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(),
2720 heap, level);
2721
2722 if (btr_insert_on_non_leaf_levelcxx . . $ btr_insert_on_non_leaf_level(3adb5c2757e97672).(flags, cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), level + 1,
2723 node_ptr, mtr) != DB_SUCCESScxx . . $ DB_SUCCESS.) {
2724 return nullptr;
2725 }
2726
2727 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_offs_validate(rec, cursor->index(), *offsets));
2728 return(rec);
2729 }
2730
2731 /*************************************************************//**
2732 Moves record list end to another page. Moved records include
2733 split_rec.
2734 @return error code */
2735 static
2736 dberr_tcxx . . $ dberr_t#
2737 page_move_rec_list_endcxx . . $ page_move_rec_list_end(86dac29eba89661f).(
2738 /*===================*/
2739 buf_block_tcxx . . $ buf_block_t#* new_block, /*!< in/out: index page where to move */
2740 buf_block_tcxx . . $ buf_block_t#* block, /*!< in: index page from where to move */
2741 rec_tcxx . . $ rec_t#* split_rec, /*!< in: first record to move */
2742 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: record descriptor */
2743 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
2744 {
2745 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* new_page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(new_block);
2746 ulintcxx . . $ ulint# old_data_size;
2747 ulintcxx . . $ ulint# new_data_size;
2748 ulintcxx . . $ ulint# old_n_recs;
2749 ulintcxx . . $ ulint# new_n_recs;
2750
2751 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_spatial(index));
2752
2753 old_data_size = page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(new_page);
2754 old_n_recs = page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(new_page);
2755 #ifdef UNIV_ZIP_DEBUG
2756 {
2757 page_zip_des_t* new_page_zip
2758 = buf_block_get_page_zip(new_block);
2759 page_zip_des_t* page_zip
2760 = buf_block_get_page_zip(block);
2761 ut_a(!new_page_zip == !page_zip);
2762 ut_a(!new_page_zip
2763 || page_zip_validate(new_page_zip, new_page, index));
2764 ut_a(!page_zip
2765 || page_zip_validate(page_zip, page_align(split_rec),
2766 index));
2767 }
2768 #endif /* UNIV_ZIP_DEBUG */
2769
2770 dberr_tcxx . . $ dberr_t# err;
2771 if (!page_copy_rec_list_endcxx . . $ page_copy_rec_list_end(49a7688bb655da1e).(new_block, block,
2772 split_rec, index, mtr, &err)) {
2773 return err;
2774 }
2775
2776 new_data_size = page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(new_page);
2777 new_n_recs = page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(new_page);
2778
2779 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(new_data_size >= old_data_size);
2780
2781 return page_delete_rec_list_endcxx . . $ page_delete_rec_list_end(18251f5e7b9c159).(split_rec, block, index,
2782 new_n_recs - old_n_recs,
2783 new_data_size - old_data_size, mtr);
2784 }
2785
2786 /*************************************************************//**
2787 Moves record list start to another page. Moved records do not include
2788 split_rec.
2789 @return error code */
2790 static
2791 dberr_tcxx . . $ dberr_t#
2792 page_move_rec_list_startcxx . . $ page_move_rec_list_start(86dac29eba89661f).(
2793 /*=====================*/
2794 buf_block_tcxx . . $ buf_block_t#* new_block, /*!< in/out: index page where to move */
2795 buf_block_tcxx . . $ buf_block_t#* block, /*!< in/out: page containing split_rec */
2796 rec_tcxx . . $ rec_t#* split_rec, /*!< in: first record not to move */
2797 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: record descriptor */
2798 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
2799 {
2800 dberr_tcxx . . $ dberr_t# err;
2801 if (page_copy_rec_list_startcxx . . $ page_copy_rec_list_start(49a7688bb655da1e).(new_block, block, split_rec, index, mtr, &err))
2802 page_delete_rec_list_startcxx . . $ page_delete_rec_list_start(b15c09829b9b4138).(split_rec, block, index, mtr);
2803 return err;
2804 }
2805
2806 /*************************************************************//**
2807 Splits an index page to halves and inserts the tuple. It is assumed
2808 that mtr holds an x-latch to the index tree. NOTE: the tree x-latch is
2809 released within this function! NOTE that the operation of this
2810 function must always succeed, we cannot reverse it: therefore enough
2811 free disk space (2 pages) must be guaranteed to be available before
2812 this function is called.
2813 @return inserted record or NULL if run out of space */
2814 rec_tcxx . . $ rec_t#*
2815 btr_page_split_and_insertcxx . . $ btr_page_split_and_insert(705431d322c9a50a).(
2816 /*======================*/
2817 ulintcxx . . $ ulint# flags, /*!< in: undo logging and locking flags */
2818 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor at which to insert; when the
2819 function returns, the cursor is positioned
2820 on the predecessor of the inserted record */
2821 rec_offscxx . . $ rec_offs#** offsets,/*!< out: offsets on inserted record */
2822 mem_heap_tcxx . . $ mem_heap_t#** heap, /*!< in/out: pointer to memory heap, or NULL */
2823 const dtuple_tcxx . . $ dtuple_t#* tuple, /*!< in: tuple to insert */
2824 ulintcxx . . $ ulint# n_ext, /*!< in: number of externally stored columns */
2825 mtr_tcxx . . $ mtr_t#* mtr, /*!< in: mtr */
2826 dberr_tcxx . . $ dberr_t#* err) /*!< out: error code */
2827 {
2828 buf_block_tcxx . . $ buf_block_t#* block;
2829 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page;
2830 page_zip_des_tcxx . . $ page_zip_des_t#* page_zip;
2831 buf_block_tcxx . . $ buf_block_t#* new_block;
2832 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* new_page;
2833 page_zip_des_tcxx . . $ page_zip_des_t#* new_page_zip;
2834 rec_tcxx . . $ rec_t#* split_rec;
2835 buf_block_tcxx . . $ buf_block_t#* left_block;
2836 buf_block_tcxx . . $ buf_block_t#* right_block;
2837 page_cur_tcxx . . $ page_cur_t#* page_cursor;
2838 rec_tcxx . . $ rec_t#* first_rec;
2839 bytecxx . . $ byte#* buf = 0; /* remove warning */
2840 rec_tcxx . . $ rec_t#* move_limit;
2841 ulintcxx . . $ ulint# n_iterations = 0;
2842 ulintcxx . . $ ulint# n_uniq;
2843
2844 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(*err == DB_SUCCESS);
2845 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(dtuple_check_typed(tuple));
2846 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!cursor->index()->is_spatial());
2847
2848 buf_poolcxx . . $ buf_pool..pages_splitcxx . . $ buf_pool_t#pages_split.++cxx . . $ Atomic_counter#operator++(767fea59dce4185d).;
2849
2850 if (!*heap) {
2851 *heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(1024);
2852 }
2853 n_uniq = dict_index_get_n_unique_in_treecxx . . $ dict_index_get_n_unique_in_tree(40995254b96f8651).(cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).());
2854 func_start:
2855 mem_heap_emptycxx . . $ mem_heap_empty(5231cf397463bfab).(*heap);
2856 *offsets = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2857
2858 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&cursor->index()->lock,
2859 MTR_MEMO_X_LOCK
2860 | MTR_MEMO_SX_LOCK));
2861 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_online_ddl(cursor->index())
2862 || (flags & BTR_CREATE_FLAG)
2863 || dict_index_is_clust(cursor->index()));
2864 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->index()->lock.have_u_or_x());
2865
2866 block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor);
2867 page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
2868 page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block);
2869
2870 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
2871 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_is_empty(page));
2872
2873 /* try to insert to the next page if possible before split */
2874 if (rec_tcxx . . $ rec_t#* rec = btr_insert_into_right_siblingcxx . . $ btr_insert_into_right_sibling(b3626e1bbaba8d22).(
2875 flags, cursor, offsets, *heap, tuple, n_ext, mtr)) {
2876 return(rec);
2877 }
2878
2879 /* 1. Decide the split record; split_rec == NULL means that the
2880 tuple to be inserted should be the first record on the upper
2881 half-page */
2882 bool insert_left = false;
2883 uint32_tcxx . . $ uint32_t# hint_page_no = block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() + 1;
2884 bytecxx . . $ byte# direction = FSP_UPcxx . . $ `storage/innobase/include/fsp0types.h:53:9`!;
2885
2886 if (n_iterations > 0) {
2887 split_rec = btr_page_get_split_reccxx . . $ btr_page_get_split_rec(2234a0cda457d5f2).(cursor, tuple, n_ext);
2888
2889 if (split_rec == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
2890 insert_left = btr_page_tuple_smallercxx . . $ btr_page_tuple_smaller(80ecf9b349e94119).(
2891 cursor, tuple, offsets, n_uniq, heap);
2892 }
2893 } else if (btr_page_get_split_rec_to_rightcxx . . $ btr_page_get_split_rec_to_right(f07a715fb6186f94).(cursor, &split_rec)) {
2894 } else if ((split_rec = btr_page_get_split_rec_to_leftcxx . . $ btr_page_get_split_rec_to_left(15754bd857ff87f9).(cursor))) {
2895 direction = FSP_DOWNcxx . . $ `storage/innobase/include/fsp0types.h:54:9`!;
2896 hint_page_no -= 2;
2897 } else {
2898 /* If there is only one record in the index page, we
2899 can't split the node in the middle by default. We need
2900 to determine whether the new record will be inserted
2901 to the left or right. */
2902
2903 if (page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(page) > 1) {
2904 split_rec = page_get_middle_reccxx . . $ page_get_middle_rec(adcd832f8377c3d8).(page);
2905 } else if (btr_page_tuple_smallercxx . . $ btr_page_tuple_smaller(80ecf9b349e94119).(cursor, tuple,
2906 offsets, n_uniq, heap)) {
2907 split_rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(
2908 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page));
2909 } else {
2910 split_rec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2911 goto got_split_rec;
2912 }
2913
2914 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!split_rec)) {
2915 *err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
2916 return nullptr;
2917 }
2918 }
2919
2920 got_split_rec:
2921 /* 2. Allocate a new page to the index */
2922 const uint16_tcxx . . $ uint16_t# page_level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(page);
2923 new_block = btr_page_alloccxx . . $ btr_page_alloc(97e5958ce206bff9).(cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), hint_page_no, direction,
2924 page_level, mtr, mtr, err);
2925
2926 if (!new_block) {
2927 return nullptr;
2928 }
2929
2930 new_page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(new_block);
2931 new_page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(new_block);
2932
2933 if (page_level && UNIV_LIKELY_NULLcxx . . $ `storage/innobase/include/univ.i:393:10`!(new_page_zip)) {
2934 /* ROW_FORMAT=COMPRESSED non-leaf pages are not expected
2935 to contain FIL_NULL in FIL_PAGE_PREV at this stage. */
2936 memset_alignedcxx . . $ memset_aligned(d1de1e4fb215f1c6).<4>(new_page + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!, 0, 4);
2937 }
2938 btr_page_createcxx . . $ btr_page_create(403ca5985fa24f33).(new_block, new_page_zip, cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(),
2939 page_level, mtr);
2940
2941 /* 3. Calculate the first record on the upper half-page, and the
2942 first record (move_limit) on original page which ends up on the
2943 upper half */
2944
2945 if (split_rec) {
2946 first_rec = move_limit = split_rec;
2947
2948 *offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(split_rec, cursor->index(),
2949 *offsets, page_is_leaf(page)
2950 ? cursor->index()->n_core_fields
2951 : 0,
2952 n_uniq, heap);
2953
2954 insert_left = cmp_dtuple_reccxx . . $ cmp_dtuple_rec(fc19edad24dfa402).(tuple, split_rec, cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(),
2955 *offsets) < 0;
2956
2957 if (!insert_left && new_page_zip && n_iterations > 0) {
2958 /* If a compressed page has already been split,
2959 avoid further splits by inserting the record
2960 to an empty page. */
2961 split_rec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
2962 goto insert_empty;
2963 }
2964 } else if (insert_left) {
2965 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!n_iterations)) {
2966 corrupted:
2967 *err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
2968 return nullptr;
2969 }
2970 first_rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page));
2971 insert_move_limit:
2972 move_limit = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor));
2973 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!first_rec || !move_limit)) {
2974 goto corrupted;
2975 }
2976 } else {
2977 insert_empty:
2978 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!split_rec);
2979 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!insert_left);
2980 buf = UT_NEW_ARRAY_NOKEYcxx . . $ `storage/innobase/include/ut0new.h:995:9`!(
2981 byte,
2982 rec_get_converted_size(cursor->index(), tuple, n_ext));
2983
2984 first_rec = rec_convert_dtuple_to_reccxx . . $ rec_convert_dtuple_to_rec(7973e28c2e6dff74).(buf, cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(),
2985 tuple, n_ext);
2986 goto insert_move_limit;
2987 }
2988
2989 /* 4. Do first the modifications in the tree structure */
2990
2991 /* FIXME: write FIL_PAGE_PREV,FIL_PAGE_NEXT in new_block earlier! */
2992 *err = btr_attach_half_pagescxx . . $ btr_attach_half_pages(93bef5c7986f0682).(flags, cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), block,
2993 first_rec, new_block, direction, mtr);
2994
2995 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(*err != DB_SUCCESS)) {
2996 return nullptr;
2997 }
2998
2999 #ifdef UNIV_DEBUG
3000 /* If the split is made on the leaf level and the insert will fit
3001 on the appropriate half-page, we may release the tree x-latch.
3002 We can then move the records after releasing the tree latch,
3003 thus reducing the tree latch contention. */
3004 const bool insert_will_fit = !new_page_zip
3005 && btr_page_insert_fits(cursor, split_rec, offsets, tuple,
3006 n_ext, heap);
3007 #endif
3008 if (!split_rec && !insert_left) {
3009 UT_DELETE_ARRAYcxx . . $ `storage/innobase/include/ut0new.h:1002:9`!(buf);
3010 buf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
3011 }
3012
3013 #if 0 // FIXME: this used to be a no-op, and may cause trouble if enabled
3014 if (insert_will_fit
3015 && page_is_leaf(page)
3016 && !dict_index_is_online_ddl(cursor->index())) {
3017 mtr->release(cursor->index()->lock);
3018 /* NOTE: We cannot release root block latch here, because it
3019 has segment header and already modified in most of cases.*/
3020 }
3021 #endif
3022
3023 /* 5. Move then the records to the new page */
3024 if (direction == FSP_DOWNcxx . . $ `storage/innobase/include/fsp0types.h:54:9`!) {
3025 /* fputs("Split left\n", stderr); */
3026
3027 if (0
3028 #ifdef UNIV_ZIP_COPY
3029 || page_zip
3030 #endif /* UNIV_ZIP_COPY */
3031 || (*err = page_move_rec_list_startcxx . . $ page_move_rec_list_start(86dac29eba89661f).(new_block, block,
3032 move_limit,
3033 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(),
3034 mtr))) {
3035 if (*err != DB_FAILcxx . . $ DB_FAIL.) {
3036 return nullptr;
3037 }
3038
3039 /* For some reason, compressing new_block failed,
3040 even though it should contain fewer records than
3041 the original page. Copy the page byte for byte
3042 and then delete the records from both pages
3043 as appropriate. Deleting will always succeed. */
3044 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(new_page_zip);
3045
3046 page_zip_copy_recscxx . . $ page_zip_copy_recs(10c35386c1dea7d4).(new_block, page_zip, page,
3047 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), mtr);
3048 *err = page_delete_rec_list_endcxx . . $ page_delete_rec_list_end(18251f5e7b9c159).(move_limit
3049 - page + new_page,
3050 new_block,
3051 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(),
3052 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!,
3053 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, mtr);
3054 if (*err != DB_SUCCESScxx . . $ DB_SUCCESS.) {
3055 return nullptr;
3056 }
3057
3058 /* Update the lock table and possible hash index. */
3059 if (cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3060 lock_move_rec_list_startcxx . . $ lock_move_rec_list_start(8e975caca418fd03).(
3061 new_block, block, move_limit,
3062 new_page + PAGE_NEW_INFIMUMcxx . . $ `storage/innobase/include/page0page.h:141:9`!);
3063 }
3064
3065 btr_search_move_or_delete_hash_entriescxx . . $ btr_search_move_or_delete_hash_entries(da6997965f563264).(
3066 new_block, block);
3067
3068 /* Delete the records from the source page. */
3069
3070 page_delete_rec_list_startcxx . . $ page_delete_rec_list_start(b15c09829b9b4138).(move_limit, block,
3071 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), mtr);
3072 }
3073
3074 left_block = new_block;
3075 right_block = block;
3076
3077 if (cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3078 lock_update_split_leftcxx . . $ lock_update_split_left(71e7023f76cd449a).(right_block, left_block);
3079 }
3080 } else {
3081 /* fputs("Split right\n", stderr); */
3082
3083 if (0
3084 #ifdef UNIV_ZIP_COPY
3085 || page_zip
3086 #endif /* UNIV_ZIP_COPY */
3087 || (*err = page_move_rec_list_endcxx . . $ page_move_rec_list_end(86dac29eba89661f).(new_block, block,
3088 move_limit,
3089 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), mtr))) {
3090 if (*err != DB_FAILcxx . . $ DB_FAIL.) {
3091 return nullptr;
3092 }
3093
3094 /* For some reason, compressing new_page failed,
3095 even though it should contain fewer records than
3096 the original page. Copy the page byte for byte
3097 and then delete the records from both pages
3098 as appropriate. Deleting will always succeed. */
3099 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(new_page_zip);
3100
3101 page_zip_copy_recscxx . . $ page_zip_copy_recs(10c35386c1dea7d4).(new_block, page_zip, page,
3102 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), mtr);
3103 page_delete_rec_list_startcxx . . $ page_delete_rec_list_start(b15c09829b9b4138).(move_limit - page
3104 + new_page, new_block,
3105 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), mtr);
3106
3107 /* Update the lock table and possible hash index. */
3108 if (cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3109 lock_move_rec_list_endcxx . . $ lock_move_rec_list_end(8f3f6be5e6bf9974).(new_block, block,
3110 move_limit);
3111 }
3112
3113 btr_search_move_or_delete_hash_entriescxx . . $ btr_search_move_or_delete_hash_entries(da6997965f563264).(
3114 new_block, block);
3115
3116 /* Delete the records from the source page. */
3117
3118 *err = page_delete_rec_list_endcxx . . $ page_delete_rec_list_end(18251f5e7b9c159).(move_limit, block,
3119 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(),
3120 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!,
3121 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, mtr);
3122 if (*err != DB_SUCCESScxx . . $ DB_SUCCESS.) {
3123 return nullptr;
3124 }
3125 }
3126
3127 left_block = block;
3128 right_block = new_block;
3129
3130 if (cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3131 lock_update_split_rightcxx . . $ lock_update_split_right(71e7023f76cd449a).(right_block, left_block);
3132 }
3133 }
3134
3135 #ifdef UNIV_ZIP_DEBUG
3136 if (page_zip) {
3137 ut_a(page_zip_validate(page_zip, page, cursor->index()));
3138 ut_a(page_zip_validate(new_page_zip, new_page,
3139 cursor->index()));
3140 }
3141 #endif /* UNIV_ZIP_DEBUG */
3142
3143 /* At this point, split_rec, move_limit and first_rec may point
3144 to garbage on the old page. */
3145
3146 /* 6. The split and the tree modification is now completed. Decide the
3147 page where the tuple should be inserted */
3148 rec_tcxx . . $ rec_t#* rec;
3149 buf_block_tcxx . . $ buf_block_t#* const insert_block = insert_left
3150 ? left_block : right_block;
3151
3152 /* 7. Reposition the cursor for insert and try insertion */
3153 page_cursor = btr_cur_get_page_curcxx . . $ `storage/innobase/include/btr0cur.h:62:9`!(cursor);
3154 page_cursor->blockcxx . . $ page_cur_t#block. = insert_block;
3155
3156 uint16_tcxx . . $ uint16_t# up_match = 0, low_match = 0;
3157
3158 if (page_cur_search_with_matchcxx . . $ page_cur_search_with_match(2a162131057c114d).(tuple,
3159 PAGE_CUR_LEcxx . . $ PAGE_CUR_LE., &up_match, &low_match,
3160 page_cursor, nullptr)) {
3161 *err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
3162 return nullptr;
3163 }
3164
3165 rec = page_cur_tuple_insertcxx . . $ page_cur_tuple_insert(20b71dd453d7ef65).(page_cursor, tuple,
3166 offsets, heap, n_ext, mtr);
3167
3168 #ifdef UNIV_ZIP_DEBUG
3169 {
3170 page_t* insert_page
3171 = buf_block_get_frame(insert_block);
3172
3173 page_zip_des_t* insert_page_zip
3174 = buf_block_get_page_zip(insert_block);
3175
3176 ut_a(!insert_page_zip
3177 || page_zip_validate(insert_page_zip, insert_page,
3178 cursor->index()));
3179 }
3180 #endif /* UNIV_ZIP_DEBUG */
3181
3182 if (rec != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
3183
3184 goto func_exit;
3185 }
3186
3187 /* 8. If insert did not fit, try page reorganization.
3188 For compressed pages, page_cur_tuple_insert() will have
3189 attempted this already. */
3190
3191 if (page_cur_get_page_zipcxx . . $ `storage/innobase/include/page0cur.h:56:10`!(page_cursor)) {
3192 goto insert_failed;
3193 }
3194
3195 *err = btr_page_reorganizecxx . . $ btr_page_reorganize(e4b2ea64c1f14b9e).(page_cursor, mtr);
3196
3197 if (*err != DB_SUCCESScxx . . $ DB_SUCCESS.) {
3198 return nullptr;
3199 }
3200
3201 rec = page_cur_tuple_insertcxx . . $ page_cur_tuple_insert(20b71dd453d7ef65).(page_cursor, tuple,
3202 offsets, heap, n_ext, mtr);
3203
3204 if (rec == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
3205 /* The insert did not fit on the page: loop back to the
3206 start of the function for a new split */
3207 insert_failed:
3208 n_iterations++;
3209 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n_iterations < 2
3210 || buf_block_get_page_zip(insert_block));
3211 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!insert_will_fit);
3212
3213 goto func_start;
3214 }
3215
3216 func_exit:
3217 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_validate(buf_block_get_frame(left_block),
3218 page_cursor->index));
3219 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_validate(buf_block_get_frame(right_block),
3220 page_cursor->index));
3221
3222 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!rec || rec_offs_validate(rec, page_cursor->index, *offsets));
3223 return(rec);
3224 }
3225
3226 /** Remove a page from the level list of pages.
3227 @param[in] block page to remove
3228 @param[in] index index tree
3229 @param[in,out] mtr mini-transaction */
3230 dberr_tcxx . . $ dberr_t# btr_level_list_removecxx . . $ btr_level_list_remove(b25eca2c756f4800).(const buf_block_tcxx . . $ buf_block_t#& block,
3231 const dict_index_tcxx . . $ dict_index_t#& index, mtr_tcxx . . $ mtr_t#* mtr)
3232 {
3233 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&block, MTR_MEMO_PAGE_X_FIX));
3234 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block.zip_size() == index.table->space->zip_size());
3235 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index.table->space->id == block.page.id().space());
3236 /* Get the previous and next page numbers of page */
3237 const uint32_tcxx . . $ uint32_t# prev_page_no= btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(block.pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
3238 const uint32_tcxx . . $ uint32_t# next_page_no= btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(block.pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
3239 page_id_tcxx . . $ page_id_t# id{block.pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
3240 buf_block_tcxx . . $ buf_block_t# *prev= nullptr, *next;
3241 dberr_tcxx . . $ dberr_t# err;
3242
3243 /* Update page links of the level */
3244 if (prev_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!)
3245 {
3246 id.set_page_nocxx . . $ page_id_t#set_page_no(6bab9b75950d6f3).(prev_page_no);
3247 prev= mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(id, MTR_MEMO_PAGE_X_FIXcxx . . $ MTR_MEMO_PAGE_X_FIX.);
3248 #if 1 /* MDEV-29835 FIXME: acquire page latches upfront */
3249 if (!prev)
3250 {
3251 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains(index.lock, MTR_MEMO_X_LOCK));
3252 prev= btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(index, id.page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(), RW_X_LATCHcxx . . $ RW_X_LATCH., mtr, &err);
3253 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!prev))
3254 return err;
3255 }
3256 #endif
3257 }
3258
3259 if (next_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!)
3260 {
3261 id.set_page_nocxx . . $ page_id_t#set_page_no(6bab9b75950d6f3).(next_page_no);
3262 next= mtr->get_already_latchedcxx . . $ mtr_t#get_already_latched(c8b94b52f23d581).(id, MTR_MEMO_PAGE_X_FIXcxx . . $ MTR_MEMO_PAGE_X_FIX.);
3263 #if 1 /* MDEV-29835 FIXME: acquire page latches upfront */
3264 if (!next)
3265 {
3266 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains(index.lock, MTR_MEMO_X_LOCK));
3267 next= btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(index, id.page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(), RW_X_LATCHcxx . . $ RW_X_LATCH., mtr, &err);
3268 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!next))
3269 return err;
3270 }
3271 #endif
3272 btr_page_set_prevcxx . . $ btr_page_set_prev(3cf5e6fa100ccb2d).(next, prev_page_no, mtr);
3273 }
3274
3275 if (prev)
3276 btr_page_set_nextcxx . . $ btr_page_set_next(3cf5e6fa100ccb2d).(prev, next_page_no, mtr);
3277
3278 return DB_SUCCESScxx . . $ DB_SUCCESS.;
3279 }
3280
3281 /*************************************************************//**
3282 If page is the only on its level, this function moves its records to the
3283 father page, thus reducing the tree height.
3284 @return father block */
3285 buf_block_tcxx . . $ buf_block_t#*
3286 btr_lift_page_upcxx . . $ btr_lift_page_up(b4871ba31c407588).(
3287 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index tree */
3288 buf_block_tcxx . . $ buf_block_t#* block, /*!< in: page which is the only on its level;
3289 must not be empty: use
3290 btr_discard_only_page_on_level if the last
3291 record from the page should be removed */
3292 que_thr_tcxx . . $ que_thr_t#* thr, /*!< in/out: query thread */
3293 mtr_tcxx . . $ mtr_t#* mtr, /*!< in/out: mini-transaction */
3294 dberr_tcxx . . $ dberr_t#* err) /*!< out: error code */
3295 {
3296 buf_block_tcxx . . $ buf_block_t#* father_block;
3297 ulintcxx . . $ ulint# page_level;
3298 page_zip_des_tcxx . . $ page_zip_des_t#* father_page_zip;
3299 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
3300 ulintcxx . . $ ulint# root_page_no;
3301 buf_block_tcxx . . $ buf_block_t#* blocks[BTR_MAX_LEVELScxx . . $ `storage/innobase/include/btr0btr.h:56:9`!];
3302 ulintcxx . . $ ulint# n_blocks; /*!< last used index in blocks[] */
3303 ulintcxx . . $ ulint# i;
3304 bool lift_father_up;
3305 buf_block_tcxx . . $ buf_block_t#* block_orig = block;
3306
3307 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(page));
3308 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
3309 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_is_empty(page));
3310
3311 page_level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(page);
3312 root_page_no = dict_index_get_pagecxx . . $ dict_index_get_page(154c4aa586d360eb).(index);
3313
3314 {
3315 btr_cur_tcxx . . $ btr_cur_t# cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
3316 rec_offscxx . . $ rec_offs#* offsets = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
3317 mem_heap_tcxx . . $ mem_heap_t#* heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(
3318 sizeof(*offsets)
3319 * (REC_OFFS_HEADER_SIZE + 1 + 1
3320 + unsigned(index->n_fields)));
3321 buf_block_tcxx . . $ buf_block_t#* b;
3322 cursor.page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index;
3323 cursor.page_curcxx . . $ btr_cur_t#page_cur..blockcxx . . $ page_cur_t#block. = block;
3324
3325 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3326 offsets = rtr_page_get_father_blockcxx . . $ rtr_page_get_father_block(11147704a133bbed).(
3327 nullptr, heap, nullptr, &cursor,
3328 thr, mtr);
3329 } else {
3330 offsets = btr_page_get_father_blockcxx . . $ btr_page_get_father_block(931ebee81e95307a).(offsets, heap,
3331 mtr, &cursor);
3332 }
3333
3334 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!offsets)) {
3335 parent_corrupted:
3336 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
3337 *err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
3338 return nullptr;
3339 }
3340
3341 father_block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&cursor);
3342 father_page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(father_block);
3343
3344 n_blocks = 0;
3345
3346 /* Store all ancestor pages so we can reset their
3347 levels later on. We have to do all the searches on
3348 the tree now because later on, after we've replaced
3349 the first level, the tree is in an inconsistent state
3350 and can not be searched. */
3351 for (b = father_block;
3352 b->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() != root_page_no; ) {
3353 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(n_blocks < BTR_MAX_LEVELScxx . . $ `storage/innobase/include/btr0btr.h:56:9`!);
3354
3355 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3356 offsets = rtr_page_get_father_blockcxx . . $ rtr_page_get_father_block(11147704a133bbed).(
3357 nullptr, heap, nullptr, &cursor, thr,
3358 mtr);
3359 } else {
3360 offsets = btr_page_get_father_blockcxx . . $ btr_page_get_father_block(931ebee81e95307a).(offsets,
3361 heap,
3362 mtr,
3363 &cursor);
3364 }
3365
3366 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!offsets)) {
3367 goto parent_corrupted;
3368 }
3369
3370 blocks[n_blocks++] = b = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&cursor);
3371 }
3372
3373 lift_father_up = (n_blocks && page_level == 0);
3374 if (lift_father_up) {
3375 /* The father page also should be the only on its level (not
3376 root). We should lift up the father page at first.
3377 Because the leaf page should be lifted up only for root page.
3378 The freeing page is based on page_level (==0 or !=0)
3379 to choose segment. If the page_level is changed ==0 from !=0,
3380 later freeing of the page doesn't find the page allocation
3381 to be freed.*/
3382
3383 block = father_block;
3384 page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
3385 page_level = btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(page);
3386
3387 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(page));
3388 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block,
3389 MTR_MEMO_PAGE_X_FIX));
3390
3391 father_block = blocks[0];
3392 father_page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(father_block);
3393 }
3394
3395 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
3396 }
3397
3398 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
3399
3400 /* Make the father empty */
3401 btr_page_emptycxx . . $ btr_page_empty(403ca5985fa24f33).(father_block, father_page_zip, index, page_level, mtr);
3402 /* btr_page_empty() is supposed to zero-initialize the field. */
3403 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_get_instant(father_block->page.frame));
3404
3405 if (index->is_instantcxx . . $ dict_index_t#is_instant(50ce9a9e25b4a850).()
3406 && father_block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() == root_page_no) {
3407 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!father_page_zip);
3408
3409 if (page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(page)) {
3410 const rec_tcxx . . $ rec_t#* rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(
3411 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page));
3412 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_is_metadata(rec, *index));
3413 if (rec_is_add_metadatacxx . . $ rec_is_add_metadata(5dcd923c19b1cb7d).(rec, *index)
3414 && page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(page) == 1) {
3415 index->clear_instant_addcxx . . $ dict_index_t#clear_instant_add(49f6e7a06ebc5aa8).();
3416 goto copied;
3417 }
3418 }
3419
3420 btr_set_instantcxx . . $ btr_set_instant(c781c825a451f33b).(father_block, *index, mtr);
3421 }
3422
3423 /* Copy the records to the father page one by one. */
3424 if (0
3425 #ifdef UNIV_ZIP_COPY
3426 || father_page_zip
3427 #endif /* UNIV_ZIP_COPY */
3428 || !page_copy_rec_list_endcxx . . $ page_copy_rec_list_end(49a7688bb655da1e).(father_block, block,
3429 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page),
3430 index, mtr, err)) {
3431 switch (*err) {
3432 case DB_SUCCESScxx . . $ DB_SUCCESS.:
3433 break;
3434 case DB_FAILcxx . . $ DB_FAIL.:
3435 *err = DB_SUCCESScxx . . $ DB_SUCCESS.;
3436 break;
3437 default:
3438 return nullptr;
3439 }
3440
3441 const page_zip_des_tcxx . . $ page_zip_des_t#* page_zip
3442 = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block);
3443 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(father_page_zip);
3444 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(page_zip);
3445
3446 /* Copy the page byte for byte. */
3447 page_zip_copy_recscxx . . $ page_zip_copy_recs(10c35386c1dea7d4).(father_block,
3448 page_zip, page, index, mtr);
3449
3450 /* Update the lock table and possible hash index. */
3451
3452 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3453 lock_move_rec_list_endcxx . . $ lock_move_rec_list_end(8f3f6be5e6bf9974).(father_block, block,
3454 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page));
3455 }
3456
3457 /* Also update the predicate locks */
3458 if (dict_index_is_spatialcxx . . $ `storage/innobase/include/dict0dict.h:620:9`!(index)) {
3459 lock_prdt_rec_movecxx . . $ lock_prdt_rec_move(736e698b6e7ce61a).(father_block, block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).());
3460 } else {
3461 btr_search_move_or_delete_hash_entriescxx . . $ btr_search_move_or_delete_hash_entries(da6997965f563264).(
3462 father_block, block);
3463 }
3464 }
3465
3466 copied:
3467 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3468 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
3469 /* Free predicate page locks on the block */
3470 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3471 lock_syscxx . . $ lock_sys..prdt_page_free_from_discardcxx . . $ lock_sys_t#prdt_page_free_from_discard(1557a90a37041667).(id);
3472 } else {
3473 lock_update_copy_and_discardcxx . . $ lock_update_copy_and_discard(a59c6f65a779987b).(*father_block, id);
3474 }
3475 }
3476
3477 page_level++;
3478
3479 /* Go upward to root page, decrementing levels by one. */
3480 for (i = lift_father_up ? 1 : 0; i < n_blocks; i++, page_level++) {
3481 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_page_get_level(blocks[i]->page.frame)
3482 == page_level + 1);
3483 btr_page_set_levelcxx . . $ btr_page_set_level(3cf5e6fa100ccb2d).(blocks[i], page_level, mtr);
3484 }
3485
3486 if (dict_index_is_spatialcxx . . $ `storage/innobase/include/dict0dict.h:620:9`!(index)) {
3487 rtr_check_discard_pagecxx . . $ rtr_check_discard_page(df4e8c74944966b2).(index, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, block);
3488 }
3489
3490 /* Free the file page */
3491 btr_page_freecxx . . $ btr_page_free(afbef3f3f4a891ab).(index, block, mtr);
3492
3493 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_validate(father_block->page.frame, index));
3494 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_check_node_ptr(index, father_block, thr, mtr));
3495
3496 return(lift_father_up ? block_orig : father_block);
3497 }
3498
3499 /*************************************************************//**
3500 Tries to merge the page first to the left immediate brother if such a
3501 brother exists, and the node pointers to the current page and to the brother
3502 reside on the same page. If the left brother does not satisfy these
3503 conditions, looks at the right brother. If the page is the only one on that
3504 level lifts the records of the page to the father page, thus reducing the
3505 tree height. It is assumed that mtr holds an x-latch on the tree and on the
3506 page. If cursor is on the leaf level, mtr must also hold x-latches to the
3507 brothers, if they exist.
3508 @return error code */
3509 dberr_tcxx . . $ dberr_t#
3510 btr_compresscxx . . $ btr_compress(23f7ab79088ffd00).(
3511 /*=========*/
3512 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in/out: cursor on the page to merge
3513 or lift; the page must not be empty:
3514 when deleting records, use btr_discard_page()
3515 if the page would become empty */
3516 bool adjust, /*!< in: whether the cursor position should be
3517 adjusted even when compression occurs */
3518 mtr_tcxx . . $ mtr_t#* mtr) /*!< in/out: mini-transaction */
3519 {
3520 dict_index_tcxx . . $ dict_index_t#* index;
3521 buf_block_tcxx . . $ buf_block_t#* merge_block = nullptr;
3522 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* merge_page = nullptr;
3523 page_zip_des_tcxx . . $ page_zip_des_t#* merge_page_zip;
3524 iboolcxx . . $ `storage/innobase/include/univ.i:355:9`! is_left;
3525 buf_block_tcxx . . $ buf_block_t#* block;
3526 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page;
3527 btr_cur_tcxx . . $ btr_cur_t# father_cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
3528 mem_heap_tcxx . . $ mem_heap_t#* heap;
3529 rec_offscxx . . $ rec_offs#* offsets;
3530 ulintcxx . . $ ulint# nth_rec = 0; /* remove bogus warning */
3531 bool mbr_changed = false;
3532 #ifdef UNIV_DEBUG
3533 bool leftmost_child;
3534 #endif
3535 DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("btr_compress");
3536
3537 block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor);
3538 page = btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
3539 index = btr_cur_get_indexcxx . . $ `storage/innobase/include/btr0cur.h:82:9`!(cursor);
3540
3541 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&index->lock, MTR_MEMO_X_LOCK
3542 | MTR_MEMO_SX_LOCK));
3543 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
3544
3545 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_INDEX_MERGE_ATTEMPTS);
3546
3547 const uint32_tcxx . . $ uint32_t# left_page_no = btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(page);
3548 const uint32_tcxx . . $ uint32_t# right_page_no = btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(page);
3549 dberr_tcxx . . $ dberr_t# err = DB_SUCCESScxx . . $ DB_SUCCESS.;
3550
3551 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_is_leaf(page) || left_page_no != FIL_NULL
3552 || (REC_INFO_MIN_REC_FLAG & rec_get_info_bits(
3553 page_rec_get_next(page_get_infimum_rec(page)),
3554 page_is_comp(page))));
3555
3556 heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(100);
3557 father_cursor.page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index;
3558 father_cursor.page_curcxx . . $ btr_cur_t#page_cur..blockcxx . . $ page_cur_t#block. = block;
3559
3560 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3561 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->rtr_info);
3562 offsets = rtr_page_get_father_blockcxx . . $ rtr_page_get_father_block(11147704a133bbed).(
3563 nullptr, heap, cursor, &father_cursor,
3564 cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.->thrcxx . . $ rtr_info#thr., mtr);
3565 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cursor->page_cur.block->page.id() == block->page.id());
3566 rec_tcxx . . $ rec_t#* my_rec = father_cursor.page_curcxx . . $ btr_cur_t#page_cur..reccxx . . $ page_cur_t#rec.;
3567
3568 ulintcxx . . $ ulint# page_no = btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(my_rec, offsets);
3569
3570 if (page_no != block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()) {
3571 ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "father positioned on page "
3572 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). page_no <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "instead of "
3573 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).();
3574 goto get_offsets;
3575 }
3576 } else {
3577 get_offsets:
3578 offsets = btr_page_get_father_blockcxx . . $ btr_page_get_father_block(931ebee81e95307a).(
3579 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, heap, mtr, &father_cursor);
3580 }
3581
3582 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!offsets)) {
3583 goto corrupted;
3584 }
3585
3586 if (adjust) {
3587 nth_rec = page_rec_get_n_recs_beforecxx . . $ page_rec_get_n_recs_before(b191ace3c5bffbd9).(btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(cursor));
3588 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!nth_rec || nth_rec == ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!)) {
3589 corrupted:
3590 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
3591 goto err_exit;
3592 }
3593 }
3594
3595 if (left_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`! && right_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
3596 /* The page is the only one on the level, lift the records
3597 to the father */
3598
3599 merge_block = btr_lift_page_upcxx . . $ btr_lift_page_up(b4871ba31c407588).(index, block,
3600 cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.
3601 ? cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.->thrcxx . . $ rtr_info#thr.
3602 : nullptr, mtr, &err);
3603 success:
3604 if (adjust) {
3605 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(nth_rec > 0);
3606 if (rec_tcxx . . $ rec_t#* nth
3607 = page_rec_get_nthcxx . . $ page_rec_get_nth(7ccb9c26b1180419).(merge_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.,
3608 nth_rec)) {
3609 btr_cur_positioncxx . . $ btr_cur_position(46cb1d6e3e9bb86).(index, nth,
3610 merge_block, cursor);
3611 } else {
3612 goto corrupted;
3613 }
3614 }
3615
3616 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_INDEX_MERGE_SUCCESSFUL);
3617 err_exit:
3618 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
3619 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(err);
3620 }
3621
3622 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(leftmost_child =
3623 left_page_no != FIL_NULL
3624 && (page_rec_get_next(
3625 page_get_infimum_rec(
3626 btr_cur_get_page(&father_cursor)))
3627 == btr_cur_get_rec(&father_cursor)));
3628
3629 /* Decide the page to which we try to merge and which will inherit
3630 the locks */
3631
3632 is_left = btr_can_merge_with_pagecxx . . $ btr_can_merge_with_page(68fe3ccd9ccd8e70).(cursor, left_page_no,
3633 &merge_block, mtr);
3634
3635 DBUG_EXECUTE_IFcxx . . $ `include/my_dbug.h:172:9`!("ib_always_merge_right", is_left = FALSE;);
3636 retry:
3637 if (!is_left
3638 && !btr_can_merge_with_pagecxx . . $ btr_can_merge_with_page(68fe3ccd9ccd8e70).(cursor, right_page_no, &merge_block,
3639 mtr)) {
3640 if (!merge_block) {
3641 merge_page = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
3642 }
3643 cannot_merge:
3644 err = DB_FAILcxx . . $ DB_FAIL.;
3645 goto err_exit;
3646 }
3647
3648 merge_page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(merge_block);
3649
3650 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(memcmp_aligned<4>(merge_page + (is_left
3651 ? FIL_PAGE_NEXTcxx . . $ `storage/innobase/include/fil0fil.h:1203:9`!
3652 : FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!),
3653 block->page.frame
3654 + FIL_PAGE_OFFSETcxx . . $ `storage/innobase/include/fil0fil.h:1195:9`!, 4))) {
3655 goto corrupted;
3656 }
3657
3658 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_validate(merge_page, index));
3659
3660 merge_page_zip = buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(merge_block);
3661 #ifdef UNIV_ZIP_DEBUG
3662 if (merge_page_zip) {
3663 const page_zip_des_t* page_zip
3664 = buf_block_get_page_zip(block);
3665 ut_a(page_zip);
3666 ut_a(page_zip_validate(merge_page_zip, merge_page, index));
3667 ut_a(page_zip_validate(page_zip, page, index));
3668 }
3669 #endif /* UNIV_ZIP_DEBUG */
3670
3671 btr_cur_tcxx . . $ btr_cur_t# cursor2cxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
3672 cursor2.page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index;
3673 cursor2.page_curcxx . . $ btr_cur_t#page_cur..blockcxx . . $ page_cur_t#block. = merge_block;
3674
3675 /* Move records to the merge page */
3676 if (is_left) {
3677 rtr_mbr_tcxx . . $ rtr_mbr_t# new_mbr;
3678 rec_offscxx . . $ rec_offs#* offsets2 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
3679
3680 /* For rtree, we need to update father's mbr. */
3681 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3682 /* We only support merge pages with the same parent
3683 page */
3684 if (!rtr_check_same_blockcxx . . $ rtr_check_same_block(5ccdfa5260a32e26).(
3685 index, &cursor2,
3686 btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&father_cursor), heap)) {
3687 is_left = false;
3688 goto retry;
3689 }
3690
3691 /* Set rtr_info for cursor2, since it is
3692 necessary in recursive page merge. */
3693 cursor2.rtr_infocxx . . $ btr_cur_t#rtr_info. = cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.;
3694 cursor2.tree_heightcxx . . $ btr_cur_t#tree_height. = cursor->tree_heightcxx . . $ btr_cur_t#tree_height.;
3695
3696 offsets2 = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(
3697 btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&cursor2), index, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
3698 page_is_leaf(btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(&cursor2))
3699 ? index->n_fields : 0,
3700 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
3701
3702 /* Check if parent entry needs to be updated */
3703 mbr_changed = rtr_merge_mbr_changedcxx . . $ rtr_merge_mbr_changed(f587eec4451f306c).(
3704 &cursor2, &father_cursor,
3705 offsets2, offsets, &new_mbr);
3706 }
3707
3708 rec_tcxx . . $ rec_t#* orig_pred = page_copy_rec_list_startcxx . . $ page_copy_rec_list_start(49a7688bb655da1e).(
3709 merge_block, block, page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(page),
3710 index, mtr, &err);
3711
3712 if (!orig_pred) {
3713 goto err_exit;
3714 }
3715
3716 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
3717
3718 /* Remove the page from the level list */
3719 err = btr_level_list_removecxx . . $ btr_level_list_remove(b25eca2c756f4800).(*block, *index, mtr);
3720
3721 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(err != DB_SUCCESS)) {
3722 goto err_exit;
3723 }
3724
3725 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
3726
3727 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3728 rec_tcxx . . $ rec_t#* my_rec = father_cursor.page_curcxx . . $ btr_cur_t#page_cur..reccxx . . $ page_cur_t#rec.;
3729
3730 ulintcxx . . $ ulint# page_no = btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(
3731 my_rec, offsets);
3732
3733 if (page_no != block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()) {
3734 ibcxx . . $ ib/::fatalcxx . . $ ib/fatal#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "father positioned on "
3735 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). page_no <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " instead of "
3736 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).();
3737 }
3738
3739 if (mbr_changed) {
3740 rtr_update_mbr_fieldcxx . . $ rtr_update_mbr_field(1a4fe7edb6924cd8).(
3741 &cursor2, offsets2, &father_cursor,
3742 merge_page, &new_mbr, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, mtr);
3743 } else {
3744 rtr_node_ptr_deletecxx . . $ rtr_node_ptr_delete(97042028d5da12a4).(&father_cursor, mtr);
3745 }
3746
3747 /* No GAP lock needs to be worrying about */
3748 lock_syscxx . . $ lock_sys..prdt_page_free_from_discardcxx . . $ lock_sys_t#prdt_page_free_from_discard(1557a90a37041667).(id);
3749 } else {
3750 err = btr_cur_node_ptr_deletecxx . . $ btr_cur_node_ptr_delete(b94baeb28a69884e).(&father_cursor, mtr);
3751 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(err != DB_SUCCESS)) {
3752 goto err_exit;
3753 }
3754 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3755 lock_update_merge_leftcxx . . $ lock_update_merge_left(5b2823c106408d46).(
3756 *merge_block, orig_pred, id);
3757 }
3758 }
3759
3760 if (adjust) {
3761 ulintcxx . . $ ulint# n = page_rec_get_n_recs_beforecxx . . $ page_rec_get_n_recs_before(b191ace3c5bffbd9).(orig_pred);
3762 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!n || n == ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!)) {
3763 goto corrupted;
3764 }
3765 nth_rec += n;
3766 }
3767 } else {
3768 rec_tcxx . . $ rec_t#* orig_succ;
3769 iboolcxx . . $ `storage/innobase/include/univ.i:355:9`! compressed;
3770 dberr_tcxx . . $ dberr_t# err;
3771 bytecxx . . $ byte# fil_page_prev[4];
3772
3773 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3774 /* For spatial index, we disallow merge of blocks
3775 with different parents, since the merge would need
3776 to update entry (for MBR and Primary key) in the
3777 parent of block being merged */
3778 if (!rtr_check_same_blockcxx . . $ rtr_check_same_block(5ccdfa5260a32e26).(
3779 index, &cursor2,
3780 btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&father_cursor), heap)) {
3781 goto cannot_merge;
3782 }
3783
3784 /* Set rtr_info for cursor2, since it is
3785 necessary in recursive page merge. */
3786 cursor2.rtr_infocxx . . $ btr_cur_t#rtr_info. = cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.;
3787 cursor2.tree_heightcxx . . $ btr_cur_t#tree_height. = cursor->tree_heightcxx . . $ btr_cur_t#tree_height.;
3788 } else if (!btr_page_get_fathercxx . . $ btr_page_get_father(ef799a93ae7a666b).(mtr, &cursor2)) {
3789 goto cannot_merge;
3790 }
3791
3792 if (merge_page_zip && left_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
3793
3794 /* The function page_zip_compress(), which will be
3795 invoked by page_copy_rec_list_end() below,
3796 requires that FIL_PAGE_PREV be FIL_NULL.
3797 Clear the field, but prepare to restore it. */
3798 static_assert(FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`! % 8 == 0, "alignment");
3799 memcpy(fil_page_prev, merge_page + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!, 4);
3800 compile_time_assertcxx . . $ `include/my_global.h:377:9`!(FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`! == 0xffffffffU);
3801 memset_alignedcxx . . $ memset_aligned(d1de1e4fb215f1c6).<4>(merge_page + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!, 0xff, 4);
3802 }
3803
3804 orig_succ = page_copy_rec_list_endcxx . . $ page_copy_rec_list_end(49a7688bb655da1e).(merge_block, block,
3805 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page),
3806 cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).(), mtr, &err);
3807
3808 if (!orig_succ) {
3809 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(merge_page_zip);
3810 if (left_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
3811 /* FIL_PAGE_PREV was restored from
3812 merge_page_zip. */
3813 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp(fil_page_prev,
3814 merge_page + FIL_PAGE_PREV, 4));
3815 }
3816 goto err_exit;
3817 }
3818
3819 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
3820
3821 if (merge_page_zip && left_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
3822
3823 /* Restore FIL_PAGE_PREV in order to avoid an assertion
3824 failure in btr_level_list_remove(), which will set
3825 the field again to FIL_NULL. Even though this makes
3826 merge_page and merge_page_zip inconsistent for a
3827 split second, it is harmless, because the pages
3828 are X-latched. */
3829 memcpy(merge_page + FIL_PAGE_PREVcxx . . $ `storage/innobase/include/fil0fil.h:1196:9`!, fil_page_prev, 4);
3830 }
3831
3832 /* Remove the page from the level list */
3833 err = btr_level_list_removecxx . . $ btr_level_list_remove(b25eca2c756f4800).(*block, *index, mtr);
3834
3835 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(err != DB_SUCCESS)) {
3836 goto err_exit;
3837 }
3838
3839 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_node_ptr_get_child_page_no(
3840 btr_cur_get_rec(&father_cursor), offsets)
3841 == block->page.id().page_no());
3842
3843 /* Replace the address of the old child node (= page) with the
3844 address of the merge page to the right */
3845 btr_node_ptr_set_child_page_nocxx . . $ btr_node_ptr_set_child_page_no(74c562001a057f5).(
3846 btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&father_cursor),
3847 btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&father_cursor),
3848 offsets, right_page_no, mtr);
3849
3850 #ifdef UNIV_DEBUG
3851 if (!page_is_leaf(page) && left_page_no == FIL_NULL) {
3852 ut_ad(REC_INFO_MIN_REC_FLAG & rec_get_info_bits(
3853 page_rec_get_next(page_get_infimum_rec(
3854 buf_block_get_frame(merge_block))),
3855 page_is_comp(page)));
3856 }
3857 #endif /* UNIV_DEBUG */
3858
3859 /* For rtree, we need to update father's mbr. */
3860 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3861 rec_offscxx . . $ rec_offs#* offsets2;
3862 ulintcxx . . $ ulint# rec_info;
3863
3864 offsets2 = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(
3865 btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&cursor2), index, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
3866 page_is_leaf(btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(&cursor2))
3867 ? index->n_fields : 0,
3868 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
3869
3870 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(btr_node_ptr_get_child_page_no(
3871 btr_cur_get_rec(&cursor2), offsets2)
3872 == right_page_no);
3873
3874 rec_info = rec_get_info_bitscxx . . $ rec_get_info_bits(24af2a219f1a922e).(
3875 btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&father_cursor),
3876 rec_offs_compcxx . . $ rec_offs_comp(6fce5c29061b60f9).(offsets));
3877 if (rec_info & REC_INFO_MIN_REC_FLAGcxx . . $ `storage/innobase/include/data0type.h:504:9`!) {
3878 /* When the father node ptr is minimal rec,
3879 we will keep it and delete the node ptr of
3880 merge page. */
3881 rtr_merge_and_update_mbrcxx . . $ rtr_merge_and_update_mbr(f0195e494a6f6d4).(&father_cursor,
3882 &cursor2,
3883 offsets, offsets2,
3884 merge_page, mtr);
3885 } else {
3886 /* Otherwise, we will keep the node ptr of
3887 merge page and delete the father node ptr.
3888 This is for keeping the rec order in upper
3889 level. */
3890 rtr_merge_and_update_mbrcxx . . $ rtr_merge_and_update_mbr(f0195e494a6f6d4).(&cursor2,
3891 &father_cursor,
3892 offsets2, offsets,
3893 merge_page, mtr);
3894 }
3895 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
3896 lock_syscxx . . $ lock_sys..prdt_page_free_from_discardcxx . . $ lock_sys_t#prdt_page_free_from_discard(1557a90a37041667).(id);
3897 } else {
3898
3899 compressed = btr_cur_pessimistic_deletecxx . . $ btr_cur_pessimistic_delete(8e234601f90ce98f).(&err, TRUEcxx . . $ `include/my_global.h:476:9`!,
3900 &cursor2,
3901 BTR_CREATE_FLAGcxx . . $ BTR_CREATE_FLAG.,
3902 false, mtr);
3903 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(err == DB_SUCCESS);
3904
3905 if (!compressed) {
3906 btr_cur_compress_if_usefulcxx . . $ btr_cur_compress_if_useful(c0ed7dbe459c1b6c).(&cursor2, false,
3907 mtr);
3908 }
3909
3910 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
3911 lock_update_merge_rightcxx . . $ lock_update_merge_right(4dcfc8b2da5e2f40).(
3912 merge_block, orig_succ, block);
3913 }
3914 }
3915 }
3916
3917 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_validate(merge_page, index));
3918 #ifdef UNIV_ZIP_DEBUG
3919 ut_a(!merge_page_zip || page_zip_validate(merge_page_zip, merge_page,
3920 index));
3921 #endif /* UNIV_ZIP_DEBUG */
3922
3923 if (dict_index_is_spatialcxx . . $ `storage/innobase/include/dict0dict.h:620:9`!(index)) {
3924 rtr_check_discard_pagecxx . . $ rtr_check_discard_page(df4e8c74944966b2).(index, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, block);
3925 }
3926
3927 /* Free the file page */
3928 err = btr_page_freecxx . . $ btr_page_free(afbef3f3f4a891ab).(index, block, mtr);
3929 if (err == DB_SUCCESScxx . . $ DB_SUCCESS.) {
3930 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(leftmost_child
3931 || btr_check_node_ptr(index, merge_block,
3932 cursor->rtr_info
3933 ? cursor->rtr_info->thr
3934 : nullptr, mtr));
3935 goto success;
3936 } else {
3937 goto err_exit;
3938 }
3939 }
3940
3941 /*************************************************************//**
3942 Discards a page that is the only page on its level. This will empty
3943 the whole B-tree, leaving just an empty root page. This function
3944 should almost never be reached, because btr_compress(), which is invoked in
3945 delete operations, calls btr_lift_page_up() to flatten the B-tree. */
3946 ATTRIBUTE_COLDcxx . . $ `include/my_compiler.h:166:10`!
3947 static
3948 void
3949 btr_discard_only_page_on_levelcxx . . $ btr_discard_only_page_on_level(97042028d5da12a4).(
3950 /*===========================*/
3951 btr_cur_tcxx . . $ btr_cur_t#* cur, /*!< in: cursor on a page which is the
3952 only on its level */
3953 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
3954 {
3955 dict_index_tcxx . . $ dict_index_t#* index = cur->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).();
3956 buf_block_tcxx . . $ buf_block_t#* block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cur);
3957 ulintcxx . . $ ulint# page_level = 0;
3958
3959 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->is_dummy);
3960
3961 /* Save the PAGE_MAX_TRX_ID from the leaf page. */
3962 const trx_id_tcxx . . $ trx_id_t# max_trx_id = page_get_max_trx_idcxx . . $ page_get_max_trx_id(b191ace3c5bffbd9).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
3963 const rec_tcxx . . $ rec_t#* r = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(
3964 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(block->page.frame));
3965 /* In the caller we checked that a valid key exists in the page,
3966 because we were able to look up a parent page. */
3967 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(r);
3968 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_is_metadata(r, *index) == index->is_instant());
3969
3970 while (block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() != dict_index_get_pagecxx . . $ dict_index_get_page(154c4aa586d360eb).(index)) {
3971 btr_cur_tcxx . . $ btr_cur_t# cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
3972 buf_block_tcxx . . $ buf_block_t#* father;
3973 const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
3974
3975 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(page_get_n_recs(page) == 1);
3976 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(page_level == btr_page_get_level(page));
3977 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(!page_has_siblings(page));
3978 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(fil_page_index_page_check(page));
3979 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block->page.id().space() == index->table->space->id);
3980 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
3981 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
3982 cursor.page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index;
3983 cursor.page_curcxx . . $ btr_cur_t#page_cur..blockcxx . . $ page_cur_t#block. = block;
3984
3985 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
3986 /* Check any concurrent search having this page */
3987 rtr_check_discard_pagecxx . . $ rtr_check_discard_page(df4e8c74944966b2).(index, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, block);
3988 if (!rtr_page_get_fathercxx . . $ rtr_page_get_father(c054e3ae52061ae3).(mtr, nullptr, &cursor,
3989 cur->rtr_infocxx . . $ btr_cur_t#rtr_info.->thrcxx . . $ rtr_info#thr.)) {
3990 return;
3991 }
3992 } else {
3993 if (!btr_page_get_fathercxx . . $ btr_page_get_father(ef799a93ae7a666b).(mtr, &cursor)) {
3994 return;
3995 }
3996 }
3997 father = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&cursor);
3998
3999 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
4000 lock_update_discardcxx . . $ lock_update_discard(c39721dbe69d5bd6).(
4001 father, PAGE_HEAP_NO_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:154:9`!, block);
4002 }
4003
4004 /* Free the file page */
4005 if (btr_page_freecxx . . $ btr_page_free(afbef3f3f4a891ab).(index, block, mtr) != DB_SUCCESScxx . . $ DB_SUCCESS.) {
4006 return;
4007 }
4008
4009 block = father;
4010 page_level++;
4011 }
4012
4013 /* block is the root page, which must be empty, except
4014 for the node pointer to the (now discarded) block(s). */
4015 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_has_siblings(block->page.frame));
4016
4017 mem_heap_tcxx . . $ mem_heap_t#* heap = nullptr;
4018 const rec_tcxx . . $ rec_t#* rec = nullptr;
4019 rec_offscxx . . $ rec_offs#* offsets = nullptr;
4020 if (index->tablecxx . . $ dict_index_t#table.->instantcxx . . $ dict_table_t#instant. || index->must_avoid_clear_instant_addcxx . . $ dict_index_t#must_avoid_clear_instant_add(50ce9a9e25b4a850).()) {
4021 if (!rec_is_metadatacxx . . $ rec_is_metadata(5dcd923c19b1cb7d).(r, *index)) {
4022 } else if (!index->tablecxx . . $ dict_index_t#table.->instantcxx . . $ dict_table_t#instant.
4023 || rec_is_alter_metadatacxx . . $ rec_is_alter_metadata(5dcd923c19b1cb7d).(r, *index)) {
4024 heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(srv_page_size);
4025 offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(r, index, nullptr,
4026 index->n_core_fields,
4027 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
4028 rec = rec_copycxx . . $ rec_copy(2ec1b33954fedb8b).(mem_heap_alloccxx . . $ mem_heap_alloc(3f50e4c8b9ca77c0).(heap,
4029 rec_offs_sizecxx . . $ rec_offs_size(6fce5c29061b60f9).(offsets)),
4030 r, offsets);
4031 rec_offs_make_validcxx . . $ `storage/innobase/include/rem0rec.h:520:10`!(rec, index, true, offsets);
4032 }
4033 }
4034
4035 btr_page_emptycxx . . $ btr_page_empty(403ca5985fa24f33).(block, buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block), index, 0, mtr);
4036 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_is_leaf(buf_block_get_frame(block)));
4037 /* btr_page_empty() is supposed to zero-initialize the field. */
4038 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!page_get_instant(block->page.frame));
4039
4040 if (index->is_primarycxx . . $ dict_index_t#is_primary(50ce9a9e25b4a850).()) {
4041 if (rec) {
4042 page_cur_tcxx . . $ page_cur_t# cur;
4043 page_cur_set_before_firstcxx . . $ page_cur_set_before_first(34f1922d808032bb).(block, &cur);
4044 cur.indexcxx . . $ page_cur_t#index. = index;
4045 DBUG_ASSERTcxx . . $ `include/my_dbug.h:207:9`!(index->table->instant);
4046 DBUG_ASSERTcxx . . $ `include/my_dbug.h:207:9`!(rec_is_alter_metadata(rec, *index));
4047 btr_set_instantcxx . . $ btr_set_instant(c781c825a451f33b).(block, *index, mtr);
4048 rec = page_cur_insert_rec_lowcxx . . $ page_cur_insert_rec_low(6dc7a6069c89a9d9).(&cur, rec, offsets, mtr);
4049 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec);
4050 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
4051 } else if (index->is_instantcxx . . $ dict_index_t#is_instant(50ce9a9e25b4a850).()) {
4052 index->clear_instant_addcxx . . $ dict_index_t#clear_instant_add(49f6e7a06ebc5aa8).();
4053 }
4054 } else if (!index->tablecxx . . $ dict_index_t#table.->is_temporarycxx . . $ dict_table_t#is_temporary(50ce9a9e25b4a850).()) {
4055 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(max_trx_id);
4056 page_set_max_trx_idcxx . . $ page_set_max_trx_id(7ff4fec4cd653b55).(block,
4057 buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block),
4058 max_trx_id, mtr);
4059 }
4060 }
4061
4062 /*************************************************************//**
4063 Discards a page from a B-tree. This is used to remove the last record from
4064 a B-tree page: the whole page must be removed at the same time. This cannot
4065 be used for the root page, which is allowed to be empty. */
4066 dberr_tcxx . . $ dberr_t#
4067 btr_discard_pagecxx . . $ btr_discard_page(b94baeb28a69884e).(
4068 /*=============*/
4069 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor on the page to discard: not on
4070 the root page */
4071 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */
4072 {
4073 dict_index_tcxx . . $ dict_index_t#* index;
4074 buf_block_tcxx . . $ buf_block_t#* merge_block;
4075 buf_block_tcxx . . $ buf_block_t#* block;
4076 btr_cur_tcxx . . $ btr_cur_t# parent_cursorcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
4077
4078 block = btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor);
4079 index = btr_cur_get_indexcxx . . $ `storage/innobase/include/btr0cur.h:82:9`!(cursor);
4080 parent_cursor.page_curcxx . . $ btr_cur_t#page_cur. =cxx . . $ page_cur_t#`operator=`(396f7cf79b87c113). cursor->page_curcxx . . $ btr_cur_t#page_cur.;
4081
4082 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(dict_index_get_page(index) != block->page.id().page_no());
4083
4084 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(&index->lock, MTR_MEMO_X_LOCK
4085 | MTR_MEMO_SX_LOCK));
4086 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
4087
4088 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_INDEX_DISCARD);
4089
4090 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()
4091 ? !rtr_page_get_fathercxx . . $ rtr_page_get_father(c054e3ae52061ae3).(mtr, cursor, &parent_cursor,
4092 cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.->thrcxx . . $ rtr_info#thr.)
4093 : !btr_page_get_fathercxx . . $ btr_page_get_father(ef799a93ae7a666b).(mtr, &parent_cursor)) {
4094 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4095 }
4096
4097 /* Decide the page which will inherit the locks */
4098
4099 const uint32_tcxx . . $ uint32_t# left_page_no = btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
4100 const uint32_tcxx . . $ uint32_t# right_page_no = btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
4101 page_id_tcxx . . $ page_id_t# merge_page_id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
4102
4103 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(bool parent_is_different = false);
4104 dberr_tcxx . . $ dberr_t# err;
4105 if (left_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
4106 merge_page_id.set_page_nocxx . . $ page_id_t#set_page_no(6bab9b75950d6f3).(left_page_no);
4107 merge_block = btr_block_regetcxx . . $ btr_block_reget(795d7a25592e446a).(mtr, *index, merge_page_id,
4108 &err);
4109 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!merge_block)) {
4110 return err;
4111 }
4112 #if 1 /* MDEV-29835 FIXME: Acquire the page latch upfront. */
4113 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp_aligned<4>(merge_block->page.frame
4114 + FIL_PAGE_NEXT,
4115 block->page.frame + FIL_PAGE_OFFSET,
4116 4));
4117 #else
4118 if (UNIV_UNLIKELY(memcmp_aligned<4>(merge_block->page.frame
4119 + FIL_PAGE_NEXT,
4120 block->page.frame
4121 + FIL_PAGE_OFFSET, 4))) {
4122 return DB_CORRUPTION;
4123 }
4124 #endif
4125 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(parent_is_different =
4126 (page_rec_get_next(
4127 page_get_infimum_rec(
4128 btr_cur_get_page(
4129 &parent_cursor)))
4130 == btr_cur_get_rec(&parent_cursor)));
4131 } else if (right_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
4132 merge_page_id.set_page_nocxx . . $ page_id_t#set_page_no(6bab9b75950d6f3).(right_page_no);
4133 merge_block = btr_block_regetcxx . . $ btr_block_reget(795d7a25592e446a).(mtr, *index, merge_page_id,
4134 &err);
4135 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!merge_block)) {
4136 return err;
4137 }
4138 #if 1 /* MDEV-29835 FIXME: Acquire the page latch upfront. */
4139 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!memcmp_aligned<4>(merge_block->page.frame
4140 + FIL_PAGE_PREV,
4141 block->page.frame + FIL_PAGE_OFFSET,
4142 4));
4143 #else
4144 if (UNIV_UNLIKELY(memcmp_aligned<4>(merge_block->page.frame
4145 + FIL_PAGE_PREV,
4146 block->page.frame
4147 + FIL_PAGE_OFFSET, 4))) {
4148 return DB_CORRUPTION;
4149 }
4150 #endif
4151 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(parent_is_different = page_rec_is_supremum(
4152 page_rec_get_next(btr_cur_get_rec(&parent_cursor))));
4153 if (page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(merge_block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.)) {
4154 } else if (rec_tcxx . . $ rec_t#* node_ptr =
4155 page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(
4156 merge_block->page.frame))) {
4157 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_rec_is_user_rec(node_ptr));
4158 /* We have to mark the leftmost node pointer as the
4159 predefined minimum record. */
4160 btr_set_min_rec_markcxx . . $ btr_set_min_rec_mark(2be009421920b45e).<true>(node_ptr, *merge_block,
4161 mtr);
4162 } else {
4163 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4164 }
4165 } else {
4166 btr_discard_only_page_on_levelcxx . . $ btr_discard_only_page_on_level(97042028d5da12a4).(cursor, mtr);
4167 return DB_SUCCESScxx . . $ DB_SUCCESS.;
4168 }
4169
4170 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(memcmp_aligned<2>(&merge_block->page.frame
4171 [PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_LEVELcxx . . $ `storage/innobase/include/page0page.h:106:9`!],
4172 &block->page.frame
4173 [PAGE_HEADERcxx . . $ `storage/innobase/include/page0page.h:48:9`! + PAGE_LEVELcxx . . $ `storage/innobase/include/page0page.h:106:9`!], 2))) {
4174 return DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4175 }
4176
4177 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(block, nullptr);
4178
4179 if (dict_index_is_spatialcxx . . $ `storage/innobase/include/dict0dict.h:620:9`!(index)) {
4180 rtr_node_ptr_deletecxx . . $ rtr_node_ptr_delete(97042028d5da12a4).(&parent_cursor, mtr);
4181 } else if (dberr_tcxx . . $ dberr_t# err =
4182 btr_cur_node_ptr_deletecxx . . $ btr_cur_node_ptr_delete(b94baeb28a69884e).(&parent_cursor, mtr)) {
4183 return err;
4184 }
4185
4186 /* Remove the page from the level list */
4187 if (dberr_tcxx . . $ dberr_t# err = btr_level_list_removecxx . . $ btr_level_list_remove(b25eca2c756f4800).(*block, *index, mtr)) {
4188 return err;
4189 }
4190
4191 #ifdef UNIV_ZIP_DEBUG
4192 if (page_zip_des_t* merge_page_zip
4193 = buf_block_get_page_zip(merge_block))
4194 ut_a(page_zip_validate(merge_page_zip,
4195 merge_block->page.frame, index));
4196 #endif /* UNIV_ZIP_DEBUG */
4197
4198 if (index->has_lockingcxx . . $ dict_index_t#has_locking(c9857a73d68e59ba).()) {
4199 if (left_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
4200 lock_update_discardcxx . . $ lock_update_discard(c39721dbe69d5bd6).(merge_block, PAGE_HEAP_NO_SUPREMUMcxx . . $ `storage/innobase/include/page0page.h:154:9`!,
4201 block);
4202 } else {
4203 lock_update_discardcxx . . $ lock_update_discard(c39721dbe69d5bd6).(merge_block,
4204 lock_get_min_heap_nocxx . . $ lock_get_min_heap_no(c5885a3f2ef554d0).(merge_block),
4205 block);
4206 }
4207
4208 if (index->is_spatialcxx . . $ dict_index_t#is_spatial(50ce9a9e25b4a850).()) {
4209 rtr_check_discard_pagecxx . . $ rtr_check_discard_page(df4e8c74944966b2).(index, cursor, block);
4210 }
4211 }
4212
4213 /* Free the file page */
4214 err = btr_page_freecxx . . $ btr_page_free(afbef3f3f4a891ab).(index, block, mtr);
4215
4216 if (err == DB_SUCCESScxx . . $ DB_SUCCESS.) {
4217 /* btr_check_node_ptr() needs parent block latched.
4218 If the merge_block's parent block is not same,
4219 we cannot use btr_check_node_ptr() */
4220 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(parent_is_different
4221 || btr_check_node_ptr(index, merge_block,
4222 cursor->rtr_info
4223 ? cursor->rtr_info->thr
4224 : nullptr, mtr));
4225
4226 if (btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(&parent_cursor)->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()
4227 == index->pagecxx . . $ dict_index_t#page.
4228 && !page_has_siblingscxx . . $ page_has_siblings(190063cf6fb4afb1).(btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(&parent_cursor))
4229 && page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(&parent_cursor))
4230 == 1) {
4231 btr_lift_page_upcxx . . $ btr_lift_page_up(b4871ba31c407588).(index, merge_block,
4232 cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.
4233 ? cursor->rtr_infocxx . . $ btr_cur_t#rtr_info.->thrcxx . . $ rtr_info#thr.
4234 : nullptr, mtr, &err);
4235 }
4236 }
4237
4238 return err;
4239 }
4240
4241 #ifdef UNIV_BTR_PRINT
4242 /*************************************************************//**
4243 Prints size info of a B-tree. */
4244 void
4245 btr_print_size(
4246 /*===========*/
4247 dict_index_t* index) /*!< in: index tree */
4248 {
4249 page_t* root;
4250 fseg_header_t* seg;
4251 mtr_t mtr;
4252
4253 mtr_start(&mtr);
4254
4255 root = btr_root_get(index, &mtr);
4256
4257 seg = root + PAGE_HEADER + PAGE_BTR_SEG_TOP;
4258
4259 fputs("INFO OF THE NON-LEAF PAGE SEGMENT\n", stderr);
4260 fseg_print(seg, &mtr);
4261
4262 seg = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF;
4263
4264 fputs("INFO OF THE LEAF PAGE SEGMENT\n", stderr);
4265 fseg_print(seg, &mtr);
4266
4267 mtr_commit(&mtr);
4268 }
4269
4270 /************************************************************//**
4271 Prints recursively index tree pages. */
4272 static
4273 void
4274 btr_print_recursive(
4275 /*================*/
4276 dict_index_t* index, /*!< in: index tree */
4277 buf_block_t* block, /*!< in: index page */
4278 ulint width, /*!< in: print this many entries from start
4279 and end */
4280 mem_heap_t** heap, /*!< in/out: heap for rec_get_offsets() */
4281 rec_offs** offsets,/*!< in/out: buffer for rec_get_offsets() */
4282 mtr_t* mtr) /*!< in: mtr */
4283 {
4284 const page_t* page = buf_block_get_frame(block);
4285 page_cur_t cursor;
4286 ulint n_recs;
4287 ulint i = 0;
4288 mtr_t mtr2;
4289
4290 ut_ad(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_SX_FIX));
4291
4292 ib::info() << "NODE ON LEVEL " << btr_page_get_level(page)
4293 << " page " << block->page.id;
4294
4295 page_print(block, index, width, width);
4296
4297 n_recs = page_get_n_recs(page);
4298
4299 page_cur_set_before_first(block, &cursor);
4300 page_cur_move_to_next(&cursor);
4301
4302 while (!page_cur_is_after_last(&cursor)) {
4303
4304 if (page_is_leaf(page)) {
4305
4306 /* If this is the leaf level, do nothing */
4307
4308 } else if ((i <= width) || (i >= n_recs - width)) {
4309
4310 const rec_t* node_ptr;
4311
4312 mtr_start(&mtr2);
4313
4314 node_ptr = page_cur_get_rec(&cursor);
4315
4316 *offsets = rec_get_offsets(
4317 node_ptr, index, *offsets, 0,
4318 ULINT_UNDEFINED, heap);
4319 if (buf_block_t *child =
4320 btr_node_ptr_get_child(node_ptr, index, *offsets,
4321 &mtr2)) {
4322 btr_print_recursive(index, child, width, heap,
4323 offsets, &mtr2);
4324 }
4325 mtr_commit(&mtr2);
4326 }
4327
4328 page_cur_move_to_next(&cursor);
4329 i++;
4330 }
4331 }
4332
4333 /**************************************************************//**
4334 Prints directories and other info of all nodes in the tree. */
4335 void
4336 btr_print_index(
4337 /*============*/
4338 dict_index_t* index, /*!< in: index */
4339 ulint width) /*!< in: print this many entries from start
4340 and end */
4341 {
4342 mtr_t mtr;
4343 buf_block_t* root;
4344 mem_heap_t* heap = NULL;
4345 rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
4346 rec_offs* offsets = offsets_;
4347 rec_offs_init(offsets_);
4348
4349 fputs("--------------------------\n"
4350 "INDEX TREE PRINT\n", stderr);
4351
4352 mtr_start(&mtr);
4353
4354 root = btr_root_block_get(index, RW_SX_LATCH, &mtr);
4355
4356 btr_print_recursive(index, root, width, &heap, &offsets, &mtr);
4357 if (heap) {
4358 mem_heap_free(heap);
4359 }
4360
4361 mtr_commit(&mtr);
4362 }
4363 #endif /* UNIV_BTR_PRINT */
4364
4365 #ifdef UNIV_DEBUG
4366 /************************************************************//**
4367 Checks that the node pointer to a page is appropriate.
4368 @return TRUE */
4369 ibool
4370 btr_check_node_ptr(
4371 /*===============*/
4372 dict_index_t* index, /*!< in: index tree */
4373 buf_block_t* block, /*!< in: index page */
4374 que_thr_t* thr, /*!< in/out: query thread */
4375 mtr_t* mtr) /*!< in: mtr */
4376 {
4377 mem_heap_t* heap;
4378 dtuple_t* tuple;
4379 rec_offs* offsets;
4380 btr_cur_t cursor;
4381 page_t* page = buf_block_get_frame(block);
4382
4383 ut_ad(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX));
4384
4385 if (dict_index_get_page(index) == block->page.id().page_no()) {
4386
4387 return(TRUE);
4388 }
4389
4390 cursor.page_cur.index = index;
4391 cursor.page_cur.block = block;
4392
4393 heap = mem_heap_create(256);
4394
4395 if (dict_index_is_spatial(index)) {
4396 offsets = rtr_page_get_father_block(NULL, heap,
4397 NULL, &cursor, thr, mtr);
4398 } else {
4399 offsets = btr_page_get_father_block(NULL, heap, mtr, &cursor);
4400 }
4401
4402 ut_ad(offsets);
4403
4404 if (page_is_leaf(page)) {
4405
4406 goto func_exit;
4407 }
4408
4409 tuple = dict_index_build_node_ptr(
4410 index, page_rec_get_next(page_get_infimum_rec(page)), 0, heap,
4411 btr_page_get_level(page));
4412
4413 /* For spatial index, the MBR in the parent rec could be different
4414 with that of first rec of child, their relationship should be
4415 "WITHIN" relationship */
4416 if (dict_index_is_spatial(index)) {
4417 ut_a(!cmp_dtuple_rec_with_gis(
4418 tuple, btr_cur_get_rec(&cursor),
4419 PAGE_CUR_WITHIN));
4420 } else {
4421 ut_a(!cmp_dtuple_rec(tuple, btr_cur_get_rec(&cursor), index,
4422 offsets));
4423 }
4424 func_exit:
4425 mem_heap_free(heap);
4426
4427 return(TRUE);
4428 }
4429 #endif /* UNIV_DEBUG */
4430
4431 /************************************************************//**
4432 Display identification information for a record. */
4433 static
4434 void
4435 btr_index_rec_validate_reportcxx . . $ btr_index_rec_validate_report(a4fb8b1a89eca14e).(
4436 /*==========================*/
4437 const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page, /*!< in: index page */
4438 const rec_tcxx . . $ rec_t#* rec, /*!< in: index record */
4439 const dict_index_tcxx . . $ dict_index_t#* index) /*!< in: index */
4440 {
4441 ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Record in index " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->namecxx . . $ dict_index_t#name.
4442 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " of table " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->tablecxx . . $ dict_index_t#table.->namecxx . . $ dict_table_t#name.
4443 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", page " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).(page_get_space_idcxx . . $ page_get_space_id(ca1608e2c87725e2).(page),
4444 page_get_page_nocxx . . $ page_get_page_no(ca1608e2c87725e2).(page))
4445 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", at offset " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). rec - page;
4446 }
4447
4448 /************************************************************//**
4449 Checks the size and number of fields in a record based on the definition of
4450 the index.
4451 @return TRUE if ok */
4452 bool
4453 btr_index_rec_validatecxx . . $ btr_index_rec_validate(6d3276c4d36bc5f4).(
4454 /*===================*/
4455 const page_cur_tcxx . . $ page_cur_t#& cur, /*!< in: cursor to index record */
4456 const dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
4457 bool dump_on_error) /*!< in: true if the function
4458 should print hex dump of record
4459 and page on error */
4460 noexcept
4461 {
4462 ulintcxx . . $ ulint# len;
4463 const rec_tcxx . . $ rec_t#* rec = page_cur_get_reccxx . . $ `storage/innobase/include/page0cur.h:57:10`!(&cur);
4464 const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page = cur.blockcxx . . $ page_cur_t#block.->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.;
4465 mem_heap_tcxx . . $ mem_heap_t#* heap = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
4466 rec_offscxx . . $ rec_offs# offsets_[REC_OFFS_NORMAL_SIZEcxx . . $ REC_OFFS_NORMAL_SIZE.];
4467 rec_offscxx . . $ rec_offs#* offsets = offsets_;
4468 rec_offs_initcxx . . $ `storage/innobase/include/rem0rec.h:844:9`!(offsets_);
4469
4470 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->n_core_fields);
4471
4472 #ifdef VIRTUAL_INDEX_DEBUG
4473 if (dict_index_has_virtual(index)) {
4474 fprintf(stderr, "index name is %s\n", index->name());
4475 }
4476 #endif
4477 if ((iboolcxx . . $ `storage/innobase/include/univ.i:355:9`!)!!page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page) != dict_table_is_compcxx . . $ `storage/innobase/include/dict0dict.h:776:9`!(index->table)) {
4478 btr_index_rec_validate_reportcxx . . $ btr_index_rec_validate_report(a4fb8b1a89eca14e).(page, rec, index);
4479
4480 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Compact flag=" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). !!page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page)
4481 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", should be " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). dict_table_is_compcxx . . $ `storage/innobase/include/dict0dict.h:776:9`!(index->table);
4482
4483 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
4484 }
4485
4486 const bool is_alter_metadata = page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(page)
4487 && !page_has_prevcxx . . $ page_has_prev(190063cf6fb4afb1).(page)
4488 && index->is_primarycxx . . $ dict_index_t#is_primary(50ce9a9e25b4a850).() && index->tablecxx . . $ dict_index_t#table.->instantcxx . . $ dict_table_t#instant.
4489 && rec == page_rec_get_next_constcxx . . $ page_rec_get_next_const(e8dc1f8aea836758).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page));
4490
4491 if (is_alter_metadata
4492 && !rec_is_alter_metadatacxx . . $ rec_is_alter_metadata(3a706fe4966174d9).(rec, page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page))) {
4493 btr_index_rec_validate_reportcxx . . $ btr_index_rec_validate_report(a4fb8b1a89eca14e).(page, rec, index);
4494
4495 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "First record is not ALTER TABLE metadata";
4496 return FALSEcxx . . $ `include/my_global.h:477:9`!;
4497 }
4498
4499 if (!page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page)) {
4500 const ulintcxx . . $ ulint# n_rec_fields = rec_get_n_fields_oldcxx . . $ rec_get_n_fields_old(469dcb4e54b221a8).(rec);
4501 if (n_rec_fields == DICT_FLD__SYS_INDEXES__MERGE_THRESHOLDcxx . . $ DICT_FLD__SYS_INDEXES__MERGE_THRESHOLD.
4502 && index->idcxx . . $ dict_index_t#id. == DICT_INDEXES_IDcxx . . $ `storage/innobase/include/dict0boot.h:77:9`!) {
4503 /* A record for older SYS_INDEXES table
4504 (missing merge_threshold column) is acceptable. */
4505 } else if (is_alter_metadata) {
4506 if (n_rec_fields != ulintcxx . . $ ulint#(index->n_fieldscxx . . $ dict_index_t#n_fields.) + 1) {
4507 goto n_field_mismatch;
4508 }
4509 } else if (n_rec_fields < index->n_core_fieldscxx . . $ dict_index_t#n_core_fields.
4510 || n_rec_fields > index->n_fieldscxx . . $ dict_index_t#n_fields.) {
4511 n_field_mismatch:
4512 btr_index_rec_validate_reportcxx . . $ btr_index_rec_validate_report(a4fb8b1a89eca14e).(page, rec, index);
4513
4514 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Has " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). rec_get_n_fields_oldcxx . . $ rec_get_n_fields_old(469dcb4e54b221a8).(rec)
4515 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " fields, should have "
4516 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->n_core_fieldscxx . . $ dict_index_t#n_core_fields. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ".."
4517 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->n_fieldscxx . . $ dict_index_t#n_fields.;
4518
4519 if (dump_on_error) {
4520 fputs("InnoDB: corrupt record ", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4521 rec_print_oldcxx . . $ rec_print_old(3de6c0e1d02695d6).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, rec);
4522 putc('\n', stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4523 }
4524 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
4525 }
4526 }
4527
4528 offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(rec, index, offsets, page_is_leaf(page)
4529 ? index->n_core_fields : 0,
4530 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
4531 const dict_field_tcxx . . $ dict_field_t#* field = index->fieldscxx . . $ dict_index_t#fields.;
4532 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rec_offs_n_fields(offsets)
4533 == ulint(index->n_fields) + is_alter_metadata);
4534
4535 for (unsigned i = 0; i < rec_offs_n_fieldscxx . . $ rec_offs_n_fields(6fce5c29061b60f9).(offsets); i++) {
4536 rec_get_nth_field_offscxx . . $ rec_get_nth_field_offs(70b61031fb25acea).(offsets, i, &len);
4537
4538 ulintcxx . . $ ulint# fixed_size;
4539
4540 if (is_alter_metadata && i == index->first_user_fieldcxx . . $ dict_index_t#first_user_field(72085aa11f4b6e09).()) {
4541 fixed_size = FIELD_REF_SIZEcxx . . $ `storage/innobase/include/btr0types.h:40:9`!;
4542 if (len != FIELD_REF_SIZEcxx . . $ `storage/innobase/include/btr0types.h:40:9`!
4543 || !rec_offs_nth_externcxx . . $ rec_offs_nth_extern(878e7dc5509530f1).(offsets, i)) {
4544 goto len_mismatch;
4545 }
4546
4547 continue;
4548 } else {
4549 fixed_size = dict_col_get_fixed_sizecxx . . $ dict_col_get_fixed_size(441363759254a725).(
4550 field->colcxx . . $ dict_field_t#col., page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page));
4551 if (rec_offs_nth_externcxx . . $ rec_offs_nth_extern(878e7dc5509530f1).(offsets, i)) {
4552 const bytecxx . . $ byte#* data = rec_get_nth_fieldcxx . . $ `storage/innobase/include/rem0rec.h:562:9`!(
4553 rec, offsets, i, &len);
4554 len -= BTR_EXTERN_FIELD_REF_SIZEcxx . . $ `storage/innobase/include/btr0types.h:41:9`!;
4555 ulintcxx . . $ ulint# extern_len = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(
4556 data + len + BTR_EXTERN_LENcxx . . $ `storage/innobase/include/btr0cur.h:797:9`! + 4);
4557 if (fixed_size == extern_len + len) {
4558 goto next_field;
4559 }
4560 }
4561 }
4562
4563 /* Note that if fixed_size != 0, it equals the
4564 length of a fixed-size column in the clustered index.
4565 We should adjust it here.
4566 A prefix index of the column is of fixed, but different
4567 length. When fixed_size == 0, prefix_len is the maximum
4568 length of the prefix index column. */
4569
4570 if (len_is_storedcxx . . $ `storage/innobase/include/data0type.h:34:9`!(len)
4571 && (field->prefix_lencxx . . $ dict_field_t#prefix_len.
4572 ? len > field->prefix_lencxx . . $ dict_field_t#prefix_len.
4573 : (fixed_size && len != fixed_size))) {
4574 len_mismatch:
4575 btr_index_rec_validate_reportcxx . . $ btr_index_rec_validate_report(a4fb8b1a89eca14e).(page, rec, index);
4576 ibcxx . . $ ib/::errorcxx . . $ ib/error# error;
4577
4578 error <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Field " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). i <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " len is " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). len
4579 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", should be " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). fixed_size;
4580
4581 if (dump_on_error) {
4582 error <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "; ";
4583 rec_printcxx . . $ rec_print(a41c0dbdd3d26afd).(error.m_osscxx . . $ ib/logger#m_oss., rec,
4584 rec_get_info_bitscxx . . $ rec_get_info_bits(24af2a219f1a922e).(
4585 rec, rec_offs_compcxx . . $ rec_offs_comp(6fce5c29061b60f9).(offsets)),
4586 offsets);
4587 }
4588 if (heap) {
4589 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
4590 }
4591 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
4592 }
4593 next_field:
4594 field++;
4595 }
4596
4597 #ifdef VIRTUAL_INDEX_DEBUG
4598 if (dict_index_has_virtual(index)) {
4599 rec_print_new(stderr, rec, offsets);
4600 }
4601 #endif
4602
4603 if (heap) {
4604 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
4605 }
4606 return(TRUEcxx . . $ `include/my_global.h:476:9`!);
4607 }
4608
4609 /************************************************************//**
4610 Checks the size and number of fields in records based on the definition of
4611 the index.
4612 @return true if ok */
4613 static
4614 bool
4615 btr_index_page_validatecxx . . $ btr_index_page_validate(29922222ce9764f4).(
4616 /*====================*/
4617 buf_block_tcxx . . $ buf_block_t#* block, /*!< in: index page */
4618 dict_index_tcxx . . $ dict_index_t#* index) /*!< in: index */
4619 {
4620 page_cur_tcxx . . $ page_cur_t# cur;
4621 #ifndef DBUG_OFFcxx . . $ `<built-in>:492:9`!
4622 ulint nth = 1;
4623 #endif /* !DBUG_OFF */
4624
4625 page_cur_set_before_firstcxx . . $ page_cur_set_before_first(34f1922d808032bb).(block, &cur);
4626
4627 /* Directory slot 0 should only contain the infimum record. */
4628 DBUG_EXECUTE_IFcxx . . $ `include/my_dbug.h:172:9`!("check_table_rec_next",
4629 ut_a(page_rec_get_nth_const(
4630 page_cur_get_page(&cur), 0)
4631 == cur.rec);
4632 ut_a(page_dir_slot_get_n_owned(
4633 page_dir_get_nth_slot(
4634 page_cur_get_page(&cur), 0))
4635 == 1););
4636
4637 while (page_cur_move_to_nextcxx . . $ page_cur_move_to_next(99e08e4d4839908).(&cur)) {
4638 if (page_cur_is_after_lastcxx . . $ page_cur_is_after_last(95964a7af755c14).(&cur)) {
4639 return true;
4640 }
4641
4642 if (!btr_index_rec_validatecxx . . $ btr_index_rec_validate(6d3276c4d36bc5f4).(cur, index, TRUEcxx . . $ `include/my_global.h:476:9`!)) {
4643 break;
4644 }
4645
4646 /* Verify that page_rec_get_nth_const() is correctly
4647 retrieving each record. */
4648 DBUG_EXECUTE_IFcxx . . $ `include/my_dbug.h:172:9`!("check_table_rec_next",
4649 ut_a(cur.rec == page_rec_get_nth_const(
4650 page_cur_get_page(&cur),
4651 page_rec_get_n_recs_before(
4652 cur.rec)));
4653 ut_a(nth++ == page_rec_get_n_recs_before(
4654 cur.rec)););
4655 }
4656
4657 return false;
4658 }
4659
4660 /************************************************************//**
4661 Report an error on one page of an index tree. */
4662 static
4663 void
4664 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(
4665 /*=================*/
4666 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
4667 ulintcxx . . $ ulint# level, /*!< in: B-tree level */
4668 const buf_block_tcxx . . $ buf_block_t#* block) /*!< in: index page */
4669 {
4670 ibcxx . . $ ib/::errorcxx . . $ ib/error# error;
4671 error <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "In page " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()
4672 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " of index " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->namecxx . . $ dict_index_t#name.
4673 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " of table " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->tablecxx . . $ dict_index_t#table.->namecxx . . $ dict_table_t#name.;
4674
4675 if (level > 0) {
4676 error <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", index tree level " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). level;
4677 }
4678 }
4679
4680 /************************************************************//**
4681 Report an error on two pages of an index tree. */
4682 static
4683 void
4684 btr_validate_report2cxx . . $ btr_validate_report2(2ea6392cebd0d6b2).(
4685 /*=================*/
4686 const dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
4687 ulintcxx . . $ ulint# level, /*!< in: B-tree level */
4688 const buf_block_tcxx . . $ buf_block_t#* block1, /*!< in: first index page */
4689 const buf_block_tcxx . . $ buf_block_t#* block2) /*!< in: second index page */
4690 {
4691 ibcxx . . $ ib/::errorcxx . . $ ib/error# error;
4692 error <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "In pages " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). block1->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()
4693 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " and " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). block2->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " of index " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->namecxx . . $ dict_index_t#name.
4694 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " of table " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->tablecxx . . $ dict_index_t#table.->namecxx . . $ dict_table_t#name.;
4695
4696 if (level)
4697 error <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", index tree level " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). level;
4698 }
4699
4700 /** Validate an index tree level. */
4701 static
4702 dberr_tcxx . . $ dberr_t#
4703 btr_validate_levelcxx . . $ btr_validate_level(c7aae675deeef3b).(
4704 /*===============*/
4705 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index tree */
4706 trx_tcxx . . $ trx_t#* trx, /*!< in: transaction */
4707 ulintcxx . . $ ulint# level) /*!< in: level number */
4708 {
4709 buf_block_tcxx . . $ buf_block_t#* block;
4710 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page;
4711 buf_block_tcxx . . $ buf_block_t#* right_block = 0; /* remove warning */
4712 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* right_page = 0; /* remove warning */
4713 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* father_page;
4714 btr_cur_tcxx . . $ btr_cur_t# node_curcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
4715 btr_cur_tcxx . . $ btr_cur_t# right_node_curcxx . . $ btr_cur_t#btr_cur_t(49f6e7a06ebc5aa8).;
4716 rec_tcxx . . $ rec_t#* rec;
4717 page_cur_tcxx . . $ page_cur_t# cursor;
4718 dtuple_tcxx . . $ dtuple_t#* node_ptr_tuple;
4719 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{trx};
4720 mem_heap_tcxx . . $ mem_heap_t#* heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(256);
4721 rec_offscxx . . $ rec_offs#* offsets = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
4722 rec_offscxx . . $ rec_offs#* offsets2= NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
4723 #ifdef UNIV_ZIP_DEBUG
4724 page_zip_des_t* page_zip;
4725 #endif /* UNIV_ZIP_DEBUG */
4726
4727 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
4728
4729 mtr_x_lock_indexcxx . . $ `storage/innobase/include/mtr0mtr.h:46:10`!(index, &mtr);
4730
4731 dberr_tcxx . . $ dberr_t# err;
4732 block = btr_root_block_getcxx . . $ btr_root_block_get(4bcbd40788d58e0a).(index, RW_SX_LATCHcxx . . $ RW_SX_LATCH., &mtr, &err);
4733 if (!block) {
4734 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
4735 return err;
4736 }
4737 page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
4738
4739 fil_space_tcxx . . $ fil_space_t#* space = index->tablecxx . . $ dict_index_t#table.->spacecxx . . $ dict_table_t#space.;
4740
4741 while (level != btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(page)) {
4742 const rec_tcxx . . $ rec_t#* node_ptr;
4743 switch (dberr_tcxx . . $ dberr_t# e =
4744 fseg_page_is_allocatedcxx . . $ fseg_page_is_allocated(6d2f533a32123586).(&mtr, space,
4745 block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).())) {
4746 case DB_SUCCESS_LOCKED_RECcxx . . $ DB_SUCCESS_LOCKED_REC.:
4747 break;
4748 case DB_SUCCESScxx . . $ DB_SUCCESS.:
4749 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4750 ibcxx . . $ ib/::warncxx . . $ ib/warn#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Page is free";
4751 e = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4752 /* fall through */
4753 default:
4754 err = e;
4755 }
4756 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->table->space_id == block->page.id().space());
4757 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block->page.id().space() == page_get_space_id(page));
4758 #ifdef UNIV_ZIP_DEBUG
4759 page_zip = buf_block_get_page_zip(block);
4760 ut_a(!page_zip || page_zip_validate(page_zip, page, index));
4761 #endif /* UNIV_ZIP_DEBUG */
4762 if (page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(page)) {
4763 corrupted:
4764 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4765 goto invalid_page;
4766 }
4767
4768 page_cur_set_before_firstcxx . . $ page_cur_set_before_first(34f1922d808032bb).(block, &cursor);
4769 if (!(node_ptr = page_cur_move_to_nextcxx . . $ page_cur_move_to_next(99e08e4d4839908).(&cursor))) {
4770 goto corrupted;
4771 }
4772
4773 offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(node_ptr, index, offsets, 0,
4774 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
4775
4776 block = btr_node_ptr_get_childcxx . . $ btr_node_ptr_get_child(809ad4b01f04a0a4).(node_ptr, index, offsets, &mtr,
4777 &err);
4778 if (!block) {
4779 break;
4780 }
4781 page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
4782
4783 /* For R-Tree, since record order might not be the same as
4784 linked index page in the lower level, we need to travers
4785 backwards to get the first page rec in this level.
4786 This is only used for index validation. Spatial index
4787 does not use such scan for any of its DML or query
4788 operations */
4789 if (dict_index_is_spatialcxx . . $ `storage/innobase/include/dict0dict.h:620:9`!(index)) {
4790 uint32_tcxx . . $ uint32_t# left_page_no = btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(page);
4791
4792 while (left_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
4793 /* To obey latch order of tree blocks,
4794 we should release the right_block once to
4795 obtain lock of the uncle block. */
4796 mtr.release_last_pagecxx . . $ mtr_t#release_last_page(49f6e7a06ebc5aa8).();
4797
4798 block = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*index, left_page_no,
4799 RW_SX_LATCHcxx . . $ RW_SX_LATCH., &mtr, &err);
4800 if (!block) {
4801 goto invalid_page;
4802 }
4803 page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
4804 left_page_no = btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(page);
4805 }
4806 }
4807 }
4808
4809 /* Now we are on the desired level. Loop through the pages on that
4810 level. */
4811
4812 loop:
4813 if (!block) {
4814 invalid_page:
4815 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
4816 func_exit:
4817 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
4818 return err;
4819 }
4820
4821 mem_heap_emptycxx . . $ mem_heap_empty(5231cf397463bfab).(heap);
4822 offsets = offsets2 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
4823
4824 mtr_x_lock_indexcxx . . $ `storage/innobase/include/mtr0mtr.h:46:10`!(index, &mtr);
4825
4826 page = block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.;
4827
4828 #ifdef UNIV_ZIP_DEBUG
4829 page_zip = buf_block_get_page_zip(block);
4830 ut_a(!page_zip || page_zip_validate(page_zip, page, index));
4831 #endif /* UNIV_ZIP_DEBUG */
4832
4833 if (DB_SUCCESS_LOCKED_RECcxx . . $ DB_SUCCESS_LOCKED_REC.
4834 != fseg_page_is_allocatedcxx . . $ fseg_page_is_allocated(6d2f533a32123586).(&mtr, space,
4835 block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).())) {
4836 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4837
4838 ibcxx . . $ ib/::warncxx . . $ ib/warn#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Page is marked as free";
4839 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4840 } else if (btr_page_get_index_idcxx . . $ btr_page_get_index_id(b191ace3c5bffbd9).(page) != index->idcxx . . $ dict_index_t#id.) {
4841 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Page index id " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). btr_page_get_index_idcxx . . $ btr_page_get_index_id(b191ace3c5bffbd9).(page)
4842 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " != data dictionary index id " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). index->idcxx . . $ dict_index_t#id.;
4843 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4844 } else if (!page_validatecxx . . $ page_validate(a2ed68b78ae19a27).(page, index)) {
4845 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4846 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4847 } else if (btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(page) != level) {
4848 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4849 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Page level is not " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). level;
4850 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4851 } else if (level == 0 && !btr_index_page_validatecxx . . $ btr_index_page_validate(29922222ce9764f4).(block, index)) {
4852 /* We are on level 0. Check that the records have the right
4853 number of fields, and field lengths are right. */
4854 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4855 } else if (!page_is_emptycxx . . $ page_is_empty(190063cf6fb4afb1).(page)) {
4856 } else if (level) {
4857 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4858 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Non-leaf page is empty";
4859 } else if (block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() != index->pagecxx . . $ dict_index_t#page.) {
4860 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4861 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Empty leaf page is not index root";
4862 }
4863
4864 uint32_tcxx . . $ uint32_t# right_page_no = btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(page);
4865 uint32_tcxx . . $ uint32_t# left_page_no = btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(page);
4866
4867 if (right_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
4868 const rec_tcxx . . $ rec_t#* right_rec;
4869
4870 right_block = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*index, right_page_no, RW_SX_LATCHcxx . . $ RW_SX_LATCH.,
4871 &mtr, &err);
4872 if (!right_block) {
4873 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4874 fputs("InnoDB: broken FIL_PAGE_NEXT link\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4875 goto invalid_page;
4876 }
4877 right_page = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(right_block);
4878
4879 if (btr_page_get_prevcxx . . $ btr_page_get_prev(ca1608e2c87725e2).(right_page) != page_get_page_nocxx . . $ page_get_page_no(ca1608e2c87725e2).(page)) {
4880 btr_validate_report2cxx . . $ btr_validate_report2(2ea6392cebd0d6b2).(index, level, block, right_block);
4881 fputs("InnoDB: broken FIL_PAGE_NEXT"
4882 " or FIL_PAGE_PREV links\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4883 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4884 }
4885
4886 if (!(rec = page_rec_get_prevcxx . . $ page_rec_get_prev(adcd832f8377c3d8).(page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(page)))) {
4887 broken_links:
4888 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4889 fputs("InnoDB: broken record links\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4890 goto invalid_page;
4891 }
4892 if (!(right_rec =
4893 page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(right_page)))) {
4894 goto broken_links;
4895 }
4896
4897 offsets = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(rec, index, offsets,
4898 page_is_leaf(page)
4899 ? index->n_core_fields : 0,
4900 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
4901 offsets2 = rec_get_offsetscxx . . $ `storage/innobase/include/rem0rec.h:475:10`!(right_rec, index, offsets2,
4902 page_is_leaf(right_page)
4903 ? index->n_core_fields : 0,
4904 ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!, &heap);
4905
4906 /* For spatial index, we cannot guarantee the key ordering
4907 across pages, so skip the record compare verification for
4908 now. Will enhanced in special R-Tree index validation scheme */
4909 if (index->is_btreecxx . . $ dict_index_t#is_btree(50ce9a9e25b4a850).()
4910 && cmp_rec_reccxx . . $ cmp_rec_rec(ead216ea62cda37a).(rec, right_rec,
4911 offsets, offsets2, index) >= 0) {
4912
4913 btr_validate_report2cxx . . $ btr_validate_report2(2ea6392cebd0d6b2).(index, level, block, right_block);
4914
4915 fputs("InnoDB: records in wrong order"
4916 " on adjacent pages\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4917
4918 rec = page_rec_get_prevcxx . . $ page_rec_get_prev(adcd832f8377c3d8).(page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(page));
4919 if (rec) {
4920 fputs("InnoDB: record ", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4921 rec_printcxx . . $ rec_print(fe60279f5763606a).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, rec, index);
4922 putc('\n', stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4923 }
4924 fputs("InnoDB: record ", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4925 rec = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(
4926 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(right_page));
4927 if (rec) {
4928 rec_printcxx . . $ rec_print(fe60279f5763606a).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, rec, index);
4929 }
4930 putc('\n', stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4931 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4932 }
4933 }
4934
4935 if (!level || left_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
4936 } else if (const rec_tcxx . . $ rec_t#* first =
4937 page_rec_get_next_constcxx . . $ page_rec_get_next_const(e8dc1f8aea836758).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page))) {
4938 if (!(REC_INFO_MIN_REC_FLAGcxx . . $ `storage/innobase/include/data0type.h:504:9`!
4939 & rec_get_info_bitscxx . . $ rec_get_info_bits(24af2a219f1a922e).(first, page_is_compcxx . . $ page_is_comp(f3688bc2ee54ea05).(page)))) {
4940 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4941 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Missing REC_INFO_MIN_REC_FLAG";
4942 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4943 }
4944 } else {
4945 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4946 goto node_ptr_fails;
4947 }
4948
4949 /* Similarly skip the father node check for spatial index for now,
4950 for a couple of reasons:
4951 1) As mentioned, there is no ordering relationship between records
4952 in parent level and linked pages in the child level.
4953 2) Search parent from root is very costly for R-tree.
4954 We will add special validation mechanism for R-tree later (WL #7520) */
4955 if (index->is_btreecxx . . $ dict_index_t#is_btree(50ce9a9e25b4a850).() && block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).() != index->pagecxx . . $ dict_index_t#page.) {
4956 /* Check father node pointers */
4957 rec_tcxx . . $ rec_t#* node_ptr
4958 = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page));
4959 if (!node_ptr) {
4960 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
4961 goto node_ptr_fails;
4962 }
4963
4964 btr_cur_positioncxx . . $ btr_cur_position(46cb1d6e3e9bb86).(index, node_ptr, block, &node_cur);
4965 offsets = btr_page_get_father_node_ptr_for_validatecxx . . $ btr_page_get_father_node_ptr_for_validate(fbc97b7d2f73ee90).(
4966 offsets, heap, &node_cur, &mtr);
4967
4968 father_page = btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(&node_cur);
4969 node_ptr = btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&node_cur);
4970
4971 rec = page_rec_get_prevcxx . . $ page_rec_get_prev(adcd832f8377c3d8).(page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(page));
4972 if (rec) {
4973 btr_cur_positioncxx . . $ btr_cur_position(46cb1d6e3e9bb86).(index, rec, block, &node_cur);
4974
4975 offsets = btr_page_get_father_node_ptr_for_validatecxx . . $ btr_page_get_father_node_ptr_for_validate(fbc97b7d2f73ee90).(
4976 offsets, heap, &node_cur, &mtr);
4977 } else {
4978 offsets = nullptr;
4979 }
4980
4981 if (!offsets || node_ptr != btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&node_cur)
4982 || btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(node_ptr, offsets)
4983 != block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).()) {
4984
4985 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
4986
4987 fputs("InnoDB: node pointer to the page is wrong\n",
4988 stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4989
4990 fputs("InnoDB: node ptr ", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
4991 rec_printcxx . . $ rec_print(fe60279f5763606a).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, node_ptr, index);
4992
4993 if (offsets) {
4994 rec = btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&node_cur);
4995 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"
4996 "InnoDB: node ptr child page n:o %u\n",
4997 btr_node_ptr_get_child_page_nocxx . . $ btr_node_ptr_get_child_page_no(9efe0e53bf5e4c88).(
4998 rec, offsets));
4999 fputs("InnoDB: record on page ", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5000 rec_print_newcxx . . $ rec_print_new(423d6296895597b1).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, rec, offsets);
5001 putc('\n', stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5002 }
5003
5004 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5005 goto node_ptr_fails;
5006 }
5007
5008 if (page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(page)) {
5009 } else if (const rec_tcxx . . $ rec_t#* first_rec =
5010 page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(page))) {
5011 node_ptr_tuple = dict_index_build_node_ptrcxx . . $ dict_index_build_node_ptr(21b5a4827c82add7).(
5012 index, first_rec,
5013 0, heap, btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(page));
5014
5015 if (cmp_dtuple_reccxx . . $ cmp_dtuple_rec(fc19edad24dfa402).(node_ptr_tuple, node_ptr, index,
5016 offsets)) {
5017 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level, block);
5018
5019 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Node ptrs differ on levels > 0";
5020
5021 fputs("InnoDB: node ptr ",stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5022 rec_print_newcxx . . $ rec_print_new(423d6296895597b1).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, node_ptr, offsets);
5023 fputs("InnoDB: first rec ", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5024 rec_printcxx . . $ rec_print(fe60279f5763606a).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, first_rec, index);
5025 putc('\n', stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5026 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5027 goto node_ptr_fails;
5028 }
5029 } else {
5030 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5031 goto node_ptr_fails;
5032 }
5033
5034 if (left_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
5035 if (page_has_prevcxx . . $ page_has_prev(190063cf6fb4afb1).(father_page)
5036 || node_ptr != page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(
5037 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(father_page))) {
5038 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5039 goto node_ptr_fails;
5040 }
5041 }
5042
5043 if (right_page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
5044 if (page_has_nextcxx . . $ page_has_next(190063cf6fb4afb1).(father_page)
5045 || node_ptr != page_rec_get_prevcxx . . $ page_rec_get_prev(adcd832f8377c3d8).(
5046 page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(father_page))) {
5047 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5048 goto node_ptr_fails;
5049 }
5050 } else if (const rec_tcxx . . $ rec_t#* right_node_ptr
5051 = page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(node_ptr)) {
5052 btr_cur_positioncxx . . $ btr_cur_position(46cb1d6e3e9bb86).(
5053 index,
5054 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(right_block->page.frame),
5055 right_block, &right_node_cur);
5056 if (!page_cur_move_to_nextcxx . . $ page_cur_move_to_next(99e08e4d4839908).(&right_node_cur.page_curcxx . . $ btr_cur_t#page_cur.)) {
5057 goto node_pointer_corrupted;
5058 }
5059
5060 offsets = btr_page_get_father_node_ptr_for_validatecxx . . $ btr_page_get_father_node_ptr_for_validate(fbc97b7d2f73ee90).(
5061 offsets, heap, &right_node_cur, &mtr);
5062
5063 if (right_node_ptr
5064 != page_get_supremum_reccxx . . $ `storage/innobase/include/page0page.h:532:9`!(father_page)) {
5065
5066 if (btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&right_node_cur)
5067 != right_node_ptr) {
5068 node_pointer_corrupted:
5069 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5070 fputs("InnoDB: node pointer to"
5071 " the right page is wrong\n",
5072 stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5073
5074 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level,
5075 block);
5076 }
5077 } else {
5078 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* right_father_page
5079 = btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(&right_node_cur);
5080
5081 if (btr_cur_get_reccxx . . $ `storage/innobase/include/btr0cur.h:64:9`!(&right_node_cur)
5082 != page_rec_get_nextcxx . . $ page_rec_get_next(adcd832f8377c3d8).(
5083 page_get_infimum_reccxx . . $ `storage/innobase/include/page0page.h:531:9`!(
5084 right_father_page))) {
5085 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5086 fputs("InnoDB: node pointer 2 to"
5087 " the right page is wrong\n",
5088 stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5089
5090 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level,
5091 block);
5092 }
5093
5094 if (page_get_page_nocxx . . $ page_get_page_no(ca1608e2c87725e2).(right_father_page)
5095 != btr_page_get_nextcxx . . $ btr_page_get_next(ca1608e2c87725e2).(father_page)) {
5096
5097 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5098 fputs("InnoDB: node pointer 3 to"
5099 " the right page is wrong\n",
5100 stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
5101
5102 btr_validate_report1cxx . . $ btr_validate_report1(774a7aa366a13f4f).(index, level,
5103 block);
5104 }
5105 }
5106 } else {
5107 err = DB_CORRUPTIONcxx . . $ DB_CORRUPTION.;
5108 }
5109 }
5110
5111 node_ptr_fails:
5112 /* Commit the mini-transaction to release the latch on 'page'.
5113 Re-acquire the latch on right_page, which will become 'page'
5114 on the next loop. The page has already been checked. */
5115 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
5116
5117 if (trx_is_interruptedcxx . . $ trx_is_interrupted(823690d58da80358).(trx)) {
5118 /* On interrupt, return the current status. */
5119 } else if (right_page_no != FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
5120
5121 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
5122
5123 block = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*index, right_page_no, RW_SX_LATCHcxx . . $ RW_SX_LATCH.,
5124 &mtr, &err);
5125 goto loop;
5126 }
5127
5128 goto func_exit;
5129 }
5130
5131 /**************************************************************//**
5132 Checks the consistency of an index tree.
5133 @return DB_SUCCESS if ok, error code if not */
5134 dberr_tcxx . . $ dberr_t#
5135 btr_validate_indexcxx . . $ btr_validate_index(755a948055ab7b2f).(
5136 /*===============*/
5137 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
5138 trx_tcxx . . $ trx_t#* trx) /*!< in: transaction */
5139 {
5140 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{trx};
5141 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
5142
5143 mtr_x_lock_indexcxx . . $ `storage/innobase/include/mtr0mtr.h:46:10`!(index, &mtr);
5144
5145 dberr_tcxx . . $ dberr_t# err;
5146 if (page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *root= btr_root_getcxx . . $ btr_root_get(a67aff4a3674617f).(index, &mtr, &err))
5147 for (auto level= btr_page_get_levelcxx . . $ btr_page_get_level(469dcb4e54b221a8).(root);; level--)
5148 {
5149 if (dberr_tcxx . . $ dberr_t# err_level= btr_validate_levelcxx . . $ btr_validate_level(c7aae675deeef3b).(index, trx, level))
5150 err= err_level;
5151 if (!level)
5152 break;
5153 }
5154
5155 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
5156 return err;
5157 }
5158
5159 /**************************************************************//**
5160 Checks if the page in the cursor can be merged with given page.
5161 If necessary, re-organize the merge_page.
5162 @return true if possible to merge. */
5163 static
5164 bool
5165 btr_can_merge_with_pagecxx . . $ btr_can_merge_with_page(68fe3ccd9ccd8e70).(
5166 /*====================*/
5167 btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: cursor on the page to merge */
5168 uint32_tcxx . . $ uint32_t# page_no, /*!< in: a sibling page */
5169 buf_block_tcxx . . $ buf_block_t#** merge_block, /*!< out: the merge block */
5170 mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mini-transaction */
5171 {
5172 dict_index_tcxx . . $ dict_index_t#* index;
5173 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* page;
5174 ulintcxx . . $ ulint# n_recs;
5175 ulintcxx . . $ ulint# data_size;
5176 ulintcxx . . $ ulint# max_ins_size_reorg;
5177 ulintcxx . . $ ulint# max_ins_size;
5178 buf_block_tcxx . . $ buf_block_t#* mblock;
5179 page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`!* mpage;
5180 DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("btr_can_merge_with_page");
5181
5182 if (page_no == FIL_NULLcxx . . $ `storage/innobase/include/fil0fil.h:1175:9`!) {
5183 error:
5184 *merge_block = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
5185 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(false);
5186 }
5187
5188 index = btr_cur_get_indexcxx . . $ `storage/innobase/include/btr0cur.h:82:9`!(cursor);
5189 page = btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor);
5190
5191 mblock = btr_block_getcxx . . $ btr_block_get(fa2ba45a54fcd0c4).(*index, page_no, RW_X_LATCHcxx . . $ RW_X_LATCH., mtr);
5192 if (!mblock) {
5193 goto error;
5194 }
5195 mpage = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(mblock);
5196
5197 n_recs = page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(page);
5198 data_size = page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(page);
5199
5200 max_ins_size_reorg = page_get_max_insert_size_after_reorganizecxx . . $ page_get_max_insert_size_after_reorganize(4adc7973d4c4f159).(
5201 mpage, n_recs);
5202
5203 if (data_size > max_ins_size_reorg) {
5204 goto error;
5205 }
5206
5207 /* If compression padding tells us that merging will result in
5208 too packed up page i.e.: which is likely to cause compression
5209 failure then don't merge the pages. */
5210 if (mblock->pagecxx . . $ buf_block_t#page..zipcxx . . $ buf_page_t#zip..datacxx . . $ page_zip_des_t#data. && page_is_leafcxx . . $ page_is_leaf(190063cf6fb4afb1).(mpage)
5211 && (page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(mpage) + data_size
5212 >= dict_index_zip_pad_optimal_page_sizecxx . . $ dict_index_zip_pad_optimal_page_size(2e6d4b3eeae69f8c).(index))) {
5213
5214 goto error;
5215 }
5216
5217 max_ins_size = page_get_max_insert_sizecxx . . $ page_get_max_insert_size(4adc7973d4c4f159).(mpage, n_recs);
5218
5219 if (data_size > max_ins_size) {
5220 /* We have to reorganize mpage */
5221 if (btr_page_reorganize_blockcxx . . $ btr_page_reorganize_block(b7f2450dfd4d62c3).(page_zip_levelcxx . . $ page_zip_level., mblock, index,
5222 mtr) != DB_SUCCESScxx . . $ DB_SUCCESS.) {
5223 goto error;
5224 }
5225
5226 max_ins_size = page_get_max_insert_sizecxx . . $ page_get_max_insert_size(4adc7973d4c4f159).(mpage, n_recs);
5227
5228 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(page_validate(mpage, index));
5229 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(max_ins_size == max_ins_size_reorg);
5230
5231 if (data_size > max_ins_size) {
5232
5233 /* Add fault tolerance, though this should
5234 never happen */
5235
5236 goto error;
5237 }
5238 }
5239
5240 *merge_block = mblock;
5241 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(true);
5242 }