MySQL 8.0.31
Source Code Documentation
lock0prdt.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2014, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/lock0prdt.h
28 The predicate lock system
29
30 Created 9/7/2013 Jimmy Yang
31 *******************************************************/
32#ifndef lock0prdt_h
33#define lock0prdt_h
34
35#include "lock0lock.h"
36#include "univ.i"
37
38/* Predicate lock data */
39typedef struct lock_prdt {
40 void *data; /* Predicate data */
41 uint16 op; /* Predicate operator */
43
44/** Acquire a predicate lock on a block
45 @return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, or DB_DEADLOCK */
46dberr_t lock_prdt_lock(buf_block_t *block, /*!< in/out: buffer block of rec */
47 lock_prdt_t *prdt, /*!< in: Predicate for the lock */
48 dict_index_t *index, /*!< in: secondary index */
49 enum lock_mode mode, /*!< in: mode of the lock which
50 the read cursor should set on
51 records: LOCK_S or LOCK_X; the
52 latter is possible in
53 SELECT FOR UPDATE */
54 ulint type_mode,
55 /*!< in: LOCK_PREDICATE or LOCK_PRDT_PAGE */
56 que_thr_t *thr); /*!< in: query thread
57 (can be NULL if BTR_NO_LOCKING_FLAG) */
58
59/** Acquire a "Page" lock on a block
60@param[in] page_id id of the page to lock
61@param[in] index secondary index
62@param[in] thr query thread
63@return DB_SUCCESS */
65 que_thr_t *thr);
66
67/** Initiate a Predicate lock from a MBR */
69 lock_prdt_t *prdt, /*!< in/out: predicate to initialized */
70 rtr_mbr_t *mbr, /*!< in: Minimum Bounding Rectangle */
71 ulint mode, /*!< in: Search mode */
72 mem_heap_t *heap); /*!< in: heap for allocating memory */
73
74/** Get predicate lock's minimum bounding box
75 @return the minimum bounding box*/
76lock_prdt_t *lock_get_prdt_from_lock(const lock_t *lock); /*!< in: the lock */
77
78/** Checks if a predicate lock request for a new lock has to wait for
79 request lock2.
80 @return true if new lock has to wait for lock2 to be removed */
82 const trx_t *trx, /*!< in: trx of new lock */
83 ulint type_mode, /*!< in: precise mode of the new lock
84 to set: LOCK_S or LOCK_X, possibly
85 ORed to LOCK_PREDICATE or LOCK_PRDT_PAGE,
86 LOCK_INSERT_INTENTION */
87 lock_prdt_t *prdt, /*!< in: lock predicate to check */
88 const lock_t *lock2); /*!< in: another record lock; NOTE that
89 it is assumed that this has a lock bit
90 set on the same record as in the new
91 lock we are setting */
92
93/** Update predicate lock when page splits
94
95@param[in,out] block page to be split
96@param[in,out] new_block the new half page
97@param[in] prdt MBR on the old page
98@param[in] new_prdt MBR on the new page
99*/
100void lock_prdt_update_split(buf_block_t *block, buf_block_t *new_block,
101 lock_prdt_t *prdt, lock_prdt_t *new_prdt);
102
103/** Adjust locks from an ancestor page of Rtree on the appropriate level .
104Check whether any predicate lock in parent needs to propagate to child page
105after split.
106
107@param[in,out] left_block page to be split
108@param[in,out] right_block the new half page
109@param[in] left_prdt MBR on the old page
110@param[in] right_prdt MBR on the new page
111@param[in] page_id the parent's page id
112*/
113void lock_prdt_update_parent(buf_block_t *left_block, buf_block_t *right_block,
114 lock_prdt_t *left_prdt, lock_prdt_t *right_prdt,
115 const page_id_t &page_id);
116
117/** Checks if locks of other transactions prevent an immediate insert of
118 a predicate record.
119 @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
121 ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG bit is
122 set, does nothing */
123 const rec_t *rec, /*!< in: record after which to insert */
124 buf_block_t *block, /*!< in/out: buffer block of rec */
125 dict_index_t *index, /*!< in: index */
126 que_thr_t *thr, /*!< in: query thread */
127 mtr_t *mtr, /*!< in/out: mini-transaction */
128 lock_prdt_t *prdt); /*!< in: Minimum Bound Rectangle */
129
130/** Append a predicate to the lock
131@param[in] lock Lock
132@param[in] prdt Predicate */
133void lock_prdt_set_prdt(lock_t *lock, const lock_prdt_t *prdt);
134
135#if 0
136
137/*********************************************************************//**
138Get predicate lock's minimum bounding box
139@return the minimum bounding box*/
140static inline
143 const lock_prdt_t* prdt); /*!< in: the lock predicate */
144
145#endif
146/** Moves the locks of a record to another record and resets the lock bits of
147 the donating record. */
149 const buf_block_t *receiver, /*!< in: buffer block containing
150 the receiving record */
151 const buf_block_t *donator); /*!< in: buffer block containing
152 the donating record */
153
154/** Check whether there are no R-tree Page locks on a page by other transactions
155@param[in] trx trx to test the lock
156@param[in] page_id id of the page
157@retval true if there is no lock
158@retval false if some transaction other than trx holds a page lock */
159bool lock_test_prdt_page_lock(const trx_t *trx, const page_id_t &page_id);
160
161/** Removes predicate lock objects set on an index page which is discarded.
162@param[in] block page to be discarded
163@param[in] lock_hash lock hash */
165 hash_table_t *lock_hash);
166
167#endif
Definition: hash0hash.h:373
Page identifier.
Definition: buf0types.h:206
dberr_t
Definition: db0err.h:38
static int flags[50]
Definition: hp_test1.cc:39
The transaction lock system.
static rtr_mbr_t * prdt_get_mbr_from_prdt(const lock_prdt_t *prdt)
Get a minimum bounding box from a Predicate.
Definition: lock0prdt.cc:52
lock_prdt_t * lock_get_prdt_from_lock(const lock_t *lock)
Get predicate lock's minimum bounding box.
Definition: lock0prdt.cc:62
struct lock_prdt lock_prdt_t
void lock_init_prdt_from_mbr(lock_prdt_t *prdt, rtr_mbr_t *mbr, ulint mode, mem_heap_t *heap)
Initiate a Predicate lock from a MBR.
Definition: lock0prdt.cc:632
void lock_prdt_update_parent(buf_block_t *left_block, buf_block_t *right_block, lock_prdt_t *left_prdt, lock_prdt_t *right_prdt, const page_id_t &page_id)
Adjust locks from an ancestor page of Rtree on the appropriate level .
Definition: lock0prdt.cc:518
void lock_prdt_update_split(buf_block_t *block, buf_block_t *new_block, lock_prdt_t *prdt, lock_prdt_t *new_prdt)
Update predicate lock when page splits.
Definition: lock0prdt.cc:621
bool lock_prdt_has_to_wait(const trx_t *trx, ulint type_mode, lock_prdt_t *prdt, const lock_t *lock2)
Checks if a predicate lock request for a new lock has to wait for request lock2.
Definition: lock0prdt.cc:145
void lock_prdt_page_free_from_discard(const buf_block_t *block, hash_table_t *lock_hash)
Removes predicate lock objects set on an index page which is discarded.
Definition: lock0prdt.cc:841
dberr_t lock_place_prdt_page_lock(const page_id_t &page_id, dict_index_t *index, que_thr_t *thr)
Acquire a "Page" lock on a block.
Definition: lock0prdt.cc:745
bool lock_test_prdt_page_lock(const trx_t *trx, const page_id_t &page_id)
Check whether there are no R-tree Page locks on a page by other transactions.
Definition: lock0prdt.cc:797
dberr_t lock_prdt_lock(buf_block_t *block, lock_prdt_t *prdt, dict_index_t *index, enum lock_mode mode, ulint type_mode, que_thr_t *thr)
Acquire a predicate lock on a block.
Definition: lock0prdt.cc:653
void lock_prdt_rec_move(const buf_block_t *receiver, const buf_block_t *donator)
Moves the locks of a record to another record and resets the lock bits of the donating record.
Definition: lock0prdt.cc:812
dberr_t lock_prdt_insert_check_and_lock(ulint flags, const rec_t *rec, buf_block_t *block, dict_index_t *index, que_thr_t *thr, mtr_t *mtr, lock_prdt_t *prdt)
Checks if locks of other transactions prevent an immediate insert of a predicate record.
Definition: lock0prdt.cc:431
void lock_prdt_set_prdt(lock_t *lock, const lock_prdt_t *prdt)
Append a predicate to the lock.
Definition: lock0prdt.cc:88
lock_mode
Definition: lock0types.h:51
uint16_t uint16
Definition: my_inttypes.h:64
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:78
mode
Definition: file_handle.h:59
byte rec_t
Definition: rem0types.h:40
The buffer control block structure.
Definition: buf0buf.h:1664
Data structure for an index.
Definition: dict0mem.h:1021
Definition: lock0prdt.h:39
uint16 op
Definition: lock0prdt.h:41
void * data
Definition: lock0prdt.h:40
Lock struct; protected by lock_sys latches.
Definition: lock0priv.h:135
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:299
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:181
Definition: que0que.h:241
In memory representation of a minimum bounding rectangle.
Definition: rtree_support.h:39
Definition: trx0trx.h:680
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407