3

Can anyone please tell the difference between the following sql,

SELECT * FROM TABLE

VS

SELECT * FROM TABLE FOR UPDATE

When and at what situation i need to use For Update

It is taking more time for getting the data if i use update and getting stopped. What is happening on Update to increase the time. Please tell me the entire process happening on this.

Vinoth Babu
  • 6,724
  • 10
  • 36
  • 55

2 Answers2

8

I think the sentence from the MariaDB / MySQL manual is self-explanatory:

If you use FOR UPDATE with a storage engine that uses page or row locks, rows examined by the query are write-locked until the end of the current transaction.

DejanLekic
  • 18,787
  • 4
  • 46
  • 77
0

SELECT ... FOR UPDATE acquires write locks on objects (rows, pages, depending on engine). This involves some overhead. Additionally, the database (the InnoDB engine in most cases) needs to do additional book keeping for multi-version concurrency control (MVCC).

See the MySQL documentation on SELECT ... FOR UPDATE for in-depth information and examples.