MySQL UPDATE LOW_PRIORITY 和 INSERT DELAYED INTO 的优点是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3234972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:32:25  来源:igfitidea点击:

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

mysql

提问by mathew

I was going through some code and noticed that UPDATE LOW_PRIORITYand INSERT DELAYED INTOare 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?

我所经历的一些代码,发现UPDATE LOW_PRIORITYINSERT DELAYED INTO用于更新数据库。这些陈述有什么用?我应该在同一个数据库中的各个表的每个插入和更新语句中使用这些吗?

回答by Sjoerd

With the LOW_PRIORITYkeyword, 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.

使用LOW_PRIORITY关键字,UPDATE 的执行被延迟,直到没有其他客户端从表中读取。通常,读取客户端会被搁置,直到更新查询完成。如果你想让阅读客户端优先于更新查询,你应该使用 LOW_PRIORITY。

The DELAYEDoption 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.

INSERT 语句的DELAYED选项是标准 SQL 的 MySQL 扩展,如果您的客户端不能或不需要等待 INSERT 完成,它非常有用。当您使用 MySQL 进行日志记录并且您还定期运行需要很长时间才能完成的 SELECT 和 UPDATE 语句时,这是一种常见情况。

回答by Federico Razzoli

LOW_PRIORITY, HIGH_PRIORITYand DELAYEDare 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.

LOW_PRIORITYHIGH_PRIORITY并且DELAYED仅在少数情况下有用。如果您没有大负载,他们将无法帮助您。如果你有,不要做任何你不完全理解的事情。

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

所有这些选项仅适用于 MyISAM,不适用于 InnoDB,不适用于视图。

DELAYEDdoesn'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 SELECTfrom that table, because an insert delayed is never concurrent.

DELAYED不适用于分区表,它显然是为数据仓库设计的。客户端发送插入然后忘记它,无需等待结果。因此,您将不知道插入是否成功,是否存在重复值等。在其他线程可以SELECT从该表中使用时,永远不应使用它,因为延迟插入永远不会并发。

LOW_PRIORITYwaits 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 :)

LOW_PRIORITY等到没有客户端访问该表。但是,如果您的流量很高,则可能会等到连接超时……这不是您想要的,我想:)

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

另请注意,DELAYED它将在 Oracle MySQL 5.7 中删除(但不在 MariaDB 中)。

回答by Dharma

If your UPDATEs on MySQL a read intensive environment are taking as much as 1800 seconds then it is advisable to use the UPDATE LOW_PRIORITY.

如果您在 MySQL 上的 UPDATE 读取密集型环境需要多达 1800 秒,那么建议使用 UPDATE LOW_PRIORITY。

回答by Liutas

If you need to use these, then you have a big load on your server, and you know that some UPDATE or INSERT statements are not high priority and they can act on load.

如果您需要使用这些,那么您的服务器上就会有很大的负载,并且您知道某些 UPDATE 或 INSERT 语句的优先级不高,它们可以对负载进行操作。

Example: SQL that generates some statistics or items top. They are slow, and do not need to be executed immediately.

示例:生成一些统计信息或项目顶部的 SQL。它们很慢,不需要立即执行。