Debian Codegraph @

storage/innobase/include/lock0prdt.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2014, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/lock0prdt.h
29 The predicate lock system
30
31 Created 9/7/2013 Jimmy Yang
32 *******************************************************/
33 #ifndef lock0prdt_h
34 #define lock0prdt_h
35
36 #include "lock0lock.h"
37 #include "univ.i"
38
39 /* Predicate lock data */
40 typedef struct lock_prdt {
41 void *data; /* Predicate data */
42 uint16 op; /* Predicate operator */
43 } lock_prdt_t;
44
45 /** Acquires LOCK_S | LOCK_PREDICATE on a block. Always succeeds, because it
46 never has to wait, because their only purpose is to block conflicting
47 LOCK_X | LOCK_PREDICATE | LOCK_INSERT_INTENTION into the locked area.
48 (In other words they are conceptually similar to gap locks in regular indexes,
49 which also never have to wait for similar reasons)
50 @param[in] block Buffer block containing the rec
51 @param[in] prdt Predicate for the lock
52 @param[in] index Secondary index containing the block
53 @param[in] thr The query thread requesting the lock */
54 void lock_prdt_lock(buf_block_t *block, lock_prdt_t *prdt, dict_index_t *index,
55 que_thr_t *thr);
56
57 /** Acquire a "Page" lock on a block
58 @param[in] page_id id of the page to lock
59 @param[in] index secondary index
60 @param[in] thr query thread
61 @return DB_SUCCESS */
62 dberr_t lock_place_prdt_page_lock(const page_id_t &page_id, dict_index_t *index,
63 que_thr_t *thr);
64
65 /** Initiate a Predicate lock from a MBR */
66 void lock_init_prdt_from_mbr(
67 lock_prdt_t *prdt, /*!< in/out: predicate to initialized */
68 rtr_mbr_t *mbr, /*!< in: Minimum Bounding Rectangle */
69 ulint mode, /*!< in: Search mode */
70 mem_heap_t *heap); /*!< in: heap for allocating memory */
71
72 /** Get predicate lock's minimum bounding box
73 @return the minimum bounding box*/
74 lock_prdt_t *lock_get_prdt_from_lock(const lock_t *lock); /*!< in: the lock */
75
76 /** Checks if a predicate lock request for a new lock has to wait for
77 request lock2.
78 @return true if new lock has to wait for lock2 to be removed */
79 bool lock_prdt_has_to_wait(
80 const trx_t *trx, /*!< in: trx of new lock */
81 ulint type_mode, /*!< in: precise mode of the new lock
82 to set: LOCK_S or LOCK_X, possibly
83 ORed to LOCK_PREDICATE or LOCK_PRDT_PAGE,
84 LOCK_INSERT_INTENTION */
85 lock_prdt_t *prdt, /*!< in: lock predicate to check */
86 const lock_t *lock2); /*!< in: another record lock; NOTE that
87 it is assumed that this has a lock bit
88 set on the same record as in the new
89 lock we are setting */
90
91 /** Update predicate lock when page splits
92
93 @param[in,out] block page to be split
94 @param[in,out] new_block the new half page
95 @param[in] prdt MBR on the old page
96 @param[in] new_prdt MBR on the new page
97 */
98 void lock_prdt_update_split(buf_block_t *block, buf_block_t *new_block,
99 lock_prdt_t *prdt, lock_prdt_t *new_prdt);
100
101 /** Adjust locks from an ancestor page of Rtree on the appropriate level .
102 Check whether any predicate lock in parent needs to propagate to child page
103 after split.
104
105 @param[in,out] left_block page to be split
106 @param[in,out] right_block the new half page
107 @param[in] left_prdt MBR on the old page
108 @param[in] right_prdt MBR on the new page
109 @param[in] page_id the parent's page id
110 */
111 void lock_prdt_update_parent(buf_block_t *left_block, buf_block_t *right_block,
112 lock_prdt_t *left_prdt, lock_prdt_t *right_prdt,
113 const page_id_t &page_id);
114
115 /** Checks if locks of other transactions prevent an immediate insert of
116 a predicate record.
117 @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
118 dberr_t lock_prdt_insert_check_and_lock(
119 ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG bit is
120 set, does nothing */
121 const rec_t *rec, /*!< in: record after which to insert */
122 buf_block_t *block, /*!< in/out: buffer block of rec */
123 dict_index_t *index, /*!< in: index */
124 que_thr_t *thr, /*!< in: query thread */
125 mtr_t *mtr, /*!< in/out: mini-transaction */
126 lock_prdt_t *prdt); /*!< in: Minimum Bound Rectangle */
127
128 /** Append a predicate to the lock
129 @param[in] lock Lock
130 @param[in] prdt Predicate */
131 void lock_prdt_set_prdt(lock_t *lock, const lock_prdt_t *prdt);
132
133 #if 0
134
135 /*********************************************************************//**
136 Get predicate lock's minimum bounding box
137 @return the minimum bounding box*/
138 static inline
139 rtr_mbr_t*
140 prdt_get_mbr_from_prdt(
141 const lock_prdt_t* prdt); /*!< in: the lock predicate */
142
143 #endif
144 /** Moves the locks of a record to another record and resets the lock bits of
145 the donating record. */
146 void lock_prdt_rec_move(
147 const buf_block_t *receiver, /*!< in: buffer block containing
148 the receiving record */
149 const buf_block_t *donator); /*!< in: buffer block containing
150 the donating record */
151
152 /** Check whether there are R-tree Page locks on a page by other transactions
153 @param[in] trx trx to test the lock
154 @param[in] page_id id of the page
155 @retval false if there is no lock
156 @retval true if some transaction other than trx holds a page lock */
157 bool lock_other_has_prdt_page_lock(const trx_t *trx, const page_id_t &page_id);
158
159 /** Removes predicate lock objects set on an index page which is discarded.
160 @param[in] block page to be discarded
161 @param[in] lock_hash lock hash */
162 void lock_prdt_page_free_from_discard(const buf_block_t *block,
163 struct Locks_hashtable &lock_hash);
164
165 #endif