我正在为收集element
与查询匹配的网站运行搜索查询。但是,可能有也可能没有一个或多个items
链接到element
. 所以,我有一个子查询来计算所有items
链接到element
.
这个查询确实有效。但慢得令人难以置信。目前我需要大约 50 秒。如果我放弃子查询,它会快得多。
SELECT DISTINCT e.id,
MATCH (e.heading) AGAINST ('+(room)') AS h_score,
MATCH (e.text) AGAINST ('+(room)') AS t_score,
(
SELECT SUM( MATCH (item.heading, item.text) AGAINST ('+(room)') ) AS itemscore
FROM item LEFT JOIN _element_item ON item.id = _element_item.item_id
WHERE _element_item.item_id = e.id
AND MATCH (item.heading, item.text) AGAINST ('+(room)')
) AS i_score
FROM element AS e
LEFT JOIN _element_brand ON e.id = _element_brand.element_id
LEFT JOIN _element_language ON e.id = _element_language.element_id
LEFT JOIN _element_region ON e.id = _element_region.element_id
LEFT JOIN _element_type ON e.id = _element_type.element_id
LEFT JOIN _element_group ON e.id = _element_group.element_id
WHERE _element_brand.brand_id = 1
AND _element_language.language_iso = 'en'
AND _element_region.region_id = 1
AND _element_type.type_id = 1
AND _element_group.group_id = 1
AND e.replacement_id IS NULL
AND e.status = 1
AND MATCH (e.heading, e.text) AGAINST ('+(room)')
ORDER BY t_score + h_score DESC LIMIT 100
有没有办法让它运行得更快?
我猜它element
在匹配element
? 我可以让它只对父查询中的匹配项运行子查询吗?如果是这样,怎么做?