相比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