From 8e1d4913bb6144ae56f8f128811f073cb4b97850 Mon Sep 17 00:00:00 2001 From: yikeke Date: Wed, 29 Jul 2020 17:56:35 +0800 Subject: [PATCH 01/28] update information-schema.md --- .../information-schema-analyze-status.md | 52 +++++++ .../information-schema-character-sets.md | 53 +++++++ .../information-schema.md | 130 ++++++++++-------- 3 files changed, 181 insertions(+), 54 deletions(-) create mode 100644 information-schema/information-schema-analyze-status.md create mode 100644 information-schema/information-schema-character-sets.md rename system-tables/system-table-information-schema.md => information-schema/information-schema.md (83%) diff --git a/information-schema/information-schema-analyze-status.md b/information-schema/information-schema-analyze-status.md new file mode 100644 index 000000000000..3334fa6f49af --- /dev/null +++ b/information-schema/information-schema-analyze-status.md @@ -0,0 +1,52 @@ +--- +title: ANALYZE_STATUS +summary: 了解 information_schema 表 `ANALYZE_STATUS`。 +--- + +# ANALYZE_STATUS + +`ANALYZE_STATUS` 表提供正在执行的收集统计信息的任务以及有限条历史任务记录。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC analyze_status; +``` + +```sql ++----------------+---------------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------+---------------------+------+------+---------+-------+ +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| PARTITION_NAME | varchar(64) | YES | | NULL | | +| JOB_INFO | varchar(64) | YES | | NULL | | +| PROCESSED_ROWS | bigint(20) unsigned | YES | | NULL | | +| START_TIME | datetime | YES | | NULL | | +| STATE | varchar(64) | YES | | NULL | | ++----------------+---------------------+------+------+---------+-------+ +7 rows in set (0.00 sec) +``` + +`STATE` 列表示特定 `ANALYZE` 任务的执行状态。其值可以是 `pending`、`running`、`finished` 或者 `failed`。 + +{{< copyable "sql" >}} + +```sql +SELECT * FROM `ANALYZE_STATUS`; +``` + +```sql ++--------------+------------+----------------+-------------------+----------------+---------------------+----------+ +| TABLE_SCHEMA | TABLE_NAME | PARTITION_NAME | JOB_INFO | PROCESSED_ROWS | START_TIME | STATE | ++--------------+------------+----------------+-------------------+----------------+---------------------+----------+ +| test | t | | analyze index idx | 2 | 2019-06-21 19:51:14 | finished | +| test | t | | analyze columns | 2 | 2019-06-21 19:51:14 | finished | +| test | t1 | p0 | analyze columns | 0 | 2019-06-21 19:51:15 | finished | +| test | t1 | p3 | analyze columns | 0 | 2019-06-21 19:51:15 | finished | +| test | t1 | p1 | analyze columns | 0 | 2019-06-21 19:51:15 | finished | +| test | t1 | p2 | analyze columns | 1 | 2019-06-21 19:51:15 | finished | ++--------------+------------+----------------+-------------------+----------------+---------------------+----------+ +6 rows in set +``` diff --git a/information-schema/information-schema-character-sets.md b/information-schema/information-schema-character-sets.md new file mode 100644 index 000000000000..8be9772b5567 --- /dev/null +++ b/information-schema/information-schema-character-sets.md @@ -0,0 +1,53 @@ +--- +title: CHARACTER_SETS +summary: 了解 information_schema 表 `CHARACTER_SETS`。 +--- + +# CHARACTER_SETS + +`CHARACTER_SETS` 表提供[字符集](/character-set-and-collation.md)相关的信息。TiDB 目前仅支持部分字符集。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC character_sets; +``` + +``` ++----------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------------+-------------+------+------+---------+-------+ +| CHARACTER_SET_NAME | varchar(32) | YES | | NULL | | +| DEFAULT_COLLATE_NAME | varchar(32) | YES | | NULL | | +| DESCRIPTION | varchar(60) | YES | | NULL | | +| MAXLEN | bigint(3) | YES | | NULL | | ++----------------------+-------------+------+------+---------+-------+ +4 rows in set (0.00 sec) +``` + +`CHARACTER_SETS` 表中列的含义如下: + +* `CHARACTER_SET_NAME`:字符集名称 +* `DEFAULT_COLLATE_NAME`:字符集的默认排序规则名称 +* `DESCRIPTION`:字符集的描述信息 +* `MAXLEN`:该字符集存储一个字符所需要的最大字节数 + +{{< copyable "sql" >}} + +```sql +SELECT * FROM `character_sets`; +``` + +``` ++--------------------+----------------------+---------------+--------+ +| CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION | MAXLEN | ++--------------------+----------------------+---------------+--------+ +| utf8 | utf8_bin | UTF-8 Unicode | 3 | +| utf8mb4 | utf8mb4_bin | UTF-8 Unicode | 4 | +| ascii | ascii_bin | US ASCII | 1 | +| latin1 | latin1_bin | Latin1 | 1 | +| binary | binary | binary | 1 | ++--------------------+----------------------+---------------+--------+ +5 rows in set (0.00 sec) +``` diff --git a/system-tables/system-table-information-schema.md b/information-schema/information-schema.md similarity index 83% rename from system-tables/system-table-information-schema.md rename to information-schema/information-schema.md index 432c8437cec1..1673249ff2b4 100644 --- a/system-tables/system-table-information-schema.md +++ b/information-schema/information-schema.md @@ -1,65 +1,87 @@ --- title: Information Schema -aliases: ['/docs-cn/dev/reference/system-databases/information-schema/'] +aliases: ['/docs-cn/dev/reference/system-databases/information-schema/','/docs-cn/dev/reference/system-databases/information-schema/','/docs-cn/dev/system-tables/system-table-information-schema/','/zh/tidb/dev/system-table-information-schema/']] --- # Information Schema -为了和 MySQL 保持兼容,TiDB 支持很多 `INFORMATION_SCHEMA` 表,其中有不少表都支持相应的 `SHOW` 命令。查询 `INFORMATION_SCHEMA` 表也为表的连接操作提供了可能。 +Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。除了包含与 MySQL 兼容的表外,TiDB 还提供了许多自定义的 `INFORMATION_SCHEMA` 表。 + +许多 `INFORMATION_SCHEMA` 表都有相应的 `SHOW` 命令。查询 `INFORMATION_SCHEMA` 的好处是可以在表之间进行 `join` 操作。 + +## 与 MySQL 兼容的表 + +| 表名 | 描述 | +|-----------------------------------------------------------------------------------------|-----------------------------| +| [`CHARACTER_SETS`](/information-schema/information-schema-character-sets.md) | 提供 TiDB 支持的字符集列表。 | +| [`COLLATIONS`](/information-schema/information-schema-collations.md) | 提供 TiDB 支持的排序规则列表。 | +| [`COLLATION_CHARACTER_SET_APPLICABILITY`](/information-schema/information-schema-collation-character-set-applicability.md) | 说明哪些排序规则适用于哪些字符集。 | +| [`COLUMNS`](/information-schema/information-schema-columns.md) | 提供所有表中列的列表。 | +| `COLUMN_PRIVILEGES` | TiDB 未实现,返回零行。 | +| `COLUMN_STATISTICS` | TiDB 未实现,返回零行。 | +| [`ENGINES`](/information-schema/information-schema-engines.md) | 提供支持的存储引擎列表。 | +| `EVENTS` | TiDB 未实现,返回零行。 | +| `FILES` | TiDB 未实现,返回零行。 | +| `GLOBAL_STATUS` | TiDB 未实现,返回零行。 | +| `GLOBAL_VARIABLES` | TiDB 未实现,返回零行。 | +| [`KEY_COLUMN_USAGE`](/information-schema/information-schema-key-column-usage.md) | 描述列的键约束,例如主键约束。| +| `OPTIMIZER_TRACE` | TiDB 未实现,返回零行。 | +| `PARAMETERS` | TiDB 未实现,返回零行。 | +| [`PARTITIONS`](/information-schema/information-schema-partitions.md) | 提供表分区的列表。 | +| `PLUGINS` | TiDB 未实现,返回零行。 | +| [`PROCESSLIST`](/information-schema/information-schema-processlist.md) | 提供与 `SHOW PROCESSLIST` 命令类似的信息。 | +| `PROFILING` | TiDB 未实现,返回零行。 | +| `REFERENTIAL_CONSTRAINTS` | TiDB 未实现,返回零行。 | +| `ROUTINES` | TiDB 未实现,返回零行。 | +| [`SCHEMATA`](/information-schema/information-schema-schemata.md) | 提供与 `SHOW DATABASES` 命令类似的信息。 | +| `SCHEMA_PRIVILEGES` | TiDB 未实现,返回零行。 | +| `SESSION_STATUS` | TiDB 未实现,返回零行。 | +| [`SESSION_VARIABLES`](/information-schema/information-schema-session-variables.md) | 提供与 `SHOW SESSION VARIABLES` 命令类似的功能。| +| [`STATISTICS`](/information-schema/information-schema-statistics.md) | 提供有关表索引的信息。 | +| [`TABLES`](/information-schema/information-schema-tables.md) | 提供当前用户可见的表的列表。 类似于 `SHOW TABLES`。 | +| `TABLESPACES` | TiDB 未实现,返回零行。 | +| [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) | 提供有关主键、唯一索引和外键的信息。 | +| `TABLE_PRIVILEGES` | TiDB 未实现,返回零行。 | +| `TRIGGERS` | TiDB 未实现,返回零行。 | +| [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) | 汇总与当前用户相关的权限。 | +| [`VIEWS`](/information-schema/information-schema-views.md) | 提供当前用户可见的视图列表。类似于 `SHOW FULL TABLES WHERE table_type = 'VIEW'`。 | + +## TiDB 中的扩展表 + +| 表名 | 描述 | +|-----------------------------------------------------------------------------------------|-------------| +| [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md) | 提供有关收集统计信息的任务的信息。 | +| [`CLUSTER_CONFIG`](/information-schema/information-schema-cluster-config.md) | 提供有关整个 TiDB 集群的配置设置的详细信息。 | +| [`CLUSTER_HARDWARE`](/information-schema/information-schema-cluster-info.md) | 提供在每个 TiDB 组件上发现的底层物理硬件的详细信息。 | +| [`CLUSTER_INFO`](/information-schema/information-schema-cluster-info.md) | 提供当前集群拓扑的详细信息。 | +| [`CLUSTER_LOAD`](/information-schema/information-schema-cluster-load.md) | 提供集群中 TiDB 服务器的当前负载信息。 | +| [`CLUSTER_LOG`](/information-schema/information-schema-cluster-log.md) | 提供整个 TiDB 集群的日志。 | +| `CLUSTER_PROCESSLIST` | 提供 `PROCESSLIST` 表的集群级别的视图。 | +| `CLUSTER_SLOW_QUERY` | 提供 `SLOW_QUERY` 表的集群级别的视图。 | +| `CLUSTER_STATEMENTS_SUMMARY` | 提供 `STATEMENTS_SUMMARY` 表的集群级别的视图。 | +| `CLUSTER_STATEMENTS_SUMMARY_HISTORY` | 提供 `CLUSTER_STATEMENTS_SUMMARY_HISTORY` 表的集群级别的视图。 | +| [`CLUSTER_SYSTEMINFO`](/information-schema/information-schema-cluster-systeminfo.md) | 提供集群中服务器的内核参数配置的详细信息。 | +| [`DDL_JOBS`](/information-schema/information-schema-ddl-jobs.md) | 提供与 `ADMIN SHOW DDL JOBS` 类似的输出。 | +| [`INSPECTION_RESULT`](/information-schema/information-schema-inspection-result.md) | 触发内部诊断检查。 | +| [`INSPECTION_RULES`](/information-schema/information-schema-inspection-rules.md) | 进行的内部诊断检查的列表。 | +| [`INSPECTION_SUMMARY`](/information-schema/information-schema-inspection-summary.md) | 重要监视指标的摘要报告。 | +| [`METRICS_SUMMARY`](/information-schema/information-schema-metrics-summary.md) | 从 Prometheus 获取的指标的摘要。 | +| `METRICS_SUMMARY_BY_LABEL` | 参见 `METRICS_SUMMARY` 表。 | +| [`METRICS_TABLES`](/information-schema/information-schema-metrics-tables.md) | 为 `METRICS_SCHEMA` 中的表提供 PromQL 定义。 | +| [`SEQUENCES`](/information-schema/information-schema-sequences.md) | 描述了基于 MariaDB 实现的 TiDB 序列。 | +| [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md) | 提供当前 TiDB 服务器上慢查询的信息。 | +| [`STATEMENTS_SUMMARY`](/statement-summary-tables.md) | 类似于 MySQL 中的 performance_schema 语句摘要。 | +| [`STATEMENTS_SUMMARY_HISTORY`](/statement-summary-tables.md) | 类似于 MySQL 中的 performance_schema 语句摘要历史。 | +| [`TABLE_STORAGE_STATS`](/information-schema/information-schema-table-storage-stats.md) | 提供存储的表的大小的详细信息。 | +| [`TIDB_HOT_REGIONS`](/information-schema/information-schema-tidb-hot-regions.md) | 提供有关哪些 Region 访问次数最多的统计信息。| +| [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md) | 提供有关 TiDB 表的索引信息。 | +| [`TIDB_SERVERS_INFO`](/information-schema/information-schema-tidb-servers-info.md) | 提供 TiDB 服务器的列表 | +| [`TIFLASH_REPLICA`](/information-schema/information-schema-tiflash-replica.md) | 提供有关 TiFlash 副本的详细信息。 | +| [`TIKV_REGION_PEERS`](/information-schema/information-schema-tikv-region-peers.md) | 提供 Region 存储位置的详细信息。 | +| [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | +| [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | -## ANALYZE_STATUS 表 -`ANALYZE_STATUS` 表提供正在执行的收集统计信息的任务以及有限条历史任务记录。 - -{{< copyable "sql" >}} - -```sql -select * from `ANALYZE_STATUS`; -``` - -```sql -+--------------+------------+----------------+-------------------+----------------+---------------------+----------+ -| TABLE_SCHEMA | TABLE_NAME | PARTITION_NAME | JOB_INFO | PROCESSED_ROWS | START_TIME | STATE | -+--------------+------------+----------------+-------------------+----------------+---------------------+----------+ -| test | t | | analyze index idx | 2 | 2019-06-21 19:51:14 | finished | -| test | t | | analyze columns | 2 | 2019-06-21 19:51:14 | finished | -| test | t1 | p0 | analyze columns | 0 | 2019-06-21 19:51:15 | finished | -| test | t1 | p3 | analyze columns | 0 | 2019-06-21 19:51:15 | finished | -| test | t1 | p1 | analyze columns | 0 | 2019-06-21 19:51:15 | finished | -| test | t1 | p2 | analyze columns | 1 | 2019-06-21 19:51:15 | finished | -+--------------+------------+----------------+-------------------+----------------+---------------------+----------+ -6 rows in set -``` - -## CHARACTER_SETS 表 - -`CHARACTER_SETS` 表提供[字符集](/character-set-and-collation.md)相关的信息。TiDB 目前仅支持部分字符集。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM character_sets; -``` - -```sql -+--------------------+----------------------+---------------+--------+ -| CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION | MAXLEN | -+--------------------+----------------------+---------------+--------+ -| utf8 | utf8_bin | UTF-8 Unicode | 3 | -| utf8mb4 | utf8mb4_bin | UTF-8 Unicode | 4 | -| ascii | ascii_bin | US ASCII | 1 | -| latin1 | latin1_bin | Latin1 | 1 | -| binary | binary | binary | 1 | -+--------------------+----------------------+---------------+--------+ -5 rows in set (0.00 sec) -``` - -`CHARACTER_SETS` 表中列的含义如下: - -* `CHARACTER_SET_NAME`:字符集名称 -* `DEFAULT_COLLATE_NAME`:字符集的默认排序规则名称 -* `DESCRIPTION`:字符集的描述信息 -* `MAXLEN`:该字符集存储一个字符所需要的最大字节数 ## COLLATIONS 表 From 54d1c05f62702dfd6f76169308b41196eff23d76 Mon Sep 17 00:00:00 2001 From: yikeke Date: Wed, 29 Jul 2020 18:42:56 +0800 Subject: [PATCH 02/28] add 6 files --- .../information-schema-character-sets.md | 14 +- ...a-collation-character-set-applicability.md | 45 +++ .../information-schema-collations.md | 53 +++ .../information-schema-columns.md | 122 +++++++ .../information-schema-engines.md | 53 +++ .../information-schema-key-column-usage.md | 86 +++++ .../information-schema-processlist.md | 94 ++++++ information-schema/information-schema.md | 302 ------------------ 8 files changed, 460 insertions(+), 309 deletions(-) create mode 100644 information-schema/information-schema-collation-character-set-applicability.md create mode 100644 information-schema/information-schema-collations.md create mode 100644 information-schema/information-schema-columns.md create mode 100644 information-schema/information-schema-engines.md create mode 100644 information-schema/information-schema-key-column-usage.md create mode 100644 information-schema/information-schema-processlist.md diff --git a/information-schema/information-schema-character-sets.md b/information-schema/information-schema-character-sets.md index 8be9772b5567..e52b45947b80 100644 --- a/information-schema/information-schema-character-sets.md +++ b/information-schema/information-schema-character-sets.md @@ -26,13 +26,6 @@ DESC character_sets; 4 rows in set (0.00 sec) ``` -`CHARACTER_SETS` 表中列的含义如下: - -* `CHARACTER_SET_NAME`:字符集名称 -* `DEFAULT_COLLATE_NAME`:字符集的默认排序规则名称 -* `DESCRIPTION`:字符集的描述信息 -* `MAXLEN`:该字符集存储一个字符所需要的最大字节数 - {{< copyable "sql" >}} ```sql @@ -51,3 +44,10 @@ SELECT * FROM `character_sets`; +--------------------+----------------------+---------------+--------+ 5 rows in set (0.00 sec) ``` + +`CHARACTER_SETS` 表中列的含义如下: + +* `CHARACTER_SET_NAME`:字符集名称 +* `DEFAULT_COLLATE_NAME`:字符集的默认排序规则名称 +* `DESCRIPTION`:字符集的描述信息 +* `MAXLEN`:该字符集存储一个字符所需要的最大字节数 diff --git a/information-schema/information-schema-collation-character-set-applicability.md b/information-schema/information-schema-collation-character-set-applicability.md new file mode 100644 index 000000000000..c3b62d8e7521 --- /dev/null +++ b/information-schema/information-schema-collation-character-set-applicability.md @@ -0,0 +1,45 @@ +--- +title: COLLATION_CHARACTER_SET_APPLICABILITY +summary: 了解 information_schema 表 `COLLATION_CHARACTER_SET_APPLICABILITY`。 +--- + +# COLLATION_CHARACTER_SET_APPLICABILITY + +`COLLATION_CHARACTER_SET_APPLICABILITY` 表将排序规则映射至适用的字符集名称。和 `COLLATIONS` 表一样,包含此表只是为了兼容 MySQL。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC collation_character_set_applicability; +``` + +```sql ++--------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+-------------+------+------+---------+-------+ +| COLLATION_NAME | varchar(32) | NO | | NULL | | +| CHARACTER_SET_NAME | varchar(32) | NO | | NULL | | ++--------------------+-------------+------+------+---------+-------+ +2 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM collation_character_set_applicability WHERE character_set_name='utf8mb4'; +``` + +``` ++----------------+--------------------+ +| COLLATION_NAME | CHARACTER_SET_NAME | ++----------------+--------------------+ +| utf8mb4_bin | utf8mb4 | ++----------------+--------------------+ +1 row in set (0.00 sec) +``` + +`COLLATION_CHARACTER_SET_APPLICABILITY` 表中列的含义如下: + +* `COLLATION_NAME`:排序规则名称 +* `CHARACTER_SET_NAME`:排序规则所属的字符集名称 diff --git a/information-schema/information-schema-collations.md b/information-schema/information-schema-collations.md new file mode 100644 index 000000000000..6226632b5be0 --- /dev/null +++ b/information-schema/information-schema-collations.md @@ -0,0 +1,53 @@ +--- +title: COLLATIONS +summary: 了解 information_schema 表 `COLLATIONS`。 +--- + +# COLLATIONS + +`COLLATIONS` 表提供了 `CHARACTER_SETS` 表中字符集对应的排序规则列表。目前 TiDB 包含该表仅为兼容 MySQL。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC collations; +``` + +```sql ++--------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+-------------+------+------+---------+-------+ +| COLLATION_NAME | varchar(32) | YES | | NULL | | +| CHARACTER_SET_NAME | varchar(32) | YES | | NULL | | +| ID | bigint(11) | YES | | NULL | | +| IS_DEFAULT | varchar(3) | YES | | NULL | | +| IS_COMPILED | varchar(3) | YES | | NULL | | +| SORTLEN | bigint(3) | YES | | NULL | | ++--------------------+-------------+------+------+---------+-------+ +6 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM collations WHERE character_set_name='utf8mb4'; +``` + +``` ++----------------+--------------------+------+------------+-------------+---------+ +| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN | ++----------------+--------------------+------+------------+-------------+---------+ +| utf8mb4_bin | utf8mb4 | 46 | Yes | Yes | 1 | ++----------------+--------------------+------+------------+-------------+---------+ +1 row in set (0.00 sec) +``` + +`COLLATION` 表中列的含义如下: + +* `COLLATION_NAME`:排序规则名称 +* `CHARACTER_SET_NAME`:排序规则所属的字符集名称 +* `ID`:排序规则的 ID +* `IS_DEFAULT`:该排序规则是否是所属字符集的默认排序规则 +* `IS_COMPILED`:字符集是否编译到服务器中 +* `SORTLEN`:排序规则在对字符进行排序时,所分配内存的最小长度 diff --git a/information-schema/information-schema-columns.md b/information-schema/information-schema-columns.md new file mode 100644 index 000000000000..122279a3b8c1 --- /dev/null +++ b/information-schema/information-schema-columns.md @@ -0,0 +1,122 @@ +--- +title: COLUMNS +summary: 了解 information_schema 表 `COLUMNS`。 +--- + +# COLUMNS + +`COLUMNS` 表提供了表的所有列的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC columns; +``` + +```sql ++--------------------------+---------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------------+---------------+------+------+---------+-------+ +| TABLE_CATALOG | varchar(512) | YES | | NULL | | +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| COLUMN_NAME | varchar(64) | YES | | NULL | | +| ORDINAL_POSITION | bigint(64) | YES | | NULL | | +| COLUMN_DEFAULT | text | YES | | NULL | | +| IS_NULLABLE | varchar(3) | YES | | NULL | | +| DATA_TYPE | varchar(64) | YES | | NULL | | +| CHARACTER_MAXIMUM_LENGTH | bigint(21) | YES | | NULL | | +| CHARACTER_OCTET_LENGTH | bigint(21) | YES | | NULL | | +| NUMERIC_PRECISION | bigint(21) | YES | | NULL | | +| NUMERIC_SCALE | bigint(21) | YES | | NULL | | +| DATETIME_PRECISION | bigint(21) | YES | | NULL | | +| CHARACTER_SET_NAME | varchar(32) | YES | | NULL | | +| COLLATION_NAME | varchar(32) | YES | | NULL | | +| COLUMN_TYPE | text | YES | | NULL | | +| COLUMN_KEY | varchar(3) | YES | | NULL | | +| EXTRA | varchar(30) | YES | | NULL | | +| PRIVILEGES | varchar(80) | YES | | NULL | | +| COLUMN_COMMENT | varchar(1024) | YES | | NULL | | +| GENERATION_EXPRESSION | text | NO | | NULL | | ++--------------------------+---------------+------+------+---------+-------+ +21 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +CREATE TABLE test.t1 (a int); +SELECT * FROM columns WHERE table_schema='test' AND TABLE_NAME='t1'\G +``` + +```sql +*************************** 1. row *************************** + TABLE_CATALOG: def + TABLE_SCHEMA: test + TABLE_NAME: t1 + COLUMN_NAME: a + ORDINAL_POSITION: 1 + COLUMN_DEFAULT: NULL + IS_NULLABLE: YES + DATA_TYPE: int +CHARACTER_MAXIMUM_LENGTH: NULL + CHARACTER_OCTET_LENGTH: NULL + NUMERIC_PRECISION: 11 + NUMERIC_SCALE: 0 + DATETIME_PRECISION: NULL + CHARACTER_SET_NAME: NULL + COLLATION_NAME: NULL + COLUMN_TYPE: int(11) + COLUMN_KEY: + EXTRA: + PRIVILEGES: select,insert,update,references + COLUMN_COMMENT: + GENERATION_EXPRESSION: +1 row in set (0.02 sec) +``` + +`COLUMNS` 表中列的含义如下: + +* `TABLE_CATALOG`:包含列的表所属的目录的名称。该值始终为 `def`。 +* `TABLE_SCHEMA`:包含列的表所属的数据库的名称。 +* `TABLE_NAME`:包含列的表的名称。 +* `COLUMN_NAME`:列的名称。 +* `ORDINAL_POSITION`:表中列的位置。 +* `COLUMN_DEFAULT`:列的默认值。如果列的显式默认值为 `NULL`,或者列定义中不包含 `default` 子句,则此值为 `NULL`。 +* `IS_NULLABLE`:列的可空性。如果列中可以存储空值,则该值为 `YES`,否则为 `NO`。 +* `DATA_TYPE`:列的数据类型。 +* `CHARACTER_MAXIMUM_LENGTH`:对于字符串列,以字符为单位的最大长度。 +* `CHARACTER_OCTET_LENGTH`:对于字符串列,以字节为单位的最大长度。 +* `NUMERIC_PRECISION`:对于数字列,为数字精度。 +* `NUMERIC_SCALE`:对于数字列,为数字刻度。 +* `DATETIME_PRECISION`:对于时间列,小数秒精度。 +* `CHARACTER_SET_NAME`:对于字符串列,字符集名称。 +* `COLLATION_NAME`:对于字符串列,排序规则名称。 +* `COLUMN_TYPE`:列类型。 +* `COLUMN_KEY`:该列是否被索引。具体显示如下: + * 如果此值为空,则该列要么未被索引,要么被索引且是多列非唯一索引中的第二列。 + * 如果此值是 `PRI`,则该列是主键,或者是多列主键中的一列。 + * 如果此值是 `UNI`,则该列是唯一索引的第一列。 + * 如果此值是 `MUL`,则该列是非唯一索引的第一列,在该列中允许给定值的多次出现。 +* `EXTRA`:关于给定列的任何附加信息。 +* `PRIVILEGES`:当前用户对该列拥有的权限。目前在 TiDB 中,此值为定值,一直为 `select,insert,update,references`。 +* `COLUMN_COMMENT`:列定义中包含的注释。 +* `GENERATION_EXPRESSION`:对于生成的列,显示用于计算列值的表达式。对于未生成的列为空。 + +对应的 `SHOW` 语句如下: + +{{< copyable "sql" >}} + +```sql +SHOW COLUMNS FROM t1 FROM test; +``` + +```sql ++-------+---------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------+---------+------+------+---------+-------+ +| a | int(11) | YES | | NULL | | ++-------+---------+------+------+---------+-------+ +1 row in set (0.00 sec) +``` diff --git a/information-schema/information-schema-engines.md b/information-schema/information-schema-engines.md new file mode 100644 index 000000000000..e411a32766ac --- /dev/null +++ b/information-schema/information-schema-engines.md @@ -0,0 +1,53 @@ +--- +title: ENGINES +summary: 了解 information_schema 表 `ENGINES`。 +--- + +# ENGINES + +`ENGINES` 表提供了关于存储引擎的信息。从和 MySQL 兼容性上考虑,TiDB 会一直将 InnoDB 描述为唯一支持的引擎。此外,`ENGINES` 表中其它列值也都是定值。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC engines; +``` + +```sql ++--------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------+-------------+------+------+---------+-------+ +| ENGINE | varchar(64) | YES | | NULL | | +| SUPPORT | varchar(8) | YES | | NULL | | +| COMMENT | varchar(80) | YES | | NULL | | +| TRANSACTIONS | varchar(3) | YES | | NULL | | +| XA | varchar(3) | YES | | NULL | | +| SAVEPOINTS | varchar(3) | YES | | NULL | | ++--------------+-------------+------+------+---------+-------+ +6 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM engines; +``` + +```sql ++--------+---------+------------------------------------------------------------+--------------+------+------------+ +| ENGINE | SUPPORT | COMMENT | TRANSACTIONS | XA | SAVEPOINTS | ++--------+---------+------------------------------------------------------------+--------------+------+------------+ +| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | ++--------+---------+------------------------------------------------------------+--------------+------+------------+ +1 row in set (0.01 sec) +``` + +`ENGINES` 表中列的含义如下: + +* `ENGINE`:存储引擎的名称。 +* `SUPPORT`:服务器对存储引擎的支持级别,在 TiDB 中此值一直是 `DEFAULT`。 +* `COMMENT`:存储引擎的简要描述。 +* `TRANSACTIONS`:存储引擎是否支持事务。 +* `XA`:存储引擎是否支持 XA 事务。 +* `SAVEPOINTS`:存储引擎是否支持 `savepoints`。 diff --git a/information-schema/information-schema-key-column-usage.md b/information-schema/information-schema-key-column-usage.md new file mode 100644 index 000000000000..56d063b81840 --- /dev/null +++ b/information-schema/information-schema-key-column-usage.md @@ -0,0 +1,86 @@ +--- +title: KEY_COLUMN_USAGE +summary: 了解 information_schema 表 `KEY_COLUMN_USAGE`。 +--- + +# KEY_COLUMN_USAGE + +`KEY_COLUMN_USAGE` 表描述了列的键约束,比如主键约束。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC key_column_usage; +``` + +``` ++-------------------------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------------------------------+--------------+------+------+---------+-------+ +| CONSTRAINT_CATALOG | varchar(512) | NO | | NULL | | +| CONSTRAINT_SCHEMA | varchar(64) | NO | | NULL | | +| CONSTRAINT_NAME | varchar(64) | NO | | NULL | | +| TABLE_CATALOG | varchar(512) | NO | | NULL | | +| TABLE_SCHEMA | varchar(64) | NO | | NULL | | +| TABLE_NAME | varchar(64) | NO | | NULL | | +| COLUMN_NAME | varchar(64) | NO | | NULL | | +| ORDINAL_POSITION | bigint(10) | NO | | NULL | | +| POSITION_IN_UNIQUE_CONSTRAINT | bigint(10) | YES | | NULL | | +| REFERENCED_TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| REFERENCED_TABLE_NAME | varchar(64) | YES | | NULL | | +| REFERENCED_COLUMN_NAME | varchar(64) | YES | | NULL | | ++-------------------------------+--------------+------+------+---------+-------+ +12 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM key_column_usage WHERE table_schema='mysql' and table_name='user'; +``` + +``` +*************************** 1. row *************************** + CONSTRAINT_CATALOG: def + CONSTRAINT_SCHEMA: mysql + CONSTRAINT_NAME: PRIMARY + TABLE_CATALOG: def + TABLE_SCHEMA: mysql + TABLE_NAME: user + COLUMN_NAME: Host + ORDINAL_POSITION: 1 +POSITION_IN_UNIQUE_CONSTRAINT: NULL + REFERENCED_TABLE_SCHEMA: NULL + REFERENCED_TABLE_NAME: NULL + REFERENCED_COLUMN_NAME: NULL +*************************** 2. row *************************** + CONSTRAINT_CATALOG: def + CONSTRAINT_SCHEMA: mysql + CONSTRAINT_NAME: PRIMARY + TABLE_CATALOG: def + TABLE_SCHEMA: mysql + TABLE_NAME: user + COLUMN_NAME: User + ORDINAL_POSITION: 2 +POSITION_IN_UNIQUE_CONSTRAINT: NULL + REFERENCED_TABLE_SCHEMA: NULL + REFERENCED_TABLE_NAME: NULL + REFERENCED_COLUMN_NAME: NULL +2 rows in set (0.00 sec) +``` + +`KEY_COLUMN_USAGE` 表中列的含义如下: + +* `CONSTRAINT_CATALOG`:约束所属的目录的名称。该值始终为 `def`。 +* `CONSTRAINT_SCHEMA`:约束所属的数据库的名称。 +* `CONSTRAINT_NAME`:约束名称。 +* `TABLE_CATALOG`:表所属目录的名称。该值始终为 `def`。 +* `TABLE_SCHEMA`:表所属的架构数据库的名称。 +* `TABLE_NAME`:具有约束的表的名称。 +* `COLUMN_NAME`:具有约束的列的名称。 +* `ORDINAL_POSITION`:列在约束中的位置,而不是列在表中的位置。列位置从 1 开始编号。 +* `POSITION_IN_UNIQUE_CONSTRAINT`:唯一约束和主键约束为空。对于外键约束,此列是被引用的表的键的序号位置。 +* `REFERENCED_TABLE_SCHEMA`:约束引用的数据库的名称。目前在 TiDB 中,除了外键约束,其它约束此列的值都为 `nil`。 +* `REFERENCED_TABLE_NAME`:约束引用的表的名称。目前在 TiDB 中,除了外键约束,其它约束此列的值都为 `nil`。 +* `REFERENCED_COLUMN_NAME`:约束引用的列的名称。目前在 TiDB 中,除了外键约束,其它约束此列的值都为 `nil`。 diff --git a/information-schema/information-schema-processlist.md b/information-schema/information-schema-processlist.md new file mode 100644 index 000000000000..0a960b073f17 --- /dev/null +++ b/information-schema/information-schema-processlist.md @@ -0,0 +1,94 @@ +--- +title: PROCESSLIST +summary: 了解 information_schema 表 `PROCESSLIST`。 +--- + +# PROCESSLIST + +`PROCESSLIST` 和 `SHOW PROCESSLIST` 的功能一样,都是查看当前正在处理的请求。 + +`PROCESSLIST` 表比 `SHOW PROCESSLIST` 的结果多出下面几列: + +* `MEM` 列:`MEM` 显示正在处理的请求已使用的内存,单位是 byte。 +* `TxnStart`列:显示事务的开始时间 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC processlist; +``` + +``` ++----------+---------------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------+---------------------+------+------+---------+-------+ +| ID | bigint(21) unsigned | NO | | 0 | | +| USER | varchar(16) | NO | | | | +| HOST | varchar(64) | NO | | | | +| DB | varchar(64) | YES | | NULL | | +| COMMAND | varchar(16) | NO | | | | +| TIME | int(7) | NO | | 0 | | +| STATE | varchar(7) | YES | | NULL | | +| INFO | binary(512) | YES | | NULL | | +| MEM | bigint(21) unsigned | YES | | NULL | | +| TxnStart | varchar(64) | NO | | | | ++----------+---------------------+------+------+---------+-------+ +10 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM processlist\G +``` + +``` +*************************** 1. row *************************** + ID: 16 + USER: root + HOST: 127.0.0.1 + DB: information_schema + COMMAND: Query + TIME: 0 + STATE: autocommit + INFO: SELECT * FROM processlist + MEM: 0 +TxnStart: +1 row in set (0.00 sec) +``` + +`PROCESSLIST` 表各列的含义如下: + +* ID:客户连接 ID。 +* USER:执行当前 PROCESS 的用户名。 +* HOST:客户连接的地址。 +* DB:当前连接的默认数据库名。 +* COMMAND:当前 PROCESS 执行的命令类型。 +* TIME:当前 PROCESS 的已经执行的时间,单位是秒。 +* STATE:当前连接的状态。 +* INFO:正在处理的请求语句。 +* MEM:正在处理的请求已使用的内存,单位是 byte。 +* `TxnStart`列:显示事务的开始时间 + +## CLUSTER_PROCESSLIST + +`CLUSTER_PROCESSLIST` 是 `PROCESSLIST` 对应的集群系统表,用于查询集群中所有 TiDB 节点的 `PROCESSLIST` 信息。`CLUSTER_PROCESSLIST` 表结构上比 `PROCESSLIST` 多一列 `INSTANCE`,表示该行数据来自的 TiDB 节点地址。 + +{{< copyable "sql" >}} + +```sql +SELECT * FROM cluster_processlist; +``` + +``` ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ +| INSTANCE | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | TxnStart | ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ +| 10.0.1.22:10080 | 150 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077223) | +| 10.0.1.22:10080 | 138 | root | 10.0.1.1 | test | Query | 0 | autocommit | SELECT * FROM information_schema.cluster_processlist | 0 | 05-28 03:54:21.230(416976223923077220) | +| 10.0.1.22:10080 | 151 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077224) | +| 10.0.1.21:10080 | 15 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077222) | +| 10.0.1.21:10080 | 14 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077225) | ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ +``` diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 1673249ff2b4..35bf3fa3bac1 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -81,308 +81,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 | [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | | [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | - - -## COLLATIONS 表 - -`COLLATIONS` 表提供了 `CHARACTER_SETS` 表中字符集对应的排序规则列表。TiDB 当前仅支持二进制排序规则,包含该表仅为兼容 MySQL。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM collations WHERE character_set_name='utf8mb4'; -``` - -```sql -+------------------------+--------------------+------+------------+-------------+---------+ -| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN | -+------------------------+--------------------+------+------------+-------------+---------+ -| utf8mb4_general_ci | utf8mb4 | 45 | Yes | Yes | 1 | -| utf8mb4_bin | utf8mb4 | 46 | | Yes | 1 | -| utf8mb4_unicode_ci | utf8mb4 | 224 | | Yes | 1 | -| utf8mb4_icelandic_ci | utf8mb4 | 225 | | Yes | 1 | -| utf8mb4_latvian_ci | utf8mb4 | 226 | | Yes | 1 | -| utf8mb4_romanian_ci | utf8mb4 | 227 | | Yes | 1 | -| utf8mb4_slovenian_ci | utf8mb4 | 228 | | Yes | 1 | -| utf8mb4_polish_ci | utf8mb4 | 229 | | Yes | 1 | -| utf8mb4_estonian_ci | utf8mb4 | 230 | | Yes | 1 | -| utf8mb4_spanish_ci | utf8mb4 | 231 | | Yes | 1 | -| utf8mb4_swedish_ci | utf8mb4 | 232 | | Yes | 1 | -| utf8mb4_turkish_ci | utf8mb4 | 233 | | Yes | 1 | -| utf8mb4_czech_ci | utf8mb4 | 234 | | Yes | 1 | -| utf8mb4_danish_ci | utf8mb4 | 235 | | Yes | 1 | -| utf8mb4_lithuanian_ci | utf8mb4 | 236 | | Yes | 1 | -| utf8mb4_slovak_ci | utf8mb4 | 237 | | Yes | 1 | -| utf8mb4_spanish2_ci | utf8mb4 | 238 | | Yes | 1 | -| utf8mb4_roman_ci | utf8mb4 | 239 | | Yes | 1 | -| utf8mb4_persian_ci | utf8mb4 | 240 | | Yes | 1 | -| utf8mb4_esperanto_ci | utf8mb4 | 241 | | Yes | 1 | -| utf8mb4_hungarian_ci | utf8mb4 | 242 | | Yes | 1 | -| utf8mb4_sinhala_ci | utf8mb4 | 243 | | Yes | 1 | -| utf8mb4_german2_ci | utf8mb4 | 244 | | Yes | 1 | -| utf8mb4_croatian_ci | utf8mb4 | 245 | | Yes | 1 | -| utf8mb4_unicode_520_ci | utf8mb4 | 246 | | Yes | 1 | -| utf8mb4_vietnamese_ci | utf8mb4 | 247 | | Yes | 1 | -+------------------------+--------------------+------+------------+-------------+---------+ -26 rows in set (0.00 sec) -``` - -`COLLATION` 表中列的含义如下: - -* `COLLATION_NAME`:排序规则名称 -* `CHARACTER_SET_NAME`:排序规则所属的字符集名称 -* `ID`:排序规则的 ID -* `IS_DEFAULT`:该排序规则是否是所属字符集的默认排序规则 -* `IS_COMPILED`:字符集是否编译到服务器中 -* `SORTLEN`:排序规则在对字符进行排序时,所分配内存的最小长度 - -## COLLATION_CHARACTER_SET_APPLICABILITY 表 - -`COLLATION_CHARACTER_SET_APPLICABILITY` 表将排序规则映射至适用的字符集名称。和 `COLLATIONS` 表一样,包含此表也是为了兼容 MySQL。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM collation_character_set_applicability WHERE character_set_name='utf8mb4'; -``` - -```sql -+----------------+--------------------+ -| COLLATION_NAME | CHARACTER_SET_NAME | -+----------------+--------------------+ -| utf8mb4_bin | utf8mb4 | -+----------------+--------------------+ -``` - -`COLLATION_CHARACTER_SET_APPLICABILITY` 表中列的含义如下: - -* `COLLATION_NAME`:排序规则名称 -* `CHARACTER_SET_NAME`:排序规则所属的字符集名称 - -## COLUMNS 表 - -`COLUMNS` 表提供了表的所有列的信息。 - -{{< copyable "sql" >}} - -```sql -CREATE TABLE test.t1 (a int); -``` - -``` -1 row in set (0.01 sec) -``` - -{{< copyable "sql" >}} - -```sql -SELECT * FROM information_schema.columns WHERE table_schema='test' AND TABLE_NAME='t1'; -``` - -``` -*************************** 1. row *************************** - TABLE_CATALOG: def - TABLE_SCHEMA: test - TABLE_NAME: t1 - COLUMN_NAME: a - ORDINAL_POSITION: 1 - COLUMN_DEFAULT: NULL - IS_NULLABLE: YES - DATA_TYPE: int -CHARACTER_MAXIMUM_LENGTH: NULL - CHARACTER_OCTET_LENGTH: NULL - NUMERIC_PRECISION: 11 - NUMERIC_SCALE: 0 - DATETIME_PRECISION: NULL - CHARACTER_SET_NAME: NULL - COLLATION_NAME: NULL - COLUMN_TYPE: int(11) - COLUMN_KEY: - EXTRA: - PRIVILEGES: select,insert,update,references - COLUMN_COMMENT: - GENERATION_EXPRESSION: -1 row in set (0.01 sec) -``` - -`COLUMNS` 表中列的含义如下: - -* `TABLE_CATALOG`:包含列的表所属的目录的名称。该值始终为 `def`。 -* `TABLE_SCHEMA`:包含列的表所属的数据库的名称。 -* `TABLE_NAME`:包含列的表的名称。 -* `COLUMN_NAME`:列的名称。 -* `ORDINAL_POSITION`:表中列的位置。 -* `COLUMN_DEFAULT`:列的默认值。如果列的显式默认值为 `NULL`,或者列定义中不包含 `default` 子句,则此值为 `NULL`。 -* `IS_NULLABLE`:列的可空性。如果列中可以存储空值,则该值为 `YES`,则为 `NO`。 -* `DATA_TYPE`:列数据类型。 -* `CHARACTER_MAXIMUM_LENGTH`:对于字符串列,以字符为单位的最大长度。 -* `CHARACTER_OCTET_LENGTH`:对于字符串列,以字节为单位的最大长度。 -* `NUMERIC_PRECISION`:对于数字列,为数字精度。 -* `NUMERIC_SCALE`:对于数字列,为数字刻度。 -* `DATETIME_PRECISION`:对于时间列,小数秒精度。 -* `CHARACTER_SET_NAME`:对于字符串列,字符集名称。 -* `COLLATION_NAME`:对于字符串列,排序规则名称。 -* `COLUMN_TYPE`:列类型。 -* `COLUMN_KEY`:该列是否被索引。具体显示如下: - * 如果此值为空,则该列要么未被索引,要么被索引且是多列非唯一索引中的第二列。 - * 如果此值是`PRI`,则该列是主键,或者是多列主键中的一列。 - * 如果此值是`UNI`,则该列是唯一索引的第一列。 - * 如果此值是`MUL`,则该列是非唯一索引的第一列,在该列中允许给定值的多次出现。 -* `EXTRA`:关于给定列的任何附加信息。 -* `PRIVILEGES`:当前用户对该列拥有的权限。目前在 TiDB 中,此值为定值,一直为 `select,insert,update,references`。 -* `COLUMN_COMMENT`:列定义中包含的注释。 -* `GENERATION_EXPRESSION`:对于生成的列,显示用于计算列值的表达式。对于未生成的列为空。 - -对应的 `SHOW` 语句如下: - -{{< copyable "sql" >}} - -```sql -SHOW COLUMNS FROM t1 FROM test; -``` - -```sql -+-------+---------+------+------+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+-------+---------+------+------+---------+-------+ -| a | int(11) | YES | | NULL | | -+-------+---------+------+------+---------+-------+ -1 row in set (0.00 sec) -``` - -## ENGINES 表 - -`ENGINES` 表提供了关于存储引擎的信息。从和 MySQL 兼容性上考虑,TiDB 会一直将 InnoDB 描述为唯一支持的引擎。此外,`ENGINES` 表中其它列值也都是定值。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM engines; -``` - -``` -*************************** 1. row *************************** - ENGINE: InnoDB - SUPPORT: DEFAULT - COMMENT: Supports transactions, row-level locking, and foreign keys -TRANSACTIONS: YES - XA: YES - SAVEPOINTS: YES -1 row in set (0.00 sec) -``` - -`ENGINES` 表中列的含义如下: - -* `ENGINE`:存储引擎的名称。 -* `SUPPORT`:服务器对存储引擎的支持级别,在 TiDB 中此值一直是 `DEFAULT`。 -* `COMMENT`:存储引擎的简要描述。 -* `TRANSACTIONS`:存储引擎是否支持事务。 -* `XA`:存储引擎是否支持 XA 事务。 -* `SAVEPOINTS`:存储引擎是否支持 `savepoints`。 - -## KEY_COLUMN_USAGE 表 - -`KEY_COLUMN_USAGE` 表描述了列的键约束,比如主键约束。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM key_column_usage WHERE table_schema='mysql' and table_name='user'; -``` - -``` -*************************** 1. row *************************** - CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: PRIMARY - TABLE_CATALOG: def - TABLE_SCHEMA: mysql - TABLE_NAME: user - COLUMN_NAME: Host - ORDINAL_POSITION: 1 -POSITION_IN_UNIQUE_CONSTRAINT: NULL - REFERENCED_TABLE_SCHEMA: NULL - REFERENCED_TABLE_NAME: NULL - REFERENCED_COLUMN_NAME: NULL -*************************** 2. row *************************** - CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: PRIMARY - TABLE_CATALOG: def - TABLE_SCHEMA: mysql - TABLE_NAME: user - COLUMN_NAME: User - ORDINAL_POSITION: 2 -POSITION_IN_UNIQUE_CONSTRAINT: NULL - REFERENCED_TABLE_SCHEMA: NULL - REFERENCED_TABLE_NAME: NULL - REFERENCED_COLUMN_NAME: NULL -2 rows in set (0.00 sec) -``` - -`KEY_COLUMN_USAGE` 表中列的含义如下: - -* `CONSTRAINT_CATALOG`:约束所属的目录的名称。该值始终为 `def`。 -* `CONSTRAINT_SCHEMA`:约束所属的数据库的名称。 -* `CONSTRAINT_NAME`:约束名称。 -* `TABLE_CATALOG`:表所属目录的名称。该值始终为 `def`。 -* `TABLE_SCHEMA`:表所属的架构数据库的名称。 -* `TABLE_NAME`:具有约束的表的名称。 -* `COLUMN_NAME`:具有约束的列的名称。 -* `ORDINAL_POSITION`:列在约束中的位置,而不是列在表中的位置。列位置从 1 开始编号。 -* `POSITION_IN_UNIQUE_CONSTRAINT`:唯一约束和主键约束为空。对于外键约束,此列是被引用的表的键的序号位置。 -* `REFERENCED_TABLE_SCHEMA`:约束引用的数据库的名称。目前在 TiDB 中,除了外键约束,其它约束此列的值都为 `nil`。 -* `REFERENCED_TABLE_NAME`:约束引用的表的名称。目前在 TiDB 中,除了外键约束,其它约束此列的值都为 `nil`。 -* `REFERENCED_COLUMN_NAME`:约束引用的列的名称。目前在 TiDB 中,除了外键约束,其它约束此列的值都为 `nil`。 - -## PROCESSLIST 表 - -`PROCESSLIST` 和 `show processlist` 的功能一样,都是查看当前正在处理的请求。 - -`PROCESSLIST` 表会比 `show processlist` 多一个 `MEM` 列,`MEM` 是指正在处理的请求已使用的内存,单位是 byte。 - -```sql -+----+------+------+--------------------+---------+------+-------+---------------------------+-----+ -| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | -+----+------+------+--------------------+---------+------+-------+---------------------------+-----+ -| 1 | root | ::1 | INFORMATION_SCHEMA | Query | 0 | 2 | select * from PROCESSLIST | 0 | -+----+------+------+--------------------+---------+------+-------+---------------------------+-----+ -``` - -`PROCESSLIST` 表各列的含义如下: - -* ID:客户连接 ID。 -* USER:执行当前 PROCESS 的用户名。 -* HOST:客户连接的地址。 -* DB:当前连接的默认数据库名。 -* COMMAND:当前 PROCESS 执行的命令类型。 -* TIME:当前 PROCESS 的已经执行的时间,单位是秒。 -* STATE:当前连接的状态。 -* INFO:正在处理的请求语句。 -* MEM:正在处理的请求已使用的内存,单位是 byte。 - -## CLUSTER_PROCESSLIST - -`CLUSTER_PROCESSLIST` 是 `PROCESSLIST` 对应的集群系统表,用于查询集群中所有 TiDB 节点的 `PROCESSLIST` 信息。`CLUSTER_PROCESSLIST` 表结构上比 `PROCESSLIST` 多一列 `INSTANCE`,表示该行数据来自的 TiDB 节点地址。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM information_schema.cluster_processlist; -``` - -```sql -+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ -| INSTANCE | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | TxnStart | -+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ -| 10.0.1.22:10080 | 150 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077223) | -| 10.0.1.22:10080 | 138 | root | 10.0.1.1 | test | Query | 0 | autocommit | SELECT * FROM information_schema.cluster_processlist | 0 | 05-28 03:54:21.230(416976223923077220) | -| 10.0.1.22:10080 | 151 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077224) | -| 10.0.1.21:10080 | 15 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077222) | -| 10.0.1.21:10080 | 14 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077225) | -+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ -``` - ## SCHEMATA 表 `SCHEMATA` 表提供了关于数据库的信息。表中的数据与 `SHOW DATABASES` 语句的执行结果等价。 From 95eb068b567eb19936524ec1bff288367fb5b9e6 Mon Sep 17 00:00:00 2001 From: yikeke Date: Wed, 29 Jul 2020 18:59:24 +0800 Subject: [PATCH 03/28] add 5 files --- .../information-schema-schemata.md | 55 +++ .../information-schema-session-variables.md | 54 +++ .../information-schema-slow-query.md | 180 +++++++++ .../information-schema-statistics.md | 53 +++ .../information-schema-tables.md | 126 ++++++ information-schema/information-schema.md | 366 ------------------ 6 files changed, 468 insertions(+), 366 deletions(-) create mode 100644 information-schema/information-schema-schemata.md create mode 100644 information-schema/information-schema-session-variables.md create mode 100644 information-schema/information-schema-slow-query.md create mode 100644 information-schema/information-schema-statistics.md create mode 100644 information-schema/information-schema-tables.md diff --git a/information-schema/information-schema-schemata.md b/information-schema/information-schema-schemata.md new file mode 100644 index 000000000000..5be8705c17cb --- /dev/null +++ b/information-schema/information-schema-schemata.md @@ -0,0 +1,55 @@ +--- +title: SCHEMATA +summary: 了解 information_schema 表 `SCHEMATA`。 +--- + +# SCHEMATA + +`SCHEMATA` 表提供了关于数据库的信息。表中的数据与 `SHOW DATABASES` 语句的执行结果等价。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +desc SCHEMATA; +``` + +``` ++----------------------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------------------+--------------+------+------+---------+-------+ +| CATALOG_NAME | varchar(512) | YES | | NULL | | +| SCHEMA_NAME | varchar(64) | YES | | NULL | | +| DEFAULT_CHARACTER_SET_NAME | varchar(64) | YES | | NULL | | +| DEFAULT_COLLATION_NAME | varchar(32) | YES | | NULL | | +| SQL_PATH | varchar(512) | YES | | NULL | | ++----------------------------+--------------+------+------+---------+-------+ +5 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM SCHEMATA; +``` + +``` ++--------------+--------------------+----------------------------+------------------------+----------+ +| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | ++--------------+--------------------+----------------------------+------------------------+----------+ +| def | INFORMATION_SCHEMA | utf8mb4 | utf8mb4_bin | NULL | +| def | METRICS_SCHEMA | utf8mb4 | utf8mb4_bin | NULL | +| def | mysql | utf8mb4 | utf8mb4_bin | NULL | +| def | PERFORMANCE_SCHEMA | utf8mb4 | utf8mb4_bin | NULL | +| def | test | utf8mb4 | utf8mb4_bin | NULL | ++--------------+--------------------+----------------------------+------------------------+----------+ +5 rows in set (0.00 sec) +``` + +`SCHEMATA` 表各列字段含义如下: + +* CATALOG_NAME:数据库归属的目录名,该列值永远为 `def`。 +* SCHEMA_NAME:数据库的名字。 +* DEFAULT_CHARACTER_SET_NAME:数据库的默认字符集。 +* DEFAULT_COLLATION_NAME:数据库的默认 collation。 +* SQL_PATH:该项值永远为 `NULL`。 diff --git a/information-schema/information-schema-session-variables.md b/information-schema/information-schema-session-variables.md new file mode 100644 index 000000000000..518ac62f5181 --- /dev/null +++ b/information-schema/information-schema-session-variables.md @@ -0,0 +1,54 @@ +--- +title: SESSION_VARIABLES +summary: 了解 information_schema 表 `SESSION_VARIABLES`。 +--- + +# SESSION_VARIABLES + +`SESSION_VARIABLES` 表提供了关于 session 变量的信息。表中的数据跟 `SHOW SESSION VARIABLES` 语句执行结果类似。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC session_variables; +``` + +``` ++----------------+---------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------+---------------+------+------+---------+-------+ +| VARIABLE_NAME | varchar(64) | YES | | NULL | | +| VARIABLE_VALUE | varchar(1024) | YES | | NULL | | ++----------------+---------------+------+------+---------+-------+ +2 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM session_variables ORDER BY variable_name LIMIT 10; +``` + +``` ++-----------------------------------+------------------+ +| VARIABLE_NAME | VARIABLE_VALUE | ++-----------------------------------+------------------+ +| allow_auto_random_explicit_insert | off | +| auto_increment_increment | 1 | +| auto_increment_offset | 1 | +| autocommit | 1 | +| automatic_sp_privileges | 1 | +| avoid_temporal_upgrade | 0 | +| back_log | 80 | +| basedir | /usr/local/mysql | +| big_tables | 0 | +| bind_address | * | ++-----------------------------------+------------------+ +10 rows in set (0.00 sec) +``` + +`SESSION_VARIABLES` 表各列字段含义如下: + +* `VARIABLE_NAME`:数据库中 session 级变量的名称。 +* `VARIABLE_VALUE`:数据库中对应该 session 变量名的具体值。 diff --git a/information-schema/information-schema-slow-query.md b/information-schema/information-schema-slow-query.md new file mode 100644 index 000000000000..221dc5495687 --- /dev/null +++ b/information-schema/information-schema-slow-query.md @@ -0,0 +1,180 @@ +--- +title: SLOW_QUERY +summary: 了解 information_schema 表 `SLOW_QUERY`。 +--- + +# SLOW_QUERY + +`SLOW_QUERY` 表中提供了当前节点的慢查询相关的信息,其内容通过解析当前节点的 TiDB 慢查询日志而来,列名和慢日志中的字段名是一一对应。关于如何使用该表调查和改善慢查询,请参考[慢查询日志文档](/identify-slow-queries.md)。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC slow_query; +``` + +```sql ++---------------------------+---------------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------------------+---------------------+------+------+---------+-------+ +| Time | timestamp(6) | YES | | NULL | | +| Txn_start_ts | bigint(20) unsigned | YES | | NULL | | +| User | varchar(64) | YES | | NULL | | +| Host | varchar(64) | YES | | NULL | | +| Conn_ID | bigint(20) unsigned | YES | | NULL | | +| Query_time | double | YES | | NULL | | +| Parse_time | double | YES | | NULL | | +| Compile_time | double | YES | | NULL | | +| Rewrite_time | double | YES | | NULL | | +| Preproc_subqueries | bigint(20) unsigned | YES | | NULL | | +| Preproc_subqueries_time | double | YES | | NULL | | +| Optimize_time | double | YES | | NULL | | +| Wait_TS | double | YES | | NULL | | +| Prewrite_time | double | YES | | NULL | | +| Wait_prewrite_binlog_time | double | YES | | NULL | | +| Commit_time | double | YES | | NULL | | +| Get_commit_ts_time | double | YES | | NULL | | +| Commit_backoff_time | double | YES | | NULL | | +| Backoff_types | varchar(64) | YES | | NULL | | +| Resolve_lock_time | double | YES | | NULL | | +| Local_latch_wait_time | double | YES | | NULL | | +| Write_keys | bigint(22) | YES | | NULL | | +| Write_size | bigint(22) | YES | | NULL | | +| Prewrite_region | bigint(22) | YES | | NULL | | +| Txn_retry | bigint(22) | YES | | NULL | | +| Cop_time | double | YES | | NULL | | +| Process_time | double | YES | | NULL | | +| Wait_time | double | YES | | NULL | | +| Backoff_time | double | YES | | NULL | | +| LockKeys_time | double | YES | | NULL | | +| Request_count | bigint(20) unsigned | YES | | NULL | | +| Total_keys | bigint(20) unsigned | YES | | NULL | | +| Process_keys | bigint(20) unsigned | YES | | NULL | | +| DB | varchar(64) | YES | | NULL | | +| Index_names | varchar(100) | YES | | NULL | | +| Is_internal | tinyint(1) | YES | | NULL | | +| Digest | varchar(64) | YES | | NULL | | +| Stats | varchar(512) | YES | | NULL | | +| Cop_proc_avg | double | YES | | NULL | | +| Cop_proc_p90 | double | YES | | NULL | | +| Cop_proc_max | double | YES | | NULL | | +| Cop_proc_addr | varchar(64) | YES | | NULL | | +| Cop_wait_avg | double | YES | | NULL | | +| Cop_wait_p90 | double | YES | | NULL | | +| Cop_wait_max | double | YES | | NULL | | +| Cop_wait_addr | varchar(64) | YES | | NULL | | +| Mem_max | bigint(20) | YES | | NULL | | +| Disk_max | bigint(20) | YES | | NULL | | +| Succ | tinyint(1) | YES | | NULL | | +| Plan_from_cache | tinyint(1) | YES | | NULL | | +| Plan | longblob | YES | | NULL | | +| Plan_digest | varchar(128) | YES | | NULL | | +| Prev_stmt | longblob | YES | | NULL | | +| Query | longblob | YES | | NULL | | ++---------------------------+---------------------+------+------+---------+-------+ +54 rows in set (0.00 sec) +``` + +## CLUSTER_SLOW_QUERY table + +`CLUSTER_SLOW_QUERY` 表中提供了集群所有节点的慢查询相关的信息,其内容通过解析 TiDB 慢查询日志而来,该表使用上和 `SLOW_QUERY` 表一样。`CLUSTER_SLOW_QUERY` 表结构上比 `SLOW_QUERY` 多一列 `INSTANCE`,表示该行慢查询信息来自的 TiDB 节点地址。关于如何使用该表调查和改善慢查询,请参考[慢查询日志文档](/identify-slow-queries.md)。 + +{{< copyable "sql" >}} + +```sql +desc cluster_slow_query; +``` + +```sql ++---------------------------+---------------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------------------+---------------------+------+------+---------+-------+ +| INSTANCE | varchar(64) | YES | | NULL | | +| Time | timestamp(6) | YES | | NULL | | +| Txn_start_ts | bigint(20) unsigned | YES | | NULL | | +| User | varchar(64) | YES | | NULL | | +| Host | varchar(64) | YES | | NULL | | +| Conn_ID | bigint(20) unsigned | YES | | NULL | | +| Query_time | double | YES | | NULL | | +| Parse_time | double | YES | | NULL | | +| Compile_time | double | YES | | NULL | | +| Rewrite_time | double | YES | | NULL | | +| Preproc_subqueries | bigint(20) unsigned | YES | | NULL | | +| Preproc_subqueries_time | double | YES | | NULL | | +| Optimize_time | double | YES | | NULL | | +| Wait_TS | double | YES | | NULL | | +| Prewrite_time | double | YES | | NULL | | +| Wait_prewrite_binlog_time | double | YES | | NULL | | +| Commit_time | double | YES | | NULL | | +| Get_commit_ts_time | double | YES | | NULL | | +| Commit_backoff_time | double | YES | | NULL | | +| Backoff_types | varchar(64) | YES | | NULL | | +| Resolve_lock_time | double | YES | | NULL | | +| Local_latch_wait_time | double | YES | | NULL | | +| Write_keys | bigint(22) | YES | | NULL | | +| Write_size | bigint(22) | YES | | NULL | | +| Prewrite_region | bigint(22) | YES | | NULL | | +| Txn_retry | bigint(22) | YES | | NULL | | +| Cop_time | double | YES | | NULL | | +| Process_time | double | YES | | NULL | | +| Wait_time | double | YES | | NULL | | +| Backoff_time | double | YES | | NULL | | +| LockKeys_time | double | YES | | NULL | | +| Request_count | bigint(20) unsigned | YES | | NULL | | +| Total_keys | bigint(20) unsigned | YES | | NULL | | +| Process_keys | bigint(20) unsigned | YES | | NULL | | +| DB | varchar(64) | YES | | NULL | | +| Index_names | varchar(100) | YES | | NULL | | +| Is_internal | tinyint(1) | YES | | NULL | | +| Digest | varchar(64) | YES | | NULL | | +| Stats | varchar(512) | YES | | NULL | | +| Cop_proc_avg | double | YES | | NULL | | +| Cop_proc_p90 | double | YES | | NULL | | +| Cop_proc_max | double | YES | | NULL | | +| Cop_proc_addr | varchar(64) | YES | | NULL | | +| Cop_wait_avg | double | YES | | NULL | | +| Cop_wait_p90 | double | YES | | NULL | | +| Cop_wait_max | double | YES | | NULL | | +| Cop_wait_addr | varchar(64) | YES | | NULL | | +| Mem_max | bigint(20) | YES | | NULL | | +| Disk_max | bigint(20) | YES | | NULL | | +| Succ | tinyint(1) | YES | | NULL | | +| Plan_from_cache | tinyint(1) | YES | | NULL | | +| Plan | longblob | YES | | NULL | | +| Plan_digest | varchar(128) | YES | | NULL | | +| Prev_stmt | longblob | YES | | NULL | | +| Query | longblob | YES | | NULL | | ++---------------------------+---------------------+------+------+---------+-------+ +55 rows in set (0.00 sec) +``` + +查询集群系统表时,TiDB 也会将相关计算下推给其他节点执行,而不是把所有节点的数据都取回来,可以查看执行计划,如下: + +{{< copyable "sql" >}} + +```sql +desc SELECT count(*) FROM cluster_slow_query WHERE user = 'u1'; +``` + +``` ++--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ +| id | estRows | task | access object | operator info | ++--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ +| StreamAgg_20 | 1.00 | root | | funcs:count(Column#53)->Column#51 | +| └─TableReader_21 | 1.00 | root | | data:StreamAgg_9 | +| └─StreamAgg_9 | 1.00 | cop[tidb] | | funcs:count(1)->Column#53 | +| └─Selection_19 | 10.00 | cop[tidb] | | eq(information_schema.cluster_slow_query.user, "u1") | +| └─TableFullScan_18 | 10000.00 | cop[tidb] | table:CLUSTER_SLOW_QUERY | keep order:false, stats:pseudo | ++--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ +``` + +上面执行计划表示,会将 `user = u1` 条件下推给其他的 (`cop`) TiDB 节点执行,也会把聚合算子(即图中的 `StreamAgg` 算子)下推。 + +目前由于没有对系统表收集统计信息,所以有时会导致某些聚合算子不能下推,导致执行较慢,用户可以通过手动指定聚合下推的 SQL HINT 来将聚合算子下推,示例如下: + +{{< copyable "sql" >}} + +```sql +SELECT /*+ AGG_TO_COP() */ count(*) FROM cluster_slow_query GROUP BY user; +``` diff --git a/information-schema/information-schema-statistics.md b/information-schema/information-schema-statistics.md new file mode 100644 index 000000000000..e1eb697058b8 --- /dev/null +++ b/information-schema/information-schema-statistics.md @@ -0,0 +1,53 @@ +--- +title: STATISTICS +summary: 了解 information_schema 表 `STATISTICS`。 +--- + +# STATISTICS + +`STATISTICS` 表提供了关于表索引的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC statistics; +``` + +```sql ++---------------+---------------+------+------+---------+-------+ +| 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 | | ++---------------+---------------+------+------+---------+-------+ +18 rows in set (0.00 sec) +``` + +下列语句是等价的: + +```sql +SELECT * FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'tbl_name' + AND table_schema = 'db_name' + +SHOW INDEX + FROM tbl_name + FROM db_name +``` diff --git a/information-schema/information-schema-tables.md b/information-schema/information-schema-tables.md new file mode 100644 index 000000000000..ff7ac01c5887 --- /dev/null +++ b/information-schema/information-schema-tables.md @@ -0,0 +1,126 @@ +--- +title: TABLES +summary: 了解 information_schema 表 `TABLES`。 +--- + +# TABLES + +`TABLES` 表提供了数据库里关于表的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tables; +``` + +```sql ++---------------------------+---------------+------+------+----------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------------------+---------------+------+------+----------+-------+ +| TABLE_CATALOG | varchar(512) | YES | | NULL | | +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| TABLE_TYPE | varchar(64) | YES | | NULL | | +| ENGINE | varchar(64) | YES | | NULL | | +| VERSION | bigint(21) | YES | | NULL | | +| ROW_FORMAT | varchar(10) | YES | | NULL | | +| TABLE_ROWS | bigint(21) | YES | | NULL | | +| AVG_ROW_LENGTH | bigint(21) | YES | | NULL | | +| DATA_LENGTH | bigint(21) | YES | | NULL | | +| MAX_DATA_LENGTH | bigint(21) | YES | | NULL | | +| INDEX_LENGTH | bigint(21) | YES | | NULL | | +| DATA_FREE | bigint(21) | YES | | NULL | | +| AUTO_INCREMENT | bigint(21) | YES | | NULL | | +| CREATE_TIME | datetime | YES | | NULL | | +| UPDATE_TIME | datetime | YES | | NULL | | +| CHECK_TIME | datetime | YES | | NULL | | +| TABLE_COLLATION | varchar(32) | NO | | utf8_bin | | +| CHECKSUM | bigint(21) | YES | | NULL | | +| CREATE_OPTIONS | varchar(255) | YES | | NULL | | +| TABLE_COMMENT | varchar(2048) | YES | | NULL | | +| TIDB_TABLE_ID | bigint(21) | YES | | NULL | | +| TIDB_ROW_ID_SHARDING_INFO | varchar(255) | YES | | NULL | | ++---------------------------+---------------+------+------+----------+-------+ +23 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM tables WHERE table_schema='mysql' AND table_name='user'\G +``` + +```sql +*************************** 1. row *************************** + TABLE_CATALOG: def + TABLE_SCHEMA: mysql + TABLE_NAME: user + TABLE_TYPE: BASE TABLE + ENGINE: InnoDB + VERSION: 10 + ROW_FORMAT: Compact + TABLE_ROWS: 0 + AVG_ROW_LENGTH: 0 + DATA_LENGTH: 0 + MAX_DATA_LENGTH: 0 + INDEX_LENGTH: 0 + DATA_FREE: 0 + AUTO_INCREMENT: NULL + CREATE_TIME: 2020-07-05 09:25:51 + UPDATE_TIME: NULL + CHECK_TIME: NULL + TABLE_COLLATION: utf8mb4_bin + CHECKSUM: NULL + CREATE_OPTIONS: + TABLE_COMMENT: + TIDB_TABLE_ID: 5 +TIDB_ROW_ID_SHARDING_INFO: NULL +1 row in set (0.00 sec) +``` + +下列语句是等价的: + +```sql +SELECT table_name FROM INFORMATION_SCHEMA.TABLES + WHERE table_schema = 'db_name' + [AND table_name LIKE 'wild'] + +SHOW TABLES + FROM db_name + [LIKE 'wild'] +``` + +`TABLES` 表各列字段含义如下: + +* `TABLE_CATALOG`:表所属的目录的名称。该值始终为 `def`。 +* `TABLE_SCHEMA`:表所属数据库的名称。 +* `TABLE_NAME`:表的名称。 +* `TABLE_TYPE`:表的类型。 +* `ENGINE`:存储引擎类型。该值暂为 ‘InnoDB’。 +* `VERSION`:版本,默认值为 10。 +* `ROW_FORMAT`:行格式。该值暂为 ‘Compact’。 +* `TABLE_ROWS`:统计信息中该表所存的行数。 +* `AVG_ROW_LENGTH`:该表中所存数据的平均行长度。平均行长度 = DATA_LENGTH / 统计信息中的行数。 +* `DATA_LENGTH`:数据长度。数据长度 = 统计信息中的行数 × 元组各列存储长度和,这里尚未考虑 TiKV 的副本数。 +* `MAX_DATA_LENGTH`:最大数据长度。该值暂为 0,表示没有最大数据长度的限制。 +* `INDEX_LENGTH`:索引长度。索引长度 = 统计信息中的行数 × 索引元组各列长度和,这里尚未考虑 TiKV 的副本数。 +* `DATA_FREE`:空间碎片。该值暂为 0。 +* `AUTO_INCREMENT`:该表中自增主键自动增量的当前值。 +* `CREATE_TIME`:该表的创建时间。 +* `UPDATE_TIME`:该表的更新时间。 +* `CHECK_TIME`:该表的检查时间。 +* `TABLE_COLLATION`:该表的字符校验编码集。 +* `CHECKSUM`:校验和。 +* `CREATE_OPTIONS`:创建选项。 +* `TABLE_COMMENT`:表的注释、备注。 + +表中的信息大部分定义自 MySQL,只有两列是 TiDB 新增的: + +* `TIDB_TABLE_ID`:标识表的内部 ID,该 ID 在一个 TiDB 集群内部唯一。 +* `TIDB_ROW_ID_SHARDING_INFO`:标识表的 Sharding 类型,可能的值为: + - `"NOT_SHARDED"`:表未被 Shard。 + - `"NOT_SHARDED(PK_IS_HANDLE)"`:一个定义了整型主键的表未被 Shard。 + - `"PK_AUTO_RANDOM_BITS={bit_number}"`:一个定义了整型主键的表由于定义了 `AUTO_RANDOM` 而被 Shard。 + - `"SHARD_BITS={bit_number}"`:表使用 `SHARD_ROW_ID_BITS={bit_number}` 进行了 Shard。 + - NULL:表属于系统表或 View,无法被 Shard。 diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 35bf3fa3bac1..db0d119223c3 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -81,372 +81,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 | [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | | [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | -## SCHEMATA 表 - -`SCHEMATA` 表提供了关于数据库的信息。表中的数据与 `SHOW DATABASES` 语句的执行结果等价。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM schemata; -``` - -```sql -+--------------+--------------------+----------------------------+------------------------+----------+ -| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | -+--------------+--------------------+----------------------------+------------------------+----------+ -| def | INFORMATION_SCHEMA | utf8mb4 | utf8mb4_bin | NULL | -| def | mynewdb | utf8mb4 | utf8mb4_bin | NULL | -| def | mysql | utf8mb4 | utf8mb4_bin | NULL | -| def | PERFORMANCE_SCHEMA | utf8mb4 | utf8mb4_bin | NULL | -| def | test | utf8mb4 | utf8mb4_bin | NULL | -+--------------+--------------------+----------------------------+------------------------+----------+ -5 rows in set (0.00 sec) -``` - -`SCHEMATA` 表各列字段含义如下: - -* CATALOG_NAME:数据库归属的目录名,该列值永远为 `def`。 -* SCHEMA_NAME:数据库的名字。 -* DEFAULT_CHARACTER_SET_NAME:数据库的默认字符集。 -* DEFAULT_COLLATION_NAME:数据库的默认 collation。 -* SQL_PATH:该项值永远为 `NULL`。 - -## SESSION_VARIABLES 表 - -`SESSION_VARIABLES` 表提供了关于 session 变量的信息。表中的数据跟 `SHOW SESSION VARIABLES` 语句执行结果类似。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM session_variables LIMIT 10; -``` - -```sql -+----------------------------------+----------------------+ -| VARIABLE_NAME | VARIABLE_VALUE | -+----------------------------------+----------------------+ -| max_write_lock_count | 18446744073709551615 | -| server_id_bits | 32 | -| net_read_timeout | 30 | -| innodb_online_alter_log_max_size | 134217728 | -| innodb_optimize_fulltext_only | OFF | -| max_join_size | 18446744073709551615 | -| innodb_read_io_threads | 4 | -| session_track_gtids | OFF | -| have_ssl | DISABLED | -| max_binlog_cache_size | 18446744073709547520 | -+----------------------------------+----------------------+ -10 rows in set (0.00 sec) -``` - -`SESSION_VARIABLES` 表各列字段含义如下: - -* `VARIABLE_NAME`:数据库中 session 级变量的名称。 -* `VARIABLE_VALUE`:数据库中对应该 session 变量名的具体值。 - -## SLOW_QUERY 表 - -`SLOW_QUERY` 表中提供了当前节点的慢查询相关的信息,其内容通过解析当前节点的 TiDB 慢查询日志而来,列名和慢日志中的字段名是一一对应。关于如何使用该表调查和改善慢查询请参考[慢查询日志文档](/identify-slow-queries.md)。 - -{{< copyable "sql" >}} - -```sql -desc information_schema.slow_query; -``` - -```sql -+---------------------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+---------------------------+---------------------+------+-----+---------+-------+ -| Time | timestamp unsigned | YES | | | | -| Txn_start_ts | bigint(20) unsigned | YES | | | | -| User | varchar(64) | YES | | | | -| Host | varchar(64) | YES | | | | -| Conn_ID | bigint(20) unsigned | YES | | | | -| Query_time | double unsigned | YES | | | | -| Parse_time | double unsigned | YES | | | | -| Compile_time | double unsigned | YES | | | | -| Prewrite_time | double unsigned | YES | | | | -| Wait_prewrite_binlog_time | double unsigned | YES | | | | -| Commit_time | double unsigned | YES | | | | -| Get_commit_ts_time | double unsigned | YES | | | | -| Commit_backoff_time | double unsigned | YES | | | | -| Backoff_types | varchar(64) | YES | | | | -| Resolve_lock_time | double unsigned | YES | | | | -| Local_latch_wait_time | double unsigned | YES | | | | -| Write_keys | bigint(22) unsigned | YES | | | | -| Write_size | bigint(22) unsigned | YES | | | | -| Prewrite_region | bigint(22) unsigned | YES | | | | -| Txn_retry | bigint(22) unsigned | YES | | | | -| Process_time | double unsigned | YES | | | | -| Wait_time | double unsigned | YES | | | | -| Backoff_time | double unsigned | YES | | | | -| LockKeys_time | double unsigned | YES | | | | -| Request_count | bigint(20) unsigned | YES | | | | -| Total_keys | bigint(20) unsigned | YES | | | | -| Process_keys | bigint(20) unsigned | YES | | | | -| DB | varchar(64) | YES | | | | -| Index_names | varchar(100) | YES | | | | -| Is_internal | tinyint(1) unsigned | YES | | | | -| Digest | varchar(64) | YES | | | | -| Stats | varchar(512) | YES | | | | -| Cop_proc_avg | double unsigned | YES | | | | -| Cop_proc_p90 | double unsigned | YES | | | | -| Cop_proc_max | double unsigned | YES | | | | -| Cop_proc_addr | varchar(64) | YES | | | | -| Cop_wait_avg | double unsigned | YES | | | | -| Cop_wait_p90 | double unsigned | YES | | | | -| Cop_wait_max | double unsigned | YES | | | | -| Cop_wait_addr | varchar(64) | YES | | | | -| Mem_max | bigint(20) unsigned | YES | | | | -| Succ | tinyint(1) unsigned | YES | | | | -| Plan_from_cache | tinyint(1) | YES | | | | -| Plan | longblob unsigned | YES | | | | -| Plan_digest | varchar(128) | YES | | | | -| Prev_stmt | longblob unsigned | YES | | | | -| Query | longblob unsigned | YES | | | | -+---------------------------+---------------------+------+-----+---------+-------+ -``` - -## CLUSTER_SLOW_QUERY 表 - -`CLUSTER_SLOW_QUERY` 表中提供了集群所有节点的慢查询相关的信息,其内容通过解析 TiDB 慢查询日志而来,该表使用上和 [`SLOW_QUERY`](#slow_query-表) 一样,表结构上比 `SLOW_QUERY` 多一列 `INSTANCE`,表示该行慢查询信息来自的 TiDB 节点地址。关于如何使用该表调查和改善慢查询请参考[慢查询日志文档](/identify-slow-queries.md)。 - -{{< copyable "sql" >}} - -```sql -desc information_schema.cluster_slow_query; -``` - -```sql -+---------------------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+---------------------------+---------------------+------+-----+---------+-------+ -| INSTANCE | varchar(64) | YES | | | | -| Time | timestamp unsigned | YES | | | | -| Txn_start_ts | bigint(20) unsigned | YES | | | | -| User | varchar(64) | YES | | | | -| Host | varchar(64) | YES | | | | -| Conn_ID | bigint(20) unsigned | YES | | | | -| Query_time | double unsigned | YES | | | | -| Parse_time | double unsigned | YES | | | | -| Compile_time | double unsigned | YES | | | | -| Prewrite_time | double unsigned | YES | | | | -| Wait_prewrite_binlog_time | double unsigned | YES | | | | -| Commit_time | double unsigned | YES | | | | -| Get_commit_ts_time | double unsigned | YES | | | | -| Commit_backoff_time | double unsigned | YES | | | | -| Backoff_types | varchar(64) | YES | | | | -| Resolve_lock_time | double unsigned | YES | | | | -| Local_latch_wait_time | double unsigned | YES | | | | -| Write_keys | bigint(22) unsigned | YES | | | | -| Write_size | bigint(22) unsigned | YES | | | | -| Prewrite_region | bigint(22) unsigned | YES | | | | -| Txn_retry | bigint(22) unsigned | YES | | | | -| Process_time | double unsigned | YES | | | | -| Wait_time | double unsigned | YES | | | | -| Backoff_time | double unsigned | YES | | | | -| LockKeys_time | double unsigned | YES | | | | -| Request_count | bigint(20) unsigned | YES | | | | -| Total_keys | bigint(20) unsigned | YES | | | | -| Process_keys | bigint(20) unsigned | YES | | | | -| DB | varchar(64) | YES | | | | -| Index_names | varchar(100) | YES | | | | -| Is_internal | tinyint(1) unsigned | YES | | | | -| Digest | varchar(64) | YES | | | | -| Stats | varchar(512) | YES | | | | -| Cop_proc_avg | double unsigned | YES | | | | -| Cop_proc_p90 | double unsigned | YES | | | | -| Cop_proc_max | double unsigned | YES | | | | -| Cop_proc_addr | varchar(64) | YES | | | | -| Cop_wait_avg | double unsigned | YES | | | | -| Cop_wait_p90 | double unsigned | YES | | | | -| Cop_wait_max | double unsigned | YES | | | | -| Cop_wait_addr | varchar(64) | YES | | | | -| Mem_max | bigint(20) unsigned | YES | | | | -| Succ | tinyint(1) unsigned | YES | | | | -| Plan_from_cache | tinyint(1) | YES | | | | -| Plan | longblob unsigned | YES | | | | -| Plan_digest | varchar(128) | YES | | | | -| Prev_stmt | longblob unsigned | YES | | | | -| Query | longblob unsigned | YES | | | | -+---------------------------+---------------------+------+-----+---------+-------+ -``` - -查询集群系统表时,TiDB 也会将相关计算下推给其他节点执行,而不是把所有节点的数据都取回来,可以查看执行计划如下: - -{{< copyable "sql" >}} - -```sql -desc select count(*) from information_schema.cluster_slow_query where user = 'u1'; -``` - -```sql -+--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ -| id | estRows | task | access object | operator info | -+--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ -| StreamAgg_20 | 1.00 | root | | funcs:count(Column#53)->Column#51 | -| └─TableReader_21 | 1.00 | root | | data:StreamAgg_9 | -| └─StreamAgg_9 | 1.00 | cop[tidb] | | funcs:count(1)->Column#53 | -| └─Selection_19 | 10.00 | cop[tidb] | | eq(information_schema.cluster_slow_query.user, "u1") | -| └─TableFullScan_18 | 10000.00 | cop[tidb] | table:CLUSTER_SLOW_QUERY | keep order:false, stats:pseudo | -+--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ -``` - -上面执行计划表示,会将 `user = u1` 条件下推给其他的 (`cop`) TiDB 节点执行,也会把聚合算子下推(即图中的 `StreamAgg` 算子)。 - -目前由于没有对系统表收集统计信息,所以有时会导致某些聚合算子不能下推,导致执行较慢,用户可以通过手动指定聚合下推的 SQL HINT 来将聚合算子下推,示例如下: - -{{< copyable "sql" >}} - -```sql -select /*+ AGG_TO_COP() */ count(*) from information_schema.cluster_slow_query group by user; -``` - -## STATISTICS 表 - -`STATISTICS` 表提供了关于表索引的信息。 - -{{< copyable "sql" >}} - -```sql -desc statistics; -``` - -```sql -+---------------+---------------+------+------+---------+-------+ -| 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 | | -+---------------+---------------+------+------+---------+-------+ -``` - -下列语句是等价的: - -{{< copyable "sql" >}} - -```sql -SELECT * FROM INFORMATION_SCHEMA.STATISTICS - WHERE table_name = 'tbl_name' - AND table_schema = 'db_name' -``` - -{{< copyable "sql" >}} - -```sql -SHOW INDEX - FROM tbl_name - FROM db_name -``` - -## TABLES 表 - -`TABLES` 表提供了数据库里面关于表的信息。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM tables WHERE table_schema='mysql' AND table_name='user'; -``` - -``` -*************************** 1. row *************************** - TABLE_CATALOG: def - TABLE_SCHEMA: mysql - TABLE_NAME: user - TABLE_TYPE: BASE TABLE - ENGINE: InnoDB - VERSION: 10 - ROW_FORMAT: Compact - TABLE_ROWS: 0 - AVG_ROW_LENGTH: 0 - DATA_LENGTH: 0 - MAX_DATA_LENGTH: 0 - INDEX_LENGTH: 0 - DATA_FREE: 0 - AUTO_INCREMENT: 0 - CREATE_TIME: 2019-03-29 09:17:27 - UPDATE_TIME: NULL - CHECK_TIME: NULL - TABLE_COLLATION: utf8mb4_bin - CHECKSUM: NULL - CREATE_OPTIONS: - TABLE_COMMENT: - TIDB_TABLE_ID: 5 -TIDB_ROW_ID_SHARDING_INFO: NULL -1 row in set (0.00 sec) -``` - -以下操作是等价的: - -{{< copyable "sql" >}} - -```sql -SELECT table_name FROM INFORMATION_SCHEMA.TABLES - WHERE table_schema = 'db_name' - [AND table_name LIKE 'wild'] -``` - -{{< copyable "sql" >}} - -```sql -SHOW TABLES - FROM db_name - [LIKE 'wild'] -``` - -`TABLES` 表各列字段含义如下: - -* `TABLE_CATALOG`:表所属的目录的名称。该值始终为 `def`。 -* `TABLE_SCHEMA`:表所属数据库的名称。 -* `TABLE_NAME`:表的名称。 -* `TABLE_TYPE`:表的类型。 -* `ENGINE`:存储引擎类型。该值暂为 ‘InnoDB’。 -* `VERSION`:版本,默认值为 10。 -* `ROW_FORMAT`:行格式。该值暂为 ‘Compact’。 -* `TABLE_ROWS`:统计信息中该表所存的行数。 -* `AVG_ROW_LENGTH`:该表中所存数据的平均行长度。平均行长度 = DATA_LENGTH / 统计信息中的行数。 -* `DATA_LENGTH`:数据长度。数据长度 = 统计信息中的行数 × 元组各列存储长度和,这里尚未考虑 TiKV 的副本数。 -* `MAX_DATA_LENGTH`:最大数据长度。该值暂为 0,表示没有最大数据长度的限制。 -* `INDEX_LENGTH`:索引长度。索引长度 = 统计信息中的行数 × 索引元组各列长度和,这里尚未考虑 TiKV 的副本数。 -* `DATA_FREE`:空间碎片。该值暂为 0。 -* `AUTO_INCREMENT`:该表中自增主键自动增量的当前值。 -* `CREATE_TIME`:该表的创建时间。 -* `UPDATE_TIME`:该表的更新时间。 -* `CHECK_TIME`:该表的检查时间。 -* `TABLE_COLLATION`:该表的字符校验编码集。 -* `CHECKSUM`:校验和。 -* `CREATE_OPTIONS`:创建选项。 -* `TABLE_COMMENT`:表的注释、备注。 - -表中的信息大部分定义自 MySQL,此外有两列是 TiDB 新增的: - -* `TIDB_TABLE_ID`:标识表的内部 ID,该 ID 在一个 TiDB 集群内部唯一。 -* `TIDB_ROW_ID_SHARDING_INFO`:标识表的 Sharding 类型,可能的值为: - - `"NOT_SHARDED"`:表未被 Shard。 - - `"NOT_SHARDED(PK_IS_HANDLE)"`:一个定义了整型主键的表未被 Shard。 - - `"PK_AUTO_RANDOM_BITS={bit_number}"`:一个定义了整型主键的表由于定义了 `AUTO_RANDOM` 而被 Shard。 - - `"SHARD_BITS={bit_number}"`:表使用 `SHARD_ROW_ID_BITS={bit_number}` 进行了 Shard。 - - NULL:表属于系统表或 View,无法被 Shard。 - ## TABLE_CONSTRAINTS 表 `TABLE_CONSTRAINTS` 表记录了表的约束信息。 From a9112d9af59ed995d061b86a606cfe36002c8cf4 Mon Sep 17 00:00:00 2001 From: yikeke Date: Wed, 29 Jul 2020 19:23:36 +0800 Subject: [PATCH 04/28] add 5 files --- .../information-schema-table-constraints.md | 55 +++++ .../information-schema-tidb-hot-regions.md | 46 ++++ .../information-schema-tidb-indexes.md | 62 +++++ .../information-schema-tikv-region-peers.md | 60 +++++ .../information-schema-tikv-region-status.md | 68 ++++++ information-schema/information-schema.md | 227 ------------------ 6 files changed, 291 insertions(+), 227 deletions(-) create mode 100644 information-schema/information-schema-table-constraints.md create mode 100644 information-schema/information-schema-tidb-hot-regions.md create mode 100644 information-schema/information-schema-tidb-indexes.md create mode 100644 information-schema/information-schema-tikv-region-peers.md create mode 100644 information-schema/information-schema-tikv-region-status.md diff --git a/information-schema/information-schema-table-constraints.md b/information-schema/information-schema-table-constraints.md new file mode 100644 index 000000000000..86c292eecd79 --- /dev/null +++ b/information-schema/information-schema-table-constraints.md @@ -0,0 +1,55 @@ +--- +title: TABLE_CONSTRAINTS +summary: 了解 information_schema 表 `TABLE_CONSTRAINTS`。 +--- + +# TABLE_CONSTRAINTS + +`TABLE_CONSTRAINTS` 表记录了表的约束信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC table_constraints; +``` + +```sql ++--------------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+--------------+------+------+---------+-------+ +| CONSTRAINT_CATALOG | varchar(512) | YES | | NULL | | +| CONSTRAINT_SCHEMA | varchar(64) | YES | | NULL | | +| CONSTRAINT_NAME | varchar(64) | YES | | NULL | | +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| CONSTRAINT_TYPE | varchar(64) | YES | | NULL | | ++--------------------+--------------+------+------+---------+-------+ +6 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM table_constraints WHERE constraint_type='UNIQUE'; +``` + +```sql ++--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+ +| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_SCHEMA | TABLE_NAME | CONSTRAINT_TYPE | ++--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+ +| def | mysql | name | mysql | help_topic | UNIQUE | +| def | mysql | tbl | mysql | stats_meta | UNIQUE | +| def | mysql | tbl | mysql | stats_histograms | UNIQUE | +| def | mysql | tbl | mysql | stats_buckets | UNIQUE | +| def | mysql | delete_range_index | mysql | gc_delete_range | UNIQUE | +| def | mysql | delete_range_done_index | mysql | gc_delete_range_done | UNIQUE | +| def | PERFORMANCE_SCHEMA | SCHEMA_NAME | PERFORMANCE_SCHEMA | events_statements_summary_by_digest | UNIQUE | ++--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+ +7 rows in set (0.01 sec) +``` + +其中: + +* `CONSTRAINT_TYPE` 的取值可以是 `UNIQUE`,`PRIMARY KEY`,或者 `FOREIGN KEY`。 +* `UNIQUE` 和 `PRIMARY KEY` 信息与 `SHOW INDEX` 语句的执行结果类似。 diff --git a/information-schema/information-schema-tidb-hot-regions.md b/information-schema/information-schema-tidb-hot-regions.md new file mode 100644 index 000000000000..344da17c36ca --- /dev/null +++ b/information-schema/information-schema-tidb-hot-regions.md @@ -0,0 +1,46 @@ +--- +title: TIDB_HOT_REGIONS +summary: 了解 information_schema 表 `TIDB_HOT_REGIONS`。 +--- + +# TIDB_HOT_REGIONS + +`TIDB_HOT_REGIONS` 表提供了关于热点 Region 的相关信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tidb_hot_regions; +``` + +```sql ++----------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------+-------------+------+------+---------+-------+ +| TABLE_ID | bigint(21) | YES | | NULL | | +| INDEX_ID | bigint(21) | YES | | NULL | | +| DB_NAME | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| INDEX_NAME | varchar(64) | YES | | NULL | | +| REGION_ID | bigint(21) | YES | | NULL | | +| TYPE | varchar(64) | YES | | NULL | | +| MAX_HOT_DEGREE | bigint(21) | YES | | NULL | | +| REGION_COUNT | bigint(21) | YES | | NULL | | +| FLOW_BYTES | bigint(21) | YES | | NULL | | ++----------------+-------------+------+------+---------+-------+ +10 rows in set (0.00 sec) +``` + +`TIDB_HOT_REGIONS` 表各列字段含义如下: + +* TABLE_ID:热点 Region 所在表的 ID。 +* INDEX_ID:热点 Region 所在索引的 ID。 +* DB_NAME:热点 Region 所在数据库对象的数据库名。 +* TABLE_NAME:热点 Region 所在表的名称。 +* INDEX_NAME:热点 Region 所在索引的名称。 +* REGION_ID:热点 Region 的 ID。 +* TYPE:热点 Region 的类型。 +* MAX_HOT_DEGREE:该 Region 的最大热度。 +* REGION_COUNT:所在实例的 Region 数量。 +* FLOW_BYTES:该 Region 内读写的字节数量。 diff --git a/information-schema/information-schema-tidb-indexes.md b/information-schema/information-schema-tidb-indexes.md new file mode 100644 index 000000000000..fc4a7e23535c --- /dev/null +++ b/information-schema/information-schema-tidb-indexes.md @@ -0,0 +1,62 @@ +--- +title: TIDB_INDEXES +summary: 了解 information_schema 表 `TIDB_INDEXES`。 +--- + +# TIDB_INDEXES + +`TIDB_INDEXES` 记录了所有表中的 INDEX 信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tidb_indexes; +``` + +```sql ++---------------+---------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------+---------------+------+------+---------+-------+ +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| NON_UNIQUE | bigint(21) | YES | | NULL | | +| KEY_NAME | varchar(64) | YES | | NULL | | +| SEQ_IN_INDEX | bigint(21) | YES | | NULL | | +| COLUMN_NAME | varchar(64) | YES | | NULL | | +| SUB_PART | bigint(21) | YES | | NULL | | +| INDEX_COMMENT | varchar(2048) | YES | | NULL | | +| Expression | varchar(64) | YES | | NULL | | +| INDEX_ID | bigint(21) | YES | | NULL | | ++---------------+---------------+------+------+---------+-------+ +10 rows in set (0.00 sec) +``` + +`INDEX_ID` 是 TiDB 为每个索引分配的唯一 ID。它可以与从另一个表或 API 获得的 `INDEX_ID` 一起执行 `join` 操作。 + +例如,你可以在 [`SLOW_QUERY` 表](/information-schema/information-schema-slow-query.md) 中获取某些慢查询所涉及的 `TABLE_ID` 和 `INDEX_ID`,然后使用以下 SQL 语句获取特定索引信息: + +```sql +SELECT + tidb_indexes.* +FROM + tidb_indexes, + tables +WHERE + tidb_indexes.table_schema = tables.table_schema + AND tidb_indexes.table_name = tidb_indexes.table_name + AND tables.tidb_table_id = ? + AND index_id = ? +``` + +`TIDB_INDEXES` 表中列的含义如下: + +* `TABLE_SCHEMA`:索引所在表的所属数据库的名称。 +* `TABLE_NAME`:索引所在表的名称。 +* `NON_UNIQUE`:如果索引是唯一的,则为 `0`,否则为 `1`。 +* `KEY_NAME`:索引的名称。如果索引是主键,则名称为 `PRIMARY`。 +* `SEQ_IN_INDEX`:索引中列的顺序编号,从 `1` 开始。 +* `COLUMN_NAME`:索引所在的列名。 +* `SUB_PART`:索引前缀长度。如果列是部分被索引,则该值为被索引的字符数量,否则为 `NULL`。 +* `INDEX_COMMENT`:创建索引时以 `COMMENT` 标注的注释。 +* `INDEX_ID`:索引的 ID。 diff --git a/information-schema/information-schema-tikv-region-peers.md b/information-schema/information-schema-tikv-region-peers.md new file mode 100644 index 000000000000..487086413d75 --- /dev/null +++ b/information-schema/information-schema-tikv-region-peers.md @@ -0,0 +1,60 @@ +--- +title: TIKV_REGION_PEERS +summary: 了解 information_schema 表 `TIKV_REGION_PEERS`。 +--- + +# TIKV_REGION_PEERS + +`TIKV_REGION_PEERS` 表提供了 TiKV 中单个 Region 节点的详细信息,比如它是一个 learner 还是一个 leader。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tikv_region_peers; +``` + +```sql ++--------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------+-------------+------+------+---------+-------+ +| REGION_ID | bigint(21) | YES | | NULL | | +| PEER_ID | bigint(21) | YES | | NULL | | +| STORE_ID | bigint(21) | YES | | NULL | | +| IS_LEARNER | tinyint(1) | NO | | 0 | | +| IS_LEADER | tinyint(1) | NO | | 0 | | +| STATUS | varchar(10) | YES | | 0 | | +| DOWN_SECONDS | bigint(21) | YES | | 0 | | ++--------------+-------------+------+------+---------+-------+ +7 rows in set (0.01 sec) +``` + +例如,使用以下 SQL 语句,你可以查询 `WRITTEN_BYTES` 最大的前 3 个 Region 所在的 TiKV 地址: + +```sql +SELECT + address, + tikv.address, + region.region_id +FROM + tikv_store_status tikv, + tikv_region_peers peer, + (SELECT * FROM tikv_region_status ORDER BY written_bytes DESC LIMIT 3) region +WHERE + region.region_id = peer.region_id + AND peer.is_leader = 1 + AND peer.store_id = tikv.store_id; +``` + +`TIKV_REGION_PEERS` 表各列含义如下: + +* REGION_ID:REGION 的 ID。 +* PEER_ID:REGION 中对应的副本 PEER 的 ID。 +* STORE_ID:REGION 所在 TiKV Store 的 ID。 +* IS_LEARNER:PEER 是否是 LEARNER。 +* IS_LEADER:PEER 是否是 LEADER。 +* STATUS:PEER 的状态,一共有 3 种状态: + * PENDING:暂时不可用状态。 + * DOWN:下线转态,该 PEER 不再提供服务。 + * NORMAL: 正常状态。 +* DOWN_SECONDS:处于下线状态的时间,单位是秒。 diff --git a/information-schema/information-schema-tikv-region-status.md b/information-schema/information-schema-tikv-region-status.md new file mode 100644 index 000000000000..9a033bc03093 --- /dev/null +++ b/information-schema/information-schema-tikv-region-status.md @@ -0,0 +1,68 @@ +--- +title: TIKV_REGION_STATUS +summary: 了解 information_schema 表 `TIKV_REGION_STATUS`。 +--- + +# TIKV_REGION_STATUS + +`TIKV_REGION_STATUS` 表通过 PD 的 API 展示 TiKV Region 的基本信息,比如 Region ID、开始和结束键值以及读写流量。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tikv_region_status; +``` + +```sql ++---------------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------------------+-------------+------+------+---------+-------+ +| REGION_ID | bigint(21) | YES | | NULL | | +| START_KEY | text | YES | | NULL | | +| END_KEY | text | YES | | NULL | | +| TABLE_ID | bigint(21) | YES | | NULL | | +| DB_NAME | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| IS_INDEX | tinyint(1) | NO | | 0 | | +| INDEX_ID | bigint(21) | YES | | NULL | | +| INDEX_NAME | varchar(64) | YES | | NULL | | +| EPOCH_CONF_VER | bigint(21) | YES | | NULL | | +| EPOCH_VERSION | bigint(21) | YES | | NULL | | +| WRITTEN_BYTES | bigint(21) | YES | | NULL | | +| READ_BYTES | bigint(21) | YES | | NULL | | +| APPROXIMATE_SIZE | bigint(21) | YES | | NULL | | +| APPROXIMATE_KEYS | bigint(21) | YES | | NULL | | +| REPLICATIONSTATUS_STATE | varchar(64) | YES | | NULL | | +| REPLICATIONSTATUS_STATEID | bigint(21) | YES | | NULL | | ++---------------------------+-------------+------+------+---------+-------+ +17 rows in set (0.00 sec) +``` + +`TIKV_REGION_STATUS` 表中列的含义如下: + +* `REGION_ID`:Region 的 ID。 +* `START_KEY`:Region 的起始 key 的值。 +* `END_KEY`:Region 的末尾 key 的值。 +* `TABLE_ID`:Region 所属的表的 ID。 +* `DB_NAME`:`TABLE_ID` 所属的数据库的名称。 +* `TABLE_NAME`:Region 所属的表的名称。 +* `IS_INDEX`:Region 数据是否是索引,0 代表不是索引,1 代表是索引。如果当前 Region 同时包含表数据和索引数据,会有多行记录,`IS_INDEX` 分别是 0 和 1。 +* `INDEX_ID`:Region 所属的索引的 ID。如果 `IS_INDEX` 为 0,这一列的值就为 NULL。 +* `INDEX_NAME`:Region 所属的索引的名称。如果 `IS_INDEX` 为 0,这一列的值就为 NULL。 +* `EPOCH_CONF_VER`:Region 的配置的版本号,在增加或减少 peer 时版本号会递增。 +* `EPOCH_VERSION`:Region 的当前版本号,在分裂或合并时版本号会递增。 +* `WRITTEN_BYTES`:已经往 Region 写入的数据量 (bytes)。 +* `READ_BYTES`:已经从 Region 读取的数据量 (bytes)。 +* `APPROXIMATE_SIZE`:Region 的近似数据量 (MB)。 +* `APPROXIMATE_KEYS`:Region 中 key 的近似数量。 +* `REPLICATIONSTATUS_STATE`:Region 当前的同步状态,可能为 `UNKNOWN` / `SIMPLE_MAJORITY` / `INTEGRITY_OVER_LABEL` 其中一种状态。 +* `REPLICATIONSTATUS_STATEID`:`REPLICATIONSTATUS_STATE` 对应的标识符。 + +通过在 `EPOCH_CONF_VER`、`WRITTEN_BYTES` 和 `READ_BYTES` 列上执行 `ORDER BY X LIMIT Y` 操作,你可以在 pd-ctl 中实现 `top confver`、`top read` 和 `top write` 操作。 + +你可以使用以下 SQL 语句查询写入数据最多的前 3 个 Region: + +```sql +SELECT * FROM tikv_region_status ORDER BY written_bytes DESC LIMIT 3; +``` \ No newline at end of file diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index db0d119223c3..3accef2ddc43 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -81,233 +81,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 | [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | | [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | -## TABLE_CONSTRAINTS 表 - -`TABLE_CONSTRAINTS` 表记录了表的约束信息。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM table_constraints WHERE constraint_type='UNIQUE'; -``` - -``` -*************************** 1. row *************************** -CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: name - TABLE_SCHEMA: mysql - TABLE_NAME: help_topic - CONSTRAINT_TYPE: UNIQUE -*************************** 2. row *************************** -CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: tbl - TABLE_SCHEMA: mysql - TABLE_NAME: stats_meta - CONSTRAINT_TYPE: UNIQUE -*************************** 3. row *************************** -CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: tbl - TABLE_SCHEMA: mysql - TABLE_NAME: stats_histograms - CONSTRAINT_TYPE: UNIQUE -*************************** 4. row *************************** -CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: tbl - TABLE_SCHEMA: mysql - TABLE_NAME: stats_buckets - CONSTRAINT_TYPE: UNIQUE -*************************** 5. row *************************** -CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: delete_range_index - TABLE_SCHEMA: mysql - TABLE_NAME: gc_delete_range - CONSTRAINT_TYPE: UNIQUE -*************************** 6. row *************************** -CONSTRAINT_CATALOG: def - CONSTRAINT_SCHEMA: mysql - CONSTRAINT_NAME: delete_range_done_index - TABLE_SCHEMA: mysql - TABLE_NAME: gc_delete_range_done - CONSTRAINT_TYPE: UNIQUE -``` - -其中: - -* `CONSTRAINT_TYPE` 的取值可以是 `UNIQUE`,`PRIMARY KEY`,或者 `FOREIGN KEY`。 -* `UNIQUE` 和 `PRIMARY KEY` 信息与 `SHOW INDEX` 语句的执行结果类似。 - -## TIDB_HOT_REGIONS 表 - -`TIDB_HOT_REGIONS` 表提供了关于热点 REGION 的相关信息。 - -{{< copyable "sql" >}} - -```sql -desc TIDB_HOT_REGIONS; -``` - -```sql -+----------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+----------------+---------------------+------+-----+---------+-------+ -| TABLE_ID | bigint(21) unsigned | YES | | | | -| INDEX_ID | bigint(21) unsigned | YES | | | | -| DB_NAME | varchar(64) | YES | | | | -| TABLE_NAME | varchar(64) | YES | | | | -| INDEX_NAME | varchar(64) | YES | | | | -| TYPE | varchar(64) | YES | | | | -| MAX_HOT_DEGREE | bigint(21) unsigned | YES | | | | -| REGION_COUNT | bigint(21) unsigned | YES | | | | -| FLOW_BYTES | bigint(21) unsigned | YES | | | | -+----------------+---------------------+------+-----+---------+-------+ -``` - -`TIDB_HOT_REGIONS` 表各列字段含义如下: - -* TABLE_ID:热点 region 所在表的 ID。 -* INDEX_ID:热点 region 所在索引的 ID。 -* DB_NAME:热点 region 所在数据库对象的数据库名。 -* TABLE_NAME:热点 region 所在表的名称。 -* INDEX_NAME:热点 region 所在索引的名称。 -* REGION_ID:热点 region 的 ID。 -* TYPE:热点 region 的类型。 -* MAX_HOT_DEGREE:该 region 的最大热度。 -* REGION_COUNT:所在 instance 的 region 数量。 -* FLOW_BYTES:该 region 内读写的字节数量。 - -## TIDB_INDEXES 表 - -`TIDB_INDEXES` 记录了所有表中的 INDEX 信息。 - -{{< copyable "sql" >}} - -```sql -desc TIDB_INDEXES; -``` - -```sql -+---------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+---------------+---------------------+------+-----+---------+-------+ -| TABLE_SCHEMA | varchar(64) | YES | | | | -| TABLE_NAME | varchar(64) | YES | | | | -| NON_UNIQUE | bigint(21) unsigned | YES | | | | -| KEY_NAME | varchar(64) | YES | | | | -| SEQ_IN_INDEX | bigint(21) unsigned | YES | | | | -| COLUMN_NAME | varchar(64) | YES | | | | -| SUB_PART | bigint(21) unsigned | YES | | | | -| INDEX_COMMENT | varchar(2048) | YES | | | | -| INDEX_ID | bigint(21) unsigned | YES | | | | -+---------------+---------------------+------+-----+---------+-------+ -``` - -`TIDB_INDEXES` 表中列的含义如下: - -* `TABLE_SCHEMA`:索引所在表的所属数据库的名称。 -* `TABLE_NAME`:索引所在表的名称。 -* `NON_UNIQUE`:如果索引是唯一的,则为 `0`,否则为 `1`。 -* `KEY_NAME`:索引的名称。如果索引是主键,则名称为 `PRIMARY`。 -* `SEQ_IN_INDEX`:索引中列的顺序编号,从 `1` 开始。 -* `COLUMN_NAME`:索引所在的列名。 -* `SUB_PART`:索引前缀长度。如果列是部分被索引,则该值为被索引的字符数量,否则为 `NULL`。 -* `INDEX_COMMENT`:创建索引时以 `COMMENT` 标注的注释。 -* `INDEX_ID`:索引的 ID。 - -## TIKV_REGION_PEERS 表 - -`TIKV_REGION_PEERS` 表提供了所有 REGION 的 peer 信息。 - -{{< copyable "sql" >}} - -```sql -desc TIKV_REGION_PEERS; -``` - -```sql -+--------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+--------------+---------------------+------+-----+---------+-------+ -| REGION_ID | bigint(21) unsigned | YES | | | | -| PEER_ID | bigint(21) unsigned | YES | | | | -| STORE_ID | bigint(21) unsigned | YES | | | | -| IS_LEARNER | tinyint(1) unsigned | YES | | | | -| IS_LEADER | tinyint(1) unsigned | YES | | | | -| STATUS | varchar(10) | YES | | | | -| DOWN_SECONDS | bigint(21) unsigned | YES | | | | -+--------------+---------------------+------+-----+---------+-------+ -``` - -`TIKV_REGION_PEERS` 表各列含义如下: - -* REGION_ID:REGION 的 ID。 -* PEER_ID:REGION 中对应的副本 PEER 的 ID。 -* STORE_ID:REGION 所在 TiKV Store 的 ID。 -* IS_LEARNER:PEER 是否是 LEARNER。 -* IS_LEADER:PEER 是否是 LEADER。 -* STATUS:PEER 的状态,一共有 3 种状态: - * PENDING:暂时不可用状态。 - * DOWN:下线转态,该 PEER 不再提供服务。 - * NORMAL: 正常状态。 -* DOWN_SECONDS:处于下线状态的时间,单位是秒。 - -## TIKV_REGION_STATUS 表 - -`TIKV_REGION_STATUS` 表提供了所有 REGION 的状态信息。 - -{{< copyable "sql" >}} - -```sql -desc TIKV_REGION_STATUS; -``` - -```sql -+---------------------------+-------------+------+------+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+---------------------------+-------------+------+------+---------+-------+ -| REGION_ID | bigint(21) | YES | | NULL | | -| START_KEY | text | YES | | NULL | | -| END_KEY | text | YES | | NULL | | -| TABLE_ID | bigint(21) | YES | | NULL | | -| DB_NAME | varchar(64) | YES | | NULL | | -| TABLE_NAME | varchar(64) | YES | | NULL | | -| IS_INDEX | tinyint(1) | NO | | 0 | | -| INDEX_ID | bigint(21) | YES | | NULL | | -| INDEX_NAME | varchar(64) | YES | | NULL | | -| EPOCH_CONF_VER | bigint(21) | YES | | NULL | | -| EPOCH_VERSION | bigint(21) | YES | | NULL | | -| WRITTEN_BYTES | bigint(21) | YES | | NULL | | -| READ_BYTES | bigint(21) | YES | | NULL | | -| APPROXIMATE_SIZE | bigint(21) | YES | | NULL | | -| APPROXIMATE_KEYS | bigint(21) | YES | | NULL | | -| REPLICATIONSTATUS_STATE | varchar(64) | YES | | NULL | | -| REPLICATIONSTATUS_STATEID | bigint(21) | YES | | NULL | | -+---------------------------+-------------+------+------+---------+-------+ -``` - -`TIKV_REGION_STATUS` 表中列的含义如下: - -* `REGION_ID`:Region 的 ID。 -* `START_KEY`:Region 的起始 key 的值。 -* `END_KEY`:Region 的末尾 key 的值。 -* `TABLE_ID`:Region 所属的表的 ID。 -* `DB_NAME`:`TABLE_ID` 所属的数据库的名称。 -* `TABLE_NAME`:Region 所属的表的名称。 -* `IS_INDEX`:Region 数据是否是索引,0 代表不是索引,1 代表是索引。如果当前 Region 同时包含表数据和索引数据,会有多行记录,`IS_INDEX` 分别是 0 和 1。 -* `INDEX_ID`:Region 所属的索引的 ID。如果 `IS_INDEX` 为 0,这一列的值就为 NULL。 -* `INDEX_NAME`:Region 所属的索引的名称。如果 `IS_INDEX` 为 0,这一列的值就为 NULL。 -* `EPOCH_CONF_VER`:Region 的配置的版本号,在增加或减少 peer 时版本号会递增。 -* `EPOCH_VERSION`:Region 的当前版本号,在分裂或合并时版本号会递增。 -* `WRITTEN_BYTES`:已经往 Region 写入的数据量 (bytes)。 -* `READ_BYTES`:已经从 Region 读取的数据量 (bytes)。 -* `APPROXIMATE_SIZE`:Region 的近似数据量 (MB)。 -* `APPROXIMATE_KEYS`:Region 中 key 的近似数量。 -* `REPLICATIONSTATUS_STATE`:Region 当前的同步状态,可能为 `UNKNOWN` / `SIMPLE_MAJORITY` / `INTEGRITY_OVER_LABEL` 其中一种状态。 -* `REPLICATIONSTATUS_STATEID`:`REPLICATIONSTATUS_STATE` 对应的标识符。 ## TIKV_STORE_STATUS 表 From 80bfa736424d16e985c00028d1628e96660e9b00 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 14:48:55 +0800 Subject: [PATCH 05/28] add commits from https://github.com/pingcap/docs-cn/pull/3470/ --- .../information-schema-analyze-status.md | 12 +++++++++-- .../information-schema-statistics.md | 21 +++++++++++++++++++ .../information-schema-table-constraints.md | 9 +++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/information-schema/information-schema-analyze-status.md b/information-schema/information-schema-analyze-status.md index 3334fa6f49af..a148ffad3276 100644 --- a/information-schema/information-schema-analyze-status.md +++ b/information-schema/information-schema-analyze-status.md @@ -29,8 +29,6 @@ DESC analyze_status; 7 rows in set (0.00 sec) ``` -`STATE` 列表示特定 `ANALYZE` 任务的执行状态。其值可以是 `pending`、`running`、`finished` 或者 `failed`。 - {{< copyable "sql" >}} ```sql @@ -50,3 +48,13 @@ SELECT * FROM `ANALYZE_STATUS`; +--------------+------------+----------------+-------------------+----------------+---------------------+----------+ 6 rows in set ``` + +`ANALYZE_STATUS` 表中列的含义如下: + +* `TABLE_SCHEMA`:表所属的数据库的名称。 +* `TABLE_NAME`:表的名称。 +* `PARTITION_NAME`:分区表的名称。 +* `JOB_INFO`:ANALYZE` 任务的信息。 +* `PROCESSED_ROWS`:已经处理的行数。 +* `START_TIME`:`ANALYZE` 任务的开始时间。 +* `STATE`:`ANALYZE` 任务的执行状态。其值可以是 `pending`、`running`、`finished` 或者 `failed`。 diff --git a/information-schema/information-schema-statistics.md b/information-schema/information-schema-statistics.md index e1eb697058b8..c4d69bf9c45a 100644 --- a/information-schema/information-schema-statistics.md +++ b/information-schema/information-schema-statistics.md @@ -40,6 +40,27 @@ DESC statistics; 18 rows in set (0.00 sec) ``` +`STATISTICS` 表中列的含义如下: + +* `TABLE_CATALOG`:包含索引的表所属的目录的名称。这个值总是 `def`。 +* `TABLE_SCHEMA`:包含索引的表所属的数据库的名称。 +* `TABLE_NAME`:包含索引的表的名称。 +* `NON_UNIQUE`:如果索引不能包含重复项,则为 `0`;如果可以,则为 `1`。 +* `INDEX_SCHEMA`:索引所属的数据库的名称。 +* `INDEX_NAME`:索引的名称。如果索引是主键,那么名称总是 `PRIMARY`。 +* `SEQ_IN_INDEX`:索引中的列序号,从 `1` 开始。 +* `COLUMN_NAME`:列名。请参见表达式列的说明。 +* `COLLATION`:列在索引中的排序方式。取值可以是 `A`(升序)、`D`(降序)或 `NULL`(未排序)。 +* `CARDINALITY`:索引中唯一值的数量的估计。要更新这个数字,执行 `ANALYZE TABLE`。 +* `SUB_PART`:索引的前缀。如果只对列的部分前缀进行索引,则为索引字符的数量;如果对整个列进行索引,则为 `NULL`。 +* `PACKED`:TiDB 未使用该字段。这个值总是 `NULL`。 +* `NULLABLE`:如果列可能包含 `NULL` 值,则值为 `YES`;如果不包含,则值为 `''`。 +* `INDEX_TYPE`:索引的类型。 +* `COMMENT`:其他与索引有关的信息。 +* `INDEX_COMMENT`:在创建索引时为索引提供的带有注释属性的任何注释。 +* `IS_VISIBLE`:优化器能否使用该索引。 +* `Expression` 对于非表达式部分的索引键,这个值为 `NULL`;对于表达式部分的索引键,这个值为表达式本身。可参考[表达式索引](/sql-statements/sql-statement-create-index.md#表达式索引) + 下列语句是等价的: ```sql diff --git a/information-schema/information-schema-table-constraints.md b/information-schema/information-schema-table-constraints.md index 86c292eecd79..fcbde4c3c5e1 100644 --- a/information-schema/information-schema-table-constraints.md +++ b/information-schema/information-schema-table-constraints.md @@ -49,7 +49,10 @@ SELECT * FROM table_constraints WHERE constraint_type='UNIQUE'; 7 rows in set (0.01 sec) ``` -其中: +`TABLE_CONSTRAINTS` 表中列的含义如下: -* `CONSTRAINT_TYPE` 的取值可以是 `UNIQUE`,`PRIMARY KEY`,或者 `FOREIGN KEY`。 -* `UNIQUE` 和 `PRIMARY KEY` 信息与 `SHOW INDEX` 语句的执行结果类似。 +* `CONSTRAINT_CATALOG`:约束所属的目录的名称。这个值总是 `def`。 +* `CONSTRAINT_SCHEMA`:约束所属的数据库的名称。 +* `CONSTRAINT_NAME`:约束的名称。 +* `TABLE_NAME`:表的名称。 +* `CONSTRAINT_TYPE`:约束的类型。取值可以是 `UNIQUE`、`PRIMARY KEY` 或者 `FOREIGN KEY`。`UNIQUE` 和 `PRIMARY KEY` 信息与 `SHOW INDEX` 语句的执行结果类似。 From 2da351c970e9b99b8f3509eba945830980606e21 Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Thu, 30 Jul 2020 14:49:33 +0800 Subject: [PATCH 06/28] Update information-schema/information-schema-analyze-status.md --- information-schema/information-schema-analyze-status.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema-analyze-status.md b/information-schema/information-schema-analyze-status.md index a148ffad3276..56e73e2492fe 100644 --- a/information-schema/information-schema-analyze-status.md +++ b/information-schema/information-schema-analyze-status.md @@ -54,7 +54,7 @@ SELECT * FROM `ANALYZE_STATUS`; * `TABLE_SCHEMA`:表所属的数据库的名称。 * `TABLE_NAME`:表的名称。 * `PARTITION_NAME`:分区表的名称。 -* `JOB_INFO`:ANALYZE` 任务的信息。 +* `JOB_INFO`:`ANALYZE` 任务的信息。 * `PROCESSED_ROWS`:已经处理的行数。 * `START_TIME`:`ANALYZE` 任务的开始时间。 * `STATE`:`ANALYZE` 任务的执行状态。其值可以是 `pending`、`running`、`finished` 或者 `failed`。 From e8faedae0d6c8c6fb7400faec352cf223a547051 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 17:23:31 +0800 Subject: [PATCH 07/28] add 3 files and rename another file --- .../information-schema-cluster-info.md | 22 +-- .../information-schema-tikv-store-status.md | 64 +++++++++ .../information-schema-user-privileges.md | 76 ++++++++++ .../information-schema-views.md | 68 +++++++++ information-schema/information-schema.md | 136 ------------------ 5 files changed, 220 insertions(+), 146 deletions(-) rename system-tables/system-table-cluster-info.md => information-schema/information-schema-cluster-info.md (62%) create mode 100644 information-schema/information-schema-tikv-store-status.md create mode 100644 information-schema/information-schema-user-privileges.md create mode 100644 information-schema/information-schema-views.md diff --git a/system-tables/system-table-cluster-info.md b/information-schema/information-schema-cluster-info.md similarity index 62% rename from system-tables/system-table-cluster-info.md rename to information-schema/information-schema-cluster-info.md index 0e82b038feca..4ba4b83adee2 100644 --- a/system-tables/system-table-cluster-info.md +++ b/information-schema/information-schema-cluster-info.md @@ -1,7 +1,7 @@ --- title: CLUSTER_INFO summary: 了解 TiDB 集群拓扑表 `CLUSTER_INFO`。 -aliases: ['/docs-cn/dev/reference/system-databases/cluster-info/'] +aliases: ['/docs-cn/dev/reference/system-databases/cluster-info/','/zh/tidb/dev/system-table-cluster-info/'] --- # CLUSTER_INFO @@ -11,7 +11,8 @@ aliases: ['/docs-cn/dev/reference/system-databases/cluster-info/'] {{< copyable "sql" >}} ```sql -desc information_schema.cluster_info; +USE information_schema; +desc cluster_info; ``` ```sql @@ -42,15 +43,16 @@ desc information_schema.cluster_info; {{< copyable "sql" >}} ```sql -select * from information_schema.cluster_info; +SELECT * FROM cluster_info; ``` ```sql -+------+-----------------+-----------------+-------------+------------------------------------------+---------------------------+--------------+ -| TYPE | INSTANCE | STATUS_ADDRESS | VERSION | GIT_HASH | START_TIME | UPTIME | -+------+-----------------+-----------------+-------------+------------------------------------------+---------------------------+--------------+ -| tidb | 0.0.0.0:4000 | 0.0.0.0:10080 | 4.0.0-beta | b5ea3232afa970f00db7a0fb13ed10857db1912e | 2020-03-02T16:27:28+08:00 | 4m18.845924s | -| pd | 127.0.0.1:2379 | 127.0.0.1:2379 | 4.1.0-alpha | 4b9bcbc1425c96848042b6d700eb63f84e72b338 | 2020-03-02T16:27:17+08:00 | 4m29.845928s | -| tikv | 127.0.0.1:20160 | 127.0.0.1:20180 | 4.1.0-alpha | 7c4202a1c8faf60eda659dfe0e64e31972488e78 | 2020-03-02T16:27:28+08:00 | 4m18.845929s | -+------+-----------------+-----------------+-------------+------------------------------------------+---------------------------+--------------+ ++------+-----------------+-----------------+--------------+------------------------------------------+---------------------------+---------------------+ +| TYPE | INSTANCE | STATUS_ADDRESS | VERSION | GIT_HASH | START_TIME | UPTIME | ++------+-----------------+-----------------+--------------+------------------------------------------+---------------------------+---------------------+ +| tidb | 0.0.0.0:4000 | 0.0.0.0:10080 | 4.0.0-beta.2 | 0df3b74f55f8f8fbde39bbd5d471783f49dc10f7 | 2020-07-05T09:25:53-06:00 | 26h39m4.352862693s | +| pd | 127.0.0.1:2379 | 127.0.0.1:2379 | 4.1.0-alpha | 1ad59bcbf36d87082c79a1fffa3b0895234ac862 | 2020-07-05T09:25:47-06:00 | 26h39m10.352868103s | +| tikv | 127.0.0.1:20165 | 127.0.0.1:20180 | 4.1.0-alpha | b45e052df8fb5d66aa8b3a77b5c992ddbfbb79df | 2020-07-05T09:25:50-06:00 | 26h39m7.352869963s | ++------+-----------------+-----------------+--------------+------------------------------------------+---------------------------+---------------------+ +3 rows in set (0.00 sec) ``` diff --git a/information-schema/information-schema-tikv-store-status.md b/information-schema/information-schema-tikv-store-status.md new file mode 100644 index 000000000000..4cccba6a26a6 --- /dev/null +++ b/information-schema/information-schema-tikv-store-status.md @@ -0,0 +1,64 @@ +--- +title: TIKV_STORE_STATUS +summary: 了解 information_schema 表 `TIKV_STORE_STATUS`。 +--- + +# TIKV_STORE_STATUS + +`TIKV_STORE_STATUS` 表通过 PD 的 API 显示了 TiKV 节点的一些基本信息,例如在集群中分配的 ID,地址和端口,状态,容量以及当前节点的 Region leader 的数量。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tikv_store_status; +``` + +```sql ++-------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------------------+-------------+------+------+---------+-------+ +| STORE_ID | bigint(21) | YES | | NULL | | +| ADDRESS | varchar(64) | YES | | NULL | | +| STORE_STATE | bigint(21) | YES | | NULL | | +| STORE_STATE_NAME | varchar(64) | YES | | NULL | | +| LABEL | json | YES | | NULL | | +| VERSION | varchar(64) | YES | | NULL | | +| CAPACITY | varchar(64) | YES | | NULL | | +| AVAILABLE | varchar(64) | YES | | NULL | | +| LEADER_COUNT | bigint(21) | YES | | NULL | | +| LEADER_WEIGHT | double | YES | | NULL | | +| LEADER_SCORE | double | YES | | NULL | | +| LEADER_SIZE | bigint(21) | YES | | NULL | | +| REGION_COUNT | bigint(21) | YES | | NULL | | +| REGION_WEIGHT | double | YES | | NULL | | +| REGION_SCORE | double | YES | | NULL | | +| REGION_SIZE | bigint(21) | YES | | NULL | | +| START_TS | datetime | YES | | NULL | | +| LAST_HEARTBEAT_TS | datetime | YES | | NULL | | +| UPTIME | varchar(64) | YES | | NULL | | ++-------------------+-------------+------+------+---------+-------+ +19 rows in set (0.00 sec) +``` + +`TIKV_STORE_STATUS` 表中列的含义如下: + +* `STORE_ID`:Store 的 ID。 +* `ADDRESS`:Store 的地址。 +* `STORE_STATE`:Store 状态的标识符,与 `STORE_STATE_NAME` 相对应。 +* `STORE_STATE_NAME`:Store 状态的名字,为 `Up` / `Offline` / `Tombstone` 中的一种。 +* `LABEL`:给 Store 设置的标签。 +* `VERSION`:Store 的版本号。 +* `CAPACITY`:Store 的存储容量。 +* `AVAILABLE`:Store 的剩余存储空间。 +* `LEADER_COUNT`:Store 上的 leader 的数量。 +* `LEADER_WEIGHT`:Store 的 leader 权重。 +* `LEADER_SCORE`:Store 的 leader 评分。 +* `LEADER_SIZE`:Store 上的所有 leader 的近似总数据量 (MB)。 +* `REGION_COUNT`:Store 上的 Region 总数。 +* `REGION_WEIGHT`:Store 的 Region 权重。 +* `REGION_SCORE`:Store 的 Region 评分。 +* `REGION_SIZE`:Store 上的所有 Region 的近似总数据量 (MB)。 +* `START_TS`:Store 启动时的时间戳。 +* `LAST_HEARTBEAT_TS`:Store 上次发出心跳的时间戳。 +* `UPTIME`:Store 启动以来的总时间。 diff --git a/information-schema/information-schema-user-privileges.md b/information-schema/information-schema-user-privileges.md new file mode 100644 index 000000000000..b419b478e510 --- /dev/null +++ b/information-schema/information-schema-user-privileges.md @@ -0,0 +1,76 @@ +--- +title: USER_PRIVILEGES +summary: 了解 information_schema 表 `USER_PRIVILEGES`。 +--- + +# USER_PRIVILEGES + +`USER_PRIVILEGES` 表提供了关于全局权限的信息。该表的数据根据 `mysql.user` 系统表生成。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC user_privileges; +``` + +```sql ++----------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------+--------------+------+------+---------+-------+ +| GRANTEE | varchar(81) | YES | | NULL | | +| TABLE_CATALOG | varchar(512) | YES | | NULL | | +| PRIVILEGE_TYPE | varchar(64) | YES | | NULL | | +| IS_GRANTABLE | varchar(3) | YES | | NULL | | ++----------------+--------------+------+------+---------+-------+ +4 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM user_privileges; +``` + +```sql ++------------+---------------+-------------------------+--------------+ +| GRANTEE | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE | ++------------+---------------+-------------------------+--------------+ +| 'root'@'%' | def | Select | YES | +| 'root'@'%' | def | Insert | YES | +| 'root'@'%' | def | Update | YES | +| 'root'@'%' | def | Delete | YES | +| 'root'@'%' | def | Create | YES | +| 'root'@'%' | def | Drop | YES | +| 'root'@'%' | def | Process | YES | +| 'root'@'%' | def | References | YES | +| 'root'@'%' | def | Alter | YES | +| 'root'@'%' | def | Show Databases | YES | +| 'root'@'%' | def | Super | YES | +| 'root'@'%' | def | Execute | YES | +| 'root'@'%' | def | Index | YES | +| 'root'@'%' | def | Create User | YES | +| 'root'@'%' | def | Trigger | YES | +| 'root'@'%' | def | Create View | YES | +| 'root'@'%' | def | Show View | YES | +| 'root'@'%' | def | Create Role | YES | +| 'root'@'%' | def | Drop Role | YES | +| 'root'@'%' | def | CREATE TEMPORARY TABLES | YES | +| 'root'@'%' | def | LOCK TABLES | YES | +| 'root'@'%' | def | CREATE ROUTINE | YES | +| 'root'@'%' | def | ALTER ROUTINE | YES | +| 'root'@'%' | def | EVENT | YES | +| 'root'@'%' | def | SHUTDOWN | YES | +| 'root'@'%' | def | RELOAD | YES | +| 'root'@'%' | def | FILE | YES | +| 'root'@'%' | def | CONFIG | YES | ++------------+---------------+-------------------------+--------------+ +28 rows in set (0.00 sec) +``` + +`USER_PRIVILEGES` 表中列的含义如下: + +* `GRANTEE`:被授权的用户名称,格式为 `'user_name'@'host_name'`。 +* `TABLE_CATALOG`:表所属的目录的名称。该值始终为 `def`。 +* `PRIVILEGE_TYPE`:被授权的权限类型,每行只列一个权限。 +* `IS_GRANTABLE`:如果用户有 `GRANT OPTION` 的权限,则为 `YES`,否则为 `NO`。 diff --git a/information-schema/information-schema-views.md b/information-schema/information-schema-views.md new file mode 100644 index 000000000000..d26a08b1155a --- /dev/null +++ b/information-schema/information-schema-views.md @@ -0,0 +1,68 @@ +--- +title: VIEWS +summary: 了解 information_schema 表 `VIEWS`。 +--- + +# VIEWS + +`VIEWS` 表提供了关于 SQL 视图的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC views; +``` + +```sql ++----------------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------------------+--------------+------+------+---------+-------+ +| TABLE_CATALOG | varchar(512) | NO | | NULL | | +| TABLE_SCHEMA | varchar(64) | NO | | NULL | | +| TABLE_NAME | varchar(64) | NO | | NULL | | +| VIEW_DEFINITION | longblob | NO | | NULL | | +| CHECK_OPTION | varchar(8) | NO | | NULL | | +| IS_UPDATABLE | varchar(3) | NO | | NULL | | +| DEFINER | varchar(77) | NO | | NULL | | +| SECURITY_TYPE | varchar(7) | NO | | NULL | | +| CHARACTER_SET_CLIENT | varchar(32) | NO | | NULL | | +| COLLATION_CONNECTION | varchar(32) | NO | | NULL | | ++----------------------+--------------+------+------+---------+-------+ +10 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +CREATE VIEW test.v1 AS SELECT 1; +SELECT * FROM views\G +``` + +```sql +*************************** 1. row *************************** + TABLE_CATALOG: def + TABLE_SCHEMA: test + TABLE_NAME: v1 + VIEW_DEFINITION: SELECT 1 + CHECK_OPTION: CASCADED + IS_UPDATABLE: NO + DEFINER: root@127.0.0.1 + SECURITY_TYPE: DEFINER +CHARACTER_SET_CLIENT: utf8mb4 +COLLATION_CONNECTION: utf8mb4_0900_ai_ci +1 row in set (0.00 sec) +``` + +`VIEWS` 表中列的含义如下: + +* `TABLE_CATALOG`:视图所属的目录的名称。该值始终为 `def`。 +* `TABLE_SCHEMA`:视图所属的数据库的名称。 +* `TABLE_NAME`:视图名称。 +* `VIEW_DEFINITION`:视图的定义,由创建视图时 `SELECT` 部分的语句组成。 +* `CHECK_OPTION`:`CHECK_OPTION` 的值。取值为 `NONE`、 `CASCADE` 或 `LOCAL`。 +* `IS_UPDATABLE`:`UPDATE`/`INSERT`/`DELETE` 是否对该视图可用。在 TiDB,始终为 `NO`。 +* `DEFINER`:视图的创建者用户名称,格式为 `'user_name'@'host_name'`。 +* `SECURITY_TYPE`:`SQL SECURITY` 的值,取值为 `DEFINER` 或 `INVOKER`。 +* `CHARACTER_SET_CLIENT`:在视图创建时 session 变量 `character_set_client` 的值。 +* `COLLATION_CONNECTION`:在视图创建时 session 变量 `collation_connection` 的值。 diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 3accef2ddc43..9fd6a2e272b6 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -81,142 +81,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 | [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | | [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | - -## TIKV_STORE_STATUS 表 - -`TIKV_STORE_STATUS` 表提供了所有 TiKV Store 的状态信息。 - -{{< copyable "sql" >}} - -```sql -desc TIKV_STORE_STATUS; -``` - -```sql -+-------------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+-------------------+---------------------+------+-----+---------+-------+ -| STORE_ID | bigint(21) unsigned | YES | | | | -| ADDRESS | varchar(64) | YES | | | | -| STORE_STATE | bigint(21) unsigned | YES | | | | -| STORE_STATE_NAME | varchar(64) | YES | | | | -| LABEL | json unsigned | YES | | | | -| VERSION | varchar(64) | YES | | | | -| CAPACITY | varchar(64) | YES | | | | -| AVAILABLE | varchar(64) | YES | | | | -| LEADER_COUNT | bigint(21) unsigned | YES | | | | -| LEADER_WEIGHT | bigint(21) unsigned | YES | | | | -| LEADER_SCORE | bigint(21) unsigned | YES | | | | -| LEADER_SIZE | bigint(21) unsigned | YES | | | | -| REGION_COUNT | bigint(21) unsigned | YES | | | | -| REGION_WEIGHT | bigint(21) unsigned | YES | | | | -| REGION_SCORE | bigint(21) unsigned | YES | | | | -| REGION_SIZE | bigint(21) unsigned | YES | | | | -| START_TS | datetime unsigned | YES | | | | -| LAST_HEARTBEAT_TS | datetime unsigned | YES | | | | -| UPTIME | varchar(64) | YES | | | | -+-------------------+---------------------+------+-----+---------+-------+ -``` - -`TIKV_STORE_STATUS` 表中列的含义如下: - -* `STORE_ID`:Store 的 ID。 -* `ADDRESS`:Store 的地址。 -* `STORE_STATE`:Store 状态的标识符,与 `STORE_STATE_NAME` 相对应。 -* `STORE_STATE_NAME`:Store 状态的名字,为 `Up` / `Offline` / `Tombstone` 中的一种。 -* `LABEL`:给 Store 设置的标签。 -* `VERSION`:Store 的版本号。 -* `CAPACITY`:Store 的存储容量。 -* `AVAILABLE`:Store 的剩余存储空间。 -* `LEADER_COUNT`:Store 上的 leader 的数量。 -* `LEADER_WEIGHT`:Store 的 leader 权重。 -* `LEADER_SCORE`:Store 的 leader 评分。 -* `LEADER_SIZE`:Store 上的所有 leader 的近似总数据量 (MB)。 -* `REGION_COUNT`:Store 上的 Region 总数。 -* `REGION_WEIGHT`:Store 的 Region 权重。 -* `REGION_SCORE`:Store 的 Region 评分。 -* `REGION_SIZE`:Store 上的所有 Region 的近似总数据量 (MB)。 -* `START_TS`:Store 启动时的时间戳。 -* `LAST_HEARTBEAT_TS`:Store 上次发出心跳的时间戳。 -* `UPTIME`:Store 启动以来的总时间。 - -## USER_PRIVILEGES 表 - -`USER_PRIVILEGES` 表提供了关于全局权限的信息。该表的数据根据 `mysql.user` 系统表生成。 - -{{< copyable "sql" >}} - -```sql -desc USER_PRIVILEGES; -``` - -```sql -+----------------|--------------|------|------|---------|-------+ -| Field | Type | Null | Key | Default | Extra | -+----------------|--------------|------|------|---------|-------+ -| GRANTEE | varchar(81) | YES | | NULL | | -| TABLE_CATALOG | varchar(512) | YES | | NULL | | -| PRIVILEGE_TYPE | varchar(64) | YES | | NULL | | -| IS_GRANTABLE | varchar(3) | YES | | NULL | | -+----------------|--------------|------|------|---------|-------+ -4 rows in set (0.00 sec) -``` - -`USER_PRIVILEGES` 表中列的含义如下: - -* `GRANTEE`:被授权的用户名称,格式为 `'user_name'@'host_name'`。 -* `TABLE_CATALOG`:表所属的目录的名称。该值始终为 `def`。 -* `PRIVILEGE_TYPE`:被授权的权限类型,每行只列一个权限。 -* `IS_GRANTABLE`:如果用户有 `GRANT OPTION` 的权限,则为 `YES`,否则为 `NO`。 - -## VIEWS 表 - -`VIEWS` 表提供了关于 SQL 视图的信息。 - -{{< copyable "sql" >}} - -```sql -create view test.v1 as select 1; -``` - -``` -Query OK, 0 rows affected (0.00 sec) -``` - -{{< copyable "sql" >}} - -```sql -select * from views; -``` - -``` -*************************** 1. row *************************** - TABLE_CATALOG: def - TABLE_SCHEMA: test - TABLE_NAME: v1 - VIEW_DEFINITION: select 1 - CHECK_OPTION: CASCADED - IS_UPDATABLE: NO - DEFINER: root@127.0.0.1 - SECURITY_TYPE: DEFINER -CHARACTER_SET_CLIENT: utf8 -COLLATION_CONNECTION: utf8_general_ci -1 row in set (0.00 sec) -``` - -`VIEWS` 表中列的含义如下: - -* `TABLE_CATALOG`:视图所属的目录的名称。该值始终为 `def`。 -* `TABLE_SCHEMA`:视图所属的数据库的名称。 -* `TABLE_NAME`:视图名称。 -* `VIEW_DEFINITION`:视图的定义,由创建视图时 `SELECT` 部分的语句组成。 -* `CHECK_OPTION`:`CHECK_OPTION` 的值。取值为 `NONE`、 `CASCADE` 或 `LOCAL`。 -* `IS_UPDATABLE`:`UPDATE`/`INSERT`/`DELETE` 是否对该视图可用。在 TiDB,始终为 `NO`。 -* `DEFINER`:视图的创建者用户名称,格式为 `'user_name'@'host_name'`。 -* `SECURITY_TYPE`:`SQL SECURITY` 的值,取值为 `DEFINER` 或 `INVOKER`。 -* `CHARACTER_SET_CLIENT`:在视图创建时 session 变量 `character_set_client` 的值。 -* `COLLATION_CONNECTION`:在视图创建时 session 变量 `collation_connection` 的值。 - ## SQL 诊断相关的表 * [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) From cec97fa591df23d33fac7302e09e47af104101a9 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 18:06:24 +0800 Subject: [PATCH 08/28] rename/update a file --- .../information-schema-cluster-config.md | 32 ++++++++++--------- .../information-schema-cluster-info.md | 2 +- information-schema/information-schema.md | 1 - 3 files changed, 18 insertions(+), 17 deletions(-) rename system-tables/system-table-cluster-config.md => information-schema/information-schema-cluster-config.md (53%) diff --git a/system-tables/system-table-cluster-config.md b/information-schema/information-schema-cluster-config.md similarity index 53% rename from system-tables/system-table-cluster-config.md rename to information-schema/information-schema-cluster-config.md index 099d6042ba92..a641103b301e 100644 --- a/system-tables/system-table-cluster-config.md +++ b/information-schema/information-schema-cluster-config.md @@ -1,17 +1,18 @@ --- title: CLUSTER_CONFIG -aliases: ['/docs-cn/dev/reference/system-databases/cluster-config/'] -summary: 了解 TiDB 集群配置表 `CLUSTER_CONFIG`。 +summary: 了解 TiDB information_schema 表 `CLUSTER_CONFIG`。 +aliases: ['/docs-cn/dev/reference/system-databases/cluster-config/','/zh/tidb/dev/system-table-cluster-config/','/docs-cn/dev/system-tables/system-table-cluster-config/'] --- # CLUSTER_CONFIG -集群配置表 `CLUSTER_CONFIG` 用于获取集群当前所有 TiDB/PD/TiKV 实例的配置。对于 TiDB 4.0 以前的版本,用户需要逐个访问各个实例的 HTTP API 才能收集到所有组件配置。 +`CLUSTER_CONFIG` 表用于获取集群当前所有组件实例的配置。在 TiDB 早前的版本,用户需要逐个访问各个实例的 HTTP API 才能收集到所有组件配置。TiDB v4.0 后,该表的引入提高了易用性。 {{< copyable "sql" >}} ```sql -desc information_schema.cluster_config; +USE information_schema; +DESC cluster_config; ``` ```sql @@ -37,18 +38,19 @@ desc information_schema.cluster_config; {{< copyable "sql" >}} ```sql -select * from information_schema.cluster_config where type='tikv' and `key` like 'coprocessor%'; +SELECT * FROM cluster_config WHERE type='tikv' AND `key` LIKE 'coprocessor%'; ``` ```sql -+------+-----------------+-----------------------------------+----------+ -| TYPE | INSTANCE | KEY | VALUE | -+------+-----------------+-----------------------------------+----------+ -| tikv | 127.0.0.1:20160 | coprocessor.batch-split-limit | 10 | -| tikv | 127.0.0.1:20160 | coprocessor.region-max-keys | 1.44e+06 | -| tikv | 127.0.0.1:20160 | coprocessor.region-max-size | 144MiB | -| tikv | 127.0.0.1:20160 | coprocessor.region-split-keys | 960000 | -| tikv | 127.0.0.1:20160 | coprocessor.region-split-size | 96MiB | -| tikv | 127.0.0.1:20160 | coprocessor.split-region-on-table | false | -+------+-----------------+-----------------------------------+----------+ ++------+-----------------+-----------------------------------+---------+ +| TYPE | INSTANCE | KEY | VALUE | ++------+-----------------+-----------------------------------+---------+ +| tikv | 127.0.0.1:20165 | coprocessor.batch-split-limit | 10 | +| tikv | 127.0.0.1:20165 | coprocessor.region-max-keys | 1440000 | +| tikv | 127.0.0.1:20165 | coprocessor.region-max-size | 144MiB | +| tikv | 127.0.0.1:20165 | coprocessor.region-split-keys | 960000 | +| tikv | 127.0.0.1:20165 | coprocessor.region-split-size | 96MiB | +| tikv | 127.0.0.1:20165 | coprocessor.split-region-on-table | false | ++------+-----------------+-----------------------------------+---------+ +6 rows in set (0.00 sec) ``` diff --git a/information-schema/information-schema-cluster-info.md b/information-schema/information-schema-cluster-info.md index 4ba4b83adee2..bd4acf15363a 100644 --- a/information-schema/information-schema-cluster-info.md +++ b/information-schema/information-schema-cluster-info.md @@ -1,7 +1,7 @@ --- title: CLUSTER_INFO summary: 了解 TiDB 集群拓扑表 `CLUSTER_INFO`。 -aliases: ['/docs-cn/dev/reference/system-databases/cluster-info/','/zh/tidb/dev/system-table-cluster-info/'] +aliases: ['/docs-cn/dev/reference/system-databases/cluster-info/','/zh/tidb/dev/system-table-cluster-info/','/docs-cn/dev/system-tables/system-table-cluster-info/'] --- # CLUSTER_INFO diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 9fd6a2e272b6..ec1df126b5a2 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -83,7 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) * [`information_schema.cluster_config`](/system-tables/system-table-cluster-config.md) * [`information_schema.cluster_hardware`](/system-tables/system-table-cluster-hardware.md) * [`information_schema.cluster_load`](/system-tables/system-table-cluster-load.md) From 95ea5c53abde557fc47b24e8372d5d0c58d9216b Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 18:10:50 +0800 Subject: [PATCH 09/28] rename cluster-hardware --- .../information-schema-cluster-hardware.md | 25 +++++++++++-------- information-schema/information-schema.md | 4 +-- 2 files changed, 15 insertions(+), 14 deletions(-) rename system-tables/system-table-cluster-hardware.md => information-schema/information-schema-cluster-hardware.md (72%) diff --git a/system-tables/system-table-cluster-hardware.md b/information-schema/information-schema-cluster-hardware.md similarity index 72% rename from system-tables/system-table-cluster-hardware.md rename to information-schema/information-schema-cluster-hardware.md index 8109650b35dc..020b35da6b5a 100644 --- a/system-tables/system-table-cluster-hardware.md +++ b/information-schema/information-schema-cluster-hardware.md @@ -1,7 +1,7 @@ --- title: CLUSTER_HARDWARE summary: 了解 TiDB 集群硬件表 `CLUSTER_HARDWARE`。 -aliases: ['/docs-cn/dev/reference/system-databases/cluster-hardware/'] +aliases: ['/docs-cn/dev/reference/system-databases/cluster-hardware/','/zh/tidb/dev/system-table-cluster-hardware/','/docs-cn/dev/system-tables/system-table-cluster-hardware/'] --- # CLUSTER_HARDWARE @@ -11,7 +11,8 @@ aliases: ['/docs-cn/dev/reference/system-databases/cluster-hardware/'] {{< copyable "sql" >}} ```sql -desc information_schema.cluster_hardware; +USE information_schema; +DESC cluster_hardware; ``` ```sql @@ -25,12 +26,13 @@ desc information_schema.cluster_hardware; | NAME | varchar(256) | YES | | NULL | | | VALUE | varchar(128) | YES | | NULL | | +-------------+--------------+------+------+---------+-------+ +6 rows in set (0.00 sec) ``` 字段解释: -* `TYPE`:对应集群信息表 [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) 中的 `TYPE` 字段,可取值为 `tidb`,`pd` 和 `tikv`。 -* `INSTANCE`:对应于集群信息表 `information_schema.cluster_info` 中的 `INSTANCE` 字段。 +* `TYPE`:对应集群信息表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 中的 `TYPE` 字段,可取值为 `tidb`,`pd` 和 `tikv`。 +* `INSTANCE`:对应于集群信息表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 中的 `INSTANCE` 字段。 * `DEVICE_TYPE`:硬件类型。目前可以查询的硬件类型有 `cpu`、`memory`、`disk` 和 `net`。 * `DEVICE_NAME`:硬件名。对于不同的 `DEVICE_TYPE`,`DEVICE_NAME` 的取值不同。 * `cpu`:硬件名为 cpu。 @@ -45,18 +47,19 @@ desc information_schema.cluster_hardware; {{< copyable "sql" >}} ```sql -select * from information_schema.cluster_hardware where device_type='cpu' and device_name='cpu' and name like '%cores'; +SELECT * FROM cluster_hardware WHERE device_type='cpu' AND device_name='cpu' AND name LIKE '%cores'; ``` ```sql +------+-----------------+-------------+-------------+--------------------+-------+ | TYPE | INSTANCE | DEVICE_TYPE | DEVICE_NAME | NAME | VALUE | +------+-----------------+-------------+-------------+--------------------+-------+ -| tidb | 0.0.0.0:4000 | cpu | cpu | cpu-logical-cores | 8 | -| tidb | 0.0.0.0:4000 | cpu | cpu | cpu-physical-cores | 4 | -| pd | 127.0.0.1:2379 | cpu | cpu | cpu-logical-cores | 8 | -| pd | 127.0.0.1:2379 | cpu | cpu | cpu-physical-cores | 4 | -| tikv | 127.0.0.1:20160 | cpu | cpu | cpu-logical-cores | 8 | -| tikv | 127.0.0.1:20160 | cpu | cpu | cpu-physical-cores | 4 | +| tidb | 0.0.0.0:4000 | cpu | cpu | cpu-logical-cores | 16 | +| tidb | 0.0.0.0:4000 | cpu | cpu | cpu-physical-cores | 8 | +| pd | 127.0.0.1:2379 | cpu | cpu | cpu-logical-cores | 16 | +| pd | 127.0.0.1:2379 | cpu | cpu | cpu-physical-cores | 8 | +| tikv | 127.0.0.1:20165 | cpu | cpu | cpu-logical-cores | 16 | +| tikv | 127.0.0.1:20165 | cpu | cpu | cpu-physical-cores | 8 | +------+-----------------+-------------+-------------+--------------------+-------+ +6 rows in set (0.03 sec) ``` diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index ec1df126b5a2..699e2f93275e 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -1,6 +1,6 @@ --- title: Information Schema -aliases: ['/docs-cn/dev/reference/system-databases/information-schema/','/docs-cn/dev/reference/system-databases/information-schema/','/docs-cn/dev/system-tables/system-table-information-schema/','/zh/tidb/dev/system-table-information-schema/']] +aliases: ['/docs-cn/dev/reference/system-databases/information-schema/','/docs-cn/dev/reference/system-databases/information-schema/','/docs-cn/dev/system-tables/system-table-information-schema/','/zh/tidb/dev/system-table-information-schema/'] --- # Information Schema @@ -83,8 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.cluster_config`](/system-tables/system-table-cluster-config.md) -* [`information_schema.cluster_hardware`](/system-tables/system-table-cluster-hardware.md) * [`information_schema.cluster_load`](/system-tables/system-table-cluster-load.md) * [`information_schema.cluster_systeminfo`](/system-tables/system-table-cluster-systeminfo.md) * [`information_schema.cluster_log`](/system-tables/system-table-cluster-log.md) From 700617fe34201e07325b1bfccf6d3fd11a0a7143 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 18:15:28 +0800 Subject: [PATCH 10/28] rename/update a file --- .../information-schema-cluster-config.md | 2 +- .../information-schema-cluster-load.md | 33 ++++++++++--------- information-schema/information-schema.md | 1 - 3 files changed, 19 insertions(+), 17 deletions(-) rename system-tables/system-table-cluster-load.md => information-schema/information-schema-cluster-load.md (72%) diff --git a/information-schema/information-schema-cluster-config.md b/information-schema/information-schema-cluster-config.md index a641103b301e..618cd39dd074 100644 --- a/information-schema/information-schema-cluster-config.md +++ b/information-schema/information-schema-cluster-config.md @@ -1,6 +1,6 @@ --- title: CLUSTER_CONFIG -summary: 了解 TiDB information_schema 表 `CLUSTER_CONFIG`。 +summary: 了解 information_schema 表 `CLUSTER_CONFIG`。 aliases: ['/docs-cn/dev/reference/system-databases/cluster-config/','/zh/tidb/dev/system-table-cluster-config/','/docs-cn/dev/system-tables/system-table-cluster-config/'] --- diff --git a/system-tables/system-table-cluster-load.md b/information-schema/information-schema-cluster-load.md similarity index 72% rename from system-tables/system-table-cluster-load.md rename to information-schema/information-schema-cluster-load.md index 6266c666616e..642e9feb9c0e 100644 --- a/system-tables/system-table-cluster-load.md +++ b/information-schema/information-schema-cluster-load.md @@ -1,7 +1,7 @@ --- title: CLUSTER_LOAD -summary: 了解 TiDB 集群负载表 `CLUSTER_LOAD`。 -aliases: ['/docs-cn/dev/reference/system-databases/cluster-load/'] +summary: 了解 information_schema 表 `CLUSTER_LOAD`。 +aliases: ['/docs-cn/dev/reference/system-databases/cluster-load/','/zh/tidb/dev/system-table-cluster-load/','/docs-cn/dev/system-tables/system-table-cluster-load/'] --- # CLUSTER_LOAD @@ -11,7 +11,8 @@ aliases: ['/docs-cn/dev/reference/system-databases/cluster-load/'] {{< copyable "sql" >}} ```sql -desc information_schema.cluster_load; +USE information_schema; +DESC cluster_load; ``` ```sql @@ -25,12 +26,13 @@ desc information_schema.cluster_load; | NAME | varchar(256) | YES | | NULL | | | VALUE | varchar(128) | YES | | NULL | | +-------------+--------------+------+------+---------+-------+ +6 rows in set (0.00 sec) ``` 字段解释: -* `TYPE`:对应于节点信息表 [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) 中的 `TYPE` 字段,可取值为 `tidb`,`pd` 和 `tikv`。 -* `INSTANCE`:对应于节点信息表 `information_schema.cluster_info` 中的 `INSTANCE` 字段。 +* `TYPE`:对应于节点信息表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 中的 `TYPE` 字段,可取值为 `tidb`,`pd` 和 `tikv`。 +* `INSTANCE`:对应于节点信息表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 中的 `INSTANCE` 字段。 * `DEVICE_TYPE`:硬件类型,目前可以查询的硬件类型有 `cpu`、`memory`、`disk` 和 `net`。 * `DEVICE_NAME`:硬件名。对于不同的 `DEVICE_TYPE`,`DEVICE_NAME` 取值不同。 * `cpu`:硬件名为 cpu。 @@ -45,21 +47,22 @@ desc information_schema.cluster_load; {{< copyable "sql" >}} ```sql -select * from information_schema.cluster_load where device_type='cpu' and device_name='cpu'; +SELECT * FROM cluster_load WHERE device_type='cpu' AND device_name='cpu'; ``` ```sql +------+-----------------+-------------+-------------+--------+-------+ | TYPE | INSTANCE | DEVICE_TYPE | DEVICE_NAME | NAME | VALUE | +------+-----------------+-------------+-------------+--------+-------+ -| tidb | 0.0.0.0:4000 | cpu | cpu | load1 | 0.39 | -| tidb | 0.0.0.0:4000 | cpu | cpu | load5 | 0.36 | -| tidb | 0.0.0.0:4000 | cpu | cpu | load15 | 0.66 | -| pd | 127.0.0.1:2379 | cpu | cpu | load1 | 0.39 | -| pd | 127.0.0.1:2379 | cpu | cpu | load5 | 0.36 | -| pd | 127.0.0.1:2379 | cpu | cpu | load15 | 0.66 | -| tikv | 127.0.0.1:20160 | cpu | cpu | load1 | 0.39 | -| tikv | 127.0.0.1:20160 | cpu | cpu | load5 | 0.36 | -| tikv | 127.0.0.1:20160 | cpu | cpu | load15 | 0.66 | +| tidb | 0.0.0.0:4000 | cpu | cpu | load1 | 0.13 | +| tidb | 0.0.0.0:4000 | cpu | cpu | load5 | 0.25 | +| tidb | 0.0.0.0:4000 | cpu | cpu | load15 | 0.31 | +| pd | 127.0.0.1:2379 | cpu | cpu | load1 | 0.13 | +| pd | 127.0.0.1:2379 | cpu | cpu | load5 | 0.25 | +| pd | 127.0.0.1:2379 | cpu | cpu | load15 | 0.31 | +| tikv | 127.0.0.1:20165 | cpu | cpu | load1 | 0.13 | +| tikv | 127.0.0.1:20165 | cpu | cpu | load5 | 0.25 | +| tikv | 127.0.0.1:20165 | cpu | cpu | load15 | 0.31 | +------+-----------------+-------------+-------------+--------+-------+ +9 rows in set (1.50 sec) ``` \ No newline at end of file diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 699e2f93275e..42530a106224 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -83,7 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.cluster_load`](/system-tables/system-table-cluster-load.md) * [`information_schema.cluster_systeminfo`](/system-tables/system-table-cluster-systeminfo.md) * [`information_schema.cluster_log`](/system-tables/system-table-cluster-log.md) * [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md) From 5decf3492fed7f5f35a127ee0d1a7a425338259d Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:13:19 +0800 Subject: [PATCH 11/28] rename/update cluster-systeminfo --- .../information-schema-cluster-systeminfo.md | 15 ++++++++------- information-schema/information-schema.md | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) rename system-tables/system-table-cluster-systeminfo.md => information-schema/information-schema-cluster-systeminfo.md (78%) diff --git a/system-tables/system-table-cluster-systeminfo.md b/information-schema/information-schema-cluster-systeminfo.md similarity index 78% rename from system-tables/system-table-cluster-systeminfo.md rename to information-schema/information-schema-cluster-systeminfo.md index 97acb7eee3c1..84c8727282af 100644 --- a/system-tables/system-table-cluster-systeminfo.md +++ b/information-schema/information-schema-cluster-systeminfo.md @@ -1,17 +1,18 @@ --- title: CLUSTER_SYSTEMINFO -summary: 了解 TiDB 集群负载表 `CLUSTER_SYSTEMINFO`。 -aliases: ['/docs-cn/dev/reference/system-databases/cluster-systeminfo/'] +summary: 了解 TiDB 内核参数表 `CLUSTER_SYSTEMINFO`。 +aliases: ['/docs-cn/dev/reference/system-databases/cluster-systeminfo/','/zh/tidb/dev/system-table-cluster-systeminfo/','/docs-cn/dev/system-tables/system-table-cluster-systeminfo/'] --- # CLUSTER_SYSTEMINFO -集群负载表 `CLUSTER_SYSTEMINFO` 用于查询集群所有实例所在服务器的内核配置信息。目前支持查询 `sysctl` 的信息。 +内核参数表 `CLUSTER_SYSTEMINFO` 用于查询集群所有实例所在服务器的内核配置信息。目前支持查询 `sysctl` 的信息。 {{< copyable "sql" >}} ```sql -desc information_schema.cluster_systeminfo; +USE information_schema; +DESC cluster_systeminfo; ``` ```sql @@ -30,8 +31,8 @@ desc information_schema.cluster_systeminfo; 字段解释: -* `TYPE`:对应于节点信息表 [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) 中的 `TYPE` 字段,可取值为 `tidb`,`pd` 和 `tikv`。 -* `INSTANCE`:对应于节点信息表 [`information_schema.cluster_info`](/system-tables/system-table-information-schema.md) 中的 `INSTANCE` 字段。 +* `TYPE`:对应于节点信息表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 中的 `TYPE` 字段,可取值为 `tidb`,`pd` 和 `tikv`。 +* `INSTANCE`:对应于节点信息表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 中的 `INSTANCE` 字段。 * `SYSTEM_TYPE`:系统类型,目前可以查询的系统类型有 `system`。 * `SYSTEM_NAME`:目前可以查询的 `SYSTEM_NAME` 为 `sysctl`。 * `NAME`:`sysctl` 对应的配置名。 @@ -40,7 +41,7 @@ desc information_schema.cluster_systeminfo; 查询集群所有服务器的内核版本示例如下: ```sql -select * from information_schema.cluster_systeminfo where name like '%kernel.osrelease%' +SELECT * FROM cluster_systeminfo WHERE name LIKE '%kernel.osrelease%' ``` ```sql diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 42530a106224..36f9985ed78e 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -83,7 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.cluster_systeminfo`](/system-tables/system-table-cluster-systeminfo.md) * [`information_schema.cluster_log`](/system-tables/system-table-cluster-log.md) * [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md) * [`information_schema.metrics_summary`](/system-tables/system-table-metrics-summary.md) From 7b4430d0c8ba0497a5bb56623aa037aa5d52e16c Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:15:34 +0800 Subject: [PATCH 12/28] rename/update cluster-log --- .../information-schema-cluster-log.md | 9 +++++---- information-schema/information-schema.md | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) rename system-tables/system-table-cluster-log.md => information-schema/information-schema-cluster-log.md (92%) diff --git a/system-tables/system-table-cluster-log.md b/information-schema/information-schema-cluster-log.md similarity index 92% rename from system-tables/system-table-cluster-log.md rename to information-schema/information-schema-cluster-log.md index 4ff3571bed87..87aae19b5324 100644 --- a/system-tables/system-table-cluster-log.md +++ b/information-schema/information-schema-cluster-log.md @@ -1,7 +1,7 @@ --- title: CLUSTER_LOG -summary: 了解 TiDB 集群日志表 `CLUSTER_LOG`。 -aliases: ['/docs-cn/dev/reference/system-databases/cluster-log/'] +summary: 了解 information_schema 表 `CLUSTER_LOG`。 +aliases: ['/docs-cn/dev/reference/system-databases/cluster-log/','/zh/tidb/dev/system-table-cluster-log/','/docs-cn/dev/system-tables/system-table-cluster-log/'] --- # CLUSTER_LOG @@ -13,7 +13,8 @@ TiDB 4.0 版本之前,要获取集群的日志,用户需要逐个登录各 {{< copyable "sql" >}} ```sql -desc information_schema.cluster_log; +USE information_schema; +DESC cluster_log; ``` ```sql @@ -48,7 +49,7 @@ desc information_schema.cluster_log; {{< copyable "sql" >}} ```sql -select time,instance,left(message,150) from information_schema.cluster_log where message like '%ddl%job%ID.80%' and type='tidb' and time > '2020-05-18 20:40:00' and time<'2020-05-18 21:40:00' +SELECT time,instance,left(message,150) FROM cluster_log WHERE message LIKE '%ddl%job%ID.80%' AND type='tidb' AND time > '2020-05-18 20:40:00' AND time < '2020-05-18 21:40:00' ``` ```sql diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 36f9985ed78e..fee9d9563a0c 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -83,7 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.cluster_log`](/system-tables/system-table-cluster-log.md) * [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md) * [`information_schema.metrics_summary`](/system-tables/system-table-metrics-summary.md) * [`information_schema.metrics_summary_by_label`](/system-tables/system-table-metrics-summary.md) From 1a50a59261e768b355ef4077911096b4e6019d90 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:24:05 +0800 Subject: [PATCH 13/28] rename/update metrics-summary and metrics-tables --- .../information-schema-metrics-summary.md | 38 +++++----- .../information-schema-metrics-tables.md | 76 +++++++++++++++++++ information-schema/information-schema.md | 2 - system-tables/system-table-metrics-tables.md | 35 --------- 4 files changed, 96 insertions(+), 55 deletions(-) rename system-tables/system-table-metrics-summary.md => information-schema/information-schema-metrics-summary.md (93%) create mode 100644 information-schema/information-schema-metrics-tables.md delete mode 100644 system-tables/system-table-metrics-tables.md diff --git a/system-tables/system-table-metrics-summary.md b/information-schema/information-schema-metrics-summary.md similarity index 93% rename from system-tables/system-table-metrics-summary.md rename to information-schema/information-schema-metrics-summary.md index 4165acaab813..ea804e5319e7 100644 --- a/system-tables/system-table-metrics-summary.md +++ b/information-schema/information-schema-metrics-summary.md @@ -1,7 +1,7 @@ --- title: METRICS_SUMMARY summary: 了解 TiDB 系统表 `METRICS_SUMMARY`。 -aliases: ['/docs-cn/dev/reference/system-databases/metrics-summary/'] +aliases: ['/docs-cn/dev/reference/system-databases/metrics-summary/','/zh/tidb/dev/system-table-metrics-summary/','/docs-cn/dev/system-tables/system-table-metrics-summary/'] --- # METRICS_SUMMARY @@ -16,7 +16,8 @@ aliases: ['/docs-cn/dev/reference/system-databases/metrics-summary/'] {{< copyable "sql" >}} ```sql -desc information_schema.metrics_summary; +USE information_schema; +DESC metrics_summary; ``` ```sql @@ -31,6 +32,7 @@ desc information_schema.metrics_summary; | MAX_VALUE | double(22,6) | YES | | NULL | | | COMMENT | varchar(256) | YES | | NULL | | +--------------+--------------+------+------+---------+-------+ +7 rows in set (0.00 sec) ``` 字段解释: @@ -49,13 +51,13 @@ desc information_schema.metrics_summary; {{< copyable "sql" >}} ```sql -select /*+ time_range('2020-03-08 13:23:00','2020-03-08 13:33:00') */ * -from information_schema.metrics_summary -where metrics_name like 'tidb%duration' - and avg_value > 0 - and quantile = 0.99 -order by avg_value desc -limit 3\G +SELECT /*+ time_range('2020-03-08 13:23:00','2020-03-08 13:33:00') */ * +FROM information_schema.metrics_summary +WHERE metrics_name LIKE 'tidb%duration' + AND avg_value > 0 + AND quantile = 0.99 +ORDER BY avg_value DESC +LIMIT 3\G ``` ```sql @@ -90,16 +92,16 @@ COMMENT | The quantile of kv requests durations by store {{< copyable "sql" >}} ```sql -select /*+ time_range('2020-03-08 13:23:00','2020-03-08 13:33:00') */ * -from information_schema.metrics_summary_by_label -where metrics_name like 'tidb%duration' - and avg_value > 0 - and quantile = 0.99 -order by avg_value desc -limit 10\G +SELECT /*+ time_range('2020-03-08 13:23:00','2020-03-08 13:33:00') */ * +FROM information_schema.metrics_summary_by_label +WHERE metrics_name LIKE 'tidb%duration' + AND avg_value > 0 + AND quantile = 0.99 +ORDER BY avg_value DESC +LIMIT 10\G ``` -``` +```sql ***************************[ 1. row ]*************************** INSTANCE | 172.16.5.40:10089 METRICS_NAME | tidb_get_token_duration @@ -157,7 +159,7 @@ JOIN (SELECT /*+ time_range("2020-03-03 17:18:00", "2020-03-03 17:21:00")*/ * FROM information_schema.metrics_summary ) t2 ON t1.metrics_name = t2.metrics_name -ORDER BY ratio DESC limit 10; +ORDER BY ratio DESC LIMIT 10; ``` ```sql diff --git a/information-schema/information-schema-metrics-tables.md b/information-schema/information-schema-metrics-tables.md new file mode 100644 index 000000000000..644c10a32670 --- /dev/null +++ b/information-schema/information-schema-metrics-tables.md @@ -0,0 +1,76 @@ +--- +title: METRICS_TABLES +summary: 了解 TiDB 系统表 `METRICS_TABLES`。 +aliases: ['/docs-cn/dev/reference/system-databases/metrics-tables/','/zh/tidb/dev/system-table-metrics-tables/','/docs-cn/dev/system-tables/system-table-metrics-tables/'] +--- + +# METRICS_TABLES + +`METRICS_TABLES` 表为 [metrics_schema](/metrics-schema.md) 数据库中的每个视图提供 PromQL(Prometheus 查询语言)定义。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC metrics_tables; +``` + +```sql ++------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++------------+--------------+------+------+---------+-------+ +| TABLE_NAME | varchar(64) | YES | | NULL | | +| PROMQL | varchar(64) | YES | | NULL | | +| LABELS | varchar(64) | YES | | NULL | | +| QUANTILE | double | YES | | NULL | | +| COMMENT | varchar(256) | YES | | NULL | | ++------------+--------------+------+------+---------+-------+ +``` + +表 `metrics_tables` 的字段解释: + +* `TABLE_NAME`:对应于 `metrics_schema` 中的表名。 +* `PROMQL`:监控表的主要原理是将 SQL 映射成 `PromQL`,并将 Prometheus 结果转换成 SQL 查询结果。这个字段是 `PromQL` 的表达式模板,查询监控表数据时使用查询条件改写模板中的变量,生成最终的查询表达式。 +* `LABELS`:监控定义的 label,每一个 label 对应监控表中的一列。SQL 中如果包含对应列的过滤,对应的 `PromQL` 也会改变。 +* `QUANTILE`:百分位。对于直方图类型的监控数据,指定一个默认百分位。如果值为 `0`,表示该监控表对应的监控不是直方图。 +* `COMMENT`:对这个监控表的注释。 + +{{< copyable "sql" >}} + +```sql +SELECT * FROM metrics_tables LIMIT 5\G +``` + +```sql +*************************** 1. row *************************** +TABLE_NAME: abnormal_stores + PROMQL: sum(pd_cluster_status{ type=~"store_disconnected_count|store_unhealth_count|store_low_space_count|store_down_count|store_offline_count|store_tombstone_count"}) + LABELS: instance,type + QUANTILE: 0 + COMMENT: +*************************** 2. row *************************** +TABLE_NAME: etcd_disk_wal_fsync_rate + PROMQL: delta(etcd_disk_wal_fsync_duration_seconds_count{$LABEL_CONDITIONS}[$RANGE_DURATION]) + LABELS: instance + QUANTILE: 0 + COMMENT: The rate of writing WAL into the persistent storage +*************************** 3. row *************************** +TABLE_NAME: etcd_wal_fsync_duration + PROMQL: histogram_quantile($QUANTILE, sum(rate(etcd_disk_wal_fsync_duration_seconds_bucket{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (le,instance)) + LABELS: instance + QUANTILE: 0.99 + COMMENT: The quantile time consumed of writing WAL into the persistent storage +*************************** 4. row *************************** +TABLE_NAME: etcd_wal_fsync_total_count + PROMQL: sum(increase(etcd_disk_wal_fsync_duration_seconds_count{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance) + LABELS: instance + QUANTILE: 0 + COMMENT: The total count of writing WAL into the persistent storage +*************************** 5. row *************************** +TABLE_NAME: etcd_wal_fsync_total_time + PROMQL: sum(increase(etcd_disk_wal_fsync_duration_seconds_sum{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance) + LABELS: instance + QUANTILE: 0 + COMMENT: The total time of writing WAL into the persistent storage +5 rows in set (0.00 sec) +``` diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index fee9d9563a0c..a08bf194b4e2 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -83,8 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md) -* [`information_schema.metrics_summary`](/system-tables/system-table-metrics-summary.md) * [`information_schema.metrics_summary_by_label`](/system-tables/system-table-metrics-summary.md) * [`information_schema.inspection_result`](/system-tables/system-table-inspection-result.md) * [`information_schema.inspection_summary`](/system-tables/system-table-inspection-summary.md) diff --git a/system-tables/system-table-metrics-tables.md b/system-tables/system-table-metrics-tables.md deleted file mode 100644 index 9357082cde70..000000000000 --- a/system-tables/system-table-metrics-tables.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: METRICS_TABLES -summary: 了解 TiDB 系统表 `METRICS_TABLES`。 -aliases: ['/docs-cn/dev/reference/system-databases/metrics-tables/'] ---- - -# METRICS_TABLES - -`INFORMATION_SCHEMA.METRICS_TABLES` 表提供了 `metrics_schema` 数据库中所有监控表的相关信息。 - -{{< copyable "sql" >}} - -```sql -desc information_schema.metrics_tables; -``` - -```sql -+------------+--------------+------+------+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+------------+--------------+------+------+---------+-------+ -| TABLE_NAME | varchar(64) | YES | | NULL | | -| PROMQL | varchar(64) | YES | | NULL | | -| LABELS | varchar(64) | YES | | NULL | | -| QUANTILE | double | YES | | NULL | | -| COMMENT | varchar(256) | YES | | NULL | | -+------------+--------------+------+------+---------+-------+ -``` - -表 `metrics_tables` 的字段解释: - -* `TABLE_NAME`:对应于 `metrics_schema` 中的表名。 -* `PROMQL`:监控表的主要原理是将 SQL 映射成 `PromQL`,并将 Prometheus 结果转换成 SQL 查询结果。这个字段是 `PromQL` 的表达式模板,查询监控表数据时使用查询条件改写模板中的变量,生成最终的查询表达式。 -* `LABELS`:监控定义的 label,每一个 label 对应监控表中的一列。SQL 中如果包含对应列的过滤,对应的 `PromQL` 也会改变。 -* `QUANTILE`:百分位。对于直方图类型的监控数据,指定一个默认百分位。如果值为 `0`,表示该监控表对应的监控不是直方图。 -* `COMMENT`:对这个监控表的解释。 From c7e5a4a619ebde8c2c09aa38b85991a4803ad999 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:28:29 +0800 Subject: [PATCH 14/28] rename/update inspection-result --- .../information-schema-inspection-result.md | 13 +++++++------ information-schema/information-schema.md | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) rename system-tables/system-table-inspection-result.md => information-schema/information-schema-inspection-result.md (97%) diff --git a/system-tables/system-table-inspection-result.md b/information-schema/information-schema-inspection-result.md similarity index 97% rename from system-tables/system-table-inspection-result.md rename to information-schema/information-schema-inspection-result.md index 8ef30a15d7c9..7d5cd5680e2c 100644 --- a/system-tables/system-table-inspection-result.md +++ b/information-schema/information-schema-inspection-result.md @@ -1,7 +1,7 @@ --- title: INSPECTION_RESULT summary: 了解 TiDB 系统表 `INSPECTION_RESULT`。 -aliases: ['/docs-cn/dev/reference/system-databases/inspection-result/'] +aliases: ['/docs-cn/dev/reference/system-databases/inspection-result/','/zh/tidb/dev/system-table-inspection-result/','/docs-cn/dev/system-tables/system-table-inspection-result/'] --- # INSPECTION_RESULT @@ -15,7 +15,8 @@ TiDB 内置了一些诊断规则,用于检测系统中的故障以及隐患。 {{< copyable "sql" >}} ```sql -desc information_schema.inspection_result; +USE information_schema; +DESC inspection_result; ``` ```sql @@ -59,7 +60,7 @@ desc information_schema.inspection_result; {{< copyable "sql" >}} ```sql -select * from information_schema.inspection_result\G +SELECT * FROM information_schema.inspection_result\G ``` ```sql @@ -234,10 +235,10 @@ select * from information_schema.inspection_rules where type='inspection'; {{< copyable "sql" >}} ```sql -select * from information_schema.inspection_result where rule='version'\G +SELECT * FROM information_schema.inspection_result WHERE rule='version'\G ``` -``` +```sql ***************************[ 1. row ]*************************** RULE | version ITEM | git_hash @@ -246,7 +247,7 @@ INSTANCE | VALUE | inconsistent REFERENCE | consistent SEVERITY | critical -DETAILS | the cluster has 2 different tidb versions, execute the sql to see more detail: select * from information_schema.cluster_info where type='tidb' +DETAILS | the cluster has 2 different tidb versions, execute the sql to see more detail: SELECT * FROM information_schema.cluster_info WHERE type='tidb' ``` ### `critical-error` 诊断规则 diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index a08bf194b4e2..f6c5e507beff 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -83,8 +83,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 ## SQL 诊断相关的表 -* [`information_schema.metrics_summary_by_label`](/system-tables/system-table-metrics-summary.md) -* [`information_schema.inspection_result`](/system-tables/system-table-inspection-result.md) * [`information_schema.inspection_summary`](/system-tables/system-table-inspection-summary.md) ## 不支持的 Information Schema 表 From 1d861757fc5d717b57ac5a4270df81eeb6daba16 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:30:25 +0800 Subject: [PATCH 15/28] rename/update inspection-summary --- .../information-schema-inspection-summary.md | 7 ++++--- information-schema/information-schema.md | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) rename system-tables/system-table-inspection-summary.md => information-schema/information-schema-inspection-summary.md (95%) diff --git a/system-tables/system-table-inspection-summary.md b/information-schema/information-schema-inspection-summary.md similarity index 95% rename from system-tables/system-table-inspection-summary.md rename to information-schema/information-schema-inspection-summary.md index 2e8b8868cce3..fd85f3c30450 100644 --- a/system-tables/system-table-inspection-summary.md +++ b/information-schema/information-schema-inspection-summary.md @@ -1,7 +1,7 @@ --- title: INSPECTION_SUMMARY summary: 了解 TiDB 系统表 `INSPECTION_SUMMARY`。 -aliases: ['/docs-cn/dev/reference/system-databases/inspection-summary/'] +aliases: ['/docs-cn/dev/reference/system-databases/inspection-summary/','/zh/tidb/dev/system-table-inspection-summary/','/docs-cn/dev/system-tables/system-table-inspection-summary/'] --- # INSPECTION_SUMMARY @@ -13,7 +13,8 @@ aliases: ['/docs-cn/dev/reference/system-databases/inspection-summary/'] {{< copyable "sql" >}} ```sql -desc information_schema.inspection_summary; +USE information_schema; +DESC inspection_summary; ``` ```sql @@ -30,7 +31,7 @@ desc information_schema.inspection_summary; | MAX_VALUE | double(22,6) | YES | | NULL | | | COMMENT | varchar(256) | YES | | NULL | | +--------------+--------------+------+------+---------+-------+ -9 rows in set +9 rows in set (0.00 sec) ``` 字段解释: diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index f6c5e507beff..e606ed13dd2b 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -81,10 +81,6 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 | [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | | [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | -## SQL 诊断相关的表 - -* [`information_schema.inspection_summary`](/system-tables/system-table-inspection-summary.md) - ## 不支持的 Information Schema 表 TiDB 包含以下 `INFORMATION_SCHEMA` 表,但仅会返回空行: From 9a37f5267aea2e407ae7402cee9107bca286dc4b Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:46:17 +0800 Subject: [PATCH 16/28] rename/update metrics-schema.md --- ...ble-metrics-schema.md => metrics-schema.md | 93 ++++++++++++++++++- 1 file changed, 90 insertions(+), 3 deletions(-) rename system-tables/system-table-metrics-schema.md => metrics-schema.md (75%) diff --git a/system-tables/system-table-metrics-schema.md b/metrics-schema.md similarity index 75% rename from system-tables/system-table-metrics-schema.md rename to metrics-schema.md index 6dcdbc523ecc..6b042fa4a97c 100644 --- a/system-tables/system-table-metrics-schema.md +++ b/metrics-schema.md @@ -1,14 +1,101 @@ --- title: Metrics Schema summary: 了解 TiDB METRICS SCHEMA 系统数据库。 -aliases: ['/docs-cn/dev/reference/system-databases/metrics-schema/'] +aliases: ['/docs-cn/dev/reference/system-databases/metrics-schema/','/zh/tidb/dev/system-table-metrics-schema/','/docs-cn/dev/system-tables/system-table-metrics-schema/'] --- # Metrics Schema -为了能够动态地观察并对比不同时间段的集群情况,TiDB 4.0 诊断系统添加了集群监控系统表。所有表都在 `metrics_schema` 数据库中,可以通过 SQL 的方式查询监控。实际上,SQL 诊断,以及 `metrics_summary`,`metrics_summary_by_label`,`inspection_result` 这三个监控相关的汇总表数据都是通过查询 metrics schema 库中的各种监控表来获取信息的。目前添加的系统表数量较多,用户可以通过 [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md) 查询这些表的相关信息。 +`METRICS_SCHEMA` 是基于 Prometheus 中 TiDB 监控指标的一组视图。每个表的 PromQL(Prometheus 查询语言)的源均可在 [`INFORMATION_SCHEMA.METRICS_TABLES`](/information-schema/information-schema-metrics-tables.md) 表中找到。 -## 监控表的使用与原理 +{{< copyable "sql" >}} + +```sql +use metrics_schema; +SELECT * FROM uptime; +SELECT * FROM information_schema.metrics_tables WHERE table_name='uptime'\G +``` + +```sql ++----------------------------+-----------------+------------+--------------------+ +| time | instance | job | value | ++----------------------------+-----------------+------------+--------------------+ +| 2020-07-06 15:26:26.203000 | 127.0.0.1:10080 | tidb | 123.60300016403198 | +| 2020-07-06 15:27:26.203000 | 127.0.0.1:10080 | tidb | 183.60300016403198 | +| 2020-07-06 15:26:26.203000 | 127.0.0.1:20180 | tikv | 123.60300016403198 | +| 2020-07-06 15:27:26.203000 | 127.0.0.1:20180 | tikv | 183.60300016403198 | +| 2020-07-06 15:26:26.203000 | 127.0.0.1:2379 | pd | 123.60300016403198 | +| 2020-07-06 15:27:26.203000 | 127.0.0.1:2379 | pd | 183.60300016403198 | +| 2020-07-06 15:26:26.203000 | 127.0.0.1:9090 | prometheus | 123.72300004959106 | +| 2020-07-06 15:27:26.203000 | 127.0.0.1:9090 | prometheus | 183.72300004959106 | ++----------------------------+-----------------+------------+--------------------+ +8 rows in set (0.00 sec) +*************************** 1. row *************************** +TABLE_NAME: uptime + PROMQL: (time() - process_start_time_seconds{$LABEL_CONDITIONS}) + LABELS: instance,job + QUANTILE: 0 + COMMENT: TiDB uptime since last restart(second) +1 row in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +show tables; +``` + +```sql ++---------------------------------------------------+ +| Tables_in_metrics_schema | ++---------------------------------------------------+ +| abnormal_stores | +| etcd_disk_wal_fsync_rate | +| etcd_wal_fsync_duration | +| etcd_wal_fsync_total_count | +| etcd_wal_fsync_total_time | +| go_gc_count | +| go_gc_cpu_usage | +| go_gc_duration | +| go_heap_mem_usage | +| go_threads | +| goroutines_count | +| node_cpu_usage | +| node_disk_available_size | +| node_disk_io_util | +| node_disk_iops | +| node_disk_read_latency | +| node_disk_size | +.. +| tikv_storage_async_request_total_time | +| tikv_storage_async_requests | +| tikv_storage_async_requests_total_count | +| tikv_storage_command_ops | +| tikv_store_size | +| tikv_thread_cpu | +| tikv_thread_nonvoluntary_context_switches | +| tikv_thread_voluntary_context_switches | +| tikv_threads_io | +| tikv_threads_state | +| tikv_total_keys | +| tikv_wal_sync_duration | +| tikv_wal_sync_max_duration | +| tikv_worker_handled_tasks | +| tikv_worker_handled_tasks_total_num | +| tikv_worker_pending_tasks | +| tikv_worker_pending_tasks_total_num | +| tikv_write_stall_avg_duration | +| tikv_write_stall_max_duration | +| tikv_write_stall_reason | +| up | +| uptime | ++---------------------------------------------------+ +626 rows in set (0.00 sec) +``` + +`METRICS_SCHEMA` 是监控相关的 summary 表的数据源,例如 [`metrics_summary`](/information-schema/information-schema-metrics-summary.md)、[`metrics_summary_by_label`](/information-schema/information-schema-metrics-summary.md) 和 [`inspection_summary`](/information-schema/information-schema-inspection-summary.md)。 + +## 更多例子 下面以 `metrics_schema` 中的 `tidb_query_duration` 监控表为例,介绍监控表相关的使用和原理,其他的监控表原理均类似。 From abe1aa4ed5d19df9d9a7b34a9665b88d59d27b86 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 19:55:36 +0800 Subject: [PATCH 17/28] rename/update mysql Schema --- metrics-schema.md | 2 +- .../system-table-overview.md => mysql-schema.md | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) rename system-tables/system-table-overview.md => mysql-schema.md (64%) diff --git a/metrics-schema.md b/metrics-schema.md index 6b042fa4a97c..5fc03e52a194 100644 --- a/metrics-schema.md +++ b/metrics-schema.md @@ -1,6 +1,6 @@ --- title: Metrics Schema -summary: 了解 TiDB METRICS SCHEMA 系统数据库。 +summary: 了解 TiDB `METRICS SCHEMA` 系统数据库。 aliases: ['/docs-cn/dev/reference/system-databases/metrics-schema/','/zh/tidb/dev/system-table-metrics-schema/','/docs-cn/dev/system-tables/system-table-metrics-schema/'] --- diff --git a/system-tables/system-table-overview.md b/mysql-schema.md similarity index 64% rename from system-tables/system-table-overview.md rename to mysql-schema.md index 3146e1d59559..b4db48f75cca 100644 --- a/system-tables/system-table-overview.md +++ b/mysql-schema.md @@ -1,11 +1,12 @@ --- -title: TiDB 系统表 -aliases: ['/docs-cn/dev/reference/system-databases/mysql/'] +title: mysql Schema +summary: 了解 TiDB 系统表。 +aliases: ['/docs-cn/dev/reference/system-databases/mysql/','/zh/tidb/dev/system-table-overview/','/docs-cn/dev/system-tables/system-table-overview/'] --- -# TiDB 系统表 +# `mysql` Schema -本文档主要介绍 TiDB 支持的系统表。 +`mysql` 库里存储的是 TiDB 系统表。该设计类似于 MySQL 中的 `mysql` 库,其中 `mysql.user` 之类的表可以直接编辑。该库还包含许多 MySQL 的扩展表。 ## 权限系统表 From 246c8ba2a0cfbdff8a6908f47246830d399b238d Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:03:37 +0800 Subject: [PATCH 18/28] rename/update sql-diagnostics --- .../information-schema-sql-diagnostics.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) rename system-tables/system-table-sql-diagnostics.md => information-schema/information-schema-sql-diagnostics.md (54%) diff --git a/system-tables/system-table-sql-diagnostics.md b/information-schema/information-schema-sql-diagnostics.md similarity index 54% rename from system-tables/system-table-sql-diagnostics.md rename to information-schema/information-schema-sql-diagnostics.md index e77848e50180..73327edae989 100644 --- a/system-tables/system-table-sql-diagnostics.md +++ b/information-schema/information-schema-sql-diagnostics.md @@ -1,7 +1,7 @@ --- title: SQL 诊断 summary: 了解 SQL 诊断功能。 -aliases: ['/docs-cn/dev/reference/system-databases/sql-diagnosis/','/docs-cn/dev/system-tables/system-table-sql-diagnosis/','/zh/tidb/dev/check-cluster-status-using-sql-statements','/docs-cn/dev/reference/performance/check-cluster-status-using-sql-statements/'] +aliases: ['/docs-cn/dev/reference/system-databases/sql-diagnosis/','/docs-cn/dev/system-tables/system-table-sql-diagnosis/','/zh/tidb/dev/check-cluster-status-using-sql-statements','/docs-cn/dev/reference/performance/check-cluster-status-using-sql-statements/','/zh/tidb/dev/system-table-sql-diagnostics/','/docs-cn/dev/system-tables/system-table-sql-diagnostics/'] --- # SQL 诊断 @@ -24,29 +24,29 @@ SQL 诊断共分三大块: 集群信息表将一个集群中的所有实例的信息都汇聚在一起,让用户仅通过一条 SQL 就能查询整个集群相关信息。 集群信息表列表如下: -* 集群拓扑表 [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) 用于获取集群当前的拓扑信息,以及各个实例的版本、版本对应的 Git Hash、各实例的启动时间、各实例的运行时间。 -* 集群配置表 [`information_schema.cluster_config`](/system-tables/system-table-cluster-config.md) 用于获取集群当前所有实例的配置。对于 TiDB 4.0 之前的版本,用户必须逐个访问各个实例的 HTTP API 才能获取这些配置信息。 -* 集群硬件表 [`information_schema.cluster_hardware`](/system-tables/system-table-cluster-hardware.md) 用于快速查询集群硬件信息。 -* 集群负载表 [`information_schema.cluster_load`](/system-tables/system-table-cluster-load.md) 用于查询集群不同实例以及不同硬件类型的负载信息。 -* 内核参数表 [`information_schema.cluster_systeminfo`](/system-tables/system-table-cluster-systeminfo.md) 用于查询集群不同实例的内核配置信息。目前支持查询 sysctl 的信息。 -* 集群日志表 [`information_schema.cluster_log`](/system-tables/system-table-cluster-log.md) 用于集群日志查询,通过将查询条件下推到各个实例,降低日志查询对集群的影响,性能影响小于等 grep 命令。 +* 集群拓扑表 [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) 用于获取集群当前的拓扑信息,以及各个实例的版本、版本对应的 Git Hash、各实例的启动时间、各实例的运行时间。 +* 集群配置表 [`information_schema.cluster_config`](/information-schema/information-schema-cluster-config.md) 用于获取集群当前所有实例的配置。对于 TiDB 4.0 之前的版本,用户必须逐个访问各个实例的 HTTP API 才能获取这些配置信息。 +* 集群硬件表 [`information_schema.cluster_hardware`](/information-schema/information-schema-cluster-hardware.md) 用于快速查询集群硬件信息。 +* 集群负载表 [`information_schema.cluster_load`](/information-schema/information-schema-cluster-load.md) 用于查询集群不同实例以及不同硬件类型的负载信息。 +* 内核参数表 [`information_schema.cluster_systeminfo`](/information-schema/information-schema-cluster-systeminfo.md) 用于查询集群不同实例的内核配置信息。目前支持查询 sysctl 的信息。 +* 集群日志表 [`information_schema.cluster_log`](/information-schema/information-schema-cluster-log.md) 用于集群日志查询,通过将查询条件下推到各个实例,降低日志查询对集群的影响,性能影响小于等 grep 命令。 -TiDB 4.0 之前的系统表,只能查看当前实例信息,TiDB 4.0 实现了对应的集群表,可以在单个 TiDB 实例上拥有整个集群的全局视图。这些表目前都位于 [`information_schema`](/system-tables/system-table-information-schema.md) 中,查询方式与其他 `information_schema` 系统表一致。 +TiDB 4.0 之前的系统表,只能查看当前实例信息,TiDB 4.0 实现了对应的集群表,可以在单个 TiDB 实例上拥有整个集群的全局视图。这些表目前都位于 `information_schema` 中,查询方式与其他 `information_schema` 系统表一致。 ## 集群监控表 为了能够动态地观察并对比不同时间段的集群情况,TiDB 4.0 诊断系统添加了集群监控系统表。所有监控表都在 `metrics_schema` 中,可以通过 SQL 的方式查询监控信息。SQL 查询监控允许用户对整个集群的所有监控进行关联查询,并对比不同时间段的结果,迅速找出性能瓶颈。 -* [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md):由于目前添加的系统表数量较多,因此用户可以通过该表查询这些监控表的相关元信息。 +* [`information_schema.metrics_tables`](/information-schema/information-schema-metrics-tables.md):由于目前添加的系统表数量较多,因此用户可以通过该表查询这些监控表的相关元信息。 由于 TiDB 集群的监控指标数量较大,因此 TiDB 4.0 提供以下监控汇总表: -* 监控汇总表 [`information_schema.metrics_summary`](/system-tables/system-table-metrics-summary.md) 用于汇总所有监控数据,以提升用户排查各监控指标的效率。 -* 监控汇总并按 label 聚合表 [`information_schema.metrics_summary_by_label`](/system-tables/system-table-metrics-summary.md) 同样用于汇总所有监控数据,但该表会对各项监控的不同的 label 进行聚合统计。 +* 监控汇总表 [`information_schema.metrics_summary`](/information-schema/information-schema-metrics-summary.md) 用于汇总所有监控数据,以提升用户排查各监控指标的效率。 +* 监控汇总并按 label 聚合表 [`information_schema.metrics_summary_by_label`](/information-schema/information-schema-metrics-summary.md) 同样用于汇总所有监控数据,但该表会对各项监控的不同的 label 进行聚合统计。 ## 自动诊断 以上集群信息表和集群监控表均需要用户手动执行 SQL 语句来排查集群问题。TiDB 4.0 中添加了自动诊断功能,根据已有的基础信息表,提供诊断相关的系统表,使诊断自动执行。自动诊断相关的系统表如下: -* 诊断结果表 [`information_schema.inspection_result`](/system-tables/system-table-inspection-result.md) 用于展示对系统的诊断结果。诊断是惰性触发,使用 `select * from inspection_result` 会触发所有诊断规则对系统进行诊断,并在结果中展示系统中的故障或风险。 -* 诊断汇总表 [`information_schema.inspection_summary`](/system-tables/system-table-inspection-summary.md) 用于对特定链路或模块的监控进行汇总,用户可以根据整个模块或链路的上下文来排查定位问题。 +* 诊断结果表 [`information_schema.inspection_result`](/information-schema/information-schema-inspection-result.md) 用于展示对系统的诊断结果。诊断是惰性触发,使用 `select * from inspection_result` 会触发所有诊断规则对系统进行诊断,并在结果中展示系统中的故障或风险。 +* 诊断汇总表 [`information_schema.inspection_summary`](/information-schema/information-schema-inspection-summary.md) 用于对特定链路或模块的监控进行汇总,用户可以根据整个模块或链路的上下文来排查定位问题。 From c8fc79f7fd5f93d8e02905eacb15ca57c80c6bb3 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:05:54 +0800 Subject: [PATCH 19/28] Update TOC.md --- TOC.md | 56 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/TOC.md b/TOC.md index 3b0bc9c1039e..6ee184f3a366 100644 --- a/TOC.md +++ b/TOC.md @@ -387,20 +387,48 @@ + [分区表](/partitioned-table.md) + [字符集和排序规则](/character-set-and-collation.md) + 系统表 - + [`mysql`](/system-tables/system-table-overview.md) - + [`information_schema`](/system-tables/system-table-information-schema.md) - + sql-diagnosis - + [`cluster_info`](/system-tables/system-table-cluster-info.md) - + [`cluster_hardware`](/system-tables/system-table-cluster-hardware.md) - + [`cluster_config`](/system-tables/system-table-cluster-config.md) - + [`cluster_load`](/system-tables/system-table-cluster-load.md) - + [`cluster_systeminfo`](/system-tables/system-table-cluster-systeminfo.md) - + [`cluster_log`](/system-tables/system-table-cluster-log.md) - + [`metrics_schema`](/system-tables/system-table-metrics-schema.md) - + [`metrics_tables`](/system-tables/system-table-metrics-tables.md) - + [`metrics_summary`](/system-tables/system-table-metrics-summary.md) - + [`inspection_result`](/system-tables/system-table-inspection-result.md) - + [`inspection_summary`](/system-tables/system-table-inspection-summary.md) + + [`mysql`](/mysql-schema.md) + + INFORMATION_SCHEMA + + [Overview](/information-schema/information-schema.md) + + [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md) + + [`CHARACTER_SETS`](/information-schema/information-schema-character-sets.md) + + [`CLUSTER_CONFIG`](/information-schema/information-schema-cluster-config.md) + + [`CLUSTER_HARDWARE`](/information-schema/information-schema-cluster-hardware.md) + + [`CLUSTER_INFO`](/information-schema/information-schema-cluster-info.md) + + [`CLUSTER_LOAD`](/information-schema/information-schema-cluster-load.md) + + [`CLUSTER_LOG`](/information-schema/information-schema-cluster-log.md) + + [`CLUSTER_SYSTEMINFO`](/information-schema/information-schema-cluster-systeminfo.md) + + [`COLLATIONS`](/information-schema/information-schema-collations.md) + + [`COLLATION_CHARACTER_SET_APPLICABILITY`](/information-schema/information-schema-collation-character-set-applicability.md) + + [`COLUMNS`](/information-schema/information-schema-columns.md) + + [`DDL_JOBS`](/information-schema/information-schema-ddl-jobs.md) + + [`ENGINES`](/information-schema/information-schema-engines.md) + + [`INSPECTION_RESULT`](/information-schema/information-schema-inspection-result.md) + + [`INSPECTION_RULES`](/information-schema/information-schema-inspection-rules.md) + + [`INSPECTION_SUMMARY`](/information-schema/information-schema-inspection-summary.md) + + [`KEY_COLUMN_USAGE`](/information-schema/information-schema-key-column-usage.md) + + [`METRICS_SUMMARY`](/information-schema/information-schema-metrics-summary.md) + + [`METRICS_TABLES`](/information-schema/information-schema-metrics-tables.md) + + [`PARTITIONS`](/information-schema/information-schema-partitions.md) + + [`PROCESSLIST`](/information-schema/information-schema-processlist.md) + + [`SCHEMATA`](/information-schema/information-schema-schemata.md) + + [`SEQUENCES`](/information-schema/information-schema-sequences.md) + + [`SESSION_VARIABLES`](/information-schema/information-schema-session-variables.md) + + [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md) + + [`STATISTICS`](/information-schema/information-schema-statistics.md) + + [`TABLES`](/information-schema/information-schema-tables.md) + + [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) + + [`TABLE_STORAGE_STATS`](/information-schema/information-schema-table-storage-stats.md) + + [`TIDB_HOT_REGIONS`](/information-schema/information-schema-tidb-hot-regions.md) + + [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md) + + [`TIDB_SERVERS_INFO`](/information-schema/information-schema-tidb-servers-info.md) + + [`TIFLASH_REPLICA`](/information-schema/information-schema-tiflash-replica.md) + + [`TIKV_REGION_PEERS`](/information-schema/information-schema-tikv-region-peers.md) + + [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) + + [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) + + [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) + + [`VIEWS`](/information-schema/information-schema-views.md) + + [`METRICS_SCHEMA`](/metrics-schema.md) + UI + TiDB Dashboard + [简介](/dashboard/dashboard-intro.md) From 80b2f6b3766c12a0f015426e24b764cf2200a865 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:19:38 +0800 Subject: [PATCH 20/28] fix links --- TOC.md | 2 +- _index.md | 2 +- dashboard/dashboard-diagnostics-report.md | 4 ++-- faq/deploy-and-maintain-faq.md | 4 ++-- identify-slow-queries.md | 4 ++-- information-schema/information-schema-inspection-result.md | 4 ++-- sql-statements/sql-statement-show-analyze-status.md | 2 +- whats-new-in-tidb-4.0.md | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/TOC.md b/TOC.md index 6ee184f3a366..f2abab60385b 100644 --- a/TOC.md +++ b/TOC.md @@ -83,7 +83,7 @@ + [TiFlash 报警规则与处理方法](/tiflash/tiflash-alert-rules.md) + 故障诊断 + [定位慢查询](/identify-slow-queries.md) - + [SQL 诊断](/system-tables/system-table-sql-diagnostics.md) + + [SQL 诊断](/information-schema/information-schema-sql-diagnostics.md) + [定位消耗系统资源多的查询](/identify-expensive-queries.md) + [SQL 语句统计](/statement-summary-tables.md) + [TiDB 集群常见问题](/troubleshoot-tidb-cluster.md) diff --git a/_index.md b/_index.md index f6bf64d5a17e..c27125ca46d6 100755 --- a/_index.md +++ b/_index.md @@ -78,7 +78,7 @@ TiDB 是 PingCAP 公司自主设计、研发的开源分布式关系型数据库 故障诊断 - [定位慢查询](/identify-slow-queries.md) -- [SQL 诊断](/system-tables/system-table-sql-diagnostics.md) +- [SQL 诊断](/information-schema/information-schema-sql-diagnostics.md) - [热点问题处理](/troubleshoot-hot-spot-issues.md) - [磁盘 I/O 过高](/troubleshoot-high-disk-io.md) - [TiCDC 常见问题](/ticdc/troubleshoot-ticdc.md) diff --git a/dashboard/dashboard-diagnostics-report.md b/dashboard/dashboard-diagnostics-report.md index 3c784cfe3997..83c519060c8f 100644 --- a/dashboard/dashboard-diagnostics-report.md +++ b/dashboard/dashboard-diagnostics-report.md @@ -60,7 +60,7 @@ title: TiDB Dashboard 诊断报告 #### Cluster Info -**Cluster Info** 为集群拓扑信息。表中信息来自 TiDB 的 [information_schema.cluster_info](/system-tables/system-table-cluster-info.md) 系统表。 +**Cluster Info** 为集群拓扑信息。表中信息来自 TiDB 的 [information_schema.cluster_info](/information-schema/information-schema-cluster-info.md) 系统表。 ![Cluster Info 报表](/media/dashboard/dashboard-diagnostics-cluster-info.png) @@ -76,7 +76,7 @@ title: TiDB Dashboard 诊断报告 ### 诊断信息 -TiDB 内置自动诊断的结果,具体各字段含义以及介绍可以参考 [information_schema.inspection_result](/system-tables/system-table-inspection-result.md) 系统表的内容。 +TiDB 内置自动诊断的结果,具体各字段含义以及介绍可以参考 [information_schema.inspection_result](/information-schema/information-schema-inspection-result.md) 系统表的内容。 ### 负载信息 diff --git a/faq/deploy-and-maintain-faq.md b/faq/deploy-and-maintain-faq.md index d9cfb0f5717e..dde55255abde 100644 --- a/faq/deploy-and-maintain-faq.md +++ b/faq/deploy-and-maintain-faq.md @@ -194,7 +194,7 @@ Direct 模式就是把写入请求直接封装成 I/O 指令发到磁盘,这 #### TiDB 有哪些系统表? -和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统数据库](/system-tables/system-table-overview.md)文档。 +和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统数据库](/information-schema/information-schema-overview.md)文档。 #### TiDB 各节点服务器下是否有日志文件,如何管理? @@ -328,7 +328,7 @@ Client 连接只能通过 TiDB 访问集群,TiDB 负责连接 PD 与 TiKV,PD #### Information_schema 能否支持更多真实信息? -Information_schema 库里面的表主要是为了兼容 MySQL 而存在,有些第三方软件会查询里面的信息。在目前 TiDB 的实现中,里面大部分只是一些空表。后续随着 TiDB 的升级,会提供更多的参数信息。当前 TiDB 支持的 Information\_schema 请参考 [TiDB 系统数据库说明文档](/system-tables/system-table-information-schema.md)。 +Information_schema 库里面的表主要是为了兼容 MySQL 而存在,有些第三方软件会查询里面的信息。在目前 TiDB 的实现中,里面大部分只是一些空表。后续随着 TiDB 的升级,会提供更多的参数信息。当前 TiDB 支持的 Information\_schema 请参考 [TiDB 系统数据库说明文档](/information-schema/information-schema.md)。 #### TiDB Backoff type 主要原因? diff --git a/identify-slow-queries.md b/identify-slow-queries.md index 0b6166423ff1..3b155315edd6 100644 --- a/identify-slow-queries.md +++ b/identify-slow-queries.md @@ -110,7 +110,7 @@ Slow Query 基础信息: ## 慢日志内存映射表 -用户可通过查询 `INFORMATION_SCHEMA.SLOW_QUERY` 表来查询慢查询日志中的内容,表中列名和慢日志中字段名一一对应,表结构可查看 [Information Schema](/system-tables/system-table-information-schema.md#information-schema) 中关于 `SLOW_QUERY` 表的介绍。 +用户可通过查询 `INFORMATION_SCHEMA.SLOW_QUERY` 表来查询慢查询日志中的内容,表中列名和慢日志中字段名一一对应,表结构可查看 [`SLOW_QUERY` 表](/information-schema/information-schema-slow-query.md) 中的介绍。 > **注意:** > @@ -162,7 +162,7 @@ where time > '2020-03-10 00:00:00' > > 如果指定时间范围内的慢日志文件被删除,或者并没有慢查询,则查询结果会返回空。 -TiDB 4.0 中新增了 [`CLUSTER_SLOW_QUERY`](/system-tables/system-table-information-schema.md#cluster_slow_query-表) 系统表,用来查询所有 TiDB 节点的慢查询信息,表结构在 `SLOW_QUERY` 的基础上多增加了 `INSTANCE` 列,表示该行慢查询信息来自的 TiDB 节点地址。使用方式和 [`SLOW_QUERY`](/system-tables/system-table-information-schema.md#slow_query-表) 系统表一样。 +TiDB 4.0 中新增了 [`CLUSTER_SLOW_QUERY`](/information-schema/information-schema-slow-query.md#cluster_slow_query-table) 系统表,用来查询所有 TiDB 节点的慢查询信息,表结构在 `SLOW_QUERY` 的基础上多增加了 `INSTANCE` 列,表示该行慢查询信息来自的 TiDB 节点地址。使用方式和 [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md) 系统表一样。 关于查询 `CLUSTER_SLOW_QUERY` 表,TiDB 会把相关的计算和判断下推到其他节点执行,而不是把其他节点的慢查询数据都取回来在一台 TiDB 上执行。 diff --git a/information-schema/information-schema-inspection-result.md b/information-schema/information-schema-inspection-result.md index 7d5cd5680e2c..93295aeff7f1 100644 --- a/information-schema/information-schema-inspection-result.md +++ b/information-schema/information-schema-inspection-result.md @@ -254,7 +254,7 @@ DETAILS | the cluster has 2 different tidb versions, execute the sql to see mo `critical-error` 诊断规则执行以下两个诊断规则: -* 通过查询 [metrics schema](/system-tables/system-table-metrics-schema.md) 数据库中相关的监控系统表,检测集群是否有出现以下比较严重的错误: +* 通过查询 [metrics schema](/information-schema/information-schema-metrics-schema.md) 数据库中相关的监控系统表,检测集群是否有出现以下比较严重的错误: | 组件 | 错误名字 | 相关监控表 | 错误说明 | | ---- | ---- | ---- | ---- | @@ -270,7 +270,7 @@ DETAILS | the cluster has 2 different tidb versions, execute the sql to see mo ### `threshold-check` 诊断规则 -`threshold-check` 诊断规则通过查询 [metrics schema](/system-tables/system-table-metrics-schema.md) 数据库中相关的监控系统表,检测集群中以下指标是否超出阈值: +`threshold-check` 诊断规则通过查询 [metrics schema](/metrics-schema.md) 数据库中相关的监控系统表,检测集群中以下指标是否超出阈值: | 组件 | 监控指标 | 相关监控表 | 预期值 | 说明 | | :---- | :---- | :---- | :---- | :---- | diff --git a/sql-statements/sql-statement-show-analyze-status.md b/sql-statements/sql-statement-show-analyze-status.md index ad7c63ac0740..54d0b8e7e873 100644 --- a/sql-statements/sql-statement-show-analyze-status.md +++ b/sql-statements/sql-statement-show-analyze-status.md @@ -45,4 +45,4 @@ show analyze status; ## 另请参阅 -* [ANALYZE_STATUS 表](/system-tables/system-table-information-schema.md#analyze_status-表) \ No newline at end of file +* [ANALYZE_STATUS 表](/information-schema/information-schema-analyze-status.md) \ No newline at end of file diff --git a/whats-new-in-tidb-4.0.md b/whats-new-in-tidb-4.0.md index 5e77abd75ef8..4a5efedbc519 100644 --- a/whats-new-in-tidb-4.0.md +++ b/whats-new-in-tidb-4.0.md @@ -57,7 +57,7 @@ TiUP 是 4.0 版本中新推出的包管理器的工具,主要用于管理 TiD - 支持 Index Merge 功能,Index Merge 是一种新的表访问方式,当查询只涉及到单张表时,优化器会自动根据查询条件读取多个索引数据并对结果求并集,提升查询单张表时的性能。详情参阅:[Index Merge](/query-execution-plan.md#indexmerge-示例)。 - 支持表达式索引 (Expression Index) 功能,表达式索引也叫函数索引,在创建索引时索引的字段不一定要是一个具体的列,而可以由一个或者多个列计算出来的表达式。对于快速访问那些基于计算结果的表非常有用(实验特性)。详情参阅:[表达式索引](/sql-statements/sql-statement-create-index.md)。 - 支持 AutoRandom Key(实验特性)作为 TiDB 在列属性上的扩展语法,AutoRandom 被设计用于解决自增主键列的写热点问题,为使用自增主键列的用户提供最低成本的 MySQL 迁移方案。详情参阅:[AutoRandom Key](/auto-random.md)。 -- 新增集群拓扑、配置信息、日志信息、硬件信息、操作系统信息、慢查询信息等系统表等,帮助 DBA 通过 SQL 快速了解、分析系统的各项指标,详情参阅:[infromation_shema](/system-tables/system-table-information-schema.md),具体信息如下: +- 新增集群拓扑、配置信息、日志信息、硬件信息、操作系统信息、慢查询信息等系统表等,帮助 DBA 通过 SQL 快速了解、分析系统的各项指标,详情参阅:[infromation_shema](/information-schema/information-schema.md),具体信息如下: - 新增集群拓扑、配置、日志、硬件、操作系统等信息表,帮助 DBA 快速了集群配置、状态信息: From 6e3d8657adce2efad2d17e75d109e33941d29120 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:20:43 +0800 Subject: [PATCH 21/28] Update information-schema.md --- information-schema/information-schema.md | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index e606ed13dd2b..5eecbe202f5b 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -80,25 +80,3 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。 | [`TIKV_REGION_PEERS`](/information-schema/information-schema-tikv-region-peers.md) | 提供 Region 存储位置的详细信息。 | | [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | 提供 Region 的统计信息。 | | [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | 提供 TiKV 服务器的基本信息。 | - -## 不支持的 Information Schema 表 - -TiDB 包含以下 `INFORMATION_SCHEMA` 表,但仅会返回空行: - -* `COLUMN_PRIVILEGES` -* `EVENTS` -* `FILES` -* `GLOBAL_STATUS` -* `GLOBAL_VARIABLES` -* `OPTIMIZER_TRACE` -* `PARAMETERS` -* `PARTITIONS` -* `PLUGINS` -* `PROFILING` -* `REFERENTIAL_CONSTRAINTS` -* `ROUTINES` -* `SCHEMA_PRIVILEGES` -* `SESSION_STATUS` -* `TABLESPACES` -* `TABLE_PRIVILEGES` -* `TRIGGERS` From f71a2e3ee7e800c2950042d38e03a89ad7353f14 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:33:20 +0800 Subject: [PATCH 22/28] add 6 files --- .../information-schema-inspection-rules.md | 55 +++++++++ .../information-schema-partitions.md | 111 ++++++++++++++++++ .../information-schema-sequences.md | 64 ++++++++++ .../information-schema-table-storage-stats.md | 52 ++++++++ .../information-schema-tidb-servers-info.md | 50 ++++++++ .../information-schema-tiflash-replica.md | 30 +++++ 6 files changed, 362 insertions(+) create mode 100644 information-schema/information-schema-inspection-rules.md create mode 100644 information-schema/information-schema-partitions.md create mode 100644 information-schema/information-schema-sequences.md create mode 100644 information-schema/information-schema-table-storage-stats.md create mode 100644 information-schema/information-schema-tidb-servers-info.md create mode 100644 information-schema/information-schema-tiflash-replica.md diff --git a/information-schema/information-schema-inspection-rules.md b/information-schema/information-schema-inspection-rules.md new file mode 100644 index 000000000000..2c5c832296d3 --- /dev/null +++ b/information-schema/information-schema-inspection-rules.md @@ -0,0 +1,55 @@ +--- +title: INSPECTION_RULES +summary: 了解 information_schema 表 `INSPECTION_RULES`。 +--- + +# INSPECTION_RULES + +`INSPECTION_RULES` 表提供在检查结果中运行哪些诊断测试的信息,示例用法参见[`inspection-result` 表](/information-schema/information-schema-inspection-result.md)。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC inspection_rules; +``` + +```sql ++---------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------+--------------+------+------+---------+-------+ +| NAME | varchar(64) | YES | | NULL | | +| TYPE | varchar(64) | YES | | NULL | | +| COMMENT | varchar(256) | YES | | NULL | | ++---------+--------------+------+------+---------+-------+ +3 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM inspection_rules; +``` + +```sql ++-----------------+------------+---------+ +| NAME | TYPE | COMMENT | ++-----------------+------------+---------+ +| config | inspection | | +| version | inspection | | +| node-load | inspection | | +| critical-error | inspection | | +| threshold-check | inspection | | +| ddl | summary | | +| gc | summary | | +| pd | summary | | +| query-summary | summary | | +| raftstore | summary | | +| read-link | summary | | +| rocksdb | summary | | +| stats | summary | | +| wait-events | summary | | +| write-link | summary | | ++-----------------+------------+---------+ +15 rows in set (0.00 sec) +``` diff --git a/information-schema/information-schema-partitions.md b/information-schema/information-schema-partitions.md new file mode 100644 index 000000000000..29af83145158 --- /dev/null +++ b/information-schema/information-schema-partitions.md @@ -0,0 +1,111 @@ +--- +title: PARTITIONS +summary: 了解 information_schema 表 `PARTITIONS`。 +--- + +# PARTITIONS + +`PARTITIONS` 表提供有关分区表的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC partitions; +``` + +```sql ++-------------------------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------------------------------+--------------+------+------+---------+-------+ +| TABLE_CATALOG | varchar(512) | YES | | NULL | | +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| PARTITION_NAME | varchar(64) | YES | | NULL | | +| SUBPARTITION_NAME | varchar(64) | YES | | NULL | | +| PARTITION_ORDINAL_POSITION | bigint(21) | YES | | NULL | | +| SUBPARTITION_ORDINAL_POSITION | bigint(21) | YES | | NULL | | +| PARTITION_METHOD | varchar(18) | YES | | NULL | | +| SUBPARTITION_METHOD | varchar(12) | YES | | NULL | | +| PARTITION_EXPRESSION | longblob | YES | | NULL | | +| SUBPARTITION_EXPRESSION | longblob | YES | | NULL | | +| PARTITION_DESCRIPTION | longblob | YES | | NULL | | +| TABLE_ROWS | bigint(21) | YES | | NULL | | +| AVG_ROW_LENGTH | bigint(21) | YES | | NULL | | +| DATA_LENGTH | bigint(21) | YES | | NULL | | +| MAX_DATA_LENGTH | bigint(21) | YES | | NULL | | +| INDEX_LENGTH | bigint(21) | YES | | NULL | | +| DATA_FREE | bigint(21) | YES | | NULL | | +| CREATE_TIME | datetime | YES | | NULL | | +| UPDATE_TIME | datetime | YES | | NULL | | +| CHECK_TIME | datetime | YES | | NULL | | +| CHECKSUM | bigint(21) | YES | | NULL | | +| PARTITION_COMMENT | varchar(80) | YES | | NULL | | +| NODEGROUP | varchar(12) | YES | | NULL | | +| TABLESPACE_NAME | varchar(64) | YES | | NULL | | ++-------------------------------+--------------+------+------+---------+-------+ +25 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +CREATE TABLE test.t1 (id INT NOT NULL PRIMARY KEY) PARTITION BY HASH (id) PARTITIONS 2; +SELECT * FROM partitions WHERE table_schema='test' AND table_name='t1'\G +``` + +```sql +*************************** 1. row *************************** + TABLE_CATALOG: def + TABLE_SCHEMA: test + TABLE_NAME: t1 + PARTITION_NAME: p0 + SUBPARTITION_NAME: NULL + PARTITION_ORDINAL_POSITION: 1 +SUBPARTITION_ORDINAL_POSITION: NULL + PARTITION_METHOD: HASH + SUBPARTITION_METHOD: NULL + PARTITION_EXPRESSION: `id` + SUBPARTITION_EXPRESSION: NULL + PARTITION_DESCRIPTION: + TABLE_ROWS: 0 + AVG_ROW_LENGTH: 0 + DATA_LENGTH: 0 + MAX_DATA_LENGTH: 0 + INDEX_LENGTH: 0 + DATA_FREE: 0 + CREATE_TIME: 2020-07-06 16:35:28 + UPDATE_TIME: NULL + CHECK_TIME: NULL + CHECKSUM: NULL + PARTITION_COMMENT: + NODEGROUP: NULL + TABLESPACE_NAME: NULL +*************************** 2. row *************************** + TABLE_CATALOG: def + TABLE_SCHEMA: test + TABLE_NAME: t1 + PARTITION_NAME: p1 + SUBPARTITION_NAME: NULL + PARTITION_ORDINAL_POSITION: 2 +SUBPARTITION_ORDINAL_POSITION: NULL + PARTITION_METHOD: HASH + SUBPARTITION_METHOD: NULL + PARTITION_EXPRESSION: `id` + SUBPARTITION_EXPRESSION: NULL + PARTITION_DESCRIPTION: + TABLE_ROWS: 0 + AVG_ROW_LENGTH: 0 + DATA_LENGTH: 0 + MAX_DATA_LENGTH: 0 + INDEX_LENGTH: 0 + DATA_FREE: 0 + CREATE_TIME: 2020-07-06 16:35:28 + UPDATE_TIME: NULL + CHECK_TIME: NULL + CHECKSUM: NULL + PARTITION_COMMENT: + NODEGROUP: NULL + TABLESPACE_NAME: NULL +2 rows in set (0.00 sec) +``` diff --git a/information-schema/information-schema-sequences.md b/information-schema/information-schema-sequences.md new file mode 100644 index 000000000000..3d0e1d7e2911 --- /dev/null +++ b/information-schema/information-schema-sequences.md @@ -0,0 +1,64 @@ +--- +title: SEQUENCES +summary: 了解 information_schema 表 `SEQUENCES`。 +--- + +# SEQUENCES + +`SEQUENCES` 表提供了有关序列的信息。TiDB 中[序列](/sql-statements/sql-statement-create-sequence.md)的功能是参照 MariaDB 中的类似功能来实现的。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC sequences; +``` + +```sql ++-----------------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-----------------+--------------+------+------+---------+-------+ +| TABLE_CATALOG | varchar(512) | NO | | NULL | | +| SEQUENCE_SCHEMA | varchar(64) | NO | | NULL | | +| SEQUENCE_NAME | varchar(64) | NO | | NULL | | +| CACHE | tinyint(4) | NO | | NULL | | +| CACHE_VALUE | bigint(21) | YES | | NULL | | +| CYCLE | tinyint(4) | NO | | NULL | | +| INCREMENT | bigint(21) | NO | | NULL | | +| MAX_VALUE | bigint(21) | YES | | NULL | | +| MIN_VALUE | bigint(21) | YES | | NULL | | +| START | bigint(21) | YES | | NULL | | +| COMMENT | varchar(64) | YES | | NULL | | ++-----------------+--------------+------+------+---------+-------+ +11 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +CREATE SEQUENCE test.seq; +SELECT nextval(test.seq); +SELECT * FROM sequences\G +``` + +```sql ++-------------------+ +| nextval(test.seq) | ++-------------------+ +| 1 | ++-------------------+ +1 row in set (0.01 sec) +*************************** 1. row *************************** + TABLE_CATALOG: def +SEQUENCE_SCHEMA: test + SEQUENCE_NAME: seq + CACHE: 1 + CACHE_VALUE: 1000 + CYCLE: 0 + INCREMENT: 1 + MAX_VALUE: 9223372036854775806 + MIN_VALUE: 1 + START: 1 + COMMENT: +1 row in set (0.00 sec) +``` diff --git a/information-schema/information-schema-table-storage-stats.md b/information-schema/information-schema-table-storage-stats.md new file mode 100644 index 000000000000..4f65ff94356d --- /dev/null +++ b/information-schema/information-schema-table-storage-stats.md @@ -0,0 +1,52 @@ +--- +title: TABLE_STORAGE_STATS +summary: 了解 information_schema 表 `TABLE_STORAGE_STATS`。 +--- + +# TABLE_STORAGE_STATS + +`TABLE_STORAGE_STATS` 表提供有关由存储引擎 (TiKV) 存储的表大小的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC table_storage_stats; +``` + +```sql ++--------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+-------------+------+------+---------+-------+ +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| TABLE_ID | bigint(21) | YES | | NULL | | +| PEER_COUNT | bigint(21) | YES | | NULL | | +| REGION_COUNT | bigint(21) | YES | | NULL | | +| EMPTY_REGION_COUNT | bigint(21) | YES | | NULL | | +| TABLE_SIZE | bigint(64) | YES | | NULL | | +| TABLE_KEYS | bigint(64) | YES | | NULL | | ++--------------------+-------------+------+------+---------+-------+ +8 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +CREATE TABLE test.t1 (id INT); +INSERT INTO test.t1 VALUES (1); +SELECT * FROM table_storage_stats WHERE table_schema = 'test' AND table_name = 't1'\G +``` + +```sql +*************************** 1. row *************************** + TABLE_SCHEMA: test + TABLE_NAME: t1 + TABLE_ID: 56 + PEER_COUNT: 1 + REGION_COUNT: 1 +EMPTY_REGION_COUNT: 1 + TABLE_SIZE: 1 + TABLE_KEYS: 0 +1 row in set (0.00 sec) +``` diff --git a/information-schema/information-schema-tidb-servers-info.md b/information-schema/information-schema-tidb-servers-info.md new file mode 100644 index 000000000000..27240a6a67c7 --- /dev/null +++ b/information-schema/information-schema-tidb-servers-info.md @@ -0,0 +1,50 @@ +--- +title: TIDB_SERVERS_INFO +summary: 了解 information_schema 表 `TIDB_SERVERS_INFO`。 +--- + +# TIDB_SERVERS_INFO + +`TIDB_SERVERS_INFO` 表提供了 TiDB 集群中 TiDB 服务器的信息(即 tidb-server 进程)。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tidb_servers_info; +``` + +```sql ++---------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------------+-------------+------+------+---------+-------+ +| DDL_ID | varchar(64) | YES | | NULL | | +| IP | varchar(64) | YES | | NULL | | +| PORT | bigint(21) | YES | | NULL | | +| STATUS_PORT | bigint(21) | YES | | NULL | | +| LEASE | varchar(64) | YES | | NULL | | +| VERSION | varchar(64) | YES | | NULL | | +| GIT_HASH | varchar(64) | YES | | NULL | | +| BINLOG_STATUS | varchar(64) | YES | | NULL | | ++---------------+-------------+------+------+---------+-------+ +8 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM tidb_servers_info\G +``` + +```sql +*************************** 1. row *************************** + DDL_ID: 771c169d-0a3a-48ea-a93c-a4d6751d3674 + IP: 0.0.0.0 + PORT: 4000 + STATUS_PORT: 10080 + LEASE: 45s + VERSION: 5.7.25-TiDB-v4.0.0-beta.2-720-g0df3b74f5 + GIT_HASH: 0df3b74f55f8f8fbde39bbd5d471783f49dc10f7 +BINLOG_STATUS: Off +1 row in set (0.00 sec) +``` diff --git a/information-schema/information-schema-tiflash-replica.md b/information-schema/information-schema-tiflash-replica.md new file mode 100644 index 000000000000..2f6769bc2063 --- /dev/null +++ b/information-schema/information-schema-tiflash-replica.md @@ -0,0 +1,30 @@ +--- +title: TIFLASH_REPLICA +summary: 了解 information_schema 表 `TIFLASH_REPLICA`。 +--- + +# TIFLASH_REPLICA + +`TIFLASH_REPLICA` 表提供了有关可用的 TiFlash 副本的信息。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tiflash_replica; +``` + +```sql ++-----------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-----------------+-------------+------+------+---------+-------+ +| TABLE_SCHEMA | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| TABLE_ID | bigint(21) | YES | | NULL | | +| REPLICA_COUNT | bigint(64) | YES | | NULL | | +| LOCATION_LABELS | varchar(64) | YES | | NULL | | +| AVAILABLE | tinyint(1) | YES | | NULL | | +| PROGRESS | double | YES | | NULL | | ++-----------------+-------------+------+------+---------+-------+ +7 rows in set (0.01 sec) +``` From 16b23b3ef6f4870741b6670ba8dc1246ca2a12ca Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:41:26 +0800 Subject: [PATCH 23/28] add a file --- .../information-schema-ddl-jobs.md | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 information-schema/information-schema-ddl-jobs.md diff --git a/information-schema/information-schema-ddl-jobs.md b/information-schema/information-schema-ddl-jobs.md new file mode 100644 index 000000000000..ac4c4b992e16 --- /dev/null +++ b/information-schema/information-schema-ddl-jobs.md @@ -0,0 +1,97 @@ +--- +title: DDL_JOBS +summary: 了解 information_schema 表 `DDL_JOBS`。 +--- + +# DDL_JOBS + +`DDL_JOBS` 表为 `ADMIN SHOW DDL JOBS` 命令提供了一个 `INFORMATION_SCHEMA` 接口。它提供了 TiDB 集群中 DDL 操作的当前状态和简短历史记录。 + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC ddl_jobs; +``` + +```sql ++--------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------+-------------+------+------+---------+-------+ +| JOB_ID | bigint(21) | YES | | NULL | | +| DB_NAME | varchar(64) | YES | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| JOB_TYPE | varchar(64) | YES | | NULL | | +| SCHEMA_STATE | varchar(64) | YES | | NULL | | +| SCHEMA_ID | bigint(21) | YES | | NULL | | +| TABLE_ID | bigint(21) | YES | | NULL | | +| ROW_COUNT | bigint(21) | YES | | NULL | | +| START_TIME | datetime | YES | | NULL | | +| END_TIME | datetime | YES | | NULL | | +| STATE | varchar(64) | YES | | NULL | | +| QUERY | varchar(64) | YES | | NULL | | ++--------------+-------------+------+------+---------+-------+ +12 rows in set (0.00 sec) +``` + +{{< copyable "sql" >}} + +```sql +SELECT * FROM ddl_jobs LIMIT 3\G +``` + +```sql +*************************** 1. row *************************** + JOB_ID: 44 + DB_NAME: mysql + TABLE_NAME: opt_rule_blacklist + JOB_TYPE: create table +SCHEMA_STATE: public + SCHEMA_ID: 3 + TABLE_ID: 43 + ROW_COUNT: 0 + START_TIME: 2020-07-06 15:24:27 + END_TIME: 2020-07-06 15:24:27 + STATE: synced + QUERY: CREATE TABLE IF NOT EXISTS mysql.opt_rule_blacklist ( + name char(100) NOT NULL + ); +*************************** 2. row *************************** + JOB_ID: 42 + DB_NAME: mysql + TABLE_NAME: expr_pushdown_blacklist + JOB_TYPE: create table +SCHEMA_STATE: public + SCHEMA_ID: 3 + TABLE_ID: 41 + ROW_COUNT: 0 + START_TIME: 2020-07-06 15:24:27 + END_TIME: 2020-07-06 15:24:27 + STATE: synced + QUERY: CREATE TABLE IF NOT EXISTS mysql.expr_pushdown_blacklist ( + name char(100) NOT NULL, + store_type char(100) NOT NULL DEFAULT 'tikv,tiflash,tidb', + reason varchar(200) + ); +*************************** 3. row *************************** + JOB_ID: 40 + DB_NAME: mysql + TABLE_NAME: stats_top_n + JOB_TYPE: create table +SCHEMA_STATE: public + SCHEMA_ID: 3 + TABLE_ID: 39 + ROW_COUNT: 0 + START_TIME: 2020-07-06 15:24:26 + END_TIME: 2020-07-06 15:24:27 + STATE: synced + QUERY: CREATE TABLE if not exists mysql.stats_top_n ( + table_id bigint(64) NOT NULL, + is_index tinyint(2) NOT NULL, + hist_id bigint(64) NOT NULL, + value longblob, + count bigint(64) UNSIGNED NOT NULL, + index tbl(table_id, is_index, hist_id) + ); +3 rows in set (0.01 sec) +``` From 5178485ebf69c841ec9ae1c56ae117c5e24c0a58 Mon Sep 17 00:00:00 2001 From: yikeke Date: Thu, 30 Jul 2020 20:44:21 +0800 Subject: [PATCH 24/28] fix 2 links --- faq/deploy-and-maintain-faq.md | 2 +- information-schema/information-schema-inspection-result.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/faq/deploy-and-maintain-faq.md b/faq/deploy-and-maintain-faq.md index dde55255abde..d3f1045fe830 100644 --- a/faq/deploy-and-maintain-faq.md +++ b/faq/deploy-and-maintain-faq.md @@ -194,7 +194,7 @@ Direct 模式就是把写入请求直接封装成 I/O 指令发到磁盘,这 #### TiDB 有哪些系统表? -和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统数据库](/information-schema/information-schema-overview.md)文档。 +和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统数据库](/mysql-schema.md)文档。 #### TiDB 各节点服务器下是否有日志文件,如何管理? diff --git a/information-schema/information-schema-inspection-result.md b/information-schema/information-schema-inspection-result.md index 93295aeff7f1..a8ff3cc99b50 100644 --- a/information-schema/information-schema-inspection-result.md +++ b/information-schema/information-schema-inspection-result.md @@ -254,7 +254,7 @@ DETAILS | the cluster has 2 different tidb versions, execute the sql to see mo `critical-error` 诊断规则执行以下两个诊断规则: -* 通过查询 [metrics schema](/information-schema/information-schema-metrics-schema.md) 数据库中相关的监控系统表,检测集群是否有出现以下比较严重的错误: +* 通过查询 [metrics schema](/metrics-schema.md) 数据库中相关的监控系统表,检测集群是否有出现以下比较严重的错误: | 组件 | 错误名字 | 相关监控表 | 错误说明 | | ---- | ---- | ---- | ---- | From a3cbdc28ba48f19a1aee23e463162be9a6906a69 Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Thu, 30 Jul 2020 20:48:50 +0800 Subject: [PATCH 25/28] Update faq/deploy-and-maintain-faq.md --- faq/deploy-and-maintain-faq.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/faq/deploy-and-maintain-faq.md b/faq/deploy-and-maintain-faq.md index d3f1045fe830..df6692d23035 100644 --- a/faq/deploy-and-maintain-faq.md +++ b/faq/deploy-and-maintain-faq.md @@ -194,7 +194,8 @@ Direct 模式就是把写入请求直接封装成 I/O 指令发到磁盘,这 #### TiDB 有哪些系统表? -和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统数据库](/mysql-schema.md)文档。 +和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统表](/mysql-schema.md)文档。 + #### TiDB 各节点服务器下是否有日志文件,如何管理? From 687aa88575c011dc895536217de91646f664e107 Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Thu, 30 Jul 2020 21:00:59 +0800 Subject: [PATCH 26/28] Update faq/deploy-and-maintain-faq.md --- faq/deploy-and-maintain-faq.md | 1 - 1 file changed, 1 deletion(-) diff --git a/faq/deploy-and-maintain-faq.md b/faq/deploy-and-maintain-faq.md index df6692d23035..189dc705d340 100644 --- a/faq/deploy-and-maintain-faq.md +++ b/faq/deploy-and-maintain-faq.md @@ -196,7 +196,6 @@ Direct 模式就是把写入请求直接封装成 I/O 指令发到磁盘,这 和 MySQL 类似,TiDB 中也有系统表,用于存放数据库运行时所需信息,具体信息参考 [TiDB 系统表](/mysql-schema.md)文档。 - #### TiDB 各节点服务器下是否有日志文件,如何管理? 默认情况下各节点服务器会在日志中输出标准错误,如果启动的时候通过 `--log-file` 参数指定了日志文件,那么日志会输出到指定的文件中,并且按天做 rotation。 From c699293aaa0c6c3f5b22ccbe46c103db4a336852 Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Mon, 3 Aug 2020 14:44:01 +0800 Subject: [PATCH 27/28] Update information-schema/information-schema-cluster-config.md Co-authored-by: kissmydb --- information-schema/information-schema-cluster-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema-cluster-config.md b/information-schema/information-schema-cluster-config.md index 618cd39dd074..41fa837f853b 100644 --- a/information-schema/information-schema-cluster-config.md +++ b/information-schema/information-schema-cluster-config.md @@ -6,7 +6,7 @@ aliases: ['/docs-cn/dev/reference/system-databases/cluster-config/','/zh/tidb/de # CLUSTER_CONFIG -`CLUSTER_CONFIG` 表用于获取集群当前所有组件实例的配置。在 TiDB 早前的版本,用户需要逐个访问各个实例的 HTTP API 才能收集到所有组件配置。TiDB v4.0 后,该表的引入提高了易用性。 +`CLUSTER_CONFIG` 表用于获取集群当前所有组件实例的配置。在 TiDB 早期的版本,用户需要逐个访问各个实例的 HTTP API 才能收集到所有组件配置。TiDB v4.0 后,该表的引入提高了易用性。 {{< copyable "sql" >}} From 69f86510cafc99f2d20cc6d322347e905ad7a5be Mon Sep 17 00:00:00 2001 From: Lilian Lee Date: Wed, 5 Aug 2020 11:49:37 +0800 Subject: [PATCH 28/28] Apply suggestions from code review --- information-schema/information-schema-character-sets.md | 4 ++-- ...ormation-schema-collation-character-set-applicability.md | 2 +- information-schema/information-schema-collations.md | 2 +- information-schema/information-schema-key-column-usage.md | 4 ++-- information-schema/information-schema-processlist.md | 6 +++--- information-schema/information-schema-schemata.md | 4 ++-- information-schema/information-schema-session-variables.md | 4 ++-- information-schema/information-schema-slow-query.md | 2 +- information-schema/information-schema-tikv-region-status.md | 4 +++- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/information-schema/information-schema-character-sets.md b/information-schema/information-schema-character-sets.md index e52b45947b80..2a278829664b 100644 --- a/information-schema/information-schema-character-sets.md +++ b/information-schema/information-schema-character-sets.md @@ -14,7 +14,7 @@ USE information_schema; DESC character_sets; ``` -``` +```sql +----------------------+-------------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------------+-------------+------+------+---------+-------+ @@ -32,7 +32,7 @@ DESC character_sets; SELECT * FROM `character_sets`; ``` -``` +```sql +--------------------+----------------------+---------------+--------+ | CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION | MAXLEN | +--------------------+----------------------+---------------+--------+ diff --git a/information-schema/information-schema-collation-character-set-applicability.md b/information-schema/information-schema-collation-character-set-applicability.md index c3b62d8e7521..96a2110bee93 100644 --- a/information-schema/information-schema-collation-character-set-applicability.md +++ b/information-schema/information-schema-collation-character-set-applicability.md @@ -30,7 +30,7 @@ DESC collation_character_set_applicability; SELECT * FROM collation_character_set_applicability WHERE character_set_name='utf8mb4'; ``` -``` +```sql +----------------+--------------------+ | COLLATION_NAME | CHARACTER_SET_NAME | +----------------+--------------------+ diff --git a/information-schema/information-schema-collations.md b/information-schema/information-schema-collations.md index 6226632b5be0..3b4eb5224629 100644 --- a/information-schema/information-schema-collations.md +++ b/information-schema/information-schema-collations.md @@ -34,7 +34,7 @@ DESC collations; SELECT * FROM collations WHERE character_set_name='utf8mb4'; ``` -``` +```sql +----------------+--------------------+------+------------+-------------+---------+ | COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN | +----------------+--------------------+------+------------+-------------+---------+ diff --git a/information-schema/information-schema-key-column-usage.md b/information-schema/information-schema-key-column-usage.md index 56d063b81840..3c9f51a5e6df 100644 --- a/information-schema/information-schema-key-column-usage.md +++ b/information-schema/information-schema-key-column-usage.md @@ -14,7 +14,7 @@ USE information_schema; DESC key_column_usage; ``` -``` +```sql +-------------------------------+--------------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------------------------+--------------+------+------+---------+-------+ @@ -40,7 +40,7 @@ DESC key_column_usage; SELECT * FROM key_column_usage WHERE table_schema='mysql' and table_name='user'; ``` -``` +```sql *************************** 1. row *************************** CONSTRAINT_CATALOG: def CONSTRAINT_SCHEMA: mysql diff --git a/information-schema/information-schema-processlist.md b/information-schema/information-schema-processlist.md index 0a960b073f17..0647dd03a557 100644 --- a/information-schema/information-schema-processlist.md +++ b/information-schema/information-schema-processlist.md @@ -19,7 +19,7 @@ USE information_schema; DESC processlist; ``` -``` +```sql +----------+---------------------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+---------------------+------+------+---------+-------+ @@ -43,7 +43,7 @@ DESC processlist; SELECT * FROM processlist\G ``` -``` +```sql *************************** 1. row *************************** ID: 16 USER: root @@ -81,7 +81,7 @@ TxnStart: SELECT * FROM cluster_processlist; ``` -``` +```sql +-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ | INSTANCE | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | TxnStart | +-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ diff --git a/information-schema/information-schema-schemata.md b/information-schema/information-schema-schemata.md index 5be8705c17cb..4d16554ca7c6 100644 --- a/information-schema/information-schema-schemata.md +++ b/information-schema/information-schema-schemata.md @@ -14,7 +14,7 @@ USE information_schema; desc SCHEMATA; ``` -``` +```sql +----------------------------+--------------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------------------+--------------+------+------+---------+-------+ @@ -33,7 +33,7 @@ desc SCHEMATA; SELECT * FROM SCHEMATA; ``` -``` +```sql +--------------+--------------------+----------------------------+------------------------+----------+ | CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | +--------------+--------------------+----------------------------+------------------------+----------+ diff --git a/information-schema/information-schema-session-variables.md b/information-schema/information-schema-session-variables.md index 518ac62f5181..364aa790cadc 100644 --- a/information-schema/information-schema-session-variables.md +++ b/information-schema/information-schema-session-variables.md @@ -14,7 +14,7 @@ USE information_schema; DESC session_variables; ``` -``` +```sql +----------------+---------------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------+------+------+---------+-------+ @@ -30,7 +30,7 @@ DESC session_variables; SELECT * FROM session_variables ORDER BY variable_name LIMIT 10; ``` -``` +```sql +-----------------------------------+------------------+ | VARIABLE_NAME | VARIABLE_VALUE | +-----------------------------------+------------------+ diff --git a/information-schema/information-schema-slow-query.md b/information-schema/information-schema-slow-query.md index 221dc5495687..d91aa4f18b05 100644 --- a/information-schema/information-schema-slow-query.md +++ b/information-schema/information-schema-slow-query.md @@ -157,7 +157,7 @@ desc cluster_slow_query; desc SELECT count(*) FROM cluster_slow_query WHERE user = 'u1'; ``` -``` +```sql +--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ | id | estRows | task | access object | operator info | +--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ diff --git a/information-schema/information-schema-tikv-region-status.md b/information-schema/information-schema-tikv-region-status.md index 9a033bc03093..2fd04800f232 100644 --- a/information-schema/information-schema-tikv-region-status.md +++ b/information-schema/information-schema-tikv-region-status.md @@ -63,6 +63,8 @@ DESC tikv_region_status; 你可以使用以下 SQL 语句查询写入数据最多的前 3 个 Region: +{{< copyable "sql" >}} + ```sql SELECT * FROM tikv_region_status ORDER BY written_bytes DESC LIMIT 3; -``` \ No newline at end of file +```