事务隔离级别Serializable Isolation Level

在大型数据库中,对于更新少量行的短事务,如果并发事务修改相同行的概率较低,且存在主要是只读的长事务,Serializable隔离级别可以被考虑。然而,Serializable并不确保所有事务都能完全串行化执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In the serialization isolation level, a transaction sees only changes committed at the time the transaction—not the query—began and changes made by the transaction itself. A serializable transaction operates in an environment that makes it appear as if no other users were modifying data in the database.
--事务只能看见提交点时事务的变化,就像一个单用户环境一样

Serializable isolation is suitable for environments: --适用条件
  • With large databases and short transactions that update only a few rows   --很短的事务
  • Where the chance that two concurrent transactions will modify the same rows is relatively low  --一般没有人修改相同的数据
  • Where relatively long-running transactions are primarily read only  --相对长时间运行的事务为只读


**注意:SERIALIZABLE并不意味所有事物都能表现的好像是以一种串行方式一个接一个执行。

--以下实验以T0为时间顺序递延

EODA@PROD1> create table a( x int);

Table created.

EODA@PROD1> create table b( x int);

Table created.

EODA@PROD1> alter session set isolation_level = serializable;  --T1会话1

Session altered.

EODA@PROD1> alter session set isolation_level = serializable;  --T2会话2

Session altered.

EODA@PROD1> insert into a select count(*) from b;  --T3会话1

1 row created.

EODA@PROD1> insert into b select count(*) from a;  --T4会话2

1 row created.

EODA@PROD1> commit;  --T5会话1

Commit complete.


EODA@PROD1> commit;  --T6会话2

Commit complete.

EODA@PROD1> select * from a;

	 X
----------
	 0

EODA@PROD1> select * from b;

	 X
----------
	 0


如果是串行化完成操作那么表b行值就应该是1,但是实验结果显示都是0。因为我们count函数记数都是在T1时间。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值