Redundant Index FinderDeveloped In: SQL — Contributed by: Roland BoumanThis snippet allows you to create two views. I_S_INDEXES: lists all indexes I_S_REDUNDANT_INDEXES: lists all redundant indexes
SQL
For some reason I could not create the view and hence changed the first line to create a test table as shown here... CREATE TABLE test.I_S_INDEXES Thanks for this wonderful query. great. Heres a stored proc to drop them all
But.... I wonder why you write "todo: add "something" to indicate whether a redundant index may be required by an Innodb foreign key". Perhaps this is no longer needed on newer mysql implementations? won't the query processor recognize the existence of the other index even if the auto-created index is removed? I read that "InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan." and that "The index on the foreign key is created automatically if no index on the key columns exists." but, perhaps crucially, it goes on to say: "This is in contrast to some older versions, in which indexes had to be created explicitly or the creation of foreign key constraints would fail. " |
VotesWatches1 members are watching this tool
You must be logged in to track this tool.
Provide Feedback
You must be logged in to comment
|
Here is another query to find all the indexes in the database "my_database" that have a cardinality/count ratio of less than 0.1% Such indexes are probably not very useful, and should be looked at carefully to justify their existence.