2

我正在使用 Prestashop 解决方案开发分层导航模块,我正在尝试优化一个 Sql 查询,该查询创建一个 tmp 表来执行它,并通过这种方式在 mysql 中创建一个瓶颈。

这是查询:

SELECT p.*, p.id_category_default, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL 30 DAY)) > 0 AS new 
FROM `ps_category_product` cp 
LEFT JOIN ps_category c ON (c.id_category = cp.id_category) 
LEFT JOIN `ps_product` p ON p.`id_product` = cp.`id_product` 
LEFT JOIN ps_product_lang pl ON (pl.id_product = p.id_product) 
LEFT JOIN ps_image i ON (i.id_product = p.id_product AND i.cover = 1) 
LEFT JOIN ps_image_lang il ON (i.id_image = il.id_image AND il.id_lang = 2) 
LEFT JOIN ps_manufacturer m ON (m.id_manufacturer = p.id_manufacturer) 
WHERE p.`active` = 1 AND c.nleft >= 2 AND c.nright <= 29 AND c.active = 1 AND pl.id_lang = 2 
AND p.id_product IN (74,78,130,146,168,169,178,195,...,297,302,1986,1987,1988,1993,1999,2000,2001) 
GROUP BY p.id_product ORDER BY p.date_upd desc LIMIT 0,48

我知道 tmp 表是因为 GROUP BY 而创建的,但我不知道如何删除它。如果可以使用 PHP 而不是 SQL 完成相同的过程,那么它可能是一个解决方案。

提前致谢。

4

0 回答 0