【问题标题】:Optimize wordpress mysql database filesort in 415885 lines优化wordpress mysql数据库文件排序415885行
【发布时间】:2020-04-25 17:16:17
【问题描述】:
mysql> explain SELECT  t.*, tt.* FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag') AND tt.count > 0 ORDER BY tt.count DESC LIMIT 45;
+----+-------------+-------+------------+--------+---------------------------+----------+---------+--------------------------------------------------+--------+----------+----------------------------------------------------+
| id | select_type | table | partitions | type   | possible_keys             | key      | key_len | ref                                              | rows   | filtered | Extra                                              |
+----+-------------+-------+------------+--------+---------------------------+----------+---------+--------------------------------------------------+--------+----------+----------------------------------------------------+
|  1 | SIMPLE      | tt    | NULL       | ref    | term_id_taxonomy,taxonomy | taxonomy | 130     | const                                            | 415885 |    33.33 | Using index condition; Using where; Using filesort |
|  1 | SIMPLE      | t     | NULL       | eq_ref | PRIMARY                   | PRIMARY  | 8       | dosk_com_app20413575705d6c60930e2af.tt.term_id |      1 |   100.00 | NULL                                               |
+----+-------------+-------+------------+--------+---------------------------+----------+---------+--------------------------------------------------+--------+----------+----------------------------------------------------+

每次访问该站点时,都会在 415885 行中进行文件排序,这通常需要 14 秒。 知道如何优化吗?

谢谢

【问题讨论】:

    标签: mysql wordpress file sorting


    【解决方案1】:

    文件排序是因为 order by,但是我看不出你如何能够在像 Wordpress 这样的系统中消除它。至少试试没有 order by 的解释语句,以确保是这种情况。

    我会查看以下优化路径

    • 缓存页面
    • 查询应该是可缓存的,MySQL 查询缓存是否开启?
    • wp_term_taxonomy 听起来像一个链接表,每行应该很小。因此,表扫描不应花费 14 秒。这表明磁盘性能不足

    【讨论】:

    • 是的,它已开启,但如何修改通常在每次修改时都会失效
    • P.S.它有 831,962 行和 95.8 MiB,硬盘是 ssd
    • wp_term_taxonomy 没有索引 term_id 并且它面临 join ON t.term_id = tt.term_id
    猜你喜欢
    • 2015-12-23
    • 2011-07-16
    • 1970-01-01
    • 2012-07-20
    • 2010-12-12
    • 2013-08-14
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    相关资源
    最近更新 更多