首页 > 数据库 >lightdb使用一条sql实现高性能事务一致性归历史

lightdb使用一条sql实现高性能事务一致性归历史

时间:2022-09-04 21:11:35浏览次数:66  
标签:rows lightdb moved sql 一致性 where id delete

相比insert select,delete,如下:

-- lightdb专有oracle匿名块写法
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
insert into xx select xx from yy where id < xxx;
delete form yy where id < xxx;
end;
/

使用with delete insert实现数据移动,不仅性能更加、也能保持一致性,如下:

explain
WITH moved_rows AS (
    delete from lem_db_log_102200 ldl where id < 119894653
    RETURNING *
)
INSERT INTO lem_db_log_new_102232
SELECT * FROM moved_rows;

由于postgresql不支持delete limit,所以通常需要依赖where id限制,在lightdb中,则可以直接where limit,如下:

WITH moved_rows AS (
    delete from lem_db_log_102200 ldl limit 100
    RETURNING *
)
INSERT INTO lem_db_log_new_102232
SELECT * FROM moved_rows;

 

标签:rows,lightdb,moved,sql,一致性,where,id,delete
From: https://www.cnblogs.com/zhjh256/p/16544710.html

相关文章