Databases 11 min read

Understanding Invisible Columns, Generated Invisible Primary Keys, and Invisible Indexes in MySQL 8.0

This article explains three relatively new MySQL 8.0 features—hidden (invisible) columns, generated invisible primary keys, and invisible indexes—detailing their purpose, how to create and use them, and practical scenarios where they can help avoid schema‑change issues or test query performance.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Understanding Invisible Columns, Generated Invisible Primary Keys, and Invisible Indexes in MySQL 8.0

MySQL 8.0 introduces several “invisible” features that are not shown in default SELECT * queries but can be useful for schema evolution and testing.

Invisible Columns

Invisible columns are regular columns marked with the INVISIBLE keyword; they are omitted from SELECT * results unless explicitly referenced. They can be added to avoid breaking applications that use SELECT * when the schema changes, and later made visible with VISIBLE .

CREATE TABLE articles (
  id INT UNSIGNED AUTO_INCREMENT,
  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  article TEXT,
  PRIMARY KEY(id)
);
ALTER TABLE articles ADD COLUMN title VARCHAR(200) INVISIBLE AFTER ts;
UPDATE articles SET title='Title 1' WHERE id=1;
SELECT * FROM articles;   -- title not returned
SELECT id, ts, title, article FROM articles;   -- title returned
ALTER TABLE articles MODIFY COLUMN title VARCHAR(200) VISIBLE;

Generated Invisible Primary Key (GIPK)

When the system variable sql_generate_invisible_primary_key is ON, InnoDB automatically creates an invisible BIGINT UNSIGNED AUTO_INCREMENT column named my_row_id for tables without an explicit primary key.

SET sql_generate_invisible_primary_key=ON;
CREATE TABLE customer(name VARCHAR(50));
-- Table now has hidden primary key my_row_id
SELECT my_row_id, name FROM customer;
ALTER TABLE customer MODIFY COLUMN my_row_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT VISIBLE;

Invisible Indexes

Indexes can be marked INVISIBLE so the optimizer ignores them, allowing testing of query plans without dropping the index. The index still receives updates and can be made visible again.

ALTER TABLE mytable ALTER INDEX my_idx INVISIBLE;
ALTER TABLE mytable ALTER INDEX my_idx VISIBLE;

These features help avoid breaking applications that rely on SELECT * , provide a fallback primary key for legacy tables, and enable safe performance testing of index usage.

MySQLdatabase schemaGenerated Primary KeyInvisible ColumnsInvisible Indexes
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login 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.