MySQL 9.1.0
Source Code Documentation
lock0prdt.cc File Reference

The transaction lock system. More...

#include <set>
#include "btr0btr.h"
#include "dict0boot.h"
#include "dict0mem.h"
#include "ha_prototypes.h"
#include "lock0lock.h"
#include "lock0prdt.h"
#include "lock0priv.h"
#include "srv0mon.h"
#include "trx0purge.h"
#include "trx0sys.h"
#include "usr0sess.h"
#include "ut0vec.h"

Macros

#define LOCK_MODULE_IMPLEMENTATION
 

Functions

static rtr_mbr_tprdt_get_mbr_from_prdt (const lock_prdt_t *prdt)
 Get a minimum bounding box from a Predicate. More...
 
lock_prdt_tlock_get_prdt_from_lock (const lock_t *lock)
 Get a predicate from a lock. More...
 
static rtr_mbr_tlock_prdt_get_mbr_from_lock (const lock_t *lock)
 Get a minimum bounding box directly from a lock. More...
 
void lock_prdt_set_prdt (lock_t *lock, const lock_prdt_t *prdt)
 Append a predicate to the lock. More...
 
static bool lock_prdt_consistent (lock_prdt_t *prdt1, lock_prdt_t *prdt2, ulint op, const dd::Spatial_reference_system *srs)
 Check whether two predicate locks are compatible with each other. More...
 
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 another lock. More...
 
static lock_tlock_prdt_has_lock (ulint precise_mode, ulint type_mode, const buf_block_t *block, lock_prdt_t *prdt, const trx_t *trx)
 Checks if a transaction has a GRANTED stronger or equal predicate lock on the page. More...
 
static const lock_tlock_prdt_other_has_conflicting (ulint mode, const buf_block_t *block, lock_prdt_t *prdt, const trx_t *trx)
 Checks if some other transaction has a conflicting predicate lock request in the queue, so that we have to wait. More...
 
static void lock_prdt_enlarge_mbr (const lock_t *lock, rtr_mbr_t *mbr)
 Reset the Minimum Bounding Rectangle (to a large area) More...
 
static void lock_prdt_enlarge_prdt (lock_t *lock, lock_prdt_t *prdt)
 Reset the predicates to a "covering" (larger) predicates. More...
 
static bool lock_prdt_is_same (lock_prdt_t *prdt1, lock_prdt_t *prdt2, const dd::Spatial_reference_system *srs)
 Check two predicates' MBRs are the same. More...
 
static lock_tlock_prdt_find_on_page (ulint type_mode, const buf_block_t *block, lock_prdt_t *prdt, const trx_t *trx)
 Looks for a similar predicate lock struct by the same trx on the same page. More...
 
static lock_tlock_prdt_add_to_queue (ulint type_mode, const buf_block_t *block, dict_index_t *index, trx_t *trx, lock_prdt_t *prdt)
 Adds a predicate lock request in the predicate lock queue. More...
 
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. More...
 
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 . More...
 
static void lock_prdt_update_split_low (buf_block_t *block, buf_block_t *new_block, lock_prdt_t *prdt, lock_prdt_t *new_prdt, ulint type_mode)
 Update predicate lock when page splits. More...
 
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. More...
 
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. More...
 
void lock_prdt_lock (buf_block_t *block, lock_prdt_t *prdt, dict_index_t *index, que_thr_t *thr)
 Acquires LOCK_S | LOCK_PREDICATE on a block. More...
 
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. More...
 
bool lock_other_has_prdt_page_lock (const trx_t *trx, const page_id_t &page_id)
 Check whether there are R-tree Page locks on a page by other transactions. More...
 
void lock_prdt_rec_move (const buf_block_t *receiver, const buf_block_t *donator)
 Moves the locks of a page to another page and resets the lock bits of the donating records. More...
 
void lock_prdt_page_free_from_discard (const buf_block_t *block, Locks_hashtable &lock_hash)
 Removes predicate lock objects set on an index page which is discarded. More...
 

Detailed Description

The transaction lock system.

Created 9/7/2013 Jimmy Yang

Macro Definition Documentation

◆ LOCK_MODULE_IMPLEMENTATION

#define LOCK_MODULE_IMPLEMENTATION

Function Documentation

◆ lock_get_prdt_from_lock()

lock_prdt_t * lock_get_prdt_from_lock ( const lock_t lock)

Get a predicate from a lock.

Get predicate lock's minimum bounding box.

Returns
the predicate
Parameters
lockin: the lock

◆ lock_init_prdt_from_mbr()

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.

Initiate a Predicate lock from a MBR.

Parameters
prdtin/out: predicate to initialized
mbrin: Minimum Bounding Rectangle
modein: Search mode
heapin: heap for allocating memory

◆ lock_other_has_prdt_page_lock()

bool lock_other_has_prdt_page_lock ( const trx_t trx,
const page_id_t page_id 
)

Check whether there are R-tree Page locks on a page by other transactions.

Parameters
[in]trxtrx to test the lock
[in]page_idid of the page
Return values
falseif there is no lock
trueif some transaction other than trx holds a page lock

◆ lock_place_prdt_page_lock()

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.

Parameters
[in]page_idid of the page to lock
[in]indexsecondary index
[in]thrquery thread
Returns
DB_SUCCESS

◆ lock_prdt_add_to_queue()

static lock_t * lock_prdt_add_to_queue ( ulint  type_mode,
const buf_block_t block,
dict_index_t index,
trx_t trx,
lock_prdt_t prdt 
)
static

Adds a predicate lock request in the predicate lock queue.

Returns
lock where the bit was set
Parameters
type_modein: lock mode, wait, predicate etc. flags; type is ignored and replaced by LOCK_REC
blockin: buffer block containing the record
indexin: index of record
trxin/out: transaction
prdtin: Minimum Bounding Rectangle the new lock will be on

◆ lock_prdt_consistent()

static bool lock_prdt_consistent ( lock_prdt_t prdt1,
lock_prdt_t prdt2,
ulint  op,
const dd::Spatial_reference_system srs 
)
static

Check whether two predicate locks are compatible with each other.

Parameters
[in]prdt1first predicate lock
[in]prdt2second predicate lock
[in]oppredicate comparison operator
[in]srsSpatial reference system of R-tree
Returns
true if consistent

◆ lock_prdt_enlarge_mbr()

static void lock_prdt_enlarge_mbr ( const lock_t lock,
rtr_mbr_t mbr 
)
static

Reset the Minimum Bounding Rectangle (to a large area)

Parameters
lockin/out: lock to modify
mbrin: Minimum Bounding Rectangle

◆ lock_prdt_enlarge_prdt()

static void lock_prdt_enlarge_prdt ( lock_t lock,
lock_prdt_t prdt 
)
static

Reset the predicates to a "covering" (larger) predicates.

Parameters
lockin/out: lock to modify
prdtin: predicate

◆ lock_prdt_find_on_page()

static lock_t * lock_prdt_find_on_page ( ulint  type_mode,
const buf_block_t block,
lock_prdt_t prdt,
const trx_t trx 
)
static

Looks for a similar predicate lock struct by the same trx on the same page.

This can be used to save space when a new record lock should be set on a page: no new struct is needed, if a suitable old one is found.

Returns
lock or NULL
Parameters
type_modein: lock type_mode field
blockin: buffer block
prdtin: MBR with the lock
trxin: transaction

◆ lock_prdt_get_mbr_from_lock()

static rtr_mbr_t * lock_prdt_get_mbr_from_lock ( const lock_t lock)
inlinestatic

Get a minimum bounding box directly from a lock.

Returns
the minimum bounding box
Parameters
lockin: the lock

◆ lock_prdt_has_lock()

static lock_t * lock_prdt_has_lock ( ulint  precise_mode,
ulint  type_mode,
const buf_block_t block,
lock_prdt_t prdt,
const trx_t trx 
)
inlinestatic

Checks if a transaction has a GRANTED stronger or equal predicate lock on the page.

Returns
lock or NULL
Parameters
precise_modein: LOCK_S or LOCK_X
type_modein: LOCK_PREDICATE etc.
blockin: buffer block containing the record
prdtin: The predicate to be attached to the new lock
trxin: transaction

◆ lock_prdt_has_to_wait()

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 another lock.

Checks if a predicate lock request for a new lock has to wait for request lock2.

Returns
true if new lock has to wait for lock2 to be released
Parameters
trxin: trx of new lock
type_modein: precise mode of the new lock to set: LOCK_S or LOCK_X, possibly ORed to LOCK_PREDICATE or LOCK_PRDT_PAGE, LOCK_INSERT_INTENTION
prdtin: lock predicate to check
lock2in: another record lock; NOTE that it is assumed that this has a lock bit set on the same record as in the new lock we are setting

◆ lock_prdt_insert_check_and_lock()

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.

Returns
DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK
Parameters
flagsin: if BTR_NO_LOCKING_FLAG bit is set, does nothing
recin: record after which to insert
blockin/out: buffer block of rec
indexin: index
thrin: query thread
mtrin/out: mini-transaction
prdtin: Predicates with Minimum Bound Rectangle

◆ lock_prdt_is_same()

static bool lock_prdt_is_same ( lock_prdt_t prdt1,
lock_prdt_t prdt2,
const dd::Spatial_reference_system srs 
)
static

Check two predicates' MBRs are the same.

Returns
true if they are the same
Parameters
prdt1in: MBR with the lock
prdt2in: MBR with the lock
srsin: SRS of R-tree

◆ lock_prdt_lock()

void lock_prdt_lock ( buf_block_t block,
lock_prdt_t prdt,
dict_index_t index,
que_thr_t thr 
)

Acquires LOCK_S | LOCK_PREDICATE on a block.

Always succeeds, because it never has to wait, because their only purpose is to block conflicting LOCK_X | LOCK_PREDICATE | LOCK_INSERT_INTENTION into the locked area. (In other words they are conceptually similar to gap locks in regular indexes, which also never have to wait for similar reasons)

Parameters
[in]blockBuffer block containing the rec
[in]prdtPredicate for the lock
[in]indexSecondary index containing the block
[in]thrThe query thread requesting the lock

◆ lock_prdt_other_has_conflicting()

static const lock_t * lock_prdt_other_has_conflicting ( ulint  mode,
const buf_block_t block,
lock_prdt_t prdt,
const trx_t trx 
)
static

Checks if some other transaction has a conflicting predicate lock request in the queue, so that we have to wait.

Returns
lock or NULL
Parameters
modein: LOCK_S or LOCK_X, possibly ORed to LOCK_PREDICATE or LOCK_PRDT_PAGE, LOCK_INSERT_INTENTION
blockin: buffer block containing the record
prdtin: Predicates (currently) the Minimum Bounding Rectangle) the new lock will be on
trxin: our transaction

◆ lock_prdt_page_free_from_discard()

void lock_prdt_page_free_from_discard ( const buf_block_t block,
Locks_hashtable lock_hash 
)

Removes predicate lock objects set on an index page which is discarded.

Parameters
[in]blockpage to be discarded
[in]lock_hashlock hash

◆ lock_prdt_rec_move()

void lock_prdt_rec_move ( const buf_block_t receiver,
const buf_block_t donator 
)

Moves the locks of a page to another page and resets the lock bits of the donating records.

Moves the locks of a record to another record and resets the lock bits of the donating record.

Parameters
receiverin: buffer block containing the receiving record
donatorin: buffer block containing the donating record

◆ lock_prdt_set_prdt()

void lock_prdt_set_prdt ( lock_t lock,
const lock_prdt_t prdt 
)

Append a predicate to the lock.

Parameters
[in]lockLock
[in]prdtPredicate

◆ lock_prdt_update_parent()

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 .

Check whether any predicate lock in parent needs to propagate to child page after split.

Parameters
[in,out]left_blockpage to be split
[in,out]right_blockthe new half page
[in]left_prdtMBR on the old page
[in]right_prdtMBR on the new page
[in]page_idthe parent's page id

◆ lock_prdt_update_split()

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.

Parameters
[in,out]blockpage to be split
[in,out]new_blockthe new half page
[in]prdtMBR on the old page
[in]new_prdtMBR on the new page

◆ lock_prdt_update_split_low()

static void lock_prdt_update_split_low ( buf_block_t block,
buf_block_t new_block,
lock_prdt_t prdt,
lock_prdt_t new_prdt,
ulint  type_mode 
)
static

Update predicate lock when page splits.

Parameters
[in,out]blockpage to be split
[in,out]new_blockthe new half page
[in]prdtMBR on the old page
[in]new_prdtMBR on the new page
[in]type_modeLOCK_PREDICATE or LOCK_PRDT_PAGE

◆ prdt_get_mbr_from_prdt()

static rtr_mbr_t * prdt_get_mbr_from_prdt ( const lock_prdt_t prdt)
inlinestatic

Get a minimum bounding box from a Predicate.

Returns
the minimum bounding box
Parameters
prdtin: the lock predicate