From cdb43ebe314c39129918bf2b16aa1e4756308ff5 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 29 Apr 2024 15:41:58 +0800 Subject: [PATCH] translate 8 EBNF related PRs (#17216) (#17256) --- sql-statements/sql-statement-savepoint.md | 15 ++++ sql-statements/sql-statement-set-names.md | 41 +--------- .../sql-statement-show-columns-from.md | 78 ++++--------------- .../sql-statement-show-create-user.md | 13 ++-- sql-statements/sql-statement-show-grants.md | 36 +++------ sql-statements/sql-statement-show-profiles.md | 11 ++- .../sql-statement-show-stats-healthy.md | 27 +++---- sql-statements/sql-statement-unlock-stats.md | 2 +- 8 files changed, 67 insertions(+), 156 deletions(-) diff --git a/sql-statements/sql-statement-savepoint.md b/sql-statements/sql-statement-savepoint.md index 7728734bed8f..6c660d0f48c4 100644 --- a/sql-statements/sql-statement-savepoint.md +++ b/sql-statements/sql-statement-savepoint.md @@ -35,6 +35,19 @@ RELEASE SAVEPOINT identifier 当事务提交或者回滚后,事务中所有保存点都会被删除。 +## 语法图 + +```ebnf+diagram +SavepointStmt ::= + "SAVEPOINT" Identifier + +RollbackToStmt ::= + "ROLLBACK" "TO" "SAVEPOINT"? Identifier + +ReleaseSavepointStmt ::= + "RELEASE" "SAVEPOINT" Identifier +``` + ## 示例 创建表 `t1`: @@ -140,6 +153,8 @@ SELECT * FROM t1; 使用 `ROLLBACK TO SAVEPOINT` 语句将事物回滚到指定保存点时,MySQL 会释放该保存点之后才持有的锁,但在 TiDB 悲观事务中,不会立即释放该保存点之后才持有的锁,而是等到事务提交或者回滚时,才释放全部持有的锁。 +TiDB 不支持 MySQL 中的 `ROLLBACK WORK TO SAVEPOINT ...` 语法。 + ## 另请参阅 * [COMMIT](/sql-statements/sql-statement-commit.md) diff --git a/sql-statements/sql-statement-set-names.md b/sql-statements/sql-statement-set-names.md index 15eedfbc98bd..8d68a42519be 100644 --- a/sql-statements/sql-statement-set-names.md +++ b/sql-statements/sql-statement-set-names.md @@ -9,38 +9,13 @@ summary: TiDB 数据库中 SET [NAMES|CHARACTER SET] 的使用概况。 ## 语法图 -**SetNamesStmt:** - -![SetNamesStmt](/media/sqlgram/SetNamesStmt.png) - -**VariableAssignmentList:** - -![VariableAssignmentList](/media/sqlgram/VariableAssignmentList.png) - -**VariableAssignment:** - -![VariableAssignment](/media/sqlgram/VariableAssignment.png) - -**CharsetName:** - -![CharsetName](/media/sqlgram/CharsetName.png) - -**StringName:** - -![StringName](/media/sqlgram/StringName.png) - -**CharsetKw:** - -![CharsetKw](/media/sqlgram/CharsetKw.png) - -**CharsetNameOrDefault:** - -![CharsetNameOrDefault](/media/sqlgram/CharsetNameOrDefault.png) +```ebnf+diagram +SetNamesStmt ::= + "SET" ("NAMES" ("DEFAULT" | CharsetName ("COLLATE" ("DEFAULT" | CollationName))?) | ("CHARSET" | ("CHAR" | "CHARACTER") "SET") ("DEFAULT" | CharsetName)) +``` ## 示例 -{{< copyable "sql" >}} - ```sql SHOW VARIABLES LIKE 'character_set%'; ``` @@ -61,8 +36,6 @@ SHOW VARIABLES LIKE 'character_set%'; 8 rows in set (0.01 sec) ``` -{{< copyable "sql" >}} - ```sql SET NAMES utf8; ``` @@ -71,8 +44,6 @@ SET NAMES utf8; Query OK, 0 rows affected (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql SHOW VARIABLES LIKE 'character_set%'; ``` @@ -93,8 +64,6 @@ SHOW VARIABLES LIKE 'character_set%'; 8 rows in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql SET CHARACTER SET utf8mb4; ``` @@ -103,8 +72,6 @@ SET CHARACTER SET utf8mb4; Query OK, 0 rows affected (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql SHOW VARIABLES LIKE 'character_set%'; ``` diff --git a/sql-statements/sql-statement-show-columns-from.md b/sql-statements/sql-statement-show-columns-from.md index e9425482434a..d6861a6657f5 100644 --- a/sql-statements/sql-statement-show-columns-from.md +++ b/sql-statements/sql-statement-show-columns-from.md @@ -15,62 +15,30 @@ summary: TiDB 数据库中 SHOW [FULL] COLUMNS FROM 的使用概况。 ## 语法图 -**ShowStmt:** +```ebnf+diagram +ShowColumnsFromStmt ::= + "SHOW" "FULL"? ("COLUMNS" | "FIELDS") ("FROM" | "IN") TableName ( ("FROM" | "IN") SchemaName)? ShowLikeOrWhere? -![ShowStmt](/media/sqlgram/ShowStmt.png) +TableName ::= + (Identifier ".")? Identifier -**ShowColumnsFilterable:** - -![ShowColumnsFilterable](/media/sqlgram/ShowColumnsFilterable.png) - -**OptFull:** - -![OptFull](/media/sqlgram/OptFull.png) - -**FieldsOrColumns:** - -![FieldsOrColumns](/media/sqlgram/FieldsOrColumns.png) - -**ShowTableAliasOpt:** - -![ShowTableAliasOpt](/media/sqlgram/ShowTableAliasOpt.png) - -**FromOrIn:** - -![FromOrIn](/media/sqlgram/FromOrIn.png) - -**TableName:** - -![TableName](/media/sqlgram/TableName.png) - -**ShowDatabaseNameOpt:** - -![ShowDatabaseNameOpt](/media/sqlgram/ShowDatabaseNameOpt.png) - -**DBName:** - -![DBName](/media/sqlgram/DBName.png) - -**ShowLikeOrWhereOpt:** - -![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png) +ShowLikeOrWhere ::= + "LIKE" SimpleExpr +| "WHERE" Expression +``` ## 示例 -{{< copyable "sql" >}} - ```sql -create view v1 as select 1; +CREATE VIEW v1 AS SELECT 1; ``` ``` Query OK, 0 rows affected (0.11 sec) ``` -{{< copyable "sql" >}} - ```sql -show columns from v1; +SHOW COLUMNS FROM v1; ``` ``` @@ -82,10 +50,8 @@ show columns from v1; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql -desc v1; +DESC v1; ``` ``` @@ -97,10 +63,8 @@ desc v1; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql -describe v1; +DESCRIBE v1; ``` ``` @@ -112,10 +76,8 @@ describe v1; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql -explain v1; +EXPLAIN v1; ``` ``` @@ -127,10 +89,8 @@ explain v1; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql -show fields from v1; +SHOW FIELDS FROM v1; ``` ``` @@ -142,10 +102,8 @@ show fields from v1; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql -show full columns from v1; +SHOW FULL COLUMNS FROM v1 ``` ``` @@ -157,10 +115,8 @@ show full columns from v1; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql -show full columns from mysql.user; +SHOW FULL COLUMNS FROM mysql.user; ``` ``` diff --git a/sql-statements/sql-statement-show-create-user.md b/sql-statements/sql-statement-show-create-user.md index 95c76f7f80ea..8e7276105b5b 100644 --- a/sql-statements/sql-statement-show-create-user.md +++ b/sql-statements/sql-statement-show-create-user.md @@ -9,13 +9,10 @@ summary: TiDB 数据库中 SHOW CREATE USER 的使用概况。 ## 语法图 -**ShowCreateUserStmt:** - -![ShowCreateUserStmt](/media/sqlgram/ShowCreateUserStmt.png) - -**Username:** - -![Username](/media/sqlgram/Username.png) +```ebnf+diagram +ShowCreateUserStmt ::= + "SHOW" "CREATE" "USER" (Username ("@" Hostname)? | "CURRENT_USER" ( "(" ")" )? ) +``` ## 示例 @@ -44,7 +41,7 @@ mysql> SHOW GRANTS FOR 'root'; ## MySQL 兼容性 -* `SHOW CREATE USER` 的输出结果旨在匹配 MySQL,但 TiDB 尚不支持若干 `CREATE` 选项。尚未支持的选项在语句执行过程中会被解析但会被跳过执行。详情可参阅 [security compatibility]。 +* `SHOW CREATE USER` 的输出结果旨在匹配 MySQL,但 TiDB 尚不支持若干 `CREATE` 选项。尚未支持的选项在语句执行过程中会被解析但会被跳过执行。详情可参阅[与 MySQL 安全特性差异](/security-compatibility-with-mysql.md)。 ## 另请参阅 diff --git a/sql-statements/sql-statement-show-grants.md b/sql-statements/sql-statement-show-grants.md index c0ab48522ba2..05ffc3de86b2 100644 --- a/sql-statements/sql-statement-show-grants.md +++ b/sql-statements/sql-statement-show-grants.md @@ -9,30 +9,20 @@ summary: TiDB 数据库中 SHOW GRANTS 的使用概况。 ## 语法图 -**ShowGrantsStmt:** +```ebnf+diagram +ShowGrantsStmt ::= + "SHOW" "GRANTS" ("FOR" Username ("USING" RolenameList)?)? -![ShowGrantsStmt](/media/sqlgram/ShowGrantsStmt.png) +Username ::= + "CURRENT_USER" ( "(" ")" )? +| Username ("@" Hostname)? -**Username:** - -![Username](/media/sqlgram/Username.png) - -**UsingRoles:** - -![UsingRoles](/media/sqlgram/UsingRoles.png) - -**RolenameList:** - -![RolenameList](/media/sqlgram/RolenameList.png) - -**Rolename:** - -![Rolename](/media/sqlgram/Rolename.png) +RolenameList ::= + Rolename ("@" Hostname)? ("," Rolename ("@" Hostname)? )* +``` ## 示例 -{{< copyable "sql" >}} - ```sql SHOW GRANTS; ``` @@ -46,8 +36,6 @@ SHOW GRANTS; 1 row in set (0.00 sec) ``` -{{< copyable "sql" >}} - ```sql SHOW GRANTS FOR 'u1'; ``` @@ -56,8 +44,6 @@ SHOW GRANTS FOR 'u1'; ERROR 1141 (42000): There is no such grant defined for user 'u1' on host '%' ``` -{{< copyable "sql" >}} - ```sql CREATE USER u1; ``` @@ -66,8 +52,6 @@ CREATE USER u1; Query OK, 1 row affected (0.04 sec) ``` -{{< copyable "sql" >}} - ```sql GRANT SELECT ON test.* TO u1; ``` @@ -76,8 +60,6 @@ GRANT SELECT ON test.* TO u1; Query OK, 0 rows affected (0.04 sec) ``` -{{< copyable "sql" >}} - ```sql SHOW GRANTS FOR u1; ``` diff --git a/sql-statements/sql-statement-show-profiles.md b/sql-statements/sql-statement-show-profiles.md index cc83f6590b0d..42d08e74b2c2 100644 --- a/sql-statements/sql-statement-show-profiles.md +++ b/sql-statements/sql-statement-show-profiles.md @@ -9,14 +9,17 @@ summary: TiDB 数据库中 SHOW PROFILES 的使用概况。 ## 语法图 -**ShowStmt:** +```ebnf+diagram +ShowProfilesStmt ::= + "SHOW" "PROFILES" ShowLikeOrWhere? -![ShowStmt](/media/sqlgram/ShowStmt.png) +ShowLikeOrWhere ::= + "LIKE" SimpleExpr +| "WHERE" Expression +``` ## 示例 -{{< copyable "sql" >}} - ```sql SHOW PROFILES ``` diff --git a/sql-statements/sql-statement-show-stats-healthy.md b/sql-statements/sql-statement-show-stats-healthy.md index 991290e6e41a..30938f0a436d 100644 --- a/sql-statements/sql-statement-show-stats-healthy.md +++ b/sql-statements/sql-statement-show-stats-healthy.md @@ -7,27 +7,22 @@ summary: TiDB 数据库中 SHOW STATS_HEALTHY 的使用概况。 `SHOW STATS_HEALTHY` 语句可以预估统计信息的准确度,也就是健康度。健康度低的表可能会生成次优查询执行计划。 -可以通过执行 `ANALYZE` 表命令来改善表的健康度。当表的健康度下降到低于 [`tidb_auto_analyze_ratio`](/system-variables.md#tidb_auto_analyze_ratio) 时,则会自动执行 `ANALYZE` 命令。 +可以通过执行 [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md) 语句来改善表的健康度。当表的健康度下降到低于 [`tidb_auto_analyze_ratio`](/system-variables.md#tidb_auto_analyze_ratio) 时,则会自动执行 `ANALYZE` 语句。 ## 语法图 -**ShowStmt** +```ebnf+diagram +ShowStatsHealthyStmt ::= + "SHOW" "STATS_HEALTHY" ShowLikeOrWhere? -![ShowStmt](/media/sqlgram/ShowStmt.png) - -**ShowTargetFilterable** - -![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png) - -**ShowLikeOrWhereOpt** - -![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png) +ShowLikeOrWhere ::= + "LIKE" SimpleExpr +| "WHERE" Expression +``` ## 示例 -加载示例数据并运行 `ANALYZE` 命令: - -{{< copyable "sql" >}} +加载示例数据并运行 `ANALYZE` 语句: ```sql CREATE TABLE t1 ( @@ -48,8 +43,6 @@ ANALYZE TABLE t1; SHOW STATS_HEALTHY; # should be 100% healthy ``` -{{< copyable "sql" >}} - ```sql SHOW STATS_HEALTHY; ``` @@ -65,8 +58,6 @@ SHOW STATS_HEALTHY; 执行批量更新来删除大约 30% 的记录,然后检查统计信息的健康度: -{{< copyable "sql" >}} - ```sql DELETE FROM t1 WHERE id BETWEEN 101010 AND 201010; # delete about 30% of records SHOW STATS_HEALTHY; diff --git a/sql-statements/sql-statement-unlock-stats.md b/sql-statements/sql-statement-unlock-stats.md index c2d7486a57c5..01b8ea7c3a71 100644 --- a/sql-statements/sql-statement-unlock-stats.md +++ b/sql-statements/sql-statement-unlock-stats.md @@ -11,7 +11,7 @@ summary: TiDB 数据库中 UNLOCK STATS 的使用概况。 ```ebnf+diagram UnlockStatsStmt ::= - 'UNLOCK' 'STATS' (TableNameList) | (TableName 'PARTITION' PartitionNameList) + 'UNLOCK' 'STATS' (TableNameList | TableName 'PARTITION' PartitionNameList) TableNameList ::= TableName (',' TableName)*