当我在布尔搜索中更改关键字的顺序时,我得到的结果相同但性能结果却截然不同。
使用MyISAM表,ft_min_word_len=2
和description_index
作为FULLTEXT
和title
上的description
索引对MySQL 5.6.33进行概要分析返回:< / p>
# Query 1
SELECT id
FROM archive, topic
WHERE topic.type=0 AND archive.status=2
AND MATCH(title, description) AGAINST ('+house* +tz*' IN BOOLEAN MODE)
AND archive.topicId = topic.id
ORDER BY archive.featured DESC, archive.submissionDate DESC LIMIT 0,20
结果:
Total count: 12
Key_read_requests: 2384607
Creating sort index: 7.950430 sec (!)
Duration: 8.851252 sec
# Query 2
SELECT id
FROM archive, topic
WHERE topic.type=0 AND archive.status=2
AND MATCH(title, description) AGAINST ('+tz* +house*' IN BOOLEAN MODE)
AND archive.topicId = topic.id
ORDER BY archive.featured DESC, archive.submissionDate DESC LIMIT 0,20
结果:
Total count: 12
Key_read_requests: 415
Creating sort index: 0.003449
Duration: 0.004054 sec
每个关键字的总记录数:
tz*: 135092
tz: 25596
house*: 12
两个查询的解释相同:
id | select_type | Table | Type | Key | Key len | Ref | Rows | Extra
1 | SIMPLE | archive | fulltext | description_index | 0 | | 1 | Using where; Using filesort
1 | SIMPLE | topic | eq_ref | PRIMARY | 3 | archive.topicId | 1 | Using where
只有Key_read_requests
和Creating sort index
在两个查询之间有所不同。
似乎:
问题:
答案 0 :(得分:1)
OP评论后编辑:
解析此查询时,我不确定确切的查询计划
有时一个操作比另一个操作更昂贵,因此执行较便宜的操作首先可以挑选出许多行,然后不必经历更昂贵的操作,这样可以缩短运行时间。
(在您的示例中,匹配操作之一可能比另一个更昂贵,通过更改要匹配的字符串顺序来增加和减少运行时间。)
答案 1 :(得分:-1)
您是否针对新启动的实例运行了两个查询?你可能只是获得了性能以及第二次运行时填充的缓存。