Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low-priority query in Mysql

Tags:

mysql

Is it possible to assign a lower priority to a query in MySQL similar to the nice command on the command-line (in Linux)? If not, are there databases that can do something like that?

like image 298
Robby75 Avatar asked Jul 11 '14 18:07

Robby75


People also ask

What is low priority in SQL?

If you use the LOW_PRIORITY keyword, 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 does low priority do with insert operation?

The use of LOW_PRIORITY or HIGH_PRIORITY for an INSERT prevents Concurrent Inserts from being used.

How do I set priority in SQL query?

select * into #categories from( values (4,'Women''s'), (3,'Men''s' ), (2,'Media' ), (1,'Best of' ) ) t(priority, title); And now every customer gets the title of the higest priority he bouhgt.


1 Answers

You can use the LOW_PRIORITY or HIGH_PRIORITY in your queries depending on the type of query you execute:

INSERT [LOW_PRIORITY | HIGH_PRIORITY] INTO ...
SELECT [HIGH_PRIORITY] * FROM ...
UPDATE [LOW_PRIORITY] table ...

From the Mysql 5.7 documentation for the INSERT query for instance:

If you use the LOW_PRIORITY keyword, 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. It is possible, therefore, for a client that issues an INSERT LOW_PRIORITY statement to wait for a very long time.

But it is also said:

This affects only storage engines that use only table-level locking (such as MyISAM, MEMORY, and MERGE)

So you won't be able to use this functionnality with innodb for instance, unless you want to use LOCK_TABLES and thus reduce its performance.

like image 88
julienc Avatar answered Oct 16 '22 16:10

julienc