gpt4 book ai didi

mysql - "Using Temporary"与自定义 WordPress 搜索

转载 作者:行者123 更新时间:2023-11-30 01:25:55 29 4
gpt4 key购买 nike

我目前使用自定义 WordPress MySQL 查询来获取我的一些购物网站的相关产品。我刚刚分析了我的页面,我注意到这个查询大约需要 3 秒,但我不确定如何优化它。查询如下:

explain select 
p . *,
unix_timestamp(p.post_modified) as post_modified_ut,
unix_timestamp(p.post_date) as post_date_ut,
(((2.3 * (MATCH (p.post_title) AGAINST ('Motorola+MBP+36+Digital+Video+Monitor' IN BOOLEAN MODE)))) + (0.6 * (MATCH (p.post_content) AGAINST ('Motorola+MBP+36+Digital+Video+Monitor' IN BOOLEAN MODE)))) AS relevance
from
wp_posts as p,
wp_terms as t,
wp_term_taxonomy as tt,
wp_term_relationships as tr
where
(MATCH (p.post_title , p.post_content) AGAINST ('Motorola+MBP+36+Digital+Video+Monitor' IN BOOLEAN MODE))
and tr.object_id = p.ID
and tr.term_taxonomy_id = tt.term_taxonomy_id
and tt.term_id = t.term_id
and p.post_type = 'post'
and p.post_status in ('inherit' , 'publish')
group by p.ID , p.post_title
order by relevance desc
limit 5;

解释的结果是:

+----+-------------+-------+--------+-------------------------------------------------+------------------+---------+------------------------------------+------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+-------------------------------------------------+------------------+---------+------------------------------------+------+---------------------------------+
| 1 | SIMPLE | tt | ALL | PRIMARY,term_id_taxonomy | NULL | NULL | NULL | 2822 | Using temporary; Using filesort |
| 1 | SIMPLE | t | eq_ref | PRIMARY | PRIMARY | 8 | reviewexplorer.tt.term_id | 1 | Using index |
| 1 | SIMPLE | tr | ref | PRIMARY,term_taxonomy_id | term_taxonomy_id | 8 | reviewexplorer.tt.term_taxonomy_id | 5 | |
| 1 | SIMPLE | p | eq_ref | PRIMARY,type_status_date,searches,searches_more | PRIMARY | 8 | reviewexplorer.tr.object_id | 1 | Using where |
+----+-------------+-------+--------+-------------------------------------------------+------------------+---------+------------------------------------+------+---------------------------------+

正如您所看到的,我正在使用临时表,但我不想这样做,我想创建一个索引来加速此查询,但我不完全理解解释告诉我的内容。

最佳答案

显然,MySQL 无法在 wp_term_taxonomy 表上使用任何索引,并且必须在临时表中检查+排序所有 2822 行。话虽这么说,2822 行并没有大到可以解释这么长的查询时间。数据库或磁盘负载高吗?无论如何...

<小时/>

通过更仔细地查看您的查询,您会发现它非常令人困惑。显然,您有一个 wp_term_taxonomy.term_taxonomy_idwp_term_relationships.term_taxonomy_id 但是可能的索引位于 wp_term_taxonomy.term_id_taxonomy 上。

看出区别了吗? term_taxonomy_idterm_id_taxonomy
这是一个错字吗?一个错误? “功能”?

关于mysql - "Using Temporary"与自定义 WordPress 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17990093/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com