From 66ea2f797c13415e847c7011ebd669f5febb9cf7 Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:09:37 +0800 Subject: [PATCH 1/5] sql: introduce invisible index --- sql-statements/sql-statement-add-index.md | 1 + .../sql-statement-alter-database.md | 2 +- sql-statements/sql-statement-alter-index.md | 204 ++++++++++++++++++ sql-statements/sql-statement-alter-table.md | 1 + sql-statements/sql-statement-create-index.md | 12 ++ sql-statements/sql-statement-create-table.md | 1 + sql-statements/sql-statement-drop-index.md | 1 + sql-statements/sql-statement-rename-index.md | 1 + sql-statements/sql-statement-show-indexes.md | 42 ++-- .../system-table-information-schema.md | 42 ++-- 10 files changed, 268 insertions(+), 39 deletions(-) create mode 100644 sql-statements/sql-statement-alter-index.md diff --git a/sql-statements/sql-statement-add-index.md b/sql-statements/sql-statement-add-index.md index be9ca304db760..5a6e85ced8d32 100644 --- a/sql-statements/sql-statement-add-index.md +++ b/sql-statements/sql-statement-add-index.md @@ -113,6 +113,7 @@ mysql> EXPLAIN SELECT * FROM t1 WHERE c1 = 3; * [CREATE INDEX](/sql-statements/sql-statement-create-index.md) * [DROP INDEX](/sql-statements/sql-statement-drop-index.md) * [RENAME INDEX](/sql-statements/sql-statement-rename-index.md) +* [ALTER INDEX](/sql-statements/sql-statement-alter-index.md) * [ADD COLUMN](/sql-statements/sql-statement-add-column.md) * [CREATE TABLE](/sql-statements/sql-statement-create-table.md) * [EXPLAIN](/sql-statements/sql-statement-explain.md) diff --git a/sql-statements/sql-statement-alter-database.md b/sql-statements/sql-statement-alter-database.md index 8dddd491b7732..f75c2bd0bdf74 100644 --- a/sql-statements/sql-statement-alter-database.md +++ b/sql-statements/sql-statement-alter-database.md @@ -9,7 +9,7 @@ aliases: ['/docs/dev/reference/sql/statements/alter-database/'] `ALTER DATABASE` is used to specify or modify the default character set and collation of the current database. `ALTER SCHEMA` has the same effect as `ALTER DATABASE`. -## 语法图 +## Synopsis **AlterDatabaseStmt:** diff --git a/sql-statements/sql-statement-alter-index.md b/sql-statements/sql-statement-alter-index.md new file mode 100644 index 0000000000000..d79a26decac95 --- /dev/null +++ b/sql-statements/sql-statement-alter-index.md @@ -0,0 +1,204 @@ +--- +title: ALTER INDEX +summary: An overview of the usage of ALTER INDEX for the TiDB database. +category: reference +--- + +# ALTER INDEX + +The `ALTER INDEX` statement is used to modify the visibility of the index to `Visible` or `Invisible`. When the visibility of an index is set to `Invisible`, this index cannot be used by the optimizer. + +## Synopsis + +**AlterTableStmt:** + +![AlterTableStmt](/media/sqlgram/AlterTableStmt.png) + +**AlterTableSpec:** + +![AlterTableSpec](/media/sqlgram/AlterTableSpec.png) + +**IndexInvisible:** + +![IndexInvisible](/media/sqlgram/IndexInvisible.png) + +## Syntax + +{{< copyable "sql" >}} + +```sql +ALTER TABLE [table_name] ALTER INDEX [index_name] {VISIBLE | INVISIBLE} +``` + +## Example + +You can modify the visibility of an index using the `ALTER TABLE ... ALTER INDEX ...` statement. + +{{< copyable "sql" >}} + +```sql +CREATE TABLE t1 (c1 INT, UNIQUE(c1)); +ALTER TABLE t1 ALTER INDEX c1 INVISIBLE; +``` + +```sql +Query OK, 0 rows affected (0.02 sec) +``` + +{{< copyable "sql" >}} + +```sql +SHOW CREATE TABLE t1; +``` + +```sql ++-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| Table | Create Table + | ++-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| t1 | CREATE TABLE `t1` ( + `c1` int(11) DEFAULT NULL, + UNIQUE KEY `c1` (`c1`) /*!80000 INVISIBLE */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ++-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +1 row in set (0.00 sec) +``` + +## Invisible index + +Invisible index is a new feature introduced in MySQL 8.0 that sets an index to invisible so that the optimizer no longer uses this index. Using this feature, you can easily check whether to use or not to use the query plan of an index, and avoid resource-consuming operations such as `Drop index` or `Add index`. + +{{< copyable "sql" >}} + +```sql +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE(c2)); +CREATE UNIQUE INDEX c1 ON t1 (c1) INVISIBLE; +``` + +You can check an invisible index using the `Create Table` statement. The invisible index is identified with `/*!80000 INVISIBLE */`: + +{{< copyable "sql" >}} + +```sql +SHOW CREATE TABLE t1; +``` + +```sql ++-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| Table | Create Table + | ++-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| t1 | CREATE TABLE `t1` ( + `c1` int(11) DEFAULT NULL, + `c2` int(11) DEFAULT NULL, + UNIQUE KEY `c2` (`c2`), + UNIQUE KEY `c1` (`c1`) /*!80000 INVISIBLE */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ++-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +1 row in set (0.00 sec) +``` + +The optimizer cannot use the **invisible index** of `c1`. + +{{< copyable "sql" >}} + +```sql +EXPLAIN SELECT c1 FROM t1 ORDER BY c1; +``` + +```sql ++-------------------------+----------+-----------+---------------+--------------------------------+ +| id | estRows | task | access object | operator info | ++-------------------------+----------+-----------+---------------+--------------------------------+ +| Sort_4 | 10000.00 | root | | test.t1.c1:asc | +| └─TableReader_8 | 10000.00 | root | | data:TableFullScan_7 | +| └─TableFullScan_7 | 10000.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo | ++-------------------------+----------+-----------+---------------+--------------------------------+ +3 rows in set (0.00 sec) +``` + +By comparison, `c2` is a **visible index** and can be used by the optimizer. + +{{< copyable "sql" >}} + +```sql +EXPLAIN SELECT c2 FROM t1 ORDER BY c2; +``` + +```sql ++------------------------+----------+-----------+------------------------+-------------------------------+ +| id | estRows | task | access object | operator info | ++------------------------+----------+-----------+------------------------+-------------------------------+ +| IndexReader_13 | 10000.00 | root | | index:IndexFullScan_12 | +| └─IndexFullScan_12 | 10000.00 | cop[tikv] | table:t1, index:c2(c2) | keep order:true, stats:pseudo | ++------------------------+----------+-----------+------------------------+-------------------------------+ +2 rows in set (0.00 sec) +``` + +Even if you use the `USE INDEX` SQL hint to forcibly use indexes, the optimizer still cannot use invisible indexes; otherwise, an error is returned. + +{{< copyable "sql" >}} + +```sql +SELECT * FROM t1 USE INDEX(c1); +``` + +```sql +ERROR 1176 (42000): Key 'c1' doesn't exist in table 't1' +``` + +> **Note:** +> +> "Invisible" here means invisible only to the optimizer. You can still modify or delete invisible indexes. + +{{< copyable "sql" >}} + +```sql +ALTER TABLE t1 DROP INDEX c1; +``` + +```sql +Query OK, 0 rows affected (0.02 sec) +``` + +### Restriction + +There is a restriction on invisible indexes in MySQL: the **primary key** cannot be set to `Invisible`. TiDB is compatible with this restriction. If you set the primary key to `Invisible` in TiDB, an error is returned. + +{{< copyable "sql" >}} + +```sql +CREATE TABLE t2(c1 INT, PRIMARY KEY(c1) INVISIBLE); +``` + +```sql +ERROR 3522 (HY000): A primary key index cannot be invisible +``` + +The **primary key** above includes both the explicit primary key (specified using the `PRIMARY KEY` keyword) and the implicit primary key. + +If the explicit primary key does not exist in the table, the first `UNIQUE` index (every column of the index must be `NOT NULL`) automatically becomes the implicit index. + +This means that you cannot set this implicit primary key to `Invisible`. + +> **Note:** +> +> TiDB does not actually creates an **implicit primary key**. TiDB is compatible with this MySQL restriction only in behavior. + +{{< copyable "sql" >}} + +```sql +CREATE TABLE t2(c1 INT NOT NULL, UNIQUE(c1) INVISIBLE); +``` + +``` +ERROR 3522 (HY000): A primary key index cannot be invisible +``` + +## Reference + +* [CREATE TABLE](/sql-statements/sql-statement-create-table.md) +* [CREATE INDEX](/sql-statements/sql-statement-create-index.md) +* [ADD INDEX](/sql-statements/sql-statement-add-index.md) +* [DROP INDEX](/sql-statements/sql-statement-drop-index.md) +* [RENAME INDEX](/sql-statements/sql-statement-rename-index.md) diff --git a/sql-statements/sql-statement-alter-table.md b/sql-statements/sql-statement-alter-table.md index 50c165b660cb9..3127d174595f4 100644 --- a/sql-statements/sql-statement-alter-table.md +++ b/sql-statements/sql-statement-alter-table.md @@ -70,6 +70,7 @@ mysql> EXPLAIN SELECT * FROM t1 WHERE c1 = 3; * [ADD INDEX](/sql-statements/sql-statement-add-index.md) * [DROP INDEX](/sql-statements/sql-statement-drop-index.md) * [RENAME INDEX](/sql-statements/sql-statement-rename-index.md) +* [ALTER INDEX](/sql-statements/sql-statement-alter-index.md) * [CREATE TABLE](/sql-statements/sql-statement-create-table.md) * [DROP TABLE](/sql-statements/sql-statement-drop-table.md) * [SHOW CREATE TABLE](/sql-statements/sql-statement-show-create-table.md) diff --git a/sql-statements/sql-statement-create-index.md b/sql-statements/sql-statement-create-index.md index 9b5fd339b188c..f60397dd0dece 100644 --- a/sql-statements/sql-statement-create-index.md +++ b/sql-statements/sql-statement-create-index.md @@ -142,6 +142,17 @@ Expression indexes have the same syntax and limitations as in MySQL. They are im Currently, the optimizer can use the indexed expressions when the expressions are only in the `FIELD` clause, `WHERE` clause, and `ORDER BY` clause. The `GROUP BY` clause will be supported in future updates. +## Invisible index + +Invisible index is a new feature introduced in MySQL 8.0 that sets an index to invisible so that the optimizer no longer uses this index. + +```sql +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE(c2)); +CREATE UNIQUE INDEX c1 ON t1 (c1) INVISIBLE; +``` + +For details, see [Invisible index](/sql-statements/sql-statement-alter-index.md#invisible-index) + ## Associated session variables The global variables associated with the `CREATE INDEX` statement are `tidb_ddl_reorg_worker_cnt`, `tidb_ddl_reorg_batch_size` and `tidb_ddl_reorg_priority`. Refer to [TiDB-specific system variables](/tidb-specific-system-variables.md#tidb_ddl_reorg_worker_cnt) for details. @@ -157,6 +168,7 @@ The global variables associated with the `CREATE INDEX` statement are `tidb_ddl_ * [ADD INDEX](/sql-statements/sql-statement-add-index.md) * [DROP INDEX](/sql-statements/sql-statement-drop-index.md) * [RENAME INDEX](/sql-statements/sql-statement-rename-index.md) +* [ALTER INDEX](/sql-statements/sql-statement-alter-index.md) * [ADD COLUMN](/sql-statements/sql-statement-add-column.md) * [CREATE TABLE](/sql-statements/sql-statement-create-table.md) * [EXPLAIN](/sql-statements/sql-statement-explain.md) diff --git a/sql-statements/sql-statement-create-table.md b/sql-statements/sql-statement-create-table.md index ba757b887fbb8..169e02b24ca9f 100644 --- a/sql-statements/sql-statement-create-table.md +++ b/sql-statements/sql-statement-create-table.md @@ -185,6 +185,7 @@ index_option: KEY_BLOCK_SIZE [=] value | index_type | COMMENT 'string' + | {VISIBLE | INVISIBLE} ``` The `KEY_BLOCK_SIZE` in `index_option` is currently only supported in syntax. diff --git a/sql-statements/sql-statement-drop-index.md b/sql-statements/sql-statement-drop-index.md index 0ea13e5633116..8d125e45a69f9 100644 --- a/sql-statements/sql-statement-drop-index.md +++ b/sql-statements/sql-statement-drop-index.md @@ -81,3 +81,4 @@ Query OK, 0 rows affected (0.30 sec) * [CREATE INDEX](/sql-statements/sql-statement-create-index.md) * [ADD INDEX](/sql-statements/sql-statement-add-index.md) * [RENAME INDEX](/sql-statements/sql-statement-rename-index.md) +* [ALTER INDEX](/sql-statements/sql-statement-alter-index.md) diff --git a/sql-statements/sql-statement-rename-index.md b/sql-statements/sql-statement-rename-index.md index a7f5a15a08b7d..3d3cb52c5716f 100644 --- a/sql-statements/sql-statement-rename-index.md +++ b/sql-statements/sql-statement-rename-index.md @@ -61,3 +61,4 @@ This statement is understood to be fully compatible with MySQL. Any compatibilit * [CREATE INDEX](/sql-statements/sql-statement-create-index.md) * [DROP INDEX](/sql-statements/sql-statement-drop-index.md) * [SHOW INDEX](/sql-statements/sql-statement-show-index.md) +* [ALTER INDEX](/sql-statements/sql-statement-alter-index.md) diff --git a/sql-statements/sql-statement-show-indexes.md b/sql-statements/sql-statement-show-indexes.md index a30ae48d396f2..5ce15d50d24f6 100644 --- a/sql-statements/sql-statement-show-indexes.md +++ b/sql-statements/sql-statement-show-indexes.md @@ -38,30 +38,36 @@ mysql> CREATE TABLE t1 (id int not null primary key AUTO_INCREMENT, col1 INT, IN Query OK, 0 rows affected (0.12 sec) mysql> SHOW INDEXES FROM t1; -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ -| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ -| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | -| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | | -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ +| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ +| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | YES + | NULL | +| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | | YES + | NULL | ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 2 rows in set (0.00 sec) mysql> SHOW INDEX FROM t1; -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ -| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ -| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | -| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | | -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ +| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ +| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | YES + | NULL | +| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | | YES + | NULL | ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 2 rows in set (0.00 sec) mysql> SHOW KEYS FROM t1; -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ -| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ -| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | -| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | | -+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ +| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ +| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | YES + | NULL | +| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | | YES + | NULL | ++-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 2 rows in set (0.00 sec) ``` diff --git a/system-tables/system-table-information-schema.md b/system-tables/system-table-information-schema.md index 2bd7701f91ddb..00f2492395820 100644 --- a/system-tables/system-table-information-schema.md +++ b/system-tables/system-table-information-schema.md @@ -594,26 +594,28 @@ desc statistics; ``` ``` -+---------------|---------------------|------|------|---------|-------+ -| Field | Type | Null | Key | Default | Extra | -+---------------|---------------------|------|------|---------|-------+ -| TABLE_CATALOG | varchar(512) | YES | | NULL | | -| TABLE_SCHEMA | varchar(64) | YES | | NULL | | -| TABLE_NAME | varchar(64) | YES | | NULL | | -| NON_UNIQUE | varchar(1) | YES | | NULL | | -| INDEX_SCHEMA | varchar(64) | YES | | NULL | | -| INDEX_NAME | varchar(64) | YES | | NULL | | -| SEQ_IN_INDEX | bigint(2) UNSIGNED | YES | | NULL | | -| COLUMN_NAME | varchar(21) | YES | | NULL | | -| COLLATION | varchar(1) | YES | | NULL | | -| CARDINALITY | bigint(21) UNSIGNED | YES | | NULL | | -| SUB_PART | bigint(3) UNSIGNED | YES | | NULL | | -| PACKED | varchar(10) | YES | | NULL | | -| NULLABLE | varchar(3) | YES | | NULL | | -| INDEX_TYPE | varchar(16) | YES | | NULL | | -| COMMENT | varchar(16) | YES | | NULL | | -| INDEX_COMMENT | varchar(1024) | YES | | NULL | | -+---------------|---------------------|------|------|---------|-------+ ++---------------+---------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------+---------------+------+------+---------+-------+ +| TABLE_CATALOG | varchar(512) | YES | | NULL | | +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| NON_UNIQUE | varchar(1) | YES | | NULL | | +| INDEX_SCHEMA | varchar(64) | YES | | NULL | | +| INDEX_NAME | varchar(64) | YES | | NULL | | +| SEQ_IN_INDEX | bigint(2) | YES | | NULL | | +| COLUMN_NAME | varchar(21) | YES | | NULL | | +| COLLATION | varchar(1) | YES | | NULL | | +| CARDINALITY | bigint(21) | YES | | NULL | | +| SUB_PART | bigint(3) | YES | | NULL | | +| PACKED | varchar(10) | YES | | NULL | | +| NULLABLE | varchar(3) | YES | | NULL | | +| INDEX_TYPE | varchar(16) | YES | | NULL | | +| COMMENT | varchar(16) | YES | | NULL | | +| INDEX_COMMENT | varchar(1024) | YES | | NULL | | +| IS_VISIBLE | varchar(3) | YES | | NULL | | +| Expression | varchar(64) | YES | | NULL | | ++---------------+---------------+------+------+---------+-------+ ``` The following statements are equivalent: From 400f6d0cc71aba36702b8ec910842eacdf9dab27 Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:14:14 +0800 Subject: [PATCH 2/5] Update TOC.md --- TOC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TOC.md b/TOC.md index 9593bf1508253..a51366f8c45c8 100644 --- a/TOC.md +++ b/TOC.md @@ -205,6 +205,7 @@ + [`ADD INDEX`](/sql-statements/sql-statement-add-index.md) + [`ADMIN`](/sql-statements/sql-statement-admin.md) + [`ALTER DATABASE`](/sql-statements/sql-statement-alter-database.md) + + [`ALTER INDEX`](/sql-statements/sql-statement-alter-index.md) + [`ALTER INSTANCE`](/sql-statements/sql-statement-alter-instance.md) + [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md) + [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) From f2bd21f959d3cfad53d921b14f29771919980c75 Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:16:48 +0800 Subject: [PATCH 3/5] Apply suggestions from code review --- sql-statements/sql-statement-alter-index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-alter-index.md b/sql-statements/sql-statement-alter-index.md index d79a26decac95..3354166b707f0 100644 --- a/sql-statements/sql-statement-alter-index.md +++ b/sql-statements/sql-statement-alter-index.md @@ -183,7 +183,7 @@ This means that you cannot set this implicit primary key to `Invisible`. > **Note:** > -> TiDB does not actually creates an **implicit primary key**. TiDB is compatible with this MySQL restriction only in behavior. +> TiDB does not actually create an **implicit primary key**. TiDB is compatible with this MySQL restriction only in behavior. {{< copyable "sql" >}} @@ -195,7 +195,7 @@ CREATE TABLE t2(c1 INT NOT NULL, UNIQUE(c1) INVISIBLE); ERROR 3522 (HY000): A primary key index cannot be invisible ``` -## Reference +## See also * [CREATE TABLE](/sql-statements/sql-statement-create-table.md) * [CREATE INDEX](/sql-statements/sql-statement-create-index.md) From fe587bcf80767c01773b3dfe24291d426bdc1cfa Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Tue, 23 Jun 2020 10:21:29 +0800 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Caitin <34535727+CaitinChen@users.noreply.github.com> --- sql-statements/sql-statement-alter-index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql-statements/sql-statement-alter-index.md b/sql-statements/sql-statement-alter-index.md index 3354166b707f0..3c1e7bdcfa167 100644 --- a/sql-statements/sql-statement-alter-index.md +++ b/sql-statements/sql-statement-alter-index.md @@ -66,7 +66,7 @@ SHOW CREATE TABLE t1; ## Invisible index -Invisible index is a new feature introduced in MySQL 8.0 that sets an index to invisible so that the optimizer no longer uses this index. Using this feature, you can easily check whether to use or not to use the query plan of an index, and avoid resource-consuming operations such as `Drop index` or `Add index`. +Invisible indexes are a new feature introduced in MySQL 8.0 that sets an index to invisible so that the optimizer no longer uses this index. Using this feature, you can easily check whether to use or not to use the query plan of an index, and avoid resource-consuming operations such as `DROP INDEX` or `ADD INDEX`. {{< copyable "sql" >}} @@ -75,7 +75,7 @@ CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE(c2)); CREATE UNIQUE INDEX c1 ON t1 (c1) INVISIBLE; ``` -You can check an invisible index using the `Create Table` statement. The invisible index is identified with `/*!80000 INVISIBLE */`: +You can check an invisible index using the `CREATE TABLE` statement. The invisible index is identified with `/*!80000 INVISIBLE */`: {{< copyable "sql" >}} @@ -183,7 +183,7 @@ This means that you cannot set this implicit primary key to `Invisible`. > **Note:** > -> TiDB does not actually create an **implicit primary key**. TiDB is compatible with this MySQL restriction only in behavior. +> TiDB does not actually create an **implicit primary key**. TiDB is compatible with this MySQL restriction only in behaviors. {{< copyable "sql" >}} From af10a5a520d8824f38d5f92d170ea4282b61f2ad Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Tue, 23 Jun 2020 10:22:16 +0800 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Caitin <34535727+CaitinChen@users.noreply.github.com> --- sql-statements/sql-statement-create-index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-create-index.md b/sql-statements/sql-statement-create-index.md index f60397dd0dece..408efaf7e267f 100644 --- a/sql-statements/sql-statement-create-index.md +++ b/sql-statements/sql-statement-create-index.md @@ -144,7 +144,7 @@ Currently, the optimizer can use the indexed expressions when the expressions ar ## Invisible index -Invisible index is a new feature introduced in MySQL 8.0 that sets an index to invisible so that the optimizer no longer uses this index. +Invisible indexes are a new feature introduced in MySQL 8.0 that sets an index to invisible so that the optimizer no longer uses this index. ```sql CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE(c2));