简体   繁体   中英

Select … for update vs select on large amount of data

Assume a huge table with several hundred million records and columns are well indexed. Is there any performance concern between

SELECT * from HUGE_TABLE where ... AND ... FOR UPDATE

and

SELECT * from HUGE_TABLE where ... AND ... 

the main reason for the FOR UPDATE clause is because we may have several instance of the application running the same query at same time, but need to avoid update conflicts.

At this point is there I concern about two performance issue: 1. if there is no other query running, is select for update slower?. 2. if there are many other active query to select / update on the huge table, what will be the performance to this entire situation on this table (also update in the question)

SELECT ... FOR UPDATE creates at least two performance issues compared to a regular SELECT :

  1. Blocking other sessions. This is a bit obvious and you already understand this, but it's worth mentioning that of course creating more locks can cause performance issues. The good news is that Oracle never escalates locks, so it will only lock exactly what you ask it too.
  2. Writing lock data. The FOR UPDATE works by making a small update to each relevant block. It acts like a regular change in some ways, and will create redo and undo records as you can see by running queries like select used_urec from gv$transaction; . Depending on how many rows are locked, this could be significantly more expensive than a regular SELECT , even if no other sessions are involved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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