From 811c7984d9c083b3fb2f380b29dcd6ed54e57411 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 28 May 2020 14:36:44 +0800 Subject: [PATCH 1/4] add docs for cluster tables Signed-off-by: crazycs520 --- system-tables/system-table-cluster-tables.md | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 system-tables/system-table-cluster-tables.md diff --git a/system-tables/system-table-cluster-tables.md b/system-tables/system-table-cluster-tables.md new file mode 100644 index 000000000000..338c60c7452f --- /dev/null +++ b/system-tables/system-table-cluster-tables.md @@ -0,0 +1,55 @@ +--- +title: CLUSTER_CONFIG +category: reference +aliases: ['/docs-cn/dev/reference/system-databases/cluster-config/'] +summary: 了解 TiDB 集群配置表 `CLUSTER_CONFIG`。 +--- + +# CLUSTER_CONFIG + +集群配置表 `CLUSTER_CONFIG` 用于获取集群当前所有 TiDB/PD/TiKV 实例的配置。对于 TiDB 4.0 以前的版本,用户需要逐个访问各个实例的 HTTP API 才能收集到所有组件配置。 + +{{< copyable "sql" >}} + +```sql +desc information_schema.cluster_config; +``` + +``` ++----------+--------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+------+---------+-------+ +| TYPE | varchar(64) | YES | | NULL | | +| INSTANCE | varchar(64) | YES | | NULL | | +| KEY | varchar(256) | YES | | NULL | | +| VALUE | varchar(128) | YES | | NULL | | ++----------+--------------+------+------+---------+-------+ +``` + +字段解释: + +* `TYPE`:节点的类型,可取值为 `tidb`,`pd` 和 `tikv`。 +* `INSTANCE`:节点的服务地址。 +* `KEY`:配置项名。 +* `VALUE`:配置项值。 + +以下示例查询 TiKV 实例的 `coprocessor` 相关配置: + +{{< copyable "sql" >}} + +```sql +select * from information_schema.cluster_config where type='tikv' and `key` like 'coprocessor%'; +``` + +``` ++------+-----------------+-----------------------------------+----------+ +| 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 | ++------+-----------------+-----------------------------------+----------+ +``` From 06a049d4420f392906ef78bd479a39ae1b7a5062 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 28 May 2020 14:40:09 +0800 Subject: [PATCH 2/4] update Signed-off-by: crazycs520 --- system-tables/system-table-cluster-tables.md | 79 ++++++++++++-------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/system-tables/system-table-cluster-tables.md b/system-tables/system-table-cluster-tables.md index 338c60c7452f..0393a62be00a 100644 --- a/system-tables/system-table-cluster-tables.md +++ b/system-tables/system-table-cluster-tables.md @@ -1,55 +1,72 @@ --- -title: CLUSTER_CONFIG +title: CLUSTER TABLES category: reference -aliases: ['/docs-cn/dev/reference/system-databases/cluster-config/'] -summary: 了解 TiDB 集群配置表 `CLUSTER_CONFIG`。 +aliases: ['/docs-cn/dev/reference/system-databases/cluster-tables/'] --- -# CLUSTER_CONFIG +# CLUSTER TABLES -集群配置表 `CLUSTER_CONFIG` 用于获取集群当前所有 TiDB/PD/TiKV 实例的配置。对于 TiDB 4.0 以前的版本,用户需要逐个访问各个实例的 HTTP API 才能收集到所有组件配置。 +TiDB 有些系统表只包含单个 TiDB 节点的数据,如果想查询集群所有节点的系统表数据,可以使用 TiDB 4.0 新增的集群系统表。 + +| 单节点系统表 | 集群系统表 | +| -------------------------- | ---------------------------------- | +| PROCESSLIST | CLUSTER_PROCESSLIST | +| SLOW_QUERY | CLUSTER_SLOW_QUERY | +| STATEMENTS_SUMMARY | CLUSTER_STATEMENTS_SUMMARY | +| STATEMENTS_SUMMARY_HISTORY | CLUSTER_STATEMENTS_SUMMARY_HISTORY | + +如上表中,集群系统表的表名是 `CLUSTER_` 前缀加上对应的单节点系统表名。在表结构上,集群系统表多一个 `INSTANCE` 列,表示该行数据来自的 TiDB 节点地址。 + +## 示例 + +集群系统表使用上和单节点系统表并无差异,以下以 `CLUSTER_PROCESSLIST` 作为示例。 {{< copyable "sql" >}} ```sql -desc information_schema.cluster_config; +SELECT * FROM information_schema.cluster_processlist; ``` ``` -+----------+--------------+------+------+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+----------+--------------+------+------+---------+-------+ -| TYPE | varchar(64) | YES | | NULL | | -| INSTANCE | varchar(64) | YES | | NULL | | -| KEY | varchar(256) | YES | | NULL | | -| VALUE | varchar(128) | YES | | NULL | | -+----------+--------------+------+------+---------+-------+ ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ +| 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) | ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ ``` -字段解释: +以上查询的是集群中所有 TiDB 节点正在执行的请求,其中 `INSTANCE` 表示的是对应 TiDB 服务的 `STATUS_ADDRESS`。 -* `TYPE`:节点的类型,可取值为 `tidb`,`pd` 和 `tikv`。 -* `INSTANCE`:节点的服务地址。 -* `KEY`:配置项名。 -* `VALUE`:配置项值。 +## 集群系统表的实现 -以下示例查询 TiKV 实例的 `coprocessor` 相关配置: +查询集群系统表时,TiDB 也会将相关计算下推给其他节点执行,而不是把所有节点的数据都取回来,可以查下相应的执行计划,示例如下: {{< copyable "sql" >}} ```sql -select * from information_schema.cluster_config where type='tikv' and `key` like 'coprocessor%'; +desc select count(*) from information_schema.cluster_slow_query where user = 'u1'; ``` ``` -+------+-----------------+-----------------------------------+----------+ -| 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 | -+------+-----------------+-----------------------------------+----------+ ++--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ +| 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 来将聚合算子下推,示例如下: + +```sql +select /*+ AGG_TO_COP() */ count(*) from information_schema.cluster_slow_query group by user; ``` From 29bb9862dd9d4c7432576c6cdd7c42a84ab1a490 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 28 May 2020 14:59:08 +0800 Subject: [PATCH 3/4] update Signed-off-by: crazycs520 --- system-tables/system-table-cluster-tables.md | 72 ------------------- .../system-table-information-schema.md | 50 +++++++++++++ 2 files changed, 50 insertions(+), 72 deletions(-) delete mode 100644 system-tables/system-table-cluster-tables.md diff --git a/system-tables/system-table-cluster-tables.md b/system-tables/system-table-cluster-tables.md deleted file mode 100644 index 0393a62be00a..000000000000 --- a/system-tables/system-table-cluster-tables.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: CLUSTER TABLES -category: reference -aliases: ['/docs-cn/dev/reference/system-databases/cluster-tables/'] ---- - -# CLUSTER TABLES - -TiDB 有些系统表只包含单个 TiDB 节点的数据,如果想查询集群所有节点的系统表数据,可以使用 TiDB 4.0 新增的集群系统表。 - -| 单节点系统表 | 集群系统表 | -| -------------------------- | ---------------------------------- | -| PROCESSLIST | CLUSTER_PROCESSLIST | -| SLOW_QUERY | CLUSTER_SLOW_QUERY | -| STATEMENTS_SUMMARY | CLUSTER_STATEMENTS_SUMMARY | -| STATEMENTS_SUMMARY_HISTORY | CLUSTER_STATEMENTS_SUMMARY_HISTORY | - -如上表中,集群系统表的表名是 `CLUSTER_` 前缀加上对应的单节点系统表名。在表结构上,集群系统表多一个 `INSTANCE` 列,表示该行数据来自的 TiDB 节点地址。 - -## 示例 - -集群系统表使用上和单节点系统表并无差异,以下以 `CLUSTER_PROCESSLIST` 作为示例。 - -{{< copyable "sql" >}} - -```sql -SELECT * FROM information_schema.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) | -+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ -``` - -以上查询的是集群中所有 TiDB 节点正在执行的请求,其中 `INSTANCE` 表示的是对应 TiDB 服务的 `STATUS_ADDRESS`。 - -## 集群系统表的实现 - -查询集群系统表时,TiDB 也会将相关计算下推给其他节点执行,而不是把所有节点的数据都取回来,可以查下相应的执行计划,示例如下: - -{{< copyable "sql" >}} - -```sql -desc select count(*) from information_schema.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 来将聚合算子下推,示例如下: - -```sql -select /*+ AGG_TO_COP() */ count(*) from information_schema.cluster_slow_query group by user; -``` diff --git a/system-tables/system-table-information-schema.md b/system-tables/system-table-information-schema.md index aa31ffbad524..c5366e636452 100644 --- a/system-tables/system-table-information-schema.md +++ b/system-tables/system-table-information-schema.md @@ -304,6 +304,28 @@ SELECT * FROM schemata; 5 rows in set (0.00 sec) ``` +## CLUSTER_PROCESSLIST + +`CLUSTER_PROCESSLIST` 是 `PROCESSLIST` 对应的集群系统表,用于查询集群中所有 TiDB 节点的 `PROCESSLIST` 信息。表结构上比 `PROCESSLIST` 多一列 `INSTANCE`,表示该行数据来自的 TiDB 节点地址。 + +{{< copyable "sql" >}} + +```sql +SELECT * FROM information_schema.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) | ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ +``` + ## SESSION_VARIABLES 表 `SESSION_VARIABLES` 表提供了关于 session 变量的信息。表中的数据跟 `SHOW SESSION VARIABLES` 语句执行结果类似。 @@ -461,6 +483,34 @@ desc information_schema.cluster_slow_query; +---------------------------+---------------------+------+-----+---------+-------+ ``` +查询集群系统表时,TiDB 也会将相关计算下推给其他节点执行,而不是把所有节点的数据都取回来,可以查看执行计划如下: + +{{< copyable "sql" >}} + +```sql +desc select count(*) from information_schema.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 来将聚合算子下推,示例如下: + +```sql +select /*+ AGG_TO_COP() */ count(*) from information_schema.cluster_slow_query group by user; +``` + ## STATISTICS 表 `STATISTICS` 表提供了关于表索引的信息。 From 5bc0dba571982c4a8a1413cd89982e37222d6e20 Mon Sep 17 00:00:00 2001 From: crazycs Date: Thu, 28 May 2020 15:17:28 +0800 Subject: [PATCH 4/4] Update system-tables/system-table-information-schema.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- system-tables/system-table-information-schema.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system-tables/system-table-information-schema.md b/system-tables/system-table-information-schema.md index c5366e636452..6adfe7cad7a1 100644 --- a/system-tables/system-table-information-schema.md +++ b/system-tables/system-table-information-schema.md @@ -507,6 +507,8 @@ desc select count(*) from information_schema.cluster_slow_query where user = 'u1 目前由于没有对系统表收集统计信息,所以有时会导致某些聚合算子不能下推,导致执行较慢,用户可以通过手动指定聚合下推的 SQL HINT 来将聚合算子下推,示例如下: +{{< copyable "sql" >}} + ```sql select /*+ AGG_TO_COP() */ count(*) from information_schema.cluster_slow_query group by user; ```