From 57cb28796c140965a3c61d11433856601330d832 Mon Sep 17 00:00:00 2001 From: Ran Date: Thu, 11 Jun 2020 23:40:42 +0800 Subject: [PATCH 1/3] update docs-cn#3369 --- 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 c5304e076dd0e..ac99c87fab639 100644 --- a/system-tables/system-table-information-schema.md +++ b/system-tables/system-table-information-schema.md @@ -406,6 +406,7 @@ desc information_schema.slow_query; | 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 | | | | @@ -470,6 +471,7 @@ desc information_schema.cluster_slow_query; | 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 | | | | From 308099415fc15038e55d30a2b7086b445b4a67d3 Mon Sep 17 00:00:00 2001 From: Ran Date: Fri, 12 Jun 2020 00:00:04 +0800 Subject: [PATCH 2/3] add CLUSTER_PROCESSLIST and CLUSTER_SLOW_QUERY table --- .../system-table-information-schema.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/system-tables/system-table-information-schema.md b/system-tables/system-table-information-schema.md index ac99c87fab639..eec27007121fe 100644 --- a/system-tables/system-table-information-schema.md +++ b/system-tables/system-table-information-schema.md @@ -322,6 +322,28 @@ DEFAULT_CHARACTER_SET_NAME: utf8mb4 4 rows in set (0.00 sec) ``` +## CLUSTER_PROCESSLIST + +`CLUSTER_PROCESSLIST` is the cluster system table corresponding to `PROCESSLIST`. It is used to query the `PROCESSLIST` information of all TiDB nodes in the cluster. The table schema of `CLUSTER_PROCESSLIST` has one more column than `PROCESSLIST`, the `INSTANCE` column, which stores the address of the TiDB node this row of data is from. + +{{< 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 table The `SESSION_VARIABLES` table provides information about session variables. The table data is similar to the result of the `SHOW SESSION VARIABLES` statement: @@ -479,6 +501,36 @@ desc information_schema.cluster_slow_query; +---------------------------+---------------------+------+-----+---------+-------+ ``` +When the cluster system table is queried, TiDB does not obtain data from all nodes, but pushes down the related calculation to other nodes. The execution plan is as follows: + +{{< 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 | ++--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ +``` + +In the above execution plan, the `user = u1` condition is pushed down to other (`cop`) TiDB nodes, and the aggregate operator is also pushed down (the `StreamAgg` operator in the graph). + +Currently, because information of the system tables is not collected in the statistics, sometimes some aggregation operators cannot be pushed down, which results in slow execution. You can manually specify the SQL HINT for aggregation pushdown to push down the aggregation operators. For example: + +{{< copyable "sql" >}} + +```sql +select /*+ AGG_TO_COP() */ count(*) from information_schema.cluster_slow_query group by user; +``` + ### STATISTICS table The `STATISTICS` table provides information about table indexes: From 1d1bb779dadf6d773bd3f08aeb0fb92e4658c387 Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Tue, 16 Jun 2020 14:47:43 +0800 Subject: [PATCH 3/3] Update system-tables/system-table-information-schema.md --- system-tables/system-table-information-schema.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-tables/system-table-information-schema.md b/system-tables/system-table-information-schema.md index eec27007121fe..7fc128f1f3848 100644 --- a/system-tables/system-table-information-schema.md +++ b/system-tables/system-table-information-schema.md @@ -523,7 +523,7 @@ desc select count(*) from information_schema.cluster_slow_query where user = 'u1 In the above execution plan, the `user = u1` condition is pushed down to other (`cop`) TiDB nodes, and the aggregate operator is also pushed down (the `StreamAgg` operator in the graph). -Currently, because information of the system tables is not collected in the statistics, sometimes some aggregation operators cannot be pushed down, which results in slow execution. You can manually specify the SQL HINT for aggregation pushdown to push down the aggregation operators. For example: +Currently, because statistics of the system tables are not collected, sometimes some aggregation operators cannot be pushed down, which results in slow execution. In this case, you can manually specify the SQL HINT to push down the aggregation operators. For example: {{< copyable "sql" >}}