mysql - MySQL 中表优化的频率应由哪些因素决定?

标签 mysql

我见过许多不同的 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/

相关文章:

php - MySQL:从 INSERT SELECT 获取返回结果

php - codeigniter - MySQL - PHP 试图计算不同值的出现次数

php - 如何在 PHP/MYSQL 中将两个 mysql 查询作为一个执行?

php - 有没有办法知道 Drupal 7 中的 SelectQuery 结果中有多少行?

mysql - 将列数据转换为列并按其分组

python - Flask、MySQL 和 SQLAlchemy 查询 ID 错误

php - 使用 php 和 mysql 更新某些用户

php - 从php更新数据库信息,而不是保存

mysql - 在其他表中分离更新列是否有助于优化(MySQL MyISAM 表)?

mysql - 与记录的各个字段的多对多关系