Optimizing MySQL / MariaDB Performance Using Invisible Indexes (Zero-Risk Tuning)

Overview

Traditional database index optimization is risky in production environments. Dropping or modifying indexes can immediately impact query performance and cause outages.

Invisible Indexes provide a safe, reversible method to test index impact without affecting production queries. This feature is available in MySQL 8.0+ and MariaDB 10.6+, yet remains largely undocumented in real-world optimization guides.

This tutorial explains how to use invisible indexes to perform zero-risk database performance tuning in production systems.


Why Invisible Indexes Matter


Supported Versions

Database

Version

MySQL

8.0+

MariaDB

10.6+

Check version:

mysql --version

What Is an Invisible Index?

An invisible index:

This allows DBAs to evaluate whether an index is truly required.


Step 1: Identify Candidate Indexes

List indexes for a table:

SHOW INDEX FROM orders;

Look for:


Step 2: Make an Index Invisible (Safe Test)

ALTER TABLE orders
ALTER INDEX idx_customer_id INVISIBLE;

What Happens


Step 3: Monitor Query Performance

Use execution plans:

EXPLAIN ANALYZE
SELECT * FROM orders WHERE customer_id = 1024;

Compare:


Step 4: Enable Optimizer Tracing (Optional)

SET optimizer_trace="enabled=on";

Run query:

SELECT * FROM orders WHERE customer_id = 1024;

Retrieve trace:

SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;

This confirms whether the invisible index would have been chosen.


Step 5: Decision Point

If Performance Is Unaffected

Drop the index safely:

ALTER TABLE orders DROP INDEX idx_customer_id;

If Performance Degrades

Restore instantly:

ALTER TABLE orders
ALTER INDEX idx_customer_id VISIBLE;

No restart or rebuild required.


Step 6: Use Invisible Indexes for New Index Testing

Create an index invisibly:

CREATE INDEX idx_orders_date
ON orders(order_date)
INVISIBLE;

Test queries safely before enabling:

ALTER TABLE orders
ALTER INDEX idx_orders_date VISIBLE;

Production Safety Benefits

Action

Traditional

Invisible Index

Test index removal

Risky

Safe

Rollback

Slow

Instant

Downtime risk

High

None

Optimizer impact

Immediate

Controlled


Common Optimization Scenarios


Best Practices


Verification Commands

List invisible indexes:

SELECT
    INDEX_NAME,
    IS_VISIBLE
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_NAME = 'orders';

Limitations


Conclusion

Invisible indexes enable zero-risk database optimization, allowing DBAs to safely evaluate index usage in live production environments.

Despite being available for years, this feature remains underutilized and is rarely covered in optimization guides.