From 9268a463dda159ae8851b63fb615fbb8fabd953d Mon Sep 17 00:00:00 2001 From: JoyinQin <56883733+Joyinqin@users.noreply.github.com> Date: Tue, 13 Oct 2020 08:22:41 +0800 Subject: [PATCH 1/2] Update tidb-configuration-file.md --- tidb-configuration-file.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tidb-configuration-file.md b/tidb-configuration-file.md index 15c35742ba28f..b78d6c7b73a95 100644 --- a/tidb-configuration-file.md +++ b/tidb-configuration-file.md @@ -548,10 +548,4 @@ Configurations related to the `events_statement_summary_by_digest` table. ## experimental -The `experimental` section describes configurations related to the experimental features of TiDB. This section is introduced since v3.1.0. - -### `allow-auto-random` New in v3.1.0 - -- Determines whether to allow using `AUTO_RANDOM`. -- Default value: `false` -- By default, TiDB does not support using `AUTO_RANDOM`. When the value is `true`, you cannot set `alter-primary-key` to `true` at the same time. +The `experimental` section describes configurations related to the experimental features of TiDB. This section is introduced since v3.1.0. \ No newline at end of file From 401ba1b0ac0d6efe0781d3724ff32ae5574fc810 Mon Sep 17 00:00:00 2001 From: Joyinqin Date: Mon, 22 Mar 2021 16:05:30 +0800 Subject: [PATCH 2/2] Delete sql-statement-alter-index.md --- sql-statements/sql-statement-alter-index.md | 154 -------------------- 1 file changed, 154 deletions(-) delete mode 100644 sql-statements/sql-statement-alter-index.md diff --git a/sql-statements/sql-statement-alter-index.md b/sql-statements/sql-statement-alter-index.md deleted file mode 100644 index bff21e3ff4fca..0000000000000 --- a/sql-statements/sql-statement-alter-index.md +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: ALTER INDEX -summary: An overview of the usage of ALTER INDEX for the TiDB database. -aliases: ['/docs/dev/sql-statements/sql-statement-alter-index/'] ---- - -# ALTER INDEX - -The `ALTER INDEX` statement is used to modify the visibility of the index to `Visible` or `Invisible`. Invisible indexes are maintained by DML statements, but will not be used by the query optimizer. This is useful in scenarios where you want to double-check before removing an index permanently. - -## Synopsis - -```ebnf+diagram -AlterTableStmt ::= - 'ALTER' IgnoreOptional 'TABLE' TableName ( AlterTableSpecListOpt AlterTablePartitionOpt | 'ANALYZE' 'PARTITION' PartitionNameList ( 'INDEX' IndexNameList )? AnalyzeOptionListOpt ) - -AlterTableSpec ::= - TableOptionList -| 'SET' 'TIFLASH' 'REPLICA' LengthNum LocationLabelList -| 'CONVERT' 'TO' CharsetKw ( CharsetName | 'DEFAULT' ) OptCollate -| 'ADD' ( ColumnKeywordOpt IfNotExists ( ColumnDef ColumnPosition | '(' TableElementList ')' ) | Constraint | 'PARTITION' IfNotExists NoWriteToBinLogAliasOpt ( PartitionDefinitionListOpt | 'PARTITIONS' NUM ) ) -| ( ( 'CHECK' | 'TRUNCATE' ) 'PARTITION' | ( 'OPTIMIZE' | 'REPAIR' | 'REBUILD' ) 'PARTITION' NoWriteToBinLogAliasOpt ) AllOrPartitionNameList -| 'COALESCE' 'PARTITION' NoWriteToBinLogAliasOpt NUM -| 'DROP' ( ColumnKeywordOpt IfExists ColumnName RestrictOrCascadeOpt | 'PRIMARY' 'KEY' | 'PARTITION' IfExists PartitionNameList | ( KeyOrIndex IfExists | 'CHECK' ) Identifier | 'FOREIGN' 'KEY' IfExists Symbol ) -| 'EXCHANGE' 'PARTITION' Identifier 'WITH' 'TABLE' TableName WithValidationOpt -| ( 'IMPORT' | 'DISCARD' ) ( 'PARTITION' AllOrPartitionNameList )? 'TABLESPACE' -| 'REORGANIZE' 'PARTITION' NoWriteToBinLogAliasOpt ReorganizePartitionRuleOpt -| 'ORDER' 'BY' AlterOrderItem ( ',' AlterOrderItem )* -| ( 'DISABLE' | 'ENABLE' ) 'KEYS' -| ( 'MODIFY' ColumnKeywordOpt IfExists | 'CHANGE' ColumnKeywordOpt IfExists ColumnName ) ColumnDef ColumnPosition -| 'ALTER' ( ColumnKeywordOpt ColumnName ( 'SET' 'DEFAULT' ( SignedLiteral | '(' Expression ')' ) | 'DROP' 'DEFAULT' ) | 'CHECK' Identifier EnforcedOrNot | 'INDEX' Identifier IndexInvisible ) -| 'RENAME' ( ( 'COLUMN' | KeyOrIndex ) Identifier 'TO' Identifier | ( 'TO' | '='? | 'AS' ) TableName ) -| LockClause -| AlgorithmClause -| 'FORCE' -| ( 'WITH' | 'WITHOUT' ) 'VALIDATION' -| 'SECONDARY_LOAD' -| 'SECONDARY_UNLOAD' - -IndexInvisible ::= - 'VISIBLE' -| 'INVISIBLE' -``` - -## Examples - -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) -``` - -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) -``` - -## MySQL compatibility - -* Invisible indexes in TiDB are modeled on the equivalent feature from MySQL 8.0. -* Similiar to MySQL, TiDB does not permit `PRIMARY KEY` indexes to be made invisible. -* MySQL provides an optimizer switch `use_invisible_indexes=on` to make all invisible indexes _visible_ again. This functionality is not available in TiDB. - -## See also - -* [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)