diff --git a/HowtoMySQL/Troubleshooting.md b/HowtoMySQL/Troubleshooting.md index d5caeebf..cba5666d 100644 --- a/HowtoMySQL/Troubleshooting.md +++ b/HowtoMySQL/Troubleshooting.md @@ -954,5 +954,26 @@ Un contournement est d'utiliser l'option `--no-tablespaces`. D'autres solutions sur +## Listé les Indexs non utilisé, avec la base information_schema + +Voici une requêtes SQL qui se base sur la base `information_schema` et les tables `STATISTICS` et `INDEX_STATISTICS` qui liste les Indexes non utilisés. + +Attention, le résultat de cette requête n'est pas fiable à 100%, car ça suppose qu'un index est inutilisé que s'il n'a jamais provoqué IO wait. +Les clés primaire et les indexs UNIQUE sont exclus : + +~~~ +SELECT st.TABLE_SCHEMA, st.TABLE_NAME, st.INDEX_NAME +FROM information_schema.STATISTICS st +LEFT JOIN information_schema.INDEX_STATISTICS idx +ON idx.INDEX_NAME = st.INDEX_NAME +AND idx.TABLE_NAME = st.TABLE_NAME +AND idx.TABLE_SCHEMA = st.TABLE_SCHEMA +WHERE +(idx.INDEX_NAME IS NULL OR idx.ROWS_READ = 0) +AND st.NON_UNIQUE = 1 +ORDER BY 1, 2, 3 +; +~~~ +