Bonjour à tous.

Voilà, je suis en train de travailler sur la perf de ma boutique et notamment de requêtes mysql.
Et je me suis notamment rendu compte que le script d'origine génère autant de requêtes que de produits...

En clair, il récupère tous les produits de la catégorie:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
select distinct 
	p.products_id, p.products_price, p.products_tax_class_id ,p.products_image, pd.products_name, pd.products_head_title_tag 
from 
	products p, products_description pd, products_to_classification ptc 
where 
	ptc.classification_id ='59' 
	and ptc.products_id = p.products_id 
	and ptc.products_id =  pd.products_id
	and p.products_status = '1' 
	and p.products_quantity > '0' 
	and pd.language_id = 1 
order by 
	p.products_ordered DESC limit 0, 240
Puis pour chaque produit issu de la requête, il vérifie s'il y a une promo
Code : Sélectionner tout - Visualiser dans une fenêtre à part
select specials_new_products_price from specials where products_id = '461' and status
Ce qui génère une requête par produit. Du coup, si j'ai 150 produits ==> 151 requêtes

Du coup, je cherche à regrouper les deux.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
select distinct 
	p.products_id, p.products_price, p.products_tax_class_id ,p.products_image, pd.products_name, pd.products_head_title_tag, s.specials_new_products_price 
from 
	products p, products_description pd, products_to_classification ptc 
where 
	ptc.classification_id ='59' 
	and ptc.products_id = p.products_id 
	and ptc.products_id = s.products_id 
	and ptc.products_id =  pd.products_id
	and p.products_status = '1' 
	and p.products_quantity > '0' 
	and pd.language_id = 1 
order by 
	p.products_ordered DESC limit 0, 240

J'ai aussi essayé la jointure externe:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
SELECT DISTINCT p.products_id, p.products_price, p.products_tax_class_id, p.products_image, pd.products_name, pd.products_head_title_tag
FROM products p, products_description pd, products_to_classification ptc
LEFT JOIN specials s ON ptc.products_id = s.products_id
WHERE ptc.classification_id = '59'
AND ptc.products_id = p.products_id
AND ptc.products_id = s.products_id
AND ptc.products_id = pd.products_id
AND p.products_status = '1'
AND p.products_quantity > '0'
AND pd.language_id =1
ORDER BY p.products_ordered DESC
LIMIT 0 , 30
Mais nouvelle échec.
Du coup, comment regrouper les deux ?

Je suis désolé... je suis en train de me former.