Debian Codegraph @

storage/innobase/lock/lock0prdt.cc

raw symbols SCIP
1 /*****************************************************************************
2
3 Copyright (c) 2014, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2018, 2022, MariaDB Corporation.
5
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17
18 *****************************************************************************/
19
20 /**************************************************//**
21 @file lock/lock0prdt.cc
22 The transaction lock system
23
24 Created 9/7/2013 Jimmy Yang
25 *******************************************************/
26
27 #define LOCK_MODULE_IMPLEMENTATIONcxx . . $ `storage/innobase/lock/lock0prdt.cc:27:9`!
28
29 #include "lock0lock.h"cxx . . $ `<file>/storage/innobase/include/lock0lock.h`/
30 #include "lock0priv.h"cxx . . $ `<file>/storage/innobase/include/lock0priv.h`/
31 #include "lock0prdt.h"cxx . . $ `<file>/storage/innobase/include/lock0prdt.h`/
32 #include "dict0mem.h"cxx . . $ `<file>/storage/innobase/include/dict0mem.h`/
33 #include "que0que.h"cxx . . $ `<file>/storage/innobase/include/que0que.h`/
34
35 /*********************************************************************//**
36 Get a minimum bounding box from a Predicate
37 @return the minimum bounding box */
38 UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`!
39 rtr_mbr_tcxx . . $ rtr_mbr_t#*
40 prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(
41 /*===================*/
42 const lock_prdt_tcxx . . $ lock_prdt_t#* prdt) /*!< in: the lock predicate */
43 {
44 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr_loc = reinterpret_cast<rtr_mbr_tcxx . . $ rtr_mbr_t#*>(prdt->datacxx . . $ lock_prdt#data.);
45
46 return(mbr_loc);
47 }
48
49 /*********************************************************************//**
50 Get a predicate from a lock
51 @return the predicate */
52 lock_prdt_tcxx . . $ lock_prdt_t#*
53 lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(
54 /*====================*/
55 const lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock) /*!< in: the lock */
56 {
57 lock_prdt_tcxx . . $ lock_prdt_t#* prdt = reinterpret_cast<lock_prdt_tcxx . . $ lock_prdt_t#*>(
58 &((reinterpret_cast<bytecxx . . $ byte#*>(
59 const_cast<lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!*>(&lock[1])))[
60 UNIV_WORD_SIZEcxx . . $ `storage/innobase/include/univ.i:170:9`!]));
61
62 return(prdt);
63 }
64
65 /*********************************************************************//**
66 Get a minimum bounding box directly from a lock
67 @return the minimum bounding box*/
68 UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`!
69 rtr_mbr_tcxx . . $ rtr_mbr_t#*
70 lock_prdt_get_mbr_from_lockcxx . . $ lock_prdt_get_mbr_from_lock(6025620dc0d5b53d).(
71 /*========================*/
72 const lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock) /*!< in: the lock */
73 {
74 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->type_mode & LOCK_PREDICATE);
75
76 lock_prdt_tcxx . . $ lock_prdt_t#* prdt = lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock);
77
78 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr_loc = prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt);
79
80 return(mbr_loc);
81 }
82
83 /*********************************************************************//**
84 Append a predicate to the lock */
85 void
86 lock_prdt_set_prdtcxx . . $ lock_prdt_set_prdt(26ac1b827b09f645).(
87 /*===============*/
88 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock, /*!< in: lock */
89 const lock_prdt_tcxx . . $ lock_prdt_t#* prdt) /*!< in: Predicate */
90 {
91 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->type_mode & LOCK_PREDICATE);
92
93 memcpy(&(((bytecxx . . $ byte#*) &lock[1])[UNIV_WORD_SIZEcxx . . $ `storage/innobase/include/univ.i:170:9`!]), prdt, sizeof *prdt);
94 }
95
96
97 /** Check whether two predicate locks are compatible with each other
98 @param[in] prdt1 first predicate lock
99 @param[in] prdt2 second predicate lock
100 @param[in] op predicate comparison operator
101 @return true if consistent */
102 static
103 bool
104 lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(
105 lock_prdt_tcxx . . $ lock_prdt_t#* prdt1,
106 lock_prdt_tcxx . . $ lock_prdt_t#* prdt2,
107 ulintcxx . . $ ulint# op)
108 {
109 bool ret = false;
110 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr1 = prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt1);
111 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr2 = prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt2);
112 ulintcxx . . $ ulint# action;
113
114 if (op) {
115 action = op;
116 } else {
117 if (prdt2->opcxx . . $ lock_prdt#op. != 0 && (prdt1->opcxx . . $ lock_prdt#op. != prdt2->opcxx . . $ lock_prdt#op.)) {
118 return(false);
119 }
120
121 action = prdt1->opcxx . . $ lock_prdt#op.;
122 }
123
124 switch (action) {
125 case PAGE_CUR_CONTAINcxx . . $ PAGE_CUR_CONTAIN.:
126 ret = MBR_CONTAIN_CMPcxx . . $ `storage/innobase/include/gis0rtree.h:34:9`!(mbr1, mbr2);
127 break;
128 case PAGE_CUR_DISJOINTcxx . . $ PAGE_CUR_DISJOINT.:
129 ret = MBR_DISJOINT_CMPcxx . . $ `storage/innobase/include/gis0rtree.h:49:9`!(mbr1, mbr2);
130 break;
131 case PAGE_CUR_MBR_EQUALcxx . . $ PAGE_CUR_MBR_EQUAL.:
132 ret = MBR_EQUAL_CMPcxx . . $ `storage/innobase/include/gis0rtree.h:39:9`!(mbr1, mbr2);
133 break;
134 case PAGE_CUR_INTERSECTcxx . . $ PAGE_CUR_INTERSECT.:
135 ret = MBR_INTERSECT_CMPcxx . . $ `storage/innobase/include/gis0rtree.h:44:9`!(mbr1, mbr2);
136 break;
137 case PAGE_CUR_WITHINcxx . . $ PAGE_CUR_WITHIN.:
138 ret = MBR_WITHIN_CMPcxx . . $ `storage/innobase/include/gis0rtree.h:52:9`!(mbr1, mbr2);
139 break;
140 default:
141 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "invalid operator " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). action;
142 ut_errorcxx . . $ `storage/innobase/include/ut0dbg.h:58:9`!;
143 }
144
145 return(ret);
146 }
147
148 /*********************************************************************//**
149 Checks if a predicate lock request for a new lock has to wait for
150 another lock.
151 @return true if new lock has to wait for lock2 to be released */
152 bool
153 lock_prdt_has_to_waitcxx . . $ lock_prdt_has_to_wait(b2d164b7100a319d).(
154 /*==================*/
155 const trx_tcxx . . $ trx_t#* trx, /*!< in: trx of new lock */
156 unsigned type_mode,/*!< in: precise mode of the new lock
157 to set: LOCK_S or LOCK_X, possibly
158 ORed to LOCK_PREDICATE or LOCK_PRDT_PAGE,
159 LOCK_INSERT_INTENTION */
160 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: lock predicate to check */
161 const lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock2) /*!< in: another record lock; NOTE that
162 it is assumed that this has a lock bit
163 set on the same record as in the new
164 lock we are setting */
165 {
166 lock_prdt_tcxx . . $ lock_prdt_t#* cur_prdt = lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock2);
167
168 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx && lock2);
169 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!((lock2->type_mode & LOCK_PREDICATE && type_mode & LOCK_PREDICATE)
170 || (lock2->type_mode & LOCK_PRDT_PAGE
171 && type_mode & LOCK_PRDT_PAGE));
172
173 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE));
174
175 if (trx != lock2->trxcxx . . $ ib_lock_t#trx.
176 && !lock_mode_compatiblecxx . . $ lock_mode_compatible(c82248f4ca60b5cf).(static_cast<lock_modecxx . . $ lock_mode#>(
177 LOCK_MODE_MASKcxx . . $ `storage/innobase/include/lock0types.h:98:9`! & type_mode),
178 lock2->modecxx . . $ ib_lock_t#mode(263b2d13effa90cd).())) {
179
180 /* If it is a page lock, then return true (conflict) */
181 if (type_mode & LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!) {
182 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock2->type_mode & LOCK_PRDT_PAGE);
183
184 return(true);
185 }
186
187 /* Predicate lock does not conflicts with non-predicate lock */
188 if (!(lock2->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!)) {
189 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
190 }
191
192 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock2->type_mode & LOCK_PREDICATE);
193
194 if (!(type_mode & LOCK_INSERT_INTENTIONcxx . . $ `storage/innobase/include/lock0types.h:128:9`!)) {
195 /* PREDICATE locks without LOCK_INSERT_INTENTION flag
196 do not need to wait for anything. This is because
197 different users can have conflicting lock types
198 on predicates. */
199
200 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
201 }
202
203 if (lock2->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_INSERT_INTENTIONcxx . . $ `storage/innobase/include/lock0types.h:128:9`!) {
204
205 /* No lock request needs to wait for an insert
206 intention lock to be removed. This makes it similar
207 to GAP lock, that allows conflicting insert intention
208 locks */
209 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
210 }
211
212 if (!lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(cur_prdt, prdt, 0)) {
213 return(false);
214 }
215
216 return(TRUEcxx . . $ `include/my_global.h:476:9`!);
217 }
218
219 return(FALSEcxx . . $ `include/my_global.h:477:9`!);
220 }
221
222 /*********************************************************************//**
223 Checks if a transaction has a GRANTED stronger or equal predicate lock
224 on the page
225 @return lock or NULL */
226 UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`!
227 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!*
228 lock_prdt_has_lockcxx . . $ lock_prdt_has_lock(e3a7eaa3ee58a04b).(
229 /*===============*/
230 ulintcxx . . $ ulint# precise_mode, /*!< in: LOCK_S or LOCK_X */
231 hash_cell_tcxx . . $ hash_cell_t#& cell, /*!< hash table cell of id */
232 const page_id_tcxx . . $ page_id_t# id, /*!< in: page identifier */
233 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: The predicate to be
234 attached to the new lock */
235 const trx_tcxx . . $ trx_t#* trx) /*!< in: transaction */
236 {
237 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!((precise_mode & LOCK_MODE_MASK) == LOCK_S
238 || (precise_mode & LOCK_MODE_MASK) == LOCK_X);
239 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(precise_mode & LOCK_INSERT_INTENTION));
240
241 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!*lock= lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(dcee157701c9d3e2).(cell, id, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!);
242 lock;
243 lock = lock_rec_get_nextcxx . . $ lock_rec_get_next(6852bb7d1cb225dd).(PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!, lock)) {
244 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE));
245
246 if (lock->trxcxx . . $ ib_lock_t#trx. == trx
247 && !(lock->type_modecxx . . $ ib_lock_t#type_mode. & (LOCK_INSERT_INTENTIONcxx . . $ `storage/innobase/include/lock0types.h:128:9`! | LOCK_WAITcxx . . $ `storage/innobase/include/lock0types.h:105:9`!))
248 && lock_mode_stronger_or_eqcxx . . $ lock_mode_stronger_or_eq(c82248f4ca60b5cf).(
249 lock->modecxx . . $ ib_lock_t#mode(263b2d13effa90cd).(),
250 static_cast<lock_modecxx . . $ lock_mode#>(
251 precise_mode & LOCK_MODE_MASKcxx . . $ `storage/innobase/include/lock0types.h:98:9`!))) {
252 if (lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!) {
253 return(lock);
254 }
255
256 lock_prdt_tcxx . . $ lock_prdt_t#* cur_prdt = lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(
257 lock);
258
259 /* if the lock predicate operator is the same
260 as the one to look, and prdicate test is successful,
261 then we find a lock */
262 if (cur_prdt->opcxx . . $ lock_prdt#op. == prdt->opcxx . . $ lock_prdt#op.
263 && lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(cur_prdt, prdt, 0)) {
264
265 return(lock);
266 }
267 }
268 }
269
270 return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
271 }
272
273 /*********************************************************************//**
274 Checks if some other transaction has a conflicting predicate
275 lock request in the queue, so that we have to wait.
276 @return lock or NULL */
277 static
278 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!*
279 lock_prdt_other_has_conflictingcxx . . $ lock_prdt_other_has_conflicting(4957ecd038a0fa59).(
280 /*============================*/
281 unsigned mode, /*!< in: LOCK_S or LOCK_X,
282 possibly ORed to LOCK_PREDICATE or
283 LOCK_PRDT_PAGE, LOCK_INSERT_INTENTION */
284 const hash_cell_tcxx . . $ hash_cell_t#& cell, /*!< in: hash table cell */
285 const page_id_tcxx . . $ page_id_t# id, /*!< in: page identifier */
286 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: Predicates (currently)
287 the Minimum Bounding Rectangle)
288 the new lock will be on */
289 const trx_tcxx . . $ trx_t#* trx) /*!< in: our transaction */
290 {
291 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(dcee157701c9d3e2).(cell, id, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!);
292 lock != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
293 lock = lock_rec_get_nextcxx . . $ lock_rec_get_next(6852bb7d1cb225dd).(PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!, lock)) {
294
295 if (lock->trxcxx . . $ ib_lock_t#trx. == trx) {
296 continue;
297 }
298
299 if (lock_prdt_has_to_waitcxx . . $ lock_prdt_has_to_wait(b2d164b7100a319d).(trx, mode, prdt, lock)) {
300 return(lock);
301 }
302 }
303
304 return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
305 }
306
307 /*********************************************************************//**
308 Reset the Minimum Bounding Rectangle (to a large area) */
309 static
310 void
311 lock_prdt_enlarge_mbrcxx . . $ lock_prdt_enlarge_mbr(9b078c2f8e7b3145).(
312 /*==================*/
313 const lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock, /*!< in/out: lock to modify */
314 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr) /*!< in: Minimum Bounding Rectangle */
315 {
316 rtr_mbr_tcxx . . $ rtr_mbr_t#* cur_mbr = lock_prdt_get_mbr_from_lockcxx . . $ lock_prdt_get_mbr_from_lock(6025620dc0d5b53d).(lock);
317
318 if (cur_mbr->xmincxx . . $ rtr_mbr#xmin. > mbr->xmincxx . . $ rtr_mbr#xmin.) {
319 cur_mbr->xmincxx . . $ rtr_mbr#xmin. = mbr->xmincxx . . $ rtr_mbr#xmin.;
320 }
321
322 if (cur_mbr->ymincxx . . $ rtr_mbr#ymin. > mbr->ymincxx . . $ rtr_mbr#ymin.) {
323 cur_mbr->ymincxx . . $ rtr_mbr#ymin. = mbr->ymincxx . . $ rtr_mbr#ymin.;
324 }
325
326 if (cur_mbr->xmaxcxx . . $ rtr_mbr#xmax. < mbr->xmaxcxx . . $ rtr_mbr#xmax.) {
327 cur_mbr->xmaxcxx . . $ rtr_mbr#xmax. = mbr->xmaxcxx . . $ rtr_mbr#xmax.;
328 }
329
330 if (cur_mbr->ymaxcxx . . $ rtr_mbr#ymax. < mbr->ymaxcxx . . $ rtr_mbr#ymax.) {
331 cur_mbr->ymaxcxx . . $ rtr_mbr#ymax. = mbr->ymaxcxx . . $ rtr_mbr#ymax.;
332 }
333 }
334
335 /*********************************************************************//**
336 Reset the predicates to a "covering" (larger) predicates */
337 static
338 void
339 lock_prdt_enlarge_prdtcxx . . $ lock_prdt_enlarge_prdt(83110ba9d90a6f64).(
340 /*===================*/
341 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock, /*!< in/out: lock to modify */
342 lock_prdt_tcxx . . $ lock_prdt_t#* prdt) /*!< in: predicate */
343 {
344 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr = prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt);
345
346 lock_prdt_enlarge_mbrcxx . . $ lock_prdt_enlarge_mbr(9b078c2f8e7b3145).(lock, mbr);
347 }
348
349 /*********************************************************************//**
350 Check two predicates' MBRs are the same
351 @return true if they are the same */
352 static
353 bool
354 lock_prdt_is_samecxx . . $ lock_prdt_is_same(c91b72857693cfe6).(
355 /*==============*/
356 lock_prdt_tcxx . . $ lock_prdt_t#* prdt1, /*!< in: MBR with the lock */
357 lock_prdt_tcxx . . $ lock_prdt_t#* prdt2) /*!< in: MBR with the lock */
358 {
359 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr1 = prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt1);
360 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr2 = prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt2);
361
362 if (prdt1->opcxx . . $ lock_prdt#op. == prdt2->opcxx . . $ lock_prdt#op. && MBR_EQUAL_CMPcxx . . $ `storage/innobase/include/gis0rtree.h:39:9`!(mbr1, mbr2)) {
363 return(true);
364 }
365
366 return(false);
367 }
368
369 /*********************************************************************//**
370 Looks for a similar predicate lock struct by the same trx on the same page.
371 This can be used to save space when a new record lock should be set on a page:
372 no new struct is needed, if a suitable old one is found.
373 @return lock or NULL */
374 static
375 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!*
376 lock_prdt_find_on_pagecxx . . $ lock_prdt_find_on_page(8f9c636b8505c802).(
377 /*===================*/
378 unsigned type_mode, /*!< in: lock type_mode field */
379 const buf_block_tcxx . . $ buf_block_t#* block, /*!< in: buffer block */
380 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: MBR with the lock */
381 const trx_tcxx . . $ trx_t#* trx) /*!< in: transaction */
382 {
383 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
384 hash_cell_tcxx . . $ hash_cell_t#& cell = *lock_syscxx . . $ lock_sys..hash_getcxx . . $ lock_sys_t#hash_get(a75e325ba1d746ac).(type_mode).cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(id.foldcxx . . $ page_id_t#fold(c9b1e749b64d5edc).());
385
386 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(cell, id);
387 lock != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
388 lock = lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock)) {
389
390 if (lock->trxcxx . . $ ib_lock_t#trx. == trx
391 && lock->type_modecxx . . $ ib_lock_t#type_mode. == type_mode) {
392 if (lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!) {
393 return(lock);
394 }
395
396 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->type_mode & LOCK_PREDICATE);
397
398 if (lock_prdt_is_samecxx . . $ lock_prdt_is_same(c91b72857693cfe6).(lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock),
399 prdt)) {
400 return(lock);
401 }
402 }
403 }
404
405 return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
406 }
407
408 /*********************************************************************//**
409 Adds a predicate lock request in the predicate lock queue.
410 @return lock where the bit was set */
411 static
412 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!*
413 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(
414 /*===================*/
415 unsigned type_mode,/*!< in: lock mode, wait, predicate
416 etc. flags */
417 const buf_block_tcxx . . $ buf_block_t#* block, /*!< in: buffer block containing
418 the record */
419 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index of record */
420 trx_tcxx . . $ trx_t#* trx, /*!< in/out: transaction */
421 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: Minimum Bounding Rectangle
422 the new lock will be on */
423 bool caller_owns_trx_mutex)
424 /*!< in: TRUE if caller owns the
425 transaction mutex */
426 {
427 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(caller_owns_trx_mutex == trx->mutex_is_owner());
428 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->is_spatial());
429 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_online_ddl(index));
430 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE));
431
432 #ifdef UNIV_DEBUG
433 switch (type_mode & LOCK_MODE_MASK) {
434 case LOCK_X:
435 case LOCK_S:
436 break;
437 default:
438 ut_error;
439 }
440 #endif /* UNIV_DEBUG */
441
442 /* Try to extend a similar non-waiting lock on the same page */
443 if (!(type_mode & LOCK_WAITcxx . . $ `storage/innobase/include/lock0types.h:105:9`!)) {
444 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
445 hash_cell_tcxx . . $ hash_cell_t#& cell = *lock_syscxx . . $ lock_sys..hash_getcxx . . $ lock_sys_t#hash_get(a75e325ba1d746ac).(type_mode).
446 cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(id.foldcxx . . $ page_id_t#fold(c9b1e749b64d5edc).());
447
448 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(cell, id);
449 lock; lock = lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock)) {
450 if (lock->is_waitingcxx . . $ ib_lock_t#is_waiting(50ce9a9e25b4a850).()
451 && lock->type_modecxx . . $ ib_lock_t#type_mode.
452 & (LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`! | LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!)
453 && lock_rec_get_nth_bitcxx . . $ lock_rec_get_nth_bit(bf2a6642c42151f9).(lock, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!)) {
454 goto create;
455 }
456 }
457
458 if (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_prdt_find_on_pagecxx . . $ lock_prdt_find_on_page(8f9c636b8505c802).(type_mode, block,
459 prdt, trx)) {
460 if (lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!) {
461 lock_prdt_enlarge_prdtcxx . . $ lock_prdt_enlarge_prdt(83110ba9d90a6f64).(lock, prdt);
462 }
463
464 return lock;
465 }
466 }
467
468 create:
469 /* Note: We will not pass any conflicting lock to lock_rec_create(),
470 because we should be moving an existing waiting lock request. */
471 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(type_mode & LOCK_WAIT) || trx->lock.wait_trx);
472
473 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_rec_createcxx . . $ lock_rec_create(ef90dfa3f073ed41).(null_c_lock_infocxx . . $ null_c_lock_info.,
474 type_mode, block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).(),
475 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!, index,
476 trx, caller_owns_trx_mutex);
477
478 if (lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!) {
479 lock_prdt_set_prdtcxx . . $ lock_prdt_set_prdt(26ac1b827b09f645).(lock, prdt);
480 }
481
482 return lock;
483 }
484
485 /*********************************************************************//**
486 Checks if locks of other transactions prevent an immediate insert of
487 a predicate record.
488 @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
489 dberr_tcxx . . $ dberr_t#
490 lock_prdt_insert_check_and_lockcxx . . $ lock_prdt_insert_check_and_lock(6c2e87ea42d4d2cd).(
491 /*============================*/
492 const rec_tcxx . . $ rec_t#* rec, /*!< in: record after which to insert */
493 buf_block_tcxx . . $ buf_block_t#* block, /*!< in/out: buffer block of rec */
494 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */
495 que_thr_tcxx . . $ que_thr_t#* thr, /*!< in: query thread */
496 mtr_tcxx . . $ mtr_t#* mtr, /*!< in/out: mini-transaction */
497 lock_prdt_tcxx . . $ lock_prdt_t#* prdt) /*!< in: Predicates with Minimum Bound
498 Rectangle */
499 {
500 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(block->page.frame == page_align(rec));
501 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!index->table->is_temporary());
502 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->is_spatial());
503
504 trx_tcxx . . $ trx_t# *trx= thr_get_trxcxx . . $ thr_get_trx(bce191eb970ff2ca).(thr);
505 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
506 dberr_tcxx . . $ dberr_t# err= DB_SUCCESScxx . . $ DB_SUCCESS.;
507
508 {
509 LockGuardcxx . . $ LockGuard# gcxx . . $ LockGuard#LockGuard(ae2ccc82fd3f398d).{lock_syscxx . . $ lock_sys..prdt_hashcxx . . $ lock_sys_t#prdt_hash., id};
510 /* Because this code is invoked for a running transaction by
511 the thread that is serving the transaction, it is not necessary
512 to hold trx->mutex here. */
513 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock_table_has(trx, index->table, LOCK_IX));
514
515 /* Only need to check locks on prdt_hash */
516 if (ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(lock_t *lock=) lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(dcee157701c9d3e2).(g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), id, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!))
517 {
518 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->type_mode & LOCK_PREDICATE);
519
520 /* If another transaction has an explicit lock request which locks
521 the predicate, waiting or granted, on the successor, the insert
522 has to wait.
523
524 Similar to GAP lock, we do not consider lock from inserts conflicts
525 with each other */
526
527 const ulintcxx . . $ ulint# mode= LOCK_Xcxx . . $ LOCK_X. | LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`! | LOCK_INSERT_INTENTIONcxx . . $ `storage/innobase/include/lock0types.h:128:9`!;
528 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *c_lock= lock_prdt_other_has_conflictingcxx . . $ lock_prdt_other_has_conflicting(4957ecd038a0fa59).(mode, g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), id,
529 prdt, trx);
530
531 if (c_lock)
532 {
533 rtr_mbr_tcxx . . $ rtr_mbr_t# *mbr= prdt_get_mbr_from_prdtcxx . . $ prdt_get_mbr_from_prdt(c057aa729eed45bd).(prdt);
534 trx->mutex_lockcxx . . $ trx_t#mutex_lock(49f6e7a06ebc5aa8).();
535 /* Allocate MBR on the lock heap */
536 lock_init_prdt_from_mbrcxx . . $ lock_init_prdt_from_mbr(784f7963ebb2c1ff).(prdt, mbr, 0, trx->lockcxx . . $ trx_t#lock..lock_heapcxx . . $ trx_lock_t#lock_heap.);
537 err= lock_rec_enqueue_waitingcxx . . $ lock_rec_enqueue_waiting(9e7291d1e58569c8).({c_lock, nullptr, ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(nullptr)}, mode, id,
538 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!, index,
539 thr, prdt);
540 trx->mutex_unlockcxx . . $ trx_t#mutex_unlock(49f6e7a06ebc5aa8).();
541 }
542 }
543 }
544
545 if (err == DB_SUCCESScxx . . $ DB_SUCCESS.)
546 /* Update the page max trx id field */
547 page_update_max_trx_idcxx . . $ page_update_max_trx_id(7ff4fec4cd653b55).(block, buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(block), trx->idcxx . . $ trx_t#id., mtr);
548
549 return err;
550 }
551
552 /**************************************************************//**
553 Check whether any predicate lock in parent needs to propagate to
554 child page after split. */
555 void
556 lock_prdt_update_parentcxx . . $ lock_prdt_update_parent(396433af0f73aa2c).(
557 /*====================*/
558 buf_block_tcxx . . $ buf_block_t#* left_block, /*!< in/out: page to be split */
559 buf_block_tcxx . . $ buf_block_t#* right_block, /*!< in/out: the new half page */
560 lock_prdt_tcxx . . $ lock_prdt_t#* left_prdt, /*!< in: MBR on the old page */
561 lock_prdt_tcxx . . $ lock_prdt_t#* right_prdt, /*!< in: MBR on the new page */
562 const page_id_tcxx . . $ page_id_t# page_id) /*!< in: parent page */
563 {
564 auto fold= page_id.foldcxx . . $ page_id_t#fold(c9b1e749b64d5edc).();
565 LockMutexGuardcxx . . $ LockMutexGuard# gcxx . . $ LockMutexGuard#LockMutexGuard(b51963283f2467a4).{SRW_LOCK_CALLcxx . . $ `storage/innobase/include/srw_lock.h:44:10`!};
566 hash_cell_tcxx . . $ hash_cell_t#& cell = *lock_syscxx . . $ lock_sys..prdt_hashcxx . . $ lock_sys_t#prdt_hash..cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(fold);
567
568 /* Get all locks in parent */
569 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(cell, page_id);
570 lock;
571 lock = lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock)) {
572 lock_prdt_tcxx . . $ lock_prdt_t#* lock_prdt;
573 ulintcxx . . $ ulint# op = PAGE_CUR_DISJOINTcxx . . $ PAGE_CUR_DISJOINT.;
574
575 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock);
576
577 if (!(lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!)
578 || (lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_MODE_MASKcxx . . $ `storage/innobase/include/lock0types.h:98:9`!) == LOCK_Xcxx . . $ LOCK_X.) {
579 continue;
580 }
581
582 lock_prdt = lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock);
583
584 /* Check each lock in parent to see if it intersects with
585 left or right child */
586 if (!lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(lock_prdt, left_prdt, op)
587 && !lock_prdt_find_on_pagecxx . . $ lock_prdt_find_on_page(8f9c636b8505c802).(lock->type_modecxx . . $ ib_lock_t#type_mode., left_block,
588 lock_prdt, lock->trxcxx . . $ ib_lock_t#trx.)) {
589 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(lock->type_modecxx . . $ ib_lock_t#type_mode.,
590 left_block, lock->indexcxx . . $ ib_lock_t#index.,
591 lock->trxcxx . . $ ib_lock_t#trx., lock_prdt,
592 false);
593 }
594
595 if (!lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(lock_prdt, right_prdt, op)
596 && !lock_prdt_find_on_pagecxx . . $ lock_prdt_find_on_page(8f9c636b8505c802).(lock->type_modecxx . . $ ib_lock_t#type_mode., right_block,
597 lock_prdt, lock->trxcxx . . $ ib_lock_t#trx.)) {
598 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(lock->type_modecxx . . $ ib_lock_t#type_mode., right_block,
599 lock->indexcxx . . $ ib_lock_t#index., lock->trxcxx . . $ ib_lock_t#trx.,
600 lock_prdt, false);
601 }
602 }
603 }
604
605 /**************************************************************//**
606 Update predicate lock when page splits */
607 static
608 void
609 lock_prdt_update_split_lowcxx . . $ lock_prdt_update_split_low(e40097c0c02ef57a).(
610 /*=======================*/
611 buf_block_tcxx . . $ buf_block_t#* new_block, /*!< in/out: the new half page */
612 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: MBR on the old page */
613 lock_prdt_tcxx . . $ lock_prdt_t#* new_prdt, /*!< in: MBR on the new page */
614 const page_id_tcxx . . $ page_id_t# id, /*!< in: page number */
615 unsigned type_mode) /*!< in: LOCK_PREDICATE or
616 LOCK_PRDT_PAGE */
617 {
618 hash_cell_tcxx . . $ hash_cell_t#& cell = *lock_syscxx . . $ lock_sys..hash_getcxx . . $ lock_sys_t#hash_get(a75e325ba1d746ac).(type_mode).cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(id.foldcxx . . $ page_id_t#fold(c9b1e749b64d5edc).());
619
620 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(cell, id);
621 lock;
622 lock = lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock)) {
623 /* First dealing with Page Lock */
624 if (lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!) {
625 /* Duplicate the lock to new page */
626 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(lock->type_modecxx . . $ ib_lock_t#type_mode.,
627 new_block,
628 lock->indexcxx . . $ ib_lock_t#index.,
629 lock->trxcxx . . $ ib_lock_t#trx., nullptr, false);
630 continue;
631 }
632
633 /* Now dealing with Predicate Lock */
634 lock_prdt_tcxx . . $ lock_prdt_t#* lock_prdt;
635 ulintcxx . . $ ulint# op = PAGE_CUR_DISJOINTcxx . . $ PAGE_CUR_DISJOINT.;
636
637 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->type_mode & LOCK_PREDICATE);
638
639 /* No need to duplicate waiting X locks */
640 if ((lock->type_modecxx . . $ ib_lock_t#type_mode. & LOCK_MODE_MASKcxx . . $ `storage/innobase/include/lock0types.h:98:9`!) == LOCK_Xcxx . . $ LOCK_X.) {
641 continue;
642 }
643
644 lock_prdt = lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock);
645
646 if (!lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(lock_prdt, new_prdt, op)) {
647 /* Move the lock to new page */
648 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(lock->type_modecxx . . $ ib_lock_t#type_mode., new_block,
649 lock->indexcxx . . $ ib_lock_t#index., lock->trxcxx . . $ ib_lock_t#trx.,
650 lock_prdt, false);
651 }
652 }
653 }
654
655 /**************************************************************//**
656 Update predicate lock when page splits */
657 void
658 lock_prdt_update_splitcxx . . $ lock_prdt_update_split(16ce161e4b20edb3).(
659 /*===================*/
660 buf_block_tcxx . . $ buf_block_t#* new_block, /*!< in/out: the new half page */
661 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: MBR on the old page */
662 lock_prdt_tcxx . . $ lock_prdt_t#* new_prdt, /*!< in: MBR on the new page */
663 const page_id_tcxx . . $ page_id_t# page_id) /*!< in: page number */
664 {
665 LockMutexGuardcxx . . $ LockMutexGuard# gcxx . . $ LockMutexGuard#LockMutexGuard(b51963283f2467a4).{SRW_LOCK_CALLcxx . . $ `storage/innobase/include/srw_lock.h:44:10`!};
666 lock_prdt_update_split_lowcxx . . $ lock_prdt_update_split_low(e40097c0c02ef57a).(new_block, prdt, new_prdt,
667 page_id, LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!);
668
669 lock_prdt_update_split_lowcxx . . $ lock_prdt_update_split_low(e40097c0c02ef57a).(new_block, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
670 page_id, LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!);
671 }
672
673 /*********************************************************************//**
674 Initiate a Predicate Lock from a MBR */
675 void
676 lock_init_prdt_from_mbrcxx . . $ lock_init_prdt_from_mbr(784f7963ebb2c1ff).(
677 /*====================*/
678 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in/out: predicate to initialized */
679 rtr_mbr_tcxx . . $ rtr_mbr_t#* mbr, /*!< in: Minimum Bounding Rectangle */
680 ulintcxx . . $ ulint# mode, /*!< in: Search mode */
681 mem_heap_tcxx . . $ mem_heap_t#* heap) /*!< in: heap for allocating memory */
682 {
683 memset(prdt, 0, sizeof(*prdt));
684
685 if (heap != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
686 prdt->datacxx . . $ lock_prdt#data. = mem_heap_dupcxx . . $ mem_heap_dup(4a4c334168a9388d).(heap, mbr, sizeof *mbr);
687 } else {
688 prdt->datacxx . . $ lock_prdt#data. = static_cast<void*>(mbr);
689 }
690
691 prdt->opcxx . . $ lock_prdt#op. = static_cast<uint16cxx . . $ uint16#>(mode);
692 }
693
694 /*********************************************************************//**
695 Acquire a predicate lock on a block
696 @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
697 dberr_tcxx . . $ dberr_t#
698 lock_prdt_lockcxx . . $ lock_prdt_lock(5c1ebed45a9ad6a3).(
699 /*===========*/
700 buf_block_tcxx . . $ buf_block_t#* block, /*!< in/out: buffer block of rec */
701 lock_prdt_tcxx . . $ lock_prdt_t#* prdt, /*!< in: Predicate for the lock */
702 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: secondary index */
703 lock_modecxx . . $ lock_mode# mode, /*!< in: mode of the lock which
704 the read cursor should set on
705 records: LOCK_S or LOCK_X; the
706 latter is possible in
707 SELECT FOR UPDATE */
708 unsigned type_mode,
709 /*!< in: LOCK_PREDICATE or LOCK_PRDT_PAGE */
710 que_thr_tcxx . . $ que_thr_t#* thr) /*!< in: query thread
711 (can be NULL if BTR_NO_LOCKING_FLAG) */
712 {
713 trx_tcxx . . $ trx_t#* trx = thr_get_trxcxx . . $ thr_get_trx(bce191eb970ff2ca).(thr);
714 dberr_tcxx . . $ dberr_t# err = DB_SUCCESScxx . . $ DB_SUCCESS.;
715 lock_rec_req_statuscxx . . $ lock_rec_req_status# status = LOCK_REC_SUCCESScxx . . $ LOCK_REC_SUCCESS.;
716
717 if (trx->read_onlycxx . . $ trx_t#read_only. || index->tablecxx . . $ dict_index_t#table.->is_temporarycxx . . $ dict_table_t#is_temporary(50ce9a9e25b4a850).()) {
718 return(DB_SUCCESScxx . . $ DB_SUCCESS.);
719 }
720
721 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_clust(index));
722 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_online_ddl(index));
723 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE));
724
725 auto& hash = lock_syscxx . . $ lock_sys..prdt_hash_getcxx . . $ lock_sys_t#prdt_hash_get(2ebead86161f86e).(type_mode != LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!);
726 const page_id_tcxx . . $ page_id_t# id{block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).()};
727
728 /* Another transaction cannot have an implicit lock on the record,
729 because when we come here, we already have modified the clustered
730 index record, and this would not have been possible if another active
731 transaction had modified this secondary index record. */
732
733 LockGuardcxx . . $ LockGuard# gcxx . . $ LockGuard#LockGuard(ae2ccc82fd3f398d).{hash, id};
734
735 const unsigned prdt_mode = type_mode | mode;
736 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), id);
737
738 if (lock == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
739 lock = lock_rec_createcxx . . $ lock_rec_create(ef90dfa3f073ed41).(null_c_lock_infocxx . . $ null_c_lock_info.,
740 prdt_mode, block->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).(),
741 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!, index,
742 trx, FALSEcxx . . $ `include/my_global.h:477:9`!);
743
744 status = LOCK_REC_SUCCESS_CREATEDcxx . . $ LOCK_REC_SUCCESS_CREATED.;
745 } else {
746 if (lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock)
747 || lock->trxcxx . . $ ib_lock_t#trx. != trx
748 || lock->type_modecxx . . $ ib_lock_t#type_mode. != prdt_mode
749 || lock_rec_get_n_bitscxx . . $ lock_rec_get_n_bits(fbdb7f62ea435a77).(lock) == 0
750 || ((type_mode & LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!)
751 && (!lock_prdt_consistentcxx . . $ lock_prdt_consistent(23bdaa1d480d9854).(
752 lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock), prdt, 0)))) {
753 trx->mutex_lockcxx . . $ trx_t#mutex_lock(49f6e7a06ebc5aa8).();
754
755 lock = lock_prdt_has_lockcxx . . $ lock_prdt_has_lock(e3a7eaa3ee58a04b).(
756 mode, g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), id, prdt, trx);
757
758 if (lock) {
759 } else if (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* wait_for
760 = lock_prdt_other_has_conflictingcxx . . $ lock_prdt_other_has_conflicting(4957ecd038a0fa59).(
761 prdt_mode, g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), id, prdt,
762 trx)) {
763 err = lock_rec_enqueue_waitingcxx . . $ lock_rec_enqueue_waiting(9e7291d1e58569c8).(
764 {wait_for, nullptr, ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(nullptr)},
765 prdt_mode, id,
766 block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame., PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!,
767 index, thr, prdt);
768 } else {
769 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(
770 prdt_mode, block, index, trx,
771 prdt, true);
772 }
773
774 trx->mutex_unlockcxx . . $ trx_t#mutex_unlock(49f6e7a06ebc5aa8).();
775 } else {
776 if (!lock_rec_get_nth_bitcxx . . $ lock_rec_get_nth_bit(bf2a6642c42151f9).(lock, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!)) {
777 lock_rec_set_nth_bitcxx . . $ lock_rec_set_nth_bit(c86a3cbe55cf31c6).(lock, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!);
778 status = LOCK_REC_SUCCESS_CREATEDcxx . . $ LOCK_REC_SUCCESS_CREATED.;
779 }
780 }
781 }
782
783 if (status == LOCK_REC_SUCCESS_CREATEDcxx . . $ LOCK_REC_SUCCESS_CREATED. && type_mode == LOCK_PREDICATEcxx . . $ `storage/innobase/include/lock0types.h:136:9`!) {
784 /* Append the predicate in the lock record */
785 lock_prdt_set_prdtcxx . . $ lock_prdt_set_prdt(26ac1b827b09f645).(lock, prdt);
786 }
787
788 return(err);
789 }
790
791 /*********************************************************************//**
792 Acquire a "Page" lock on a block
793 @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
794 dberr_tcxx . . $ dberr_t#
795 lock_place_prdt_page_lockcxx . . $ lock_place_prdt_page_lock(c24ccc96c0f1e7f3).(
796 const page_id_tcxx . . $ page_id_t# page_id, /*!< in: page identifier */
797 dict_index_tcxx . . $ dict_index_t#* index, /*!< in: secondary index */
798 que_thr_tcxx . . $ que_thr_t#* thr) /*!< in: query thread */
799 {
800 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(thr != NULL);
801 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!high_level_read_only);
802
803 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(index->is_spatial());
804 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dict_index_is_online_ddl(index));
805 if (index->tablecxx . . $ dict_index_t#table.->is_temporarycxx . . $ dict_table_t#is_temporary(50ce9a9e25b4a850).()) {
806 return DB_SUCCESScxx . . $ DB_SUCCESS.;
807 }
808
809 /* Another transaction cannot have an implicit lock on the record,
810 because when we come here, we already have modified the clustered
811 index record, and this would not have been possible if another active
812 transaction had modified this secondary index record. */
813
814 LockGuardcxx . . $ LockGuard# gcxx . . $ LockGuard#LockGuard(ae2ccc82fd3f398d).{lock_syscxx . . $ lock_sys..prdt_page_hashcxx . . $ lock_sys_t#prdt_page_hash., page_id};
815
816 const lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`!* lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), page_id);
817 const ulintcxx . . $ ulint# mode = LOCK_Scxx . . $ LOCK_S. | LOCK_PRDT_PAGEcxx . . $ `storage/innobase/include/lock0types.h:137:9`!;
818 trx_tcxx . . $ trx_t#* trx = thr_get_trxcxx . . $ thr_get_trx(bce191eb970ff2ca).(thr);
819
820 if (lock != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
821 /* Find a matching record lock owned by this transaction. */
822
823 while (lock != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! && lock->trxcxx . . $ ib_lock_t#trx. != trx) {
824 lock = lock_rec_get_next_on_page_constcxx . . $ lock_rec_get_next_on_page_const(ae7f4d894c9bb90a).(lock);
825 }
826
827 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock == NULL || lock->type_mode == mode);
828 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock == NULL || lock_rec_get_n_bits(lock) != 0);
829 }
830
831 if (lock == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
832 lock = lock_rec_createcxx . . $ lock_rec_create(ef90dfa3f073ed41).(null_c_lock_infocxx . . $ null_c_lock_info.,
833 mode, page_id, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!,
834 index, trx, FALSEcxx . . $ `include/my_global.h:477:9`!);
835
836 #ifdef PRDT_DIAG
837 printf("GIS_DIAGNOSTIC: page lock %d\n", (int) page_no);
838 #endif /* PRDT_DIAG */
839 }
840
841 return(DB_SUCCESScxx . . $ DB_SUCCESS.);
842 }
843
844 /** Check whether there are R-tree Page lock on a page
845 @param[in] trx trx to test the lock
846 @param[in] page_id page identifier
847 @return true if there is none */
848 bool lock_test_prdt_page_lockcxx . . $ lock_test_prdt_page_lock(d21ec259cc96fe00).(const trx_tcxx . . $ trx_t# *trx, const page_id_tcxx . . $ page_id_t# page_id)
849 {
850 LockGuardcxx . . $ LockGuard# gcxx . . $ LockGuard#LockGuard(ae2ccc82fd3f398d).{lock_syscxx . . $ lock_sys..prdt_page_hashcxx . . $ lock_sys_t#prdt_page_hash., page_id};
851 lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock= lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(g.cellcxx . . $ LockGuard#cell(62c1d4f87430d26b).(), page_id);
852 return !lock || trx == lock->trxcxx . . $ ib_lock_t#trx.;
853 }
854
855 /*************************************************************//**
856 Moves the locks of a page to another page and resets the lock bits of
857 the donating records. */
858 void
859 lock_prdt_rec_movecxx . . $ lock_prdt_rec_move(736e698b6e7ce61a).(
860 /*===============*/
861 const buf_block_tcxx . . $ buf_block_t#* receiver, /*!< in: buffer block containing
862 the receiving record */
863 const page_id_tcxx . . $ page_id_t# donator) /*!< in: target page */
864 {
865 LockMultiGuardcxx . . $ LockMultiGuard# gcxx . . $ LockMultiGuard#LockMultiGuard(7ed4e903dc5bc0c4).{lock_syscxx . . $ lock_sys..prdt_hashcxx . . $ lock_sys_t#prdt_hash., receiver->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).(), donator};
866
867 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock = lock_sys_tcxx . . $ lock_sys_t#::get_firstcxx . . $ lock_sys_t#get_first(dcee157701c9d3e2).(g.cell2cxx . . $ LockMultiGuard#cell2(62c1d4f87430d26b).(), donator,
868 PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!);
869 lock;
870 lock = lock_rec_get_nextcxx . . $ lock_rec_get_next(6852bb7d1cb225dd).(PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!, lock)) {
871
872 const auto type_mode = lock->type_modecxx . . $ ib_lock_t#type_mode.;
873 lock_prdt_tcxx . . $ lock_prdt_t#* lock_prdt = lock_get_prdt_from_lockcxx . . $ lock_get_prdt_from_lock(d0e9ee3648c696b8).(lock);
874
875 lock_rec_reset_nth_bitcxx . . $ lock_rec_reset_nth_bit(7ed7bcc3e37c3dfc).(lock, PRDT_HEAPNOcxx . . $ `storage/innobase/include/lock0priv.h:394:9`!);
876 if (type_mode & LOCK_WAITcxx . . $ `storage/innobase/include/lock0types.h:105:9`!) {
877 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(lock->trx->lock.wait_lock == lock);
878 lock->type_modecxx . . $ ib_lock_t#type_mode. &= ~LOCK_WAITcxx . . $ `storage/innobase/include/lock0types.h:105:9`!;
879 }
880 lock_prdt_add_to_queuecxx . . $ lock_prdt_add_to_queue(73afde0ea983a692).(
881 type_mode, receiver, lock->indexcxx . . $ ib_lock_t#index., lock->trxcxx . . $ ib_lock_t#trx.,
882 lock_prdt, false);
883 }
884 }
885
886 /** Remove locks on a discarded SPATIAL INDEX page.
887 @param id page to be discarded
888 @param page whether to discard also from lock_sys.prdt_hash */
889 void lock_sys_tcxx . . $ lock_sys_t#::prdt_page_free_from_discardcxx . . $ lock_sys_t#prdt_page_free_from_discard(1557a90a37041667).(const page_id_tcxx . . $ page_id_t# id, bool all)
890 {
891 const auto id_fold= id.foldcxx . . $ page_id_t#fold(c9b1e749b64d5edc).();
892 rd_lockcxx . . $ lock_sys_t#rd_lock(b51963283f2467a4).(SRW_LOCK_CALLcxx . . $ `storage/innobase/include/srw_lock.h:44:10`!);
893 auto cell= prdt_page_hashcxx . . $ lock_sys_t#prdt_page_hash..cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(id_fold);
894 auto latch= hash_tablecxx . . $ lock_sys_t#hash_table#::latchcxx . . $ lock_sys_t#hash_table#latch(e5426f004fac3f3d).(cell);
895 latch->acquirecxx . . $ lock_sys_t#hash_latch#acquire(49f6e7a06ebc5aa8).();
896
897 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock= get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(*cell, id), *next; lock; lock= next)
898 {
899 next= lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock);
900 lock_rec_discardcxx . . $ lock_rec_discard(949a03509541f353).(lock, *cell);
901 }
902
903 if (all)
904 {
905 latch->releasecxx . . $ lock_sys_t#hash_latch#release(49f6e7a06ebc5aa8).();
906 cell= prdt_hashcxx . . $ lock_sys_t#prdt_hash..cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(id_fold);
907 latch= hash_tablecxx . . $ lock_sys_t#hash_table#::latchcxx . . $ lock_sys_t#hash_table#latch(e5426f004fac3f3d).(cell);
908 latch->acquirecxx . . $ lock_sys_t#hash_latch#acquire(49f6e7a06ebc5aa8).();
909 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock= get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(*cell, id), *next; lock; lock= next)
910 {
911 next= lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock);
912 lock_rec_discardcxx . . $ lock_rec_discard(949a03509541f353).(lock, *cell);
913 }
914 }
915
916 latch->releasecxx . . $ lock_sys_t#hash_latch#release(49f6e7a06ebc5aa8).();
917 cell= rec_hashcxx . . $ lock_sys_t#rec_hash..cell_getcxx . . $ lock_sys_t#hash_table#cell_get(95d717e53f6bbd46).(id_fold);
918 latch= hash_tablecxx . . $ lock_sys_t#hash_table#::latchcxx . . $ lock_sys_t#hash_table#latch(e5426f004fac3f3d).(cell);
919 latch->acquirecxx . . $ lock_sys_t#hash_latch#acquire(49f6e7a06ebc5aa8).();
920
921 for (lock_tcxx . . $ `storage/innobase/include/lock0types.h:34:9`! *lock= get_firstcxx . . $ lock_sys_t#get_first(685fe3c7ea83a3ed).(*cell, id), *next; lock; lock= next)
922 {
923 next= lock_rec_get_next_on_pagecxx . . $ lock_rec_get_next_on_page(a40a7ab062273eb0).(lock);
924 lock_rec_discardcxx . . $ lock_rec_discard(949a03509541f353).(lock, *cell);
925 }
926
927 latch->releasecxx . . $ lock_sys_t#hash_latch#release(49f6e7a06ebc5aa8).();
928 /* Must be last, to avoid a race with lock_sys_t::hash_table::resize() */
929 rd_unlockcxx . . $ lock_sys_t#rd_unlock(49f6e7a06ebc5aa8).();
930 }