WordPress查询耗时超过20秒,并停留在创建索引上

时间:2020-10-19 作者:Danial Akhter

您好,我需要以下查询的帮助此查询大约需要20秒,当执行多个查询时,服务器CPU使用率达到100%,服务器停止响应。

这是来自进程列表的查询。

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE \'%اهمية%\') OR (wp_posts.post_excerpt LIKE \'%اهمية%\') OR (wp_posts.post_content LIKE \'%اهمية%\')) AND ((wp_posts.post_title LIKE \'%التصنيع%\') OR (wp_posts.post_excerpt LIKE \'%التصنيع%\') OR (wp_posts.post_content LIKE \'%التصنيع%\')) AND ((wp_posts.post_title LIKE \'%الغذائي%\') OR (wp_posts.post_excerpt LIKE \'%الغذائي%\') OR (wp_posts.post_content LIKE \'%الغذائي%\'))) AND (wp_posts.post_password = \'\') AND wp_posts.post_type IN (\'post\', \'attachment\') AND (wp_posts.post_status = \'publish\') ORDER BY (CASE WHEN wp_posts.post_title LIKE \'%اهمية التصنيع الغذائي %\' THEN 1 WHEN wp_posts.post_title LIKE \'%اهمية%\' AND wp_posts.post_title LIKE \'%التصنيع%\' AND wp_posts.post_title LIKE \'%الغذائي%\' THEN 2 WHEN wp_posts.post_title LIKE \'%اهمية%\' OR wp_posts.post_title LIKE \'%التصنيع%\' OR wp_posts.post_title LIKE \'%الغذائي%\' THEN 3 WHEN wp_posts.post_excerpt LIKE \'%اهمية التصنيع الغذائي %\' THEN 4 WHEN wp_posts.post_content LIKE \'%اهمية التصنيع الغذائي %\' THEN 5 ELSE 6 END), wp_posts.post_date DESC LIMIT 0, 10

以下是wp\\U posts表上的索引

+----------+------------+---------------------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name                              | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+---------------------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| wp_posts |          0 | PRIMARY                               |            1 | ID            | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | post_name                             |            1 | post_name     | A         |      172779 |      191 | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | type_status_date                      |            1 | post_type     | A         |          32 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | type_status_date                      |            2 | post_status   | A         |          42 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | type_status_date                      |            3 | post_date     | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | type_status_date                      |            4 | ID            | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | post_parent                           |            1 | post_parent   | A         |       86389 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | post_author                           |            1 | post_author   | A         |         226 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | posttype_new                          |            1 | post_type     | A         |          32 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | posttype_new                          |            2 | ID            | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | posttype_new                          |            3 | post_status   | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wp_Type_status_date                   |            1 | ID            | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wp_Type_status_date                   |            2 | post_type     | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wp_Type_status_date                   |            3 | post_status   | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps          |            1 | post_status   | A         |          12 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps          |            2 | post_password | A         |          12 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps          |            3 | post_type     | A         |          40 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps          |            4 | post_modified | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps_postdate |            1 | post_status   | A         |          14 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps_postdate |            2 | post_password | A         |          14 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps_postdate |            3 | post_type     | A         |          42 |     NULL | NULL   |      | BTREE      |         |               |
| wp_posts |          1 | wpi_scalability_pro_sitemaps_postdate |            4 | post_date     | A         |      172779 |     NULL | NULL   |      | BTREE      |         |               |
+----------+------------+---------------------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

1 个回复
SO网友:O. Jones

看看你的查询,我看到很多东西wp_posts.post_content LIKE \'%اهمية%\'.

你应该知道column LIKE \'%matchstring%\' 是一个臭名昭著的MySQL性能杀手。如果您可以将操作更改为使用column LIKE \'matchstring%\' (无引导%) 这会变得更好。

或者,也许你应该采用像Relevansi这样的搜索插件。(我不知道它是否适用于阿拉伯语,但它确实适用于罗马字母语言。)