Salve,
ho un problema con la seguente query che include Count, Group By, Order By sul Count e vorrei ottimizzarla perchè il tempo di esecuzione è intorno a 1 secondo.
SELECT COUNT(pagamento.paid) as pagamento_preferito, pagamento.nome
FROM ordine, pasp01, pagamento
WHERE ordine.paspid = pasp01.paspid
AND pasp01.paid = pagamento.paid
GROUP BY pagamento.paid ORDER BY pagamento_preferito DESC LIMIT 1;
paid e paspid sono indici. Questo l'Explain:
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: pagamento
type: index
possible_keys: PRIMARY
key: PRIMARY
key_len: 2
ref: NULL
rows: 4
Extra: Using temporary; Using filesort
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: pasp01
type: ref
possible_keys: PRIMARY,paid
key: paid
key_len: 2
ref: ecommgiugno2.pagamento.paid
rows: 1
Extra: Using index
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: ordine
type: ref
possible_keys: paspid
key: paspid
key_len: 2
ref: ecommgiugno2.pasp01.paspid
rows: 50007
Extra: Using index
Grazie mille!

Rispondi quotando