Databases 4 min read

How Invisible Indexes in MySQL 8.0 Simplify Index Management

MySQL 8.0 introduces invisible indexes, allowing you to hide indexes from the optimizer while keeping them maintained, which serves as an index recycle bin for safe testing and removal, and the article explains their purpose, usage, and limitations with practical SQL examples.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How Invisible Indexes in MySQL 8.0 Simplify Index Management

What Is the Purpose of Invisible Indexes

MySQL 8.0 supports Invisible Indexes , a feature that lets an index be invisible to the optimizer while still being maintained during data changes. This acts like an index recycle bin, allowing you to hide rarely used indexes during optimization without dropping them.

When a database has accumulated many indexes over time, removing and recreating them can be costly, especially for large tables. By marking an index as invisible, you can test the impact of its removal and later make it visible again if needed.

In MySQL 8.0.0 only InnoDB supports invisible indexes; from 8.0.1 all storage engines can use them.

How to Use Invisible Indexes

Specify When Creating a Table

CREATE TABLE t1 (
  i INT,
  j INT,
  k INT,
  INDEX i_idx (i) INVISIBLE
) ENGINE=InnoDB;

Specify When Creating an Index

CREATE INDEX j_idx ON t1 (j) INVISIBLE;

Alter Table to Add an Invisible Index

ALTER TABLE t1 ADD INDEX k_idx (k) INVISIBLE;

Make an Invisible Index Visible

ALTER TABLE t1 ALTER INDEX i_idx VISIBLE;

Check Index Visibility

SELECT INDEX_NAME, IS_VISIBLE
FROM information_schema.statistics
WHERE TABLE_SCHEMA='db1' AND TABLE_NAME='t1';

List All Invisible Indexes

SELECT * FROM information_schema.statistics WHERE is_visible='NO';

Note: Primary key indexes cannot be made invisible. Also, a UNIQUE NOT NULL column that serves as an implicit primary key cannot be set invisible.

References

https://dev.mysql.com/doc/refman/8.0/en/invisible-indexes.html
http://mysqlserverteam.com/mysql-8-0-invisible-indexes/
https://dzone.com/articles/thoughts-on-mysql-80-invisible-indexes
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlDatabase OptimizationindexesInvisible Index
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.