InnoDB锁

news/2024/11/28 13:55:30/

This section describes lock types used by InnoDB.
本章节讲解InnoDB引擎中的锁类型

Lock Types Used By InnoDB.

  • Shared and Exclusive Locks 共享锁和排他锁
  • Intention Locks 意向锁
  • Record Locks
  • Gap Locks
  • Next-Key Locks
  • Insert Intention Locks
  • AUTO-INC Locks
  • Predicate Locks for Spatial Indexes

Shared and Exclusive Locks 共享锁和排他锁

InnoDB实现了两类标准的行级锁,分别为shared (S) 锁和 exclusive (X)锁;
shared (S) 锁:获取到该行共享锁的事务可以读取该行.
exclusive (X)锁:获取到该行排它锁的事务可以更新或删除该行.

如果事务T1在r行上获取了啊一个共享锁,那么事务T2请求获取r行的锁的处理情况如下:

  • 如果T2请求的是一个共享锁,那么立刻给予。

  • 如果T2请求的是一个排它锁,那么不能立刻给予;

如果事务T2在r行上持有一个排它锁,那么事务T2无论请求什么锁都不能被立即给予。T2必须等待T1释放T1所持有的排它锁。

Intention Locks 意向锁

InnoDB supports multiple granularity locking which permits coexistence of row locks and table locks. For example, a statement such as LOCK TABLES … WRITE takes an exclusive lock (an X lock) on the specified table. To make locking at multiple granularity levels practical, InnoDB uses intention locks. Intention locks are table-level locks that indicate which type of lock (shared or exclusive) a transaction requires later for a row in a table. There are two types of intention locks:

An intention shared lock (IS) indicates that a transaction intends to set a shared lock on individual rows in a table.

An intention exclusive lock (IX) indicates that a transaction intends to set an exclusive lock on individual rows in a table.

For example, SELECT … FOR SHARE sets an IS lock, and SELECT … FOR UPDATE sets an IX lock.

The intention locking protocol is as follows:

Before a transaction can acquire a shared lock on a row in a table, it must first acquire an IS lock or stronger on the table.

Before a transaction can acquire an exclusive lock on a row in a table, it must first acquire an IX lock on the table.

Table-level lock type compatibility is summarized in the following matrix.

X IX S IS
X Conflict Conflict Conflict Conflict
IX Conflict Compatible Conflict Compatible
S Conflict Conflict Compatible Compatible
IS Conflict Compatible Compatible Compatible
A lock is granted to a requesting transaction if it is compatible with existing locks, but not if it conflicts with existing locks. A transaction waits until the conflicting existing lock is released. If a lock request conflicts with an existing lock and cannot be granted because it would cause deadlock, an error occurs.

Intention locks do not block anything except full table requests (for example, LOCK TABLES … WRITE). The main purpose of intention locks is to show that someone is locking a row, or going to lock a row in the table.

Transaction data for an intention lock appears similar to the following in SHOW ENGINE INNODB STATUS and InnoDB monitor output:

TABLE LOCK table test.t trx id 10080 lock mode IX

Record Locks

Gap Locks

Next-Key Locks

Insert Intention Locks

AUTO-INC Locks

Predicate Locks for Spatial Indexes


http://www.ppmy.cn/news/1121398.html

相关文章

嵌入式单片机开源的串口示波器实现方法

分享一款开源的QT的串口示波器,完全开源,支持串口、TCP、波形显示、通信协议。 Sailor Project功能说明 串口调试助手功能 支持传统的串口调试助手的基本收发功能,同时可以刷新大量的数据而不卡顿 支持保存接收的数据 支持最大200条可编辑…

大模型从入门到应用——LangChain:代理(Agents)-[代理执行器(Agent Executor):处理解析错误、访问中间步骤和限制最大迭代次数]

分类目录:《大模型从入门到应用》总目录 LangChain系列文章: 基础知识快速入门 安装与环境配置链(Chains)、代理(Agent:)和记忆(Memory)快速开发聊天模型 模型(Models&…

Linux启动过程详解 Xmind导图笔记

参考大佬博客: 简要描述linux系统从开机到登陆界面的启动过程 Linux启动过程详解 Bootloader详解 来源:从BIOS开始画图了解Linux启动过程——老杨Linux

java框架-Springboot3-数据访问

整合SSM SpringSpringMVCMybatis 整合步骤 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"…

【若依框架2】前后端分离版本添加功能页

在VSCode的src/views下新建个文件平example,在example下创建test文件夹&#xff0c;在test里创建index.vue文件 <template> <h1>Hello world</h1> </template><script> export default {name: "index" } </script><style s…

《Kubernetes部署篇:Ubuntu20.04基于外部etcd+部署kubernetes1.25.14集群(多主多从)》

一、部署架构图 1、架构图如下所示: 2、部署流程图如下所示: 二、环境信息 1、资源下载基于外部etcd+部署容器版kubernetes1.25.14集群资源合集 2、部署规划主机名K8S版本系统版本内核版本IP地址备注k8s-master-121.25.14Ubuntu 20.04.5 LTS5.15.0-69-generic192.168.1.12ma…

eCognition易康操作教程(一):如何利用eCognition易康软件进行影像分割之棋盘分割、四叉树分割、光谱差异分割

一、新建工程 使用eCognition新建工程ImageSegmentation&#xff0c;加载影像数据&#xff0c;并编辑图层名称&#xff0c;将Layer 1、Layer 2、Layer 3、Layer 4的 Layer Alias 分别改为 Blue、Green、Red、如图1-1&#xff0c;图1-2所示&#xff1a; 图 1-1 图 1-2 设置加载…

分布式文件存储系统minio、大文件分片传输

上传大文件 1、Promise对象 Promise 对象代表一个异步操作&#xff0c;有三种状态&#xff1a; pending: 初始状态&#xff0c;不是成功或失败状态。fulfilled: 意味着操作成功完成。rejected: 意味着操作失败。 只有异步操作的结果&#xff0c;可以决定当前是哪一种状态&a…