Optimisation count et join
Bonjour,
J'ai cette requête :
Code:
1 2 3 4 5
| SELECT COUNT(*) AS NB, ID_LOTERIE
FROM BILLET
JOIN PARTICIPE ON PARTICIPE.ID_BILLET = BILLET.ID_BILLET
WHERE PARTICIPE.ID_LOTERIE = 29
AND VALIDITE_BILLET = 1; |
Elle prend en moyenne 500 ms.
J'ai ajouté un index sur VALIDITE_BILLET, on descend à 310-320ms.
Mais je trouve que c'est encore long.
Si je fais seulement
Code:
1 2 3 4 5
| SELECT ID_LOTERIE
FROM BILLET
JOIN PARTICIPE ON PARTICIPE.ID_BILLET = BILLET.ID_BILLET
WHERE PARTICIPE.ID_LOTERIE = 29
AND VALIDITE_BILLET = 1; |
J'arrive à 35ms.
Voici l'explain :
Code:
1 2 3 4
|
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE PARTICIPE NULL ref PRIMARY,FK_PARTICIPE3,index_loterie PRIMARY 4 const 93715 100.00 Using index
1 SIMPLE BILLET NULL eq_ref PRIMARY,index_validite PRIMARY 4 PARTICIPE.ID_BILLET 1 99.04 Using where |
Index sur la table billet
Code:
1 2 3 4 5
|
Nom index Type Unique Compressé Colonne Cardinalité Interclassement Null
PRIMARY BTREE Oui Non ID_BILLET 359948 A Non
FK_VALIDE BTREE Non Non ID_JOUEUR 1739 A Oui
index_validite BTREE Non Non VALIDITE_BILLET 2 A Non |
index de la table participe
Code:
1 2 3 4 5 6 7 8
|
Nom index Type Unique Compressé Colonne Cardinalité Interclassement Null
PRIMARY BTREE Oui Non ID_LOTERIE A Non
ID_PARIEUR A Non
ID_BILLET 359948 A Non
FK_PARTICIPE2 BTREE Non Non ID_PARIEUR 609 A Non
FK_PARTICIPE3 BTREE Non Non ID_BILLET 359948 A Non
index_loterie BTREE Non Non ID_LOTERIE 13 A Non |
Une idée pour diminuer encore le temps de traitement avec COUNT ?