Explain différent pour 2 tables de même structure
Bonjour,
les tables invoice2010 et invoice2011 ont exactement la même structure (mêmes champs et mêmes index). Dans ce cas comment se fait-il que les résultats d'un explain d'une requête sur chacune de ces tables soient différents ?
Code:
1 2 3 4 5 6 7 8 9 10
| EXPLAIN
SELECT allarticle.collectionid,
invoicetable.clientid,
invoicetable.flowtypecode,
SUM(invoicetable.quantity),
SUM(invoicetable.grossamount)
FROM invoice2010 invoicetable
JOIN allarticle ON (invoicetable.articleid = allarticle.articleid)
WHERE flowtypecode IN ('O','V','R')
GROUP BY collectionid, clientid, flowtypecode; |
donne :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| ligne 1
id : 1
select_type : SIMPLE
table : allarticle
type : index
possible_keys : PRIMARY
key : allarticle$collectionid
key_len : 4
ref : null
rows : 25352
Extra : Using index; Using temporary; Using filesort
ligne 2
id : 1
select_type : SIMPLE
table : invoicetable
type : ref
possible_keys : invoice2010$articleid,invoice2010$flowtypecode
key : invoice2010$articleid
key_len : 4
ref : allarticle.articleid
rows : 88
Extra : Using where |
temps d'exécution : 195,79 s (!)
alors que
Code:
1 2 3 4 5 6 7 8 9 10
| EXPLAIN
SELECT allarticle.collectionid,
invoicetable.clientid,
invoicetable.flowtypecode,
SUM(invoicetable.quantity),
SUM(invoicetable.grossamount)
FROM invoice2011 invoicetable
JOIN allarticle ON (invoicetable.articleid = allarticle.articleid)
WHERE flowtypecode IN ('O','V','R')
GROUP BY collectionid, clientid, flowtypecode; |
donne :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| ligne 1
id : 1
select_type : SIMPLE
table : invoicetable
type : ALL
possible_keys : invoice2011$articleid,invoice2011$flowtypecode
key : null
key_len : null
ref : null
rows : 3105041
Extra : Using index; Using temporary; Using filesort
ligne 2
id : 1
select_type : SIMPLE
table : allarticle
type : eq_ref
possible_keys : PRIMARY
key : PRIMARY
key_len : 4
ref : invoicetable.articleid
rows : 1
Extra : |
temps d'exécution : 28,63 s (!)
La table invoice2010 comporte 3.010.195 enregistrements et la table invoice2011 en comporte 3.104.783
Les index des tables invoice2010 et invoice2011 sont articleid, clientid, flowtypecode et month.
La table allarticle comporte 25.197 enregistrements.
Pourquoi une telle différence ? Et comment faire pour que la première requête se comporte comme la seconde ?
Merci pour votre aide.