Course contentsShow
← Databases & SQL
Lesson 1052 of 1,9539. MySQL and MariaDB EcosystemsFree lesson

Invisible Indexes

Test the performance impact of removing an index before dropping it from production.

In this lesson, you will learn how to safely evaluate the performance impact of removing a production index using the "Invisible Index" feature.

The Problem with Dropping Indexes

In a high-traffic production environment, dropping an index is a "measure twice, cut once" operation. If you drop an index that the query optimizer relies on for a mission-critical report, your application might experience a sudden spike in latency or CPU usage. Conversely, keeping unused indexes bloats your storage and slows down INSERT, UPDATE, and DELETE operations. Invisible indexes provide a middle ground.

How Invisible Indexes Work

An invisible index is maintained by the database engine, meaning it stays updated with every change to the data, but the optimizer is instructed to ignore it during query planning.

Think of it as a "trial removal." You can hide the index, monitor your system performance for a few hours or days, and if everything runs smoothly, you can safely drop it. If performance degrades, you can make it visible again in milliseconds, rather than waiting for an expensive CREATE INDEX operation to rebuild the structure.

Practical Implementation

In MySQL or MariaDB, you can toggle an index's visibility without deleting it:

-- Step 1: Hide the index from the optimizer
ALTER TABLE users ALTER INDEX idx_email INVISIBLE;

-- Step 2: Observe your application metrics and query logs
-- If queries are slow, revert immediately:
ALTER TABLE users ALTER INDEX idx_email VISIBLE;

-- Step 3: Once you are confident, drop the index
ALTER TABLE users DROP INDEX idx_email;

When an index is invisible, EXPLAIN plans will treat the index as if it does not exist. This allows you to verify exactly which path the optimizer will take once the index is gone. By incorporating this into your maintenance workflow, you eliminate the "guesswork" traditionally associated with index cleanup.

Key Takeaway: Use Invisible Indexes to simulate index deletion in production, ensuring you can instantly recover performance if the optimizer begins choosing inefficient execution plans.