Created
October 16, 2023 21:59
-
-
Save asamofal/6fa343db8bb26306025509c7f0448e2d to your computer and use it in GitHub Desktop.
[MySQL] Get redundant indexes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
RI.table_schema, | |
RI.table_name, | |
ROUND(IIS.stat_value * @@innodb_page_size / 1024 / 1024, 2) redundant_index_size_in_mb, | |
RI.redundant_index_name, | |
RI.redundant_index_columns, | |
RI.redundant_index_non_unique, | |
RI.dominant_index_name, | |
RI.dominant_index_columns, | |
RI.dominant_index_non_unique, | |
RI.subpart_exists, | |
RI.sql_drop_index | |
FROM sys.schema_redundant_indexes RI | |
LEFT JOIN mysql.innodb_index_stats IIS ON RI.table_schema = IIS.database_name AND RI.table_name = IIS.table_name AND RI.redundant_index_name = IIS.index_name | |
WHERE IIS.stat_name = 'size' | |
ORDER BY redundant_index_size_in_mb DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment