SELECT CONCAT(object_schema, '.', object_name) AS table_name, index_nameFROM performance_schema.table_io_waits_summary_by_index_usageWHERE index_name IS NOT NULL AND index_name <> 'PRIMARY' AND count_star = 0 AND object_schema NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')ORDER BY object_schema, object_nameNeeds something on the server: performance_schema must be ON.
This query is part of the "MySQL health" pack: connect the database in DataRunner and install the whole pack at once, with queries and dashboard.
What the query shows
This query lists the indexes that have not been read since the server started. It reads performance_schema.table_io_waits_summary_by_index_usage and keeps rows with count_star equal to zero. The PRIMARY key and the system schemas are excluded.
Every index costs disk, memory in the buffer pool and time on every INSERT, UPDATE and DELETE. An index nobody reads is pure cost. Run this before you drop anything and when writes are slower than they should be.
How to read each column
- table_name: schema and table that own the index.
- index_name: the index that had zero uses.
Zero uses means no SELECT, INSERT, UPDATE or DELETE touched that index through the table I/O instrumentation since the counters started.
How much to trust the result
Uptime decides. The counters reset on every restart. These are rules of thumb:
- Less than a few days of uptime: do not act on the list.
- A full business cycle (a month, if you have month-end reports) with the server up: the list is reliable.
- A UNIQUE index that shows up may still be doing a job: it enforces a constraint on every write even if no query reads it. Keep it.
- Foreign key indexes can show zero reads and still be needed for the constraint checks.
What to do about it
Do not drop straight away. In MySQL 8.0 make the index invisible first. The optimizer ignores it, but MySQL keeps maintaining it, so you can bring it back instantly:
ALTER TABLE shop.orders ALTER INDEX idx_old_status INVISIBLE;Watch for slow queries for a full cycle. If nothing complains, drop it. If something does, make it visible again:
ALTER TABLE shop.orders ALTER INDEX idx_old_status VISIBLE;
-- After a quiet cycle:
ALTER TABLE shop.orders DROP INDEX idx_old_status;Save the CREATE INDEX statement before dropping, so you can recreate it. On a very large table rebuilding the index can take a long time.
Limits of this query
- The performance_schema must be ON and the table I/O instrumentation enabled. Both are the defaults on MySQL 5.6 and later.
- MySQL 5.7 and later ship the sys schema with a view called sys.schema_unused_indexes. It reads the same Performance Schema table and skips the primary key. Unique indexes still show up in both lists, and they enforce a rule even when no query reads them, so leave them out of any cleanup.
- Indexes used only by a rare job, like a yearly report, look unused until that job runs.
- On a replica, the counters reflect only what runs on the replica.
- The account needs SELECT on performance_schema. MariaDB has the table, but check that its performance_schema is on.
Review it monthly in DataRunner
A monthly schedule fits this one. The server then collects a long enough window of usage, and you get the list by e-mail, Slack, Telegram, Discord, WhatsApp (beta), a signed webhook or Google Sheets. Add the option to skip a run with no rows if you only want to hear about it when there is a candidate.