我正在将MySQL数据库用于我的电子商务项目。 这是我的搜索查询:
SELECT DISTINCT p.id, p.name, p.price, p.created_at,
MATCH(p.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE) as Prv,
MATCH(b.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE) as Brv,
MATCH(bm.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE) as BMrv,
MATCH(o.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE) as Orv,
MATCH(ov.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE) as OVrv
FROM products p
LEFT JOIN brands b ON b.id = p.brand_id AND MATCH(b.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE)
LEFT JOIN brand_models bm ON bm.id = p.brand_model_id AND MATCH(bm.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE)
LEFT JOIN options o ON o.product_type_id = p.product_type_id AND MATCH(o.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE)
LEFT JOIN product_option_values pov ON pov.product_id = p.id
LEFT JOIN option_values ov ON ov.id = pov.option_value_id AND MATCH(ov.name) AGAINST('Sony* xperia* FHD* ' IN BOOLEAN MODE)
WHERE
(MATCH(p.name) AGAINST('Sony* xperia* FHD*' IN BOOLEAN MODE)
OR MATCH(b.name) AGAINST('Sony* xperia* FHD*' IN BOOLEAN MODE)
OR MATCH(bm.name) AGAINST('Sony* xperia* FHD*' IN BOOLEAN MODE)
OR MATCH(o.name) AGAINST('Sony* xperia* FHD*' IN BOOLEAN MODE)
OR MATCH(ov.name) AGAINST('Sony* xperia* FHD*' IN BOOLEAN MODE))
AND
COALESCE(b.id, bm.id, o.id, ov.id, pov.id) IS NOT NULL
GROUP BY
p.id
ORDER BY
((Prv*100) + Brv + BMrv + Orv + OVrv) DESC, p.updated_at DESC;
在这里,我使用了MATCH,再次进行了3次。 SELECT的相关性第一。在JOIN中排名第二,在WHERE中排名第三。
1)多次使用,匹配,会影响速度吗?
2)是的话,如何更改代码以获得相同的结果并降低速度?