简体   繁体   English

Oracle UPDATE语句性能

[英]Oracle UPDATE statement performance

The question is, which of the two is more performant in case of many (>1000) ids and why? 问题是,在许多(> 1000)ID的情况下,两者中的哪一个更具性能?为什么?

1) This one executed one by one for each id, and commit only after the last: 1)这个为每个id逐个执行,并且只在最后一个之后提交:

UPDATE User u SET u.status='ACTIVE' WHERE u.id=1;

2) Or: 2)或者:

UPDATE User u SET u.status='ACTIVE' WHERE u.id IN (1,2,3....)

The answer is that the second case should outperform the first. 答案是第二种情况应该胜过第一种情况。 By how much depends on how you are running these update statements. 具体取决于您运行这些更新语句的方式。 If you plan to run them from a client, eg a Java program, then your first approach would incur a big latency penalty, as you keep opening new database connections for each update. 如果您计划从客户端运行它们,例如Java程序,那么您的第一种方法会导致很大的延迟损失,因为您不断为每次更新打开新的数据库连接。 If just running separate updates on Oracle directly, you might not see much difference in performance if the list of id's in the second case are reasonably small. 如果直接在Oracle上运行单独的更新,如果第二种情况下的id列表相当小,则可能看不出性能上的差异。

There is no difference between those two statements, and the optimiser will transform the IN to the = for each ID. 这两个语句之间没有区别,优化器会将IN转换为每个ID的= But You can always check it by Execution Plans. 但您可以随时通过执行计划进行检查。 Generating and Displaying Execution Plans 生成和显示执行计划

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM