From 1077d08820241a1ad765f3be8fcc51467f4310fa Mon Sep 17 00:00:00 2001 From: emorino Date: Thu, 17 Mar 2022 16:09:34 +0100 Subject: [PATCH] =?UTF-8?q?list=C3=A9=20les=20Indexs=20non=20utilis=C3=A9,?= =?UTF-8?q?=20avec=20la=20base=20information=5Fschema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HowtoMySQL/Troubleshooting.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 +; +~~~ +