A brief analysis of scheduling priority and change of mysql statement

  • 2020-05-24 06:22:09
  • OfStack

The default scheduling policy for MySQL can be summarized as follows:
· write operations take precedence over read operations.
· write operations to a certain data table can only occur once at a certain time, and write requests are processed according to the order in which they arrive.
· multiple reads of a data table can be performed simultaneously.
MySQL allows you to change the priority of statement scheduling

MySQL provides several statement moderators that allow you to modify its scheduling policy:
· LOW_PRIORITY keyword applies to DELETE, INSERT, LOAD DATA, REPLACE and UPDATE.
· the HIGH_PRIORITY keyword applies to the SELECT and INSERT statements.
· the DELAYED keyword applies to the INSERT and REPLACE statements.
The LOW_PRIORITY and HIGH_PRIORITY moderators affect storage engines that use table locks (for example, MyISAM and MEMORY). The DELAYED adjuster ACTS on the MyISAM and MEMORY data tables.
update/insert/load data /replace/delete[low_priority]....
select/insert[high_priotiy]...

If the write operation is an LOW_PRIORITY (low priority) request, the system will not consider it to have a higher priority than the read operation. In this case, if the second reader arrives while the writer is waiting, the second reader is allowed to insert before the writer. The writer is allowed to start only when there are no other readers. In theory, this scheduling change implies that there may be situations where the LOW_PRIORITY write operation is permanently blocked. If the previous read operation did not arrive until another read operation was in progress, the new request would be inserted before the LOW_PRIORITY write operation.

The HIGH_PRIORITY (high priority) keyword for the SELECT query is similar. It allows SELECT to insert pending write operations before them, even if they would normally have a higher priority. Another effect is that high-priority SELECT is executed before normal SELECT statements because these statements are blocked by write operations.

If you want all statements that support the LOW_PRIORITY option to be processed by default at a low priority, use the -- low-priority-updates option to start the server
Note: the above instructions are for storage engines that use table locks, such as myisam and merge


Related articles: