From 81baa5695108678d853d53fd026591a24cc76416 Mon Sep 17 00:00:00 2001 From: Charlotte Liu <37295236+CharLotteiu@users.noreply.github.com> Date: Wed, 20 Jan 2021 17:58:55 +0800 Subject: [PATCH 1/2] cherry pick #5324 to release-3.0 Signed-off-by: ti-srebot --- expression-syntax.md | 31 ++++ sql-statements/sql-statement-add-column.md | 36 ++++ sql-statements/sql-statement-add-index.md | 77 +++++++++ .../sql-statement-admin-cancel-ddl.md | 12 +- .../sql-statement-admin-check-table-index.md | 12 +- .../sql-statement-admin-checksum-table.md | 12 +- .../sql-statement-admin-show-ddl.md | 17 +- sql-statements/sql-statement-admin.md | 7 +- .../sql-statement-alter-database.md | 13 ++ sql-statements/sql-statement-alter-index.md | 154 ++++++++++++++++++ .../sql-statement-alter-instance.md | 43 +++++ sql-statements/sql-statement-alter-table.md | 41 +++-- sql-statements/sql-statement-alter-user.md | 19 ++- sql-statements/sql-statement-analyze-table.md | 17 +- 14 files changed, 437 insertions(+), 54 deletions(-) create mode 100644 sql-statements/sql-statement-alter-index.md create mode 100644 sql-statements/sql-statement-alter-instance.md diff --git a/expression-syntax.md b/expression-syntax.md index b39b0cb3823f..2eb92b3ff872 100644 --- a/expression-syntax.md +++ b/expression-syntax.md @@ -34,6 +34,7 @@ PredicateExpr: | PrimaryFactor RegexpOrNotOp PrimaryExpression | PrimaryFactor +<<<<<<< HEAD PrimaryFactor: PrimaryFactor '|' PrimaryFactor | PrimaryFactor '&' PrimaryFactor @@ -64,4 +65,34 @@ PrimaryExpression: | '+' PrimaryExpression | "BINARY" PrimaryExpression | PrimaryExpression "COLLATE" StringName +======= +```ebnf+diagram +Expression ::= + ( singleAtIdentifier assignmentEq | 'NOT' | Expression ( logOr | 'XOR' | logAnd ) ) Expression +| 'MATCH' '(' ColumnNameList ')' 'AGAINST' '(' BitExpr FulltextSearchModifierOpt ')' +| PredicateExpr ( IsOrNotOp 'NULL' | CompareOp ( ( singleAtIdentifier assignmentEq )? PredicateExpr | AnyOrAll SubSelect ) )* ( IsOrNotOp ( trueKwd | falseKwd | 'UNKNOWN' ) )? + +PredicateExpr ::= + BitExpr ( BetweenOrNotOp BitExpr 'AND' BitExpr )* ( InOrNotOp ( '(' ExpressionList ')' | SubSelect ) | LikeOrNotOp SimpleExpr LikeEscapeOpt | RegexpOrNotOp SimpleExpr )? + +BitExpr ::= + BitExpr ( ( '|' | '&' | '<<' | '>>' | '*' | '/' | '%' | 'DIV' | 'MOD' | '^' ) BitExpr | ( '+' | '-' ) ( BitExpr | "INTERVAL" Expression TimeUnit ) ) +| SimpleExpr + +SimpleExpr ::= + SimpleIdent ( ( '->' | '->>' ) stringLit )? +| FunctionCallKeyword +| FunctionCallNonKeyword +| FunctionCallGeneric +| SimpleExpr ( 'COLLATE' CollationName | pipes SimpleExpr ) +| WindowFuncCall +| Literal +| paramMarker +| Variable +| SumExpr +| ( '!' | '~' | '-' | '+' | 'NOT' | 'BINARY' ) SimpleExpr +| 'EXISTS'? SubSelect +| ( ( '(' ( ExpressionList ',' )? | 'ROW' '(' ExpressionList ',' ) Expression | builtinCast '(' Expression 'AS' CastType | ( 'DEFAULT' | 'VALUES' ) '(' SimpleIdent | 'CONVERT' '(' Expression ( ',' CastType | 'USING' CharsetName ) ) ')' +| 'CASE' ExpressionOpt WhenClause+ ElseOpt 'END' +>>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ``` diff --git a/sql-statements/sql-statement-add-column.md b/sql-statements/sql-statement-add-column.md index f3dc2247b100..690d47386e55 100644 --- a/sql-statements/sql-statement-add-column.md +++ b/sql-statements/sql-statement-add-column.md @@ -10,6 +10,7 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-add-column/','/docs-cn/v3. ## 语法图 +<<<<<<< HEAD **AlterTableStmt:** ![AlterTableStmt](/media/sqlgram/AlterTableStmt.png) @@ -29,6 +30,41 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-add-column/','/docs-cn/v3. **ColumnPosition:** ![ColumnPosition](/media/sqlgram/ColumnPosition.png) +======= +```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' + +ColumnDef ::= + ColumnName ( Type | 'SERIAL' ) ColumnOptionListOpt + +ColumnPosition ::= + ( 'FIRST' | 'AFTER' ColumnName )? +``` +>>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 diff --git a/sql-statements/sql-statement-add-index.md b/sql-statements/sql-statement-add-index.md index 7b0c3e737e1d..0c01ba810e60 100644 --- a/sql-statements/sql-statement-add-index.md +++ b/sql-statements/sql-statement-add-index.md @@ -10,6 +10,7 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-add-index/','/docs-cn/v3.0 ## 语法图 +<<<<<<< HEAD **AlterTableStmt:** ![AlterTableStmt](/media/sqlgram/AlterTableStmt.png) @@ -29,6 +30,82 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-add-index/','/docs-cn/v3.0 **ColumnPosition:** ![ColumnPosition](/media/sqlgram/ColumnPosition.png) +======= +```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' + +Constraint ::= + ConstraintKeywordOpt ConstraintElem + +ConstraintKeywordOpt ::= + ( 'CONSTRAINT' Symbol? )? + +ConstraintElem ::= + ( ( 'PRIMARY' 'KEY' | KeyOrIndex IfNotExists | 'UNIQUE' KeyOrIndexOpt ) IndexNameAndTypeOpt | 'FULLTEXT' KeyOrIndexOpt IndexName ) '(' IndexPartSpecificationList ')' IndexOptionList +| 'FOREIGN' 'KEY' IfNotExists IndexName '(' IndexPartSpecificationList ')' ReferDef +| 'CHECK' '(' Expression ')' EnforcedOrNotOpt + +IndexNameAndTypeOpt ::= + IndexName ( 'USING' IndexTypeName )? +| Identifier 'TYPE' IndexTypeName + +IndexPartSpecificationList ::= + IndexPartSpecification ( ',' IndexPartSpecification )* + +IndexPartSpecification ::= + ( ColumnName OptFieldLen | '(' Expression ')' ) Order + +IndexOptionList ::= + IndexOption* + +IndexOption ::= + 'KEY_BLOCK_SIZE' '='? LengthNum +| IndexType +| 'WITH' 'PARSER' Identifier +| 'COMMENT' stringLit +| IndexInvisible + +KeyOrIndex ::= + 'KEY' +| 'INDEX' + +IndexKeyTypeOpt ::= + ( 'UNIQUE' | 'SPATIAL' | 'FULLTEXT' )? + +IndexInvisible ::= + 'VISIBLE' +| 'INVISIBLE' + +IndexTypeName ::= + 'BTREE' +| 'HASH' +| 'RTREE' +``` +>>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 diff --git a/sql-statements/sql-statement-admin-cancel-ddl.md b/sql-statements/sql-statement-admin-cancel-ddl.md index 275cb8384077..e60abcc4b095 100644 --- a/sql-statements/sql-statement-admin-cancel-ddl.md +++ b/sql-statements/sql-statement-admin-cancel-ddl.md @@ -9,13 +9,13 @@ summary: TiDB 数据库中 ADMIN CANCEL DDL 的使用概况。 ## 语法图 -**AdminStmt:** +```ebnf+diagram +AdminStmt ::= + 'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' ) -![AdminStmt](/media/sqlgram/AdminStmt.png) - -**NumList:** - -![NumList](/media/sqlgram/NumList.png) +NumList ::= + Int64Num ( ',' Int64Num )* +``` ## 示例 diff --git a/sql-statements/sql-statement-admin-check-table-index.md b/sql-statements/sql-statement-admin-check-table-index.md index 6f522590435e..9f51e08ae671 100644 --- a/sql-statements/sql-statement-admin-check-table-index.md +++ b/sql-statements/sql-statement-admin-check-table-index.md @@ -9,13 +9,13 @@ summary: TiDB 数据库中 ADMIN CHECK [TABLE|INDEX] 的使用概况。 ## 语法图 -**AdminStmt:** +```ebnf+diagram +AdminStmt ::= + 'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' ) -![AdminStmt](/media/sqlgram/AdminStmt.png) - -**TableNameList:** - -![TableNameList](/media/sqlgram/TableNameList.png) +TableNameList ::= + TableName ( ',' TableName )* +``` ## 示例 diff --git a/sql-statements/sql-statement-admin-checksum-table.md b/sql-statements/sql-statement-admin-checksum-table.md index 0816d3de7160..76c8c5f6545c 100644 --- a/sql-statements/sql-statement-admin-checksum-table.md +++ b/sql-statements/sql-statement-admin-checksum-table.md @@ -9,13 +9,13 @@ summary: TiDB 数据库中 ADMIN CHECKSUM TABLE 的使用概况。 ## 语法图 -**AdminStmt:** +```ebnf+diagram +AdminStmt ::= + 'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' ) -![AdminStmt](/media/sqlgram/AdminStmt.png) - -**TableNameList:** - -![TableNameList](/media/sqlgram/TableNameList.png) +TableNameList ::= + TableName ( ',' TableName )* +``` ## 示例 diff --git a/sql-statements/sql-statement-admin-show-ddl.md b/sql-statements/sql-statement-admin-show-ddl.md index 394809da059f..9440fc3ff3d0 100644 --- a/sql-statements/sql-statement-admin-show-ddl.md +++ b/sql-statements/sql-statement-admin-show-ddl.md @@ -9,17 +9,16 @@ summary: TiDB 数据库中 ADMIN SHOW DDL [JOBS|QUERIES] 的使用概况。 ## 语法图 -**AdminStmt:** +```ebnf+diagram +AdminStmt ::= + 'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' ) -![AdminStmt](/media/sqlgram/AdminStmt.png) +NumList ::= + Int64Num ( ',' Int64Num )* -**NumList:** - -![NumList](/media/sqlgram/NumList.png) - -**WhereClauseOptional:** - -![WhereClauseOptional](/media/sqlgram/WhereClauseOptional.png) +WhereClauseOptional ::= + WhereClause? +``` ## 示例 diff --git a/sql-statements/sql-statement-admin.md b/sql-statements/sql-statement-admin.md index 271d8b1b09d8..52a57ad7d1fc 100644 --- a/sql-statements/sql-statement-admin.md +++ b/sql-statements/sql-statement-admin.md @@ -55,9 +55,10 @@ ADMIN CHECK TABLE tbl_name [, tbl_name] ...; ## 语句概览 -**AdminStmt**: - -![AdminStmt](/media/sqlgram/AdminStmt.png) +```ebnf+diagram +AdminStmt ::= + 'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' ) +``` ## 使用示例 diff --git a/sql-statements/sql-statement-alter-database.md b/sql-statements/sql-statement-alter-database.md index 13522f8f0136..c9c304023820 100644 --- a/sql-statements/sql-statement-alter-database.md +++ b/sql-statements/sql-statement-alter-database.md @@ -8,6 +8,19 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-alter-database/','/docs-cn `ALTER DATABASE` 用于修改指定或当前数据库的默认字符集和排序规则。`ALTER SCHEMA` 跟 `ALTER DATABASE` 操作效果一样。 +<<<<<<< HEAD +======= +## 语法图 + +```ebnf+diagram +AlterDatabaseStmt ::= + 'ALTER' 'DATABASE' DBName? DatabaseOptionList + +DatabaseOption ::= + DefaultKwdOpt ( CharsetKw '='? CharsetName | 'COLLATE' '='? CollationName | 'ENCRYPTION' '='? EncryptionOpt ) +``` + +>>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 {{< copyable "sql" >}} diff --git a/sql-statements/sql-statement-alter-index.md b/sql-statements/sql-statement-alter-index.md new file mode 100644 index 000000000000..f01c31bd376b --- /dev/null +++ b/sql-statements/sql-statement-alter-index.md @@ -0,0 +1,154 @@ +--- +title: ALTER INDEX +summary: TiDB 数据库中 ALTER INDEX 的使用概况。 +aliases: ['/docs-cn/dev/sql-statements/sql-statement-alter-index/','/docs-cn/dev/reference/sql/statements/alter-index/'] +--- + +# ALTER INDEX + +`ALTER INDEX` 语句用于修改索引的可见性,可以将索引设置为 `Visible` 或者 `Invisible`。设置为 `Invisible` 的索引即不可见索引 (Invisible Index) 由 DML 语句维护,不会被查询优化器使用。 + +## 语法图 + +```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' +``` + +## 示例 + +可以通过 `ALTER TABLE ... ALTER INDEX ...` 语句,修改索引的可见性: + +{{< 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) +``` + +优化器将无法使用 `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) +``` + +作为对比,c2 是**可见的索引**,优化器将可以使用索引: + +{{< 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) +``` + +即使用 SQL Hint `USE INDEX` 强制使用索引,优化器也无法使用不可见索引,否则 SQL 语句会报错: + +{{< copyable "sql" >}} + +```sql +SELECT * FROM t1 USE INDEX(c1); +``` + +```sql +ERROR 1176 (42000): Key 'c1' doesn't exist in table 't1' +``` + +> **注意:** +> +> “不可见”是仅仅对优化器而言的,不可见索引仍然可以被修改或删除。 + +{{< copyable "sql" >}} + +```sql +ALTER TABLE t1 DROP INDEX c1; +``` + +```sql +Query OK, 0 rows affected (0.02 sec) +``` + +## MySQL 兼容性 + +* TiDB 中的不可见索引是基于 MySQL 8.0 中的同等特性构建的。 +* 与 MySQL 类似,TiDB 不允许将主键索引设为不可见。 +* MySQL 中提供的优化器开关 `use_invisible_indexes=on` 可将所有的不可见索引重新设为可见。该功能在 TiDB 中不可用。 + +## 另请参阅 + +* [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-instance.md b/sql-statements/sql-statement-alter-instance.md new file mode 100644 index 000000000000..33615ba14c49 --- /dev/null +++ b/sql-statements/sql-statement-alter-instance.md @@ -0,0 +1,43 @@ +--- +title: ALTER INSTANCE +summary: TiDB 数据库中 ALTER INSTANCE 的使用概况。 +aliases: ['/docs-cn/dev/sql-statements/sql-statement-alter-instance/','/docs-cn/dev/reference/sql/statements/alter-instance/'] +--- + +# ALTER INSTANCE + +`ALTER INSTANCE` 语句用于对单个 TiDB 实例进行变更操作。目前 TiDB 仅支持 `RELOAD TLS` 子句。 + +## RELOAD TLS + +`ALTER INSTANCE RELOAD TLS` 语句用于从原配置的证书 ([`ssl-cert`](/tidb-configuration-file.md#ssl-cert))、密钥 ([`ssl-key`](/tidb-configuration-file.md#ssl-key)) 和 CA ([`ssl-ca`](/tidb-configuration-file.md#ssl-ca)) 的路径重新加证书、密钥和 CA。 + +新加载的证书密钥和 CA 将在语句执行成功后对新建立的连接生效,不会影响语句执行前已建立的连接。 + +在重加载遇到错误时默认会报错返回且继续使用变更前的密钥和证书,但在添加可选的 `NO ROLLBACK ON ERROR` 后遇到错误将不报错并以关闭 TLS 安全连接功能的方式处理后续请求。 + +## 语法图 + +```ebnf+diagram +AlterInstanceStmt ::= + 'ALTER' 'INSTANCE' InstanceOption + +InstanceOption ::= + 'RELOAD' 'TLS' ('NO' 'ROLLBACK' 'ON' 'ERROR')? +``` + +## 示例 + +{{< copyable "sql" >}} + +```sql +ALTER INSTANCE RELOAD TLS; +``` + +## MySQL 兼容性 + +仅支持从原配置路径重加载,不支持动态修改加载路径,也不支持动态启用启动 TiDB 时未开启的 TLS 加密连接功能。 + +## 另请参阅 + +[为 TiDB 客户端服务端间通信开启加密传输](/enable-tls-between-clients-and-servers.md) diff --git a/sql-statements/sql-statement-alter-table.md b/sql-statements/sql-statement-alter-table.md index 71846d7beef9..c072d0d35944 100644 --- a/sql-statements/sql-statement-alter-table.md +++ b/sql-statements/sql-statement-alter-table.md @@ -13,17 +13,36 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-alter-table/','/docs-cn/v3 ## 语法图 -**AlterTableStmt:** - -![AlterTableStmt](/media/sqlgram/AlterTableStmt.png) - -**TableName:** - -![TableName](/media/sqlgram/TableName.png) - -**AlterTableSpec:** - -![AlterTableSpec](/media/sqlgram/AlterTableSpec.png) +```ebnf+diagram +AlterTableStmt ::= + 'ALTER' IgnoreOptional 'TABLE' TableName ( AlterTableSpecListOpt AlterTablePartitionOpt | 'ANALYZE' 'PARTITION' PartitionNameList ( 'INDEX' IndexNameList )? AnalyzeOptionListOpt ) + +TableName ::= + Identifier ('.' Identifier)? + +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' +``` ## 示例 diff --git a/sql-statements/sql-statement-alter-user.md b/sql-statements/sql-statement-alter-user.md index e626ed4ac385..42f8414656ba 100644 --- a/sql-statements/sql-statement-alter-user.md +++ b/sql-statements/sql-statement-alter-user.md @@ -10,17 +10,28 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-alter-user/','/docs-cn/v3. ## 语法图 -**AlterUserStmt:** +```ebnf+diagram +AlterUserStmt ::= + 'ALTER' 'USER' IfExists (UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions | 'USER' '(' ')' 'IDENTIFIED' 'BY' AuthString) -![AlterUserStmt](/media/sqlgram/AlterUserStmt.png) +UserSpecList ::= + UserSpec ( ',' UserSpec )* -**UserSpecList:** +UserSpec ::= + Username AuthOption -![UserSpecList](/media/sqlgram/UserSpecList.png) +Username ::= + StringName ('@' StringName | singleAtIdentifier)? | 'CURRENT_USER' OptionalBraces +<<<<<<< HEAD **UserSpec:** ![UserSpec](/media/sqlgram/UserSpec.png) +======= +AuthOption ::= + ( 'IDENTIFIED' ( 'BY' ( AuthString | 'PASSWORD' HashString ) | 'WITH' StringName ( 'BY' AuthString | 'AS' HashString )? ) )? +``` +>>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 diff --git a/sql-statements/sql-statement-analyze-table.md b/sql-statements/sql-statement-analyze-table.md index 8f1d837115d5..10e582db6a7a 100644 --- a/sql-statements/sql-statement-analyze-table.md +++ b/sql-statements/sql-statement-analyze-table.md @@ -12,17 +12,16 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-analyze-table/','/docs-cn/ ## 语法图 -**AnalyzeTableStmt:** +```ebnf+diagram +AnalyzeTableStmt ::= + 'ANALYZE' ( 'TABLE' ( TableNameList | TableName ( 'INDEX' IndexNameList | 'PARTITION' PartitionNameList ( 'INDEX' IndexNameList )? ) ) | 'INCREMENTAL' 'TABLE' TableName ( 'PARTITION' PartitionNameList )? 'INDEX' IndexNameList ) AnalyzeOptionListOpt -![AnalyzeTableStmt](/media/sqlgram/AnalyzeTableStmt.png) +TableNameList ::= + TableName (',' TableName)* -**TableNameList:** - -![TableNameList](/media/sqlgram/TableNameList.png) - -**TableName:** - -![TableName](/media/sqlgram/TableName.png) +TableName ::= + Identifier ( '.' Identifier )? +``` ## 示例 From 2cfeee487fcd54dfe16d1a8d8c1fc5a0bc91ad2c Mon Sep 17 00:00:00 2001 From: Charlotte Liu <37295236+CharLotteiu@users.noreply.github.com> Date: Thu, 21 Jan 2021 13:38:53 +0800 Subject: [PATCH 2/2] resolve conflicts --- expression-syntax.md | 31 ---- sql-statements/sql-statement-add-column.md | 25 +-- sql-statements/sql-statement-add-index.md | 72 +------- .../sql-statement-alter-database.md | 13 -- sql-statements/sql-statement-alter-index.md | 154 ------------------ .../sql-statement-alter-instance.md | 43 ----- sql-statements/sql-statement-alter-user.md | 12 -- 7 files changed, 9 insertions(+), 341 deletions(-) delete mode 100644 sql-statements/sql-statement-alter-index.md delete mode 100644 sql-statements/sql-statement-alter-instance.md diff --git a/expression-syntax.md b/expression-syntax.md index 2eb92b3ff872..b39b0cb3823f 100644 --- a/expression-syntax.md +++ b/expression-syntax.md @@ -34,7 +34,6 @@ PredicateExpr: | PrimaryFactor RegexpOrNotOp PrimaryExpression | PrimaryFactor -<<<<<<< HEAD PrimaryFactor: PrimaryFactor '|' PrimaryFactor | PrimaryFactor '&' PrimaryFactor @@ -65,34 +64,4 @@ PrimaryExpression: | '+' PrimaryExpression | "BINARY" PrimaryExpression | PrimaryExpression "COLLATE" StringName -======= -```ebnf+diagram -Expression ::= - ( singleAtIdentifier assignmentEq | 'NOT' | Expression ( logOr | 'XOR' | logAnd ) ) Expression -| 'MATCH' '(' ColumnNameList ')' 'AGAINST' '(' BitExpr FulltextSearchModifierOpt ')' -| PredicateExpr ( IsOrNotOp 'NULL' | CompareOp ( ( singleAtIdentifier assignmentEq )? PredicateExpr | AnyOrAll SubSelect ) )* ( IsOrNotOp ( trueKwd | falseKwd | 'UNKNOWN' ) )? - -PredicateExpr ::= - BitExpr ( BetweenOrNotOp BitExpr 'AND' BitExpr )* ( InOrNotOp ( '(' ExpressionList ')' | SubSelect ) | LikeOrNotOp SimpleExpr LikeEscapeOpt | RegexpOrNotOp SimpleExpr )? - -BitExpr ::= - BitExpr ( ( '|' | '&' | '<<' | '>>' | '*' | '/' | '%' | 'DIV' | 'MOD' | '^' ) BitExpr | ( '+' | '-' ) ( BitExpr | "INTERVAL" Expression TimeUnit ) ) -| SimpleExpr - -SimpleExpr ::= - SimpleIdent ( ( '->' | '->>' ) stringLit )? -| FunctionCallKeyword -| FunctionCallNonKeyword -| FunctionCallGeneric -| SimpleExpr ( 'COLLATE' CollationName | pipes SimpleExpr ) -| WindowFuncCall -| Literal -| paramMarker -| Variable -| SumExpr -| ( '!' | '~' | '-' | '+' | 'NOT' | 'BINARY' ) SimpleExpr -| 'EXISTS'? SubSelect -| ( ( '(' ( ExpressionList ',' )? | 'ROW' '(' ExpressionList ',' ) Expression | builtinCast '(' Expression 'AS' CastType | ( 'DEFAULT' | 'VALUES' ) '(' SimpleIdent | 'CONVERT' '(' Expression ( ',' CastType | 'USING' CharsetName ) ) ')' -| 'CASE' ExpressionOpt WhenClause+ ElseOpt 'END' ->>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ``` diff --git a/sql-statements/sql-statement-add-column.md b/sql-statements/sql-statement-add-column.md index 690d47386e55..1f5bea5630d2 100644 --- a/sql-statements/sql-statement-add-column.md +++ b/sql-statements/sql-statement-add-column.md @@ -10,27 +10,6 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-add-column/','/docs-cn/v3. ## 语法图 -<<<<<<< HEAD -**AlterTableStmt:** - -![AlterTableStmt](/media/sqlgram/AlterTableStmt.png) - -**AlterTableSpec:** - -![AlterTableSpec](/media/sqlgram/AlterTableSpec.png) - -**ColumnKeywordOpt:** - -![ColumnKeywordOpt](/media/sqlgram/ColumnKeywordOpt.png) - -**ColumnDef:** - -![ColumnDef](/media/sqlgram/ColumnDef.png) - -**ColumnPosition:** - -![ColumnPosition](/media/sqlgram/ColumnPosition.png) -======= ```ebnf+diagram AlterTableStmt ::= 'ALTER' IgnoreOptional 'TABLE' TableName ( AlterTableSpecListOpt AlterTablePartitionOpt | 'ANALYZE' 'PARTITION' PartitionNameList ( 'INDEX' IndexNameList )? AnalyzeOptionListOpt ) @@ -58,13 +37,15 @@ AlterTableSpec ::= | 'SECONDARY_LOAD' | 'SECONDARY_UNLOAD' +ColumnKeywordOpt ::= + 'COLUMN'? + ColumnDef ::= ColumnName ( Type | 'SERIAL' ) ColumnOptionListOpt ColumnPosition ::= ( 'FIRST' | 'AFTER' ColumnName )? ``` ->>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 diff --git a/sql-statements/sql-statement-add-index.md b/sql-statements/sql-statement-add-index.md index 0c01ba810e60..dfad9292fd1a 100644 --- a/sql-statements/sql-statement-add-index.md +++ b/sql-statements/sql-statement-add-index.md @@ -10,27 +10,6 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-add-index/','/docs-cn/v3.0 ## 语法图 -<<<<<<< HEAD -**AlterTableStmt:** - -![AlterTableStmt](/media/sqlgram/AlterTableStmt.png) - -**AlterTableSpec:** - -![AlterTableSpec](/media/sqlgram/AlterTableSpec.png) - -**ColumnKeywordOpt:** - -![ColumnKeywordOpt](/media/sqlgram/ColumnKeywordOpt.png) - -**ColumnDef:** - -![ColumnDef](/media/sqlgram/ColumnDef.png) - -**ColumnPosition:** - -![ColumnPosition](/media/sqlgram/ColumnPosition.png) -======= ```ebnf+diagram AlterTableStmt ::= 'ALTER' IgnoreOptional 'TABLE' TableName ( AlterTableSpecListOpt AlterTablePartitionOpt | 'ANALYZE' 'PARTITION' PartitionNameList ( 'INDEX' IndexNameList )? AnalyzeOptionListOpt ) @@ -58,54 +37,15 @@ AlterTableSpec ::= | 'SECONDARY_LOAD' | 'SECONDARY_UNLOAD' -Constraint ::= - ConstraintKeywordOpt ConstraintElem - -ConstraintKeywordOpt ::= - ( 'CONSTRAINT' Symbol? )? - -ConstraintElem ::= - ( ( 'PRIMARY' 'KEY' | KeyOrIndex IfNotExists | 'UNIQUE' KeyOrIndexOpt ) IndexNameAndTypeOpt | 'FULLTEXT' KeyOrIndexOpt IndexName ) '(' IndexPartSpecificationList ')' IndexOptionList -| 'FOREIGN' 'KEY' IfNotExists IndexName '(' IndexPartSpecificationList ')' ReferDef -| 'CHECK' '(' Expression ')' EnforcedOrNotOpt - -IndexNameAndTypeOpt ::= - IndexName ( 'USING' IndexTypeName )? -| Identifier 'TYPE' IndexTypeName - -IndexPartSpecificationList ::= - IndexPartSpecification ( ',' IndexPartSpecification )* - -IndexPartSpecification ::= - ( ColumnName OptFieldLen | '(' Expression ')' ) Order - -IndexOptionList ::= - IndexOption* - -IndexOption ::= - 'KEY_BLOCK_SIZE' '='? LengthNum -| IndexType -| 'WITH' 'PARSER' Identifier -| 'COMMENT' stringLit -| IndexInvisible - -KeyOrIndex ::= - 'KEY' -| 'INDEX' - -IndexKeyTypeOpt ::= - ( 'UNIQUE' | 'SPATIAL' | 'FULLTEXT' )? +ColumnKeywordOpt ::= + 'COLUMN'? -IndexInvisible ::= - 'VISIBLE' -| 'INVISIBLE' +ColumnDef ::= + ColumnName ( Type | 'SERIAL' ) ColumnOptionListOpt -IndexTypeName ::= - 'BTREE' -| 'HASH' -| 'RTREE' +ColumnPosition ::= + ( 'FIRST' | 'AFTER' ColumnName )? ``` ->>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 diff --git a/sql-statements/sql-statement-alter-database.md b/sql-statements/sql-statement-alter-database.md index c9c304023820..13522f8f0136 100644 --- a/sql-statements/sql-statement-alter-database.md +++ b/sql-statements/sql-statement-alter-database.md @@ -8,19 +8,6 @@ aliases: ['/docs-cn/v3.0/sql-statements/sql-statement-alter-database/','/docs-cn `ALTER DATABASE` 用于修改指定或当前数据库的默认字符集和排序规则。`ALTER SCHEMA` 跟 `ALTER DATABASE` 操作效果一样。 -<<<<<<< HEAD -======= -## 语法图 - -```ebnf+diagram -AlterDatabaseStmt ::= - 'ALTER' 'DATABASE' DBName? DatabaseOptionList - -DatabaseOption ::= - DefaultKwdOpt ( CharsetKw '='? CharsetName | 'COLLATE' '='? CollationName | 'ENCRYPTION' '='? EncryptionOpt ) -``` - ->>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例 {{< copyable "sql" >}} diff --git a/sql-statements/sql-statement-alter-index.md b/sql-statements/sql-statement-alter-index.md deleted file mode 100644 index f01c31bd376b..000000000000 --- a/sql-statements/sql-statement-alter-index.md +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: ALTER INDEX -summary: TiDB 数据库中 ALTER INDEX 的使用概况。 -aliases: ['/docs-cn/dev/sql-statements/sql-statement-alter-index/','/docs-cn/dev/reference/sql/statements/alter-index/'] ---- - -# ALTER INDEX - -`ALTER INDEX` 语句用于修改索引的可见性,可以将索引设置为 `Visible` 或者 `Invisible`。设置为 `Invisible` 的索引即不可见索引 (Invisible Index) 由 DML 语句维护,不会被查询优化器使用。 - -## 语法图 - -```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' -``` - -## 示例 - -可以通过 `ALTER TABLE ... ALTER INDEX ...` 语句,修改索引的可见性: - -{{< 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) -``` - -优化器将无法使用 `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) -``` - -作为对比,c2 是**可见的索引**,优化器将可以使用索引: - -{{< 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) -``` - -即使用 SQL Hint `USE INDEX` 强制使用索引,优化器也无法使用不可见索引,否则 SQL 语句会报错: - -{{< copyable "sql" >}} - -```sql -SELECT * FROM t1 USE INDEX(c1); -``` - -```sql -ERROR 1176 (42000): Key 'c1' doesn't exist in table 't1' -``` - -> **注意:** -> -> “不可见”是仅仅对优化器而言的,不可见索引仍然可以被修改或删除。 - -{{< copyable "sql" >}} - -```sql -ALTER TABLE t1 DROP INDEX c1; -``` - -```sql -Query OK, 0 rows affected (0.02 sec) -``` - -## MySQL 兼容性 - -* TiDB 中的不可见索引是基于 MySQL 8.0 中的同等特性构建的。 -* 与 MySQL 类似,TiDB 不允许将主键索引设为不可见。 -* MySQL 中提供的优化器开关 `use_invisible_indexes=on` 可将所有的不可见索引重新设为可见。该功能在 TiDB 中不可用。 - -## 另请参阅 - -* [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-instance.md b/sql-statements/sql-statement-alter-instance.md deleted file mode 100644 index 33615ba14c49..000000000000 --- a/sql-statements/sql-statement-alter-instance.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: ALTER INSTANCE -summary: TiDB 数据库中 ALTER INSTANCE 的使用概况。 -aliases: ['/docs-cn/dev/sql-statements/sql-statement-alter-instance/','/docs-cn/dev/reference/sql/statements/alter-instance/'] ---- - -# ALTER INSTANCE - -`ALTER INSTANCE` 语句用于对单个 TiDB 实例进行变更操作。目前 TiDB 仅支持 `RELOAD TLS` 子句。 - -## RELOAD TLS - -`ALTER INSTANCE RELOAD TLS` 语句用于从原配置的证书 ([`ssl-cert`](/tidb-configuration-file.md#ssl-cert))、密钥 ([`ssl-key`](/tidb-configuration-file.md#ssl-key)) 和 CA ([`ssl-ca`](/tidb-configuration-file.md#ssl-ca)) 的路径重新加证书、密钥和 CA。 - -新加载的证书密钥和 CA 将在语句执行成功后对新建立的连接生效,不会影响语句执行前已建立的连接。 - -在重加载遇到错误时默认会报错返回且继续使用变更前的密钥和证书,但在添加可选的 `NO ROLLBACK ON ERROR` 后遇到错误将不报错并以关闭 TLS 安全连接功能的方式处理后续请求。 - -## 语法图 - -```ebnf+diagram -AlterInstanceStmt ::= - 'ALTER' 'INSTANCE' InstanceOption - -InstanceOption ::= - 'RELOAD' 'TLS' ('NO' 'ROLLBACK' 'ON' 'ERROR')? -``` - -## 示例 - -{{< copyable "sql" >}} - -```sql -ALTER INSTANCE RELOAD TLS; -``` - -## MySQL 兼容性 - -仅支持从原配置路径重加载,不支持动态修改加载路径,也不支持动态启用启动 TiDB 时未开启的 TLS 加密连接功能。 - -## 另请参阅 - -[为 TiDB 客户端服务端间通信开启加密传输](/enable-tls-between-clients-and-servers.md) diff --git a/sql-statements/sql-statement-alter-user.md b/sql-statements/sql-statement-alter-user.md index 42f8414656ba..4aa07c1a3ed9 100644 --- a/sql-statements/sql-statement-alter-user.md +++ b/sql-statements/sql-statement-alter-user.md @@ -19,19 +19,7 @@ UserSpecList ::= UserSpec ::= Username AuthOption - -Username ::= - StringName ('@' StringName | singleAtIdentifier)? | 'CURRENT_USER' OptionalBraces - -<<<<<<< HEAD -**UserSpec:** - -![UserSpec](/media/sqlgram/UserSpec.png) -======= -AuthOption ::= - ( 'IDENTIFIED' ( 'BY' ( AuthString | 'PASSWORD' HashString ) | 'WITH' StringName ( 'BY' AuthString | 'AS' HashString )? ) )? ``` ->>>>>>> 59ffc3de... sql-statements: use EBNF to render syntax diagrams for ADD, ALTER and ANALYZE statements (#5324) ## 示例