Vadim wrote some time ago about how to find unused indexes with single query.

I was working on the system today and found hundreds of unused indexes on dozens of tables so just dropping indexes manually did not look fun. So I extended Vadim’s query to generate ALTER TABLE statements automatically. I also made it to look only at tables which were accessed:

I however would warn against using it blindly in production. It is possible some indexes were not used since startup but are still used… for example if you’re having monthly billing or something like it.

However it is very helpful for testing allowing to drop all potentially not needed indexes so you can perform proper QA and ensure you really did not drop anything you needed. In such case it would make sense to run this query in production but then do changes in test envinronment first.

Note this query requres MySQL with Percona Extensions and user statistics running.

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jan

Is it possible to find unused index also on a MyISAM table? The above query says “#1109 – Unknown table ‘index_statistics’ in information_schema” at my system (MySQL 5.0.67).

pat

Plus doesn’t dropping the index lock the table for the duration?

I remain skeptical of the utility of dropping unused (or rarely used) indexes.

The load on most web applications is heavily weighted towards SELECT operations and there’s little downside to having “too many” indexes in that case. Only thing its really going to cost you is insert/update/delete time and some disk space.

To be sure, there will be cases where you’ve got an update bound workload and removing useless indexes is the solution, but, at least for the kind of applications I work with, that’s very much the edge case.

Baron Schwartz

Don’t forget about extraordinary circumstances, such as restoring from backups, checking for corruption after a crash, etc.

PHP Programmer

I had a problem with my database searching in DVLA number plates ’35785613′ Records altogather 1.6 GB database size when I delete redudant indexes, my search was improved.