[英]In PostgreSql which is more efficient bulk Update or delete?
In my java web application, I need to delete a set of records from a table.在我的 java web 应用程序中,我需要从表中删除一组记录。 I have 2 options:
我有两个选择:
The number of records can range from 10 to 100000. My intent here is to know the efficient and safe way to do that without putting too much load on the server.记录的数量可以在 10 到 100000 之间。我的目的是了解在不给服务器增加太多负载的情况下实现这一点的有效且安全的方法。
PS: Feel free to share any other suitable approach. PS:随意分享任何其他合适的方法。
Under the hood, an UPDATE
is actually:在引擎盖下,
UPDATE
实际上是:
Therefore, since an UPDATE
operation involves two writes, a DELETE
is actually more efficient, as it simply flags the deleted row, using one write (because of the Multi-Version Concurrency Control (MVCC) framework)因此,由于
UPDATE
操作涉及两次写入,因此DELETE
实际上更有效,因为它只是使用一次写入标记已删除的行(因为多版本并发控制 (MVCC) 框架)
Disclosure: I work for EnterpriseDB (EDB)披露:我为EnterpriseDB (EDB)工作
Update command takes much more time as compared to delete command.与删除命令相比,更新命令需要更多时间。 In the update, you are actually making a copy of the data and the old version of the data is just hidden from the view.
在更新中,您实际上是在制作数据的副本,而旧版本的数据只是从视图中隐藏。
If you require these records in the future, you can move these records in another table.如果以后需要这些记录,可以将这些记录移到另一个表中。
The advantage of this approach are:-这种方法的优点是:-
Update更新
As you don't need the records and as update is more expensive then delete you should issue a delete call in batches of let say 500 to 5000 records.由于您不需要记录并且更新比删除更昂贵,因此您应该分批发出删除调用,比如说 500 到 5000 条记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.