Database Administration — Tue Apr 07

← Home | ← database-admin

MySQL - DBA Toolkit - Index Usage and Missing Indexes

Tue Apr 07 — Identify unused indexes wasting write overhead and large tables with no useful indexes that will cause full scans under load.
#mysql #dba #monitoring #performance #tool-kit

Index Health: What You Have, What You Are Using, What You Are Missing

Bad index coverage is one of the most common causes of MySQL performance problems — and one of the easiest to miss until a query goes sideways under load.

There are two sides to this. The first is tables that are large but have no meaningful indexes. Those tables will full-scan on every query that touches them. The second is indexes that exist but are never used. Those indexes are not free — they slow down every INSERT, UPDATE, and DELETE on the table.

This script gives you both views.

IndexUsageandMissingIndexes.sql
    Loading…
  

Reading the Results

Large Tables With No Secondary Indexes

ColumnWhat to Check
table_rowsEstimated row count — larger tables hurt more without indexes
total_mbSize of the table — context for how costly a full scan is
secondary_index_countZero means every non-primary-key lookup will full-scan this table

Index Usage

ColumnWhat to Check
readsHow many times this index was used to satisfy a read
writesWrite overhead charged to this index on every DML operation
fetchesRow fetches via this index

The performance_schema.table_io_waits_summary_by_index_usage view resets on restart. Stats accumulate from the last time MySQL started — newer servers have shorter history.

What to Watch For

SignalWhat It Means
Large table with secondary_index_count = 0Every ranged query or join on this table is a full scan
Index with reads = 0 and high writesThe index is never used for lookups but paid for on every write — candidate for removal
Many indexes on a high-write tableWrite amplification — each row change updates every index
Duplicate indexes covering the same columnsRedundant overhead — MySQL cannot remove these automatically

Gareth Winterman