gpt4 book ai didi

php - 我应该在 PDO 事务中运行多个 SELECT 以提高性能吗?

转载 作者:可可西里 更新时间:2023-11-01 08:01:02 26 4
gpt4 key购买 nike

PDO 事务是否仅用于 UPDATE、INSERT 和 DELETE,或者如果您将一个事务用于多个 SELECT 查询,您能否获得性能提升?

最佳答案

从纯粹的观点来看,在 SELECT 语句上使用事务来“提高性能”是错误的。使用事务确保不会出现数据不一致的情况。

从性能的角度来看,锁定表以使其他语句无法访问它以加速您的 SELECTs 可能有效 - 但可能有更好的解决方案比起那个来说。例如,在 SELECT statement 中使用 HIGH_PRIORITY 属性:

HIGH_PRIORITY gives the SELECT higher priority than a statement that updates a table. You should use this only for queries that are very fast and must be done at once. A SELECT HIGH_PRIORITY query that is issued while the table is locked for reading runs even if there is an update statement waiting for the table to be free. This affects only storage engines that use only table-level locking (such as MyISAM, MEMORY, and MERGE).

这样您就可以使用适当的方法来实现目标,而不是让其他开发人员(甚至您的 future )想知道它为什么存在的一些 hack。

关于php - 我应该在 PDO 事务中运行多个 SELECT 以提高性能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3319260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com