我见过许多不同的 MySQL 表优化计划:从删除后立即执行,到每天执行一次,再到从不执行。我经常设置一个 cron 作业每晚运行以优化所有表。
您使用哪些因素来确定表格优化的频率?
最佳答案
还有来自MySQL themselves的这句话很好。
In most setups, you need not run OPTIMIZE TABLE at all. Even if you do a lot of updates to variable-length rows, it is not likely that you need to do this more than once a week or month and only on certain tables.
基于this article关于表优化。
This has the effect of defragmenting the table and reducing the size of the table on disk down to 105MB. It also has a very positive affect on query performance, reducing the select query response time from 0.63 to 0.39 seconds. N.B. the mysql query cache was turned off to demonstrate.
这是 "MySQL administrators guide" 的另一句话
OPTIMIZE TABLE does a table repair and a key analysis, and also sorts the index tree so that key lookups are faster.
只是因为这句话永远不能经常讲。
Premature optimization is the root of all evil
您应该做的是先进行测量,进行优化,然后再进行测量。然后第二天做同样的事情,如果性能的提升很小,那么你应该在之后做同样的事情,看看性能是否会得到很大的提升。
关于mysql - MySQL 中表优化的频率应由哪些因素决定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1022450/