事务隔离级别

概念

事务的隔离性是指并发事务之间的隔离程度,隔离程度越高,数据可见性越底,能够支持的并发程度越低。

隔离级别

  • READ UNCOMMITTED;
  • READ COMMITTED;
  • REPEATABLE READ(默认);
  • SERIALIZABLE;

READ UNCOMMITTED

定义:事务A能够读取到事务B未提交的数据; 
问题:脏读。如果事务B发生回滚,则事务A读取到的数据是错误或者不存在的。

READ COMMITTED

定义:事务A能够读取到事务B已提交的数据; 
问题:不可重复读。事务A执行过程中,如果有其它事务提交了写操作,那么事务A内的多次查询记过可能不一致。 
实现原理: 锁+MVCC,每次查询数据时,读取最新事务版本的数据。

Each consistent read, even within the same transaction, sets and reads its own fresh snapshot.

REPEATABLE READ

定义:事务A执行过程中,多次查询的结果一致; 
问题:幻读。事务A执行过程中,如果有其它事务提交了写操作,那么事务A不感知,比如事务B插入新数据。

Suppose that you are running in the default REPEATABLE READ isolation level. When you issue a consistent read (that is, an ordinary SELECT statement), InnoDB gives your transaction a timepoint according to which your query sees the database. If another transaction deletes a row and commits after your timepoint was assigned, you do not see the row as having been deleted. Inserts and updates are treated similarly.

实现原理: 锁+MVCC,每次查询数据时,只能读取小于等于当前事务版本的数据。

This is the default isolation level for InnoDB. Consistent reads within the same transaction read the snapshot established by the first read. This means that if you issue several plain (nonlocking) SELECT statements within the same transaction, these SELECT statements are consistent also with respect to each other.

SERIALIZABLE

定义:并发事务串行化执行; 
问题:性能低下,一般不使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值