Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of UPDATE LOW_PRIORITY and INSERT DELAYED INTO?

Tags:

mysql

I was going through some code and noticed that UPDATE LOW_PRIORITY and INSERT DELAYED INTO are used for updating the database. What is is the use of these statements? Should I use these in every insert and update statement for various tables in the same database?

like image 214
mathew Avatar asked Jul 13 '10 07:07

mathew


People also ask

What does Low_priority do when used with INSERT option?

If you use the LOW_PRIORITY modifier, execution of the INSERT is delayed until no other clients are reading from the table. This includes other clients that began reading while existing clients are reading, and while the INSERT LOW_PRIORITY statement is waiting.

What is INSERT delayed?

The DELAYED option for the INSERT statement is a MySQL extension to standard SQL that can be used for certain kinds of tables (such as MyISAM ). When a client uses INSERT DELAYED , it gets an okay from the server at once, and the row is queued to be inserted when the table is not in use by any other thread.

Is INSERT is same as UPDATE?

Insert is for adding data to the table, update is for updating data that is already in the table.


2 Answers

With the LOW_PRIORITY keyword, execution of the UPDATE is delayed until no other clients are reading from the table. Normally, reading clients are put on hold until the update query is done. If you want to give the reading clients priority over the update query, you should use LOW_PRIORITY.

The DELAYED option for the INSERT statement is a MySQL extension to standard SQL that is very useful if you have clients that cannot or need not wait for the INSERT to complete. This is a common situation when you use MySQL for logging and you also periodically run SELECT and UPDATE statements that take a long time to complete.

like image 93
Sjoerd Avatar answered Sep 24 '22 09:09

Sjoerd


LOW_PRIORITY, HIGH_PRIORITY and DELAYED are only useful in a few circustamces. If you don't have a BIG load they can't help you. If you have, don't do anything you don't fully understand.

All of these otpions only work with MyISAM, not InnoDB, not views.

DELAYED doesn't work with partitioned tables, and it's clearly designed for dataware house. The client sends the insert and then forgets it, without waiting for the result. So you won't know if the insert succeded, if there were duplicate values, etc. It should never be used while other threads could SELECT from that table, because an insert delayed is never concurrent.

LOW_PRIORITY waits until NO client is accessing the table. But if you have a high traffic, you may wait until the connection times out... that's not what you want, I suppose :)

Also, note that DELAYED will be removed in Oracle MySQL 5.7 (but not in MariaDB).

like image 39
Federico Razzoli Avatar answered Sep 22 '22 09:09

Federico Razzoli