数据库 Table 删除后非常慢
Database Table very slow after delete
我在 Google App-Engine 上有一个 MySQL InnoDB 数据库 运行。
其中一个 table 有当前日期和一个 user_id 作为主键存储一些额外的数据。
table 有大约 700 万行,我使用 DELETE 查询删除了其中的 600 万行。因为使用此 table 的任何查询都比以前慢得多。
任何想法可能导致此行为或如何解决此问题?
提前致谢!
在 innodb 上进行如此大规模的删除后,您最好使用 OPTIMISE table 语句
Use OPTIMIZE TABLE in these cases, depending on the type of table:
After doing substantial insert, update, or delete operations on an InnoDB table that has its own .ibd file because it was created with
the innodb_file_per_table option enabled. The table and indexes are
reorganized, and disk space can be reclaimed for use by the operating
system.
After doing substantial insert, update, or delete operations on columns that are part of a FULLTEXT index in an InnoDB table. Set the
configuration option innodb_optimize_fulltext_only=1 first. To keep
the index maintenance period to a reasonable time, set the
innodb_ft_num_word_optimize option to specify how many words to
update in the search index, and run a sequence of OPTIMIZE TABLE
statements until the search index is fully updated.
在优化之前,使用 ANALYSE TABLE, and it's indexes using SHOW INDEX 检查 table 的状态。这些说明将为您提供有关 "flaws" OPTIMIZE 可以修复的信息。
这一切在 phpmyadmin 中都很容易做到。
我在 Google App-Engine 上有一个 MySQL InnoDB 数据库 运行。 其中一个 table 有当前日期和一个 user_id 作为主键存储一些额外的数据。 table 有大约 700 万行,我使用 DELETE 查询删除了其中的 600 万行。因为使用此 table 的任何查询都比以前慢得多。
任何想法可能导致此行为或如何解决此问题?
提前致谢!
在 innodb 上进行如此大规模的删除后,您最好使用 OPTIMISE table 语句
Use OPTIMIZE TABLE in these cases, depending on the type of table:
After doing substantial insert, update, or delete operations on an InnoDB table that has its own .ibd file because it was created with
the innodb_file_per_table option enabled. The table and indexes are
reorganized, and disk space can be reclaimed for use by the operating system.After doing substantial insert, update, or delete operations on columns that are part of a FULLTEXT index in an InnoDB table. Set the configuration option innodb_optimize_fulltext_only=1 first. To keep
the index maintenance period to a reasonable time, set the
innodb_ft_num_word_optimize option to specify how many words to
update in the search index, and run a sequence of OPTIMIZE TABLE
statements until the search index is fully updated.
在优化之前,使用 ANALYSE TABLE, and it's indexes using SHOW INDEX 检查 table 的状态。这些说明将为您提供有关 "flaws" OPTIMIZE 可以修复的信息。
这一切在 phpmyadmin 中都很容易做到。