Invisible columns and indexes
INVISIBLE and VISIBLE for columns and indexes, what an invisible column is left out of, and the gaps.
An invisible column is left out of SELECT * and out of the columns an INSERT without a column list takes. An invisible index is kept and marked (D75).
Syntax#
col_name data_type ... { INVISIBLE | VISIBLE }
{ INDEX | KEY } [name] (key_part, ...) { INVISIBLE | VISIBLE }
CREATE INDEX name ON tbl_name (key_part, ...) { INVISIBLE | VISIBLE }
ALTER TABLE tbl_name ALTER COLUMN col_name SET { VISIBLE | INVISIBLE }
ALTER TABLE tbl_name ALTER INDEX index_name { VISIBLE | INVISIBLE }
ALTER TABLE tbl_name ADD COLUMN col_name data_type INVISIBLE
ALTER TABLE tbl_name MODIFY COLUMN col_name data_type INVISIBLE
ALTER TABLE tbl_name ADD INDEX name (key_part, ...) INVISIBLESHOW CREATE TABLE prints invisibility as MySQL does (/*!80023 INVISIBLE */ for columns, /*!80000 INVISIBLE */ for indexes); the parser reads that form back.
Remarks#
- An invisible column is left out of
SELECT *,t.*, derived tables made from*,TABLE tandCREATE TABLE ... AS SELECT *. It can be named everywhere else. AnINSERTwithout a column list leaves it at its default. - A table with no visible column is error 4028.
- A primary key cannot be made invisible (error 3522).
SHOW INDEXsaysVisible = NO;DESCRIBEsaysINVISIBLEinExtra;information_schema.STATISTICS.IS_VISIBLEshows the index flag in the MySQL dialect.USING xandCOMMENT 'x'after the columns of an index are accepted.- The output is identical to MySQL 9.7 (except
Cardinality, which is not compared).
Not supported yet (known gaps)#
- An invisible index is still used by this front-end's reads (results are the same; MySQL's optimizer would not use it).
EXPLAINhere does not show indexes. information_schema.COLUMNS.EXTRAdoes not show invisibility.SET SESSION optimizer_switch='use_invisible_indexes=on'is accepted and does nothing.
Examples#
Example:
CREATE TABLE t (id INT PRIMARY KEY, a INT, secret INT INVISIBLE DEFAULT 7,
note VARCHAR(10) INVISIBLE, b INT, KEY ia (a) INVISIBLE, UNIQUE KEY ub (b));
INSERT INTO t VALUES (1, 10, 100); -- id, a, b
SELECT * FROM t; -- id, a, b
SELECT id, secret, note FROM t; -- invisible columns by name
ALTER TABLE t ALTER COLUMN a SET INVISIBLE;
ALTER TABLE t ALTER INDEX ia VISIBLE;
CREATE INDEX ib2 ON t (a) INVISIBLE;