MySQL Invisible Index
Invisible Index
MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in the table. MySQL maintains the invisible indexes and keeps them updated when the data in the columns associated with the indexes changes.
MySQL management system provides a visible index by default. The invisible index supports to privacy and safety of the key columns.
Syntax
The basic syntax of the invisible index shows below.
CREATE TABLE table_name( Column1data type NOT NULL PRIMARY KEY, Column2 data type VARCHAR (10) NOT NULL, INDEX (index name)INVISIBLE);
The following points should be remembered while using this syntax:
- The primary key column does not apply an invisible index.
- The other column applies the invisible statement on the table.
The basic syntax of the invisible index shows below.
CREATE INDEX name ON table name (column1, column2, columnN) INVISIBLE;
The following points should be remembered while using this syntax:
- Create index with the required index name using MySQL query.
- The "INVISIBLE" keyword requires for invisible index.
The syntax of the invisible index on the existing table shows below.
ALTER TABLE name ALTER INDEX name INVISIBLE; The syntax of the visible index on the existing index shows below. ALTER TABLE name ALTER INDEX name VISIBLE;
Examples of the Invisible index
1) Example: Create an invisible index by using a CREATE table command.
Execute the below query to create a new index with an invisible option.
mysql> create table index_table( roll_number INT NOT NULL PRIMARY KEY, name VARCHAR(10) NOT NULL, mark text NOT NULL, img blob NOT NULL, INDEX (name)INVISIBLE);
OUTPUT
Execute the below query to show the index on the table.
mysql> show index from index_table;
The above image shows an index of the table. The name column assigns for the invisible index. Here, the visibility shows a "NO" value.
2) Example: Create an invisible index with an existing table.
Execute the below query to create a new index with an invisible option.
mysql> CREATE INDEX mark ON index_table (mark (100)) INVISIBLE;
OUTPUT
Execute the below query to show the index on the table.
mysql> show index from index_table;
The above image shows three rows of invisible indexes. It contains the key name, column name, index type, and visibility of the table. Here, the mark column visibility shows the "NO" value with prefix.
3) Example: Create an invisible index with an existing index.
Execute the below query to update the index with the invisible option.
mysql> ALTER TABLE index_table ALTER INDEX name INVISIBLE;
OUTPUT
Execute the below query to show the index on the table.
mysql> show index from index_table;
The above image shows three rows of invisible indexes. The table shows the key name, column name, index type, visibility of the table. The name isassigned with NO value in the visible column.
4) Example: Create a visible index with the existing index.
Execute the below query to update the index with the invisible option.
mysql> ALTER TABLE index_table ALTER INDEX name VISIBLE;
OUTPUT
Execute the below query to show the index on the table.
mysql> show index from index_table;
The above image shows three rows of invisible indexes. It contains the key name, column name, index type, and visibility of the table. Here, the name column is converted from an invisible to visible option.