lightdb 支持语法 for update of column

背景

在业务产品中,存在 Oracle 移植过来的 SQL 语句。它们使用 for update of column 对字段上锁。lightdb 23.4 版本对此语法糖进行了支持。

lightdb 支持语法 for update of column

在 lightdb 23.4 以后 oracle 兼容模式中 for update of column 将会锁表或者锁行,与 for update 功能保持一致。兼容 oracle 的 for update of column 写法不报错,其中 for update of 为关键字 column 为列名(语法糖实现暂时不判断列名的正确性)。该功能在执行 select 语句时上锁查询结果。被锁住的行或者表将无法执行update语句修改数据。具体如下示例

示例一锁表
在session1中创建表
create table my_column(id int , name varchar);
insert into my_column(id, name) values(1, 'mumu');
insert into my_column(id, name) values(2, 'anni');
在session1启动事务并上锁
begin;
select * from my_column , my_column as s for update of id;
在session2执行update
update my_column set name = 'dema' where id =1;

等待session1提交

在session1提交事务
commit;
在session2中

session1提交后 session2 获取锁后即执行update成功

示例二锁行
在session1中启动事务并上锁
begin;
select * from my_column where id = 1 for update of id;
在session2 中执行update
update my_column set name = 'akali' where id = 2;

执行成功

update my_column set name = 'xiong' where id = 1;

等待session1提交

在session1提交事务
commit;
在session2中

session1提交后 session2 获取锁后即执行update成功

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值