diff --git a/.github/assign-by-files.yml b/.github/assign-by-files.yml index 936f0fc22bf24..83f456879e52b 100644 --- a/.github/assign-by-files.yml +++ b/.github/assign-by-files.yml @@ -83,9 +83,9 @@ # - TomShawn # - -# 'system-tables/**/*.md': -# - TomShawn -# - +'information-schema/**/*.md': + - TomShawn + - nullnotnil 'ticdc/**/*.md': - WangXiangUSTC diff --git a/TOC.md b/TOC.md index 55f281f6b56f6..e51e92595040e 100644 --- a/TOC.md +++ b/TOC.md @@ -81,7 +81,7 @@ + Troubleshoot + [TiDB Troubleshooting Map](/tidb-troubleshooting-map.md) + [Identify Slow Queries](/identify-slow-queries.md) - + [SQL Diagnostics](/system-tables/system-table-sql-diagnostics.md) + + [SQL Diagnostics](/information-schema/information-schema-sql-diagnostics.md) + [Identify Expensive Queries](/identify-expensive-queries.md) + [Statement Summary Tables](/statement-summary-tables.md) + [Troubleshoot Hotspot Issues](/troubleshoot-hot-spot-issues.md) @@ -378,20 +378,48 @@ + [Partitioning](/partitioned-table.md) + [Character Set and Collation](/character-set-and-collation.md) + System Tables - + [`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.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 + [Overview](/dashboard/dashboard-intro.md) diff --git a/_index.md b/_index.md index 55c505c643a81..350ad63811e6c 100644 --- a/_index.md +++ b/_index.md @@ -78,7 +78,7 @@ Designed for the cloud, TiDB provides flexible scalability, reliability and secu - [TiDB Troubleshooting Map](/tidb-troubleshooting-map.md) - [Identify Slow Queries](/identify-slow-queries.md) -- [SQL Diagnostics](/system-tables/system-table-sql-diagnostics.md) +- [SQL Diagnostics](/information-schema/information-schema-sql-diagnostics.md) - [Troubleshoot Hotspot Issues](/troubleshoot-hot-spot-issues.md) - [Troubleshoot the TiDB Cluster](/troubleshoot-tidb-cluster.md) - [Troubleshoot TiCDC](/ticdc/troubleshoot-ticdc.md) diff --git a/check-cluster-status-using-sql-statements.md b/check-cluster-status-using-sql-statements.md index 9f75b2f237915..fc4342cc3b5c7 100644 --- a/check-cluster-status-using-sql-statements.md +++ b/check-cluster-status-using-sql-statements.md @@ -10,18 +10,18 @@ TiDB offers some SQL statements and system tables to check the TiDB cluster stat The `INFORMATION_SCHEMA` system database offers system tables as follows to query the cluster status and diagnose common cluster issues: -- [`TABLES`](/system-tables/system-table-information-schema.md#tables-table) -- [`TIDB_INDEXES`](/system-tables/system-table-information-schema.md#tidb_indexes-table) -- [`ANALYZE_STATUS`](/system-tables/system-table-information-schema.md#analyze_status-table) -- [`TIDB_HOT_REGIONS`](/system-tables/system-table-information-schema.md#tidb_hot_regions-table) -- [`TIKV_STORE_STATUS`](/system-tables/system-table-information-schema.md#tikv_store_status-table) -- [`TIKV_REGION_STATUS`](/system-tables/system-table-information-schema.md#tikv_region_status-table) -- [`TIKV_REGION_PEERS`](/system-tables/system-table-information-schema.md#tikv_region_peers-table) +- [`TABLES`](/information-schema/information-schema-tables.md) +- [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md) +- [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md) +- [`TIDB_HOT_REGIONS`](/information-schema/information-schema-tidb-hot-regions.md) +- [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) +- [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) +- [`TIKV_REGION_PEERS`](/information-schema/information-schema-tikv-region-peers.md) You can also use the following statements to obtain some useful information for troubleshooting and querying the TiDB cluster status. - `ADMIN SHOW DDL`: obtains the ID of TiDB with the `DDL owner` role and `IP:PORT`. -- The feature of `SHOW ANALYZE STATUS` is the same with that of [the `ANALYZE_STATUS` table](/system-tables/system-table-information-schema.md#analyze_status-table). +- The feature of `SHOW ANALYZE STATUS` is the same with that of [the `ANALYZE_STATUS` table](/information-schema/information-schema-analyze-status.md). - Specific `EXPLAIN` statements - `EXPLAIN ANALYZE`: obtains some detailed information for execution of a SQL statement. - `EXPLAIN FOR CONNECTION`: obtains the execution plan for the query executed last in a connection. Can be used along with `SHOW PROCESSLIST`. diff --git a/dashboard/dashboard-diagnostics-report.md b/dashboard/dashboard-diagnostics-report.md index 328feaa96e36b..af9660babcc37 100644 --- a/dashboard/dashboard-diagnostics-report.md +++ b/dashboard/dashboard-diagnostics-report.md @@ -62,7 +62,7 @@ The fields in the table above are described as follows: #### Cluster Topology Info -The `Cluster Info` table shows the cluster topology information. The information in this table are from TiDB [information_schema.cluster_info](/system-tables/system-table-cluster-info.md) system table. +The `Cluster Info` table shows the cluster topology information. The information in this table are from TiDB [information_schema.cluster_info](/information-schema/information-schema-cluster-info.md) system table. ![Cluster info](/media/dashboard/dashboard-diagnostics-cluster-info.png) @@ -78,7 +78,7 @@ The fields in the table above are described as follows: ### Diagnostic information -TiDB has built-in automatic diagnostic results. For the description of each field, see [information_schema.inspection-result](/system-tables/system-table-inspection-result.md) system table. +TiDB has built-in automatic diagnostic results. For the description of each field, see [information_schema.inspection-result](/information-schema/information-schema-inspection-result.md) system table. ### Load Info diff --git a/faq/tidb-faq.md b/faq/tidb-faq.md index c4fee62b7304c..4736d78b11c98 100644 --- a/faq/tidb-faq.md +++ b/faq/tidb-faq.md @@ -540,7 +540,7 @@ No. Currently, TiDB only supports the distributed storage engine and the Golevel #### Can the `Information_schema` support more real information? -As part of MySQL compatibility, TiDB supports a number of `INFORMATION_SCHEMA` tables. Many of these tables also have a corresponding SHOW command. For more information, see [Information Schema](/system-tables/system-table-information-schema.md). +As part of MySQL compatibility, TiDB supports a number of `INFORMATION_SCHEMA` tables. Many of these tables also have a corresponding SHOW command. For more information, see [Information Schema](/information-schema.md). #### What's the explanation of the TiDB Backoff type scenario? diff --git a/identify-slow-queries.md b/identify-slow-queries.md index db76306f092d4..baa5d83ee3fa2 100644 --- a/identify-slow-queries.md +++ b/identify-slow-queries.md @@ -106,7 +106,7 @@ TiKV Coprocessor Task fields: ## Memory mapping in slow log -You can query the content of the slow query log by querying the `INFORMATION_SCHEMA.SLOW_QUERY` table. Each column name in the table corresponds to one field name in the slow log. For table structure, see the introduction to the `SLOW_QUERY` table in [Information Schema](/system-tables/system-table-information-schema.md#information-schema). +You can query the content of the slow query log by querying the `INFORMATION_SCHEMA.SLOW_QUERY` table. Each column name in the table corresponds to one field name in the slow log. For table structure, see the introduction to the `SLOW_QUERY` table in [Information Schema](/information-schema/information-schema-slow-query.md). > **Note:** > @@ -158,7 +158,7 @@ For TiDB 4.0, `SLOW_QUERY` supports querying the slow log of any period of time, > > If the slow log files of the specified time range are removed, or there is no slow query, the query returns NULL. -TiDB 4.0 adds the [`CLUSTER_SLOW_QUERY`](/system-tables/system-table-information-schema.md#cluster_slow_query-table) system table to query the slow query information of all TiDB nodes. The table schema of the `CLUSTER_SLOW_QUERY` table differs from that of the `SLOW_QUERY` table in that an `INSTANCE` column is added to `CLUSTER_SLOW_QUERY`. The `INSTANCE` column represents the TiDB node address of the row information on the slow query. You can use `CLUSTER_SLOW_QUERY` the way you do with [`SLOW_QUERY`](/system-tables/system-table-information-schema.md#slow_query-table). +TiDB 4.0 adds the [`CLUSTER_SLOW_QUERY`](/information-schema/information-schema-slow-query.md#cluster_slow_query-table) system table to query the slow query information of all TiDB nodes. The table schema of the `CLUSTER_SLOW_QUERY` table differs from that of the `SLOW_QUERY` table in that an `INSTANCE` column is added to `CLUSTER_SLOW_QUERY`. The `INSTANCE` column represents the TiDB node address of the row information on the slow query. You can use `CLUSTER_SLOW_QUERY` the way you do with [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md). When you query the `CLUSTER_SLOW_QUERY` table, TiDB pushes the computation and the judgment down to other nodes, instead of retrieving all slow query information from other nodes and executing the operations on one TiDB node. diff --git a/information-schema.md b/information-schema.md new file mode 100644 index 0000000000000..677fe061aa2c1 --- /dev/null +++ b/information-schema.md @@ -0,0 +1,83 @@ +--- +title: Information Schema +summary: TiDB implements the ANSI-standard information_schema for viewing system metadata. +aliases: ['/docs/dev/system-tables/system-table-information-schema/','/docs/dev/reference/system-databases/information-schema/','/tidb/dev/system-table-information-schema/'] +--- + +# Information Schema + +Information Schema provides an ANSI-standard way of viewing system metadata. TiDB also provides a number of custom `INFORMATION_SCHEMA` tables, in addition to the tables included for MySQL compatibility. + +Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefit of querying `INFORMATION_SCHEMA` is that it is possible to join between tables. + +## Tables for MySQL compatibility + +| Table Name | Description | +|-----------------------------------------------------------------------------------------|-----------------------------| +| [`CHARACTER_SETS`](/information-schema/information-schema-character-sets.md) | Provides a list of character sets the server supports. | +| [`COLLATIONS`](/information-schema/information-schema-collations.md) | Provides a list of collations that the server supports. | +| [`COLLATION_CHARACTER_SET_APPLICABILITY`](/information-schema/information-schema-collation-character-set-applicability.md) | Explains which collations apply to which character sets. | +| [`COLUMNS`](/information-schema/information-schema-columns.md) | Provides a list of columns for all tables. | +| `COLUMN_PRIVILEGES` | Not implemented by TiDB. Returns zero rows. | +| `COLUMN_STATISTICS` | Not implemented by TiDB. Returns zero rows. | +| [`ENGINES`](/information-schema/information-schema-engines.md) | Provides a list of supported storage engines. | +| `EVENTS` | Not implemented by TiDB. Returns zero rows. | +| `FILES` | Not implemented by TiDB. Returns zero rows. | +| `GLOBAL_STATUS` | Not implemented by TiDB. Returns zero rows. | +| `GLOBAL_VARIABLES` | Not implemented by TiDB. Returns zero rows. | +| [`KEY_COLUMN_USAGE`](/information-schema/information-schema-key-column-usage.md) | Describes the key constraints of the columns, such as the primary key constraint. | +| `OPTIMIZER_TRACE` | Not implemented by TiDB. Returns zero rows. | +| `PARAMETERS` | Not implemented by TiDB. Returns zero rows. | +| [`PARTITIONS`](/information-schema/information-schema-partitions.md) | Provides a list of table partitions. | +| `PLUGINS` | Not implemented by TiDB. Returns zero rows. | +| [`PROCESSLIST`](/information-schema/information-schema-processlist.md) | Provides similar information to the command `SHOW PROCESSLIST`. | +| `PROFILING` | Not implemented by TiDB. Returns zero rows. | +| `REFERENTIAL_CONSTRAINTS` | Not implemented by TiDB. Returns zero rows. | +| `ROUTINES` | Not implemented by TiDB. Returns zero rows. | +| [`SCHEMATA`](/information-schema/information-schema-schemata.md) | Provides similar information to `SHOW DATABASES`. | +| `SCHEMA_PRIVILEGES` | Not implemented by TiDB. Returns zero rows. | +| `SESSION_STATUS` | Not implemented by TiDB. Returns zero rows. | +| [`SESSION_VARIABLES`](/information-schema/information-schema-session-variables.md) | Provides similar functionality to the command `SHOW SESSION VARIABLES` | +| [`STATISTICS`](/information-schema/information-schema-statistics.md) | Provides information on table indexes. | +| [`TABLES`](/information-schema/information-schema-tables.md) | Provides a list of tables that the current user has visibility of. Similar to `SHOW TABLES`. | +| `TABLESPACES` | Not implemented by TiDB. Returns zero rows. | +| [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) | Provides information on primary keys, unique indexes and foreign keys. | +| `TABLE_PRIVILEGES` | Not implemented by TiDB. Returns zero rows. | +| `TRIGGERS` | Not implemented by TiDB. Returns zero rows. | +| [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) | Summarizes the privileges associated with the current user. | +| [`VIEWS`](/information-schema/information-schema-views.md) | Provides a list of views that the current user has visibility of. Similar to running `SHOW FULL TABLES WHERE table_type = 'VIEW'` | + +## Tables that are TiDB extensions + +| Table Name | Description | +|-----------------------------------------------------------------------------------------|-------------| +| [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md) | Provides information about tasks to collect statistics. | +| [`CLUSTER_CONFIG`](/information-schema/information-schema-cluster-config.md) | Provides details about configuration settings for the entire TiDB cluster. | +| [`CLUSTER_HARDWARE`](/information-schema/information-schema-cluster-info.md) | Provides details on the underlying physical hardware discovered on each TiDB component. | +| [`CLUSTER_INFO`](/information-schema/information-schema-cluster-info.md) | Provides details on the current cluster topology. | +| [`CLUSTER_LOAD`](/information-schema/information-schema-cluster-load.md) | Provides current load information for TiDB servers in the cluster. | +| [`CLUSTER_LOG`](/information-schema/information-schema-cluster-log.md) | Provides a log for the entire TiDB cluster | +| `CLUSTER_PROCESSLIST` | Provides a cluster-level view of the `PROCESSLIST` table. | +| `CLUSTER_SLOW_QUERY` | Provides a cluster-level view of the `SLOW_QUERY` table. | +| `CLUSTER_STATEMENTS_SUMMARY` | Provides a cluster-level view of the `STATEMENTS_SUMMARY` table. | +| `CLUSTER_STATEMENTS_SUMMARY_HISTORY` | Provides a cluster-level view of the `CLUSTER_STATEMENTS_SUMMARY_HISTORY` table. | +| [`CLUSTER_SYSTEMINFO`](/information-schema/information-schema-cluster-systeminfo.md) | Provides details about kernel parameter configuration for servers in the cluster. | +| [`DDL_JOBS`](/information-schema/information-schema-ddl-jobs.md) | Provides similar output to `ADMIN SHOW DDL JOBS` | +| [`INSPECTION_RESULT`](/information-schema/information-schema-inspection-result.md) | Triggers internal diagnostics checks. | +| [`INSPECTION_RULES`](/information-schema/information-schema-inspection-rules.md) | A list of internal diagnostic checks performed. | +| [`INSPECTION_SUMMARY`](/information-schema/information-schema-inspection-summary.md) | A summarized report of important monitoring metrics. | +| [`METRICS_SUMMARY`](/information-schema/information-schema-metrics-summary.md) | A summary of metrics extracted from Prometheus. | +| `METRICS_SUMMARY_BY_LABEL` | See `METRICS_SUMAMARY` table. | +| [`METRICS_TABLES`](/information-schema/information-schema-metrics-tables.md) | Provides the PromQL definitions for tables in `METRICS_SCHEMA`. | +| [`SEQUENCES`](/information-schema/information-schema-sequences.md) | The TiDB implementation of sequences is based on MariaDB. | +| [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md) | Provides information on slow queries on the current TiDB server. | +| [`STATEMENTS_SUMMARY`](/statement-summary-tables.md) | Similar to performance_schema statement summary in MySQL. | +| [`STATEMENTS_SUMMARY_HISTORY`](/statement-summary-tables.md) | Similar to performance_schema statement summary history in MySQL. | +| [`TABLE_STORAGE_STATS`](/information-schema/information-schema-table-storage-stats.md) | Provides details about table sizes in storage. | +| [`TIDB_HOT_REGIONS`](/information-schema/information-schema-tidb-hot-regions.md) | Provides statistics about which regions are hot. | +| [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md) | Provides index information about TiDB tables. | +| [`TIDB_SERVERS_INFO`](/information-schema/information-schema-tidb-servers-info.md) | Provides a list of TiDB servers (i.e. tidb-server component) | +| [`TIFLASH_REPLICA`](/information-schema/information-schema-tiflash-replica.md) | Provides details about TiFlash replicas. | +| [`TIKV_REGION_PEERS`](/information-schema/information-schema-tikv-region-peers.md) | Provides details about where regions are stored. | +| [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) | Provides statistics about regions. | +| [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) | Provides basic information about TiKV servers. | diff --git a/information-schema/information-schema-analyze-status.md b/information-schema/information-schema-analyze-status.md new file mode 100644 index 0000000000000..280329928f209 --- /dev/null +++ b/information-schema/information-schema-analyze-status.md @@ -0,0 +1,52 @@ +--- +title: ANALYZE_STATUS +summary: Learn the `ANALYZE_STATUS` information_schema table. +--- + +# ANALYZE_STATUS + +The `ANALYZE_STATUS` table provides information about the running tasks that collect statistics and a limited number of history tasks. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC analyze_status; +``` + +``` ++----------------+---------------------+------+------+---------+-------+ +| 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) +``` + +The `STATE` column shows the execution status of a specific `ANALYZE` task. Its value can be `pending`, `running`,`finished` or `failed`. + +{{< copyable "sql" >}} + +```sql +SELECT * FROM `ANALYZE_STATUS`; +``` + +``` ++--------------+------------+----------------+-------------------+----------------+---------------------+----------+ +| 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 +``` \ No newline at end of file diff --git a/information-schema/information-schema-character-sets.md b/information-schema/information-schema-character-sets.md new file mode 100644 index 0000000000000..3c7939cf5ddf8 --- /dev/null +++ b/information-schema/information-schema-character-sets.md @@ -0,0 +1,46 @@ +--- +title: CHARACTER_SETS +summary: Learn the `CHARACTER_SETS` information_schema table. +--- + +# CHARACTER_SETS + +The `CHARACTER_SETS` table provides information about [character sets](/character-set-and-collation.md). Currently, TiDB only supports some of the character sets. + +{{< 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) +``` + +{{< 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) +``` \ No newline at end of file diff --git a/system-tables/system-table-cluster-config.md b/information-schema/information-schema-cluster-config.md similarity index 57% rename from system-tables/system-table-cluster-config.md rename to information-schema/information-schema-cluster-config.md index 800bbe0a7df39..205dbe7cdc4fb 100644 --- a/system-tables/system-table-cluster-config.md +++ b/information-schema/information-schema-cluster-config.md @@ -1,17 +1,18 @@ --- title: CLUSTER_CONFIG -summary: Learn the `CLUSTER_CONFIG` cluster configuration system table. -aliases: ['/docs/dev/system-tables/system-table-cluster-config/','/docs/dev/reference/system-databases/cluster-config/'] +summary: Learn the `CLUSTER_CONFIG` information_schema table. +aliases: ['/docs/dev/system-tables/system-table-cluster-config/','/docs/dev/reference/system-databases/cluster-config/','/tidb/dev/system-table-cluster-config/'] --- # CLUSTER_CONFIG -You can use the `CLUSTER_CONFIG` cluster configuration table to get the current configuration of all TiDB/PD/TiKV instances in the cluster. For TiDB versions earlier than 4.0, you need to access the HTTP API of each instance one by one to collect all component configurations. +You can use the `CLUSTER_CONFIG` cluster configuration table to get the current configuration of all server components in the cluster. This simplifies the usage over earlier releases of TiDB, where obtaining similar information would require accessing the HTTP API end points of each instance. {{< copyable "sql" >}} ```sql -desc information_schema.cluster_config; +USE information_schema; +DESC cluster_config; ``` ```sql @@ -37,18 +38,19 @@ The following example shows how to query the `coprocessor` configuration on the {{< 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/system-tables/system-table-cluster-hardware.md b/information-schema/information-schema-cluster-hardware.md similarity index 74% rename from system-tables/system-table-cluster-hardware.md rename to information-schema/information-schema-cluster-hardware.md index 1854d362e5b66..52960722c79ac 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: Learn the `CLUSTER_HARDWARE` cluster hardware system table. -aliases: ['/docs/dev/system-tables/system-table-cluster-hardware/','/docs/dev/reference/system-databases/cluster-hardware/'] +summary: Learn the `CLUSTER_HARDWARE` information_schema table. +aliases: ['/docs/dev/system-tables/system-table-cluster-hardware/','/docs/dev/reference/system-databases/cluster-hardware/','/tidb/dev/system-table-cluster-hardware/'] --- # CLUSTER_HARDWARE @@ -11,7 +11,8 @@ The `CLUSTER_HARDWARE` hardware system table provides the hardware information o {{< 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) ``` Field description: -* `TYPE`: Corresponds to the `TYPE` field in the [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) table. The optional values are `tidb`, `pd`, and `tikv`. -* `INSTANCE`: Corresponds to the `INSTANCE` field in the [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) cluster information table. +* `TYPE`: Corresponds to the `TYPE` field in the [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) table. The optional values are `tidb`, `pd`, and `tikv`. +* `INSTANCE`: Corresponds to the `INSTANCE` field in the [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) cluster information table. * `DEVICE_TYPE`: Hardware type. Currently, you can query the `cpu`, `memory`, `disk`, and `net` types. * `DEVICE_NAME`: Hardware name. The value of `DEVICE_NAME` varies with `DEVICE_TYPE`. * `cpu`: The hardware name is cpu. @@ -45,18 +47,19 @@ The following example shows how to query the CPU information using the `CLUSTER_ {{< 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) +``` \ No newline at end of file diff --git a/system-tables/system-table-cluster-info.md b/information-schema/information-schema-cluster-info.md similarity index 64% rename from system-tables/system-table-cluster-info.md rename to information-schema/information-schema-cluster-info.md index 0ba7dd6a15df3..0c40f5d551bcc 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: Learn the `CLUSTER_INFO` cluster topology information table. -aliases: ['/docs/dev/system-tables/system-table-cluster-info/','/docs/dev/reference/system-databases/cluster-info/'] +aliases: ['/docs/dev/system-tables/system-table-cluster-info/','/docs/dev/reference/system-databases/cluster-info/','/tidb/dev/system-table-cluster-info/'] --- # CLUSTER_INFO @@ -11,7 +11,8 @@ The `CLUSTER_INFO` cluster topology table provides the current topology informat {{< copyable "sql" >}} ```sql -desc information_schema.cluster_info; +USE information_schema; +desc cluster_info; ``` ```sql @@ -42,15 +43,16 @@ Field description: {{< 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/system-tables/system-table-cluster-load.md b/information-schema/information-schema-cluster-load.md similarity index 75% rename from system-tables/system-table-cluster-load.md rename to information-schema/information-schema-cluster-load.md index e59a69c1154c4..a91cb2011a06c 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: Learn the `CLUSTER_LOAD` cluster load table. -aliases: ['/docs/dev/system-tables/system-table-cluster-load/','/docs/dev/reference/system-databases/cluster-load/'] +summary: Learn the `CLUSTER_LOAD` information_schema table. +aliases: ['/docs/dev/system-tables/system-table-cluster-load/','/docs/dev/reference/system-databases/cluster-load/','/tidb/dev/system-table-cluster-load/'] --- # CLUSTER_LOAD @@ -11,7 +11,8 @@ The `CLUSTER_LOAD` cluster load table provides the current load information of t {{< 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) ``` Field description: -* `TYPE`: Corresponds to the `TYPE` field in the [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) table. The optional values are `tidb`, `pd`, and `tikv`. -* `INSTANCE`: Corresponds to the `INSTANCE` field in the [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) cluster information table. +* `TYPE`: Corresponds to the `TYPE` field in the [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) table. The optional values are `tidb`, `pd`, and `tikv`. +* `INSTANCE`: Corresponds to the `INSTANCE` field in the [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) cluster information table. * `DEVICE_TYPE`: Hardware type. Currently, you can query the `cpu`, `memory`, `disk`, and `net` types. * `DEVICE_NAME`: Hardware name. The value of `DEVICE_NAME` varies with `DEVICE_TYPE`. * `cpu`: The hardware name is cpu. @@ -45,21 +47,22 @@ The following example shows how to query the current load information of cpu usi {{< 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/system-tables/system-table-cluster-log.md b/information-schema/information-schema-cluster-log.md similarity index 93% rename from system-tables/system-table-cluster-log.md rename to information-schema/information-schema-cluster-log.md index 0d1de418ed259..7e8e69ded8062 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: Learn the `CLUSTER_LOG` cluster log table. -aliases: ['/docs/dev/system-tables/system-table-cluster-log/','/docs/dev/reference/system-databases/cluster-log/'] +summary: Learn the `CLUSTER_LOG` information_schema table. +aliases: ['/docs/dev/system-tables/system-table-cluster-log/','/docs/dev/reference/system-databases/cluster-log/','/tidb/dev/system-table-cluster-log/'] --- # CLUSTER_LOG @@ -13,7 +13,8 @@ To get the logs of the TiDB cluster before v4.0, you need to log in to each inst {{< copyable "sql" >}} ```sql -desc information_schema.cluster_log; +USE information_schema; +DESC cluster_log; ``` ```sql @@ -48,7 +49,7 @@ The following example shows how to query the execution process of a DDL statemen {{< 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/system-tables/system-table-cluster-systeminfo.md b/information-schema/information-schema-cluster-systeminfo.md similarity index 83% rename from system-tables/system-table-cluster-systeminfo.md rename to information-schema/information-schema-cluster-systeminfo.md index 2e806ad4be5ac..13d3397e669d9 100644 --- a/system-tables/system-table-cluster-systeminfo.md +++ b/information-schema/information-schema-cluster-systeminfo.md @@ -1,7 +1,7 @@ --- title: CLUSTER_SYSTEMINFO summary: Learn the `CLUSTER_SYSTEMINFO` kernel parameter table. -aliases: ['/docs/dev/system-tables/system-table-cluster-systeminfo/','/docs/dev/reference/system-databases/cluster-systeminfo/'] +aliases: ['/docs/dev/system-tables/system-table-cluster-systeminfo/','/docs/dev/reference/system-databases/cluster-systeminfo/','/tidb/dev/system-table-cluster-systeminfo/'] --- # CLUSTER_SYSTEMINFO @@ -11,7 +11,8 @@ You can use the `CLUSTER_SYSTEMINFO` kernel parameter table to query the kernel {{< copyable "sql" >}} ```sql -desc information_schema.cluster_systeminfo; +USE information_schema; +DESC cluster_systeminfo; ``` ```sql @@ -30,8 +31,8 @@ desc information_schema.cluster_systeminfo; Field description: -* `TYPE`: Corresponds to the `TYPE` field in the [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) table. The optional values are `tidb`, `pd`, and `tikv`. -* `INSTANCE`: Corresponds to the `INSTANCE` field in the [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md) cluster information table. +* `TYPE`: Corresponds to the `TYPE` field in the [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) table. The optional values are `tidb`, `pd`, and `tikv`. +* `INSTANCE`: Corresponds to the `INSTANCE` field in the [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md) cluster information table. * `SYSTEM_TYPE`: The system type. Currently, you can query the `system` system type. * `SYSTEM_NAME`: The system name. Currently, you can query the `sysctl` system name. * `NAME`: The configuration name corresponding to `sysctl`. @@ -40,7 +41,7 @@ Field description: The following example shows how to query the kernel version of all servers in the cluster using the `CLUSTER_SYSTEMINFO` system information table. ```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-collation-character-set-applicability.md b/information-schema/information-schema-collation-character-set-applicability.md new file mode 100644 index 0000000000000..67ee8ac0ae684 --- /dev/null +++ b/information-schema/information-schema-collation-character-set-applicability.md @@ -0,0 +1,40 @@ +--- +title: COLLATION_CHARACTER_SET_APPLICABILITY +summary: Learn the `COLLATION_CHARACTER_SET_APPLICABILITY` information_schema table. +--- + +# COLLATION_CHARACTER_SET_APPLICABILITY + +The `COLLATION_CHARACTER_SET_APPLICABILITY` table maps collations to the applicable character set name. Similar to the `COLLATIONS` table, it is included only for compatibility with 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) +``` diff --git a/information-schema/information-schema-collations.md b/information-schema/information-schema-collations.md new file mode 100644 index 0000000000000..5196b77c49090 --- /dev/null +++ b/information-schema/information-schema-collations.md @@ -0,0 +1,44 @@ +--- +title: COLLATIONS +summary: Learn the `COLLATIONS` information_schema table. +--- + +# COLLATIONS + +The `COLLATIONS` table provides a list of collations that correspond to character sets in the `CHARACTER_SETS` table. Currently, this table is included only for compatibility with 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) +``` diff --git a/information-schema/information-schema-columns.md b/information-schema/information-schema-columns.md new file mode 100644 index 0000000000000..cfd3d8febcb2e --- /dev/null +++ b/information-schema/information-schema-columns.md @@ -0,0 +1,122 @@ +--- +title: COLUMNS +summary: Learn the `COLUMNS` information_schema table. +--- + +# COLUMNS + +The `COLUMNS` table provides detailed information about columns in tables. + +{{< 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 +``` + +``` +*************************** 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) +``` + +The description of columns in the `COLUMNS` table is as follows: + +* `TABLE_CATALOG`: The name of the catalog to which the table with the column belongs. The value is always `def`. +* `TABLE_SCHEMA`: The name of the schema in which the table with the column is located. +* `TABLE_NAME`: The name of the table with the column. +* `COLUMN_NAME`: The name of the column. +* `ORDINAL_POSITION`: The position of the column in the table. +* `COLUMN_DEFAULT`: The default value of the column. If the explicit default value is `NULL`, or if the column definition does not include the `default` clause, this value is `NULL`. +* `IS_NULLABLE`: Whether the column is nullable. If the column can store null values, this value is `YES`; otherwise, it is `NO`. +* `DATA_TYPE`: The type of data in the column. +* `CHARACTER_MAXIMUM_LENGTH`: For string columns, the maximum length in characters. +* `CHARACTER_OCTET_LENGTH`: For string columns, the maximum length in bytes. +* `NUMERIC_PRECISION`: The numeric precision of a number-type column. +* `NUMERIC_SCALE`: The numeric scale of a number-type column. +* `DATETIME_PRECISION`: For time-type columns, the fractional seconds precision. +* `CHARACTER_SET_NAME`: The name of the character set of a string column. +* `COLLATION_NAME`: The name of the collation of a string column. +* `COLUMN_TYPE`: The column type. +* `COLUMN_KEY`: Whether this column is indexed. This field might have the following values: + * Empty: This column is not indexed, or this column is indexed and is the second column in a multi-column non-unique index. + * `PRI`: This column is the primary key or one of multiple primary keys. + * `UNI`: This column is the first column of the unique index. + * `MUL`: The column is the first column of a non-unique index, in which a given value is allowed to occur for multiple times. +* `EXTRA`: Any additional information of the given column. +* `PRIVILEGES`: The privilege that the current user has on this column. Currently, this value is fixed in TiDB, and is always `select,insert,update,references`. +* `COLUMN_COMMENT`: Comments contained in the column definition. +* `GENERATION_EXPRESSION`: For generated columns, this value displays the expression used to calculate the column value. For non-generated columns, the value is empty. + +The corresponding `SHOW` statement is as follows: + +{{< copyable "sql" >}} + +```sql +SHOW COLUMNS FROM t1 FROM test; +``` + +``` ++-------+---------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------+---------+------+------+---------+-------+ +| a | int(11) | YES | | NULL | | ++-------+---------+------+------+---------+-------+ +1 row in set (0.00 sec) +``` \ No newline at end of file diff --git a/information-schema/information-schema-ddl-jobs.md b/information-schema/information-schema-ddl-jobs.md new file mode 100644 index 0000000000000..244abcdc3b63e --- /dev/null +++ b/information-schema/information-schema-ddl-jobs.md @@ -0,0 +1,97 @@ +--- +title: DDL_JOBS +summary: Learn the `DDL_JOBS` information_schema table. +--- + +# DDL_JOBS + +The `DDL_JOBS` table provides an `INFORMATION_SCHEMA` interface to the `ADMIN SHOW DDL JOBS` command. It provides both the current status and a short history of DDL operations across the TiDB cluster. + +{{< 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) +``` \ No newline at end of file diff --git a/information-schema/information-schema-engines.md b/information-schema/information-schema-engines.md new file mode 100644 index 0000000000000..fe27f0b6e2a3f --- /dev/null +++ b/information-schema/information-schema-engines.md @@ -0,0 +1,53 @@ +--- +title: ENGINES +summary: Learn the `ENGINES` information_schema table. +--- + +# ENGINES + +The `ENGINES` table provides information about storage engines. For compatibility, TiDB will always describe InnoDB as the only supported engine. In addition, other column values in the `ENGINES` table are also fixed values. + +{{< 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; +``` + +``` ++--------+---------+------------------------------------------------------------+--------------+------+------------+ +| 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) +``` + +The description of columns in the `ENGINES` table is as follows: + +* `ENGINES`: The name of the storage engine. +* `SUPPORT`: The level of support that the server has on the storage engine. In TiDB, the value is always `DEFAULT`. +* `COMMENT`: The brief comment on the storage engine. +* `TRANSACTIONS`:Whether the storage engine supports transactions. +* `XA`: Whether the storage engine supports XA transactions. +* `SAVEPOINTS`: Whether the storage engine supports `savepoints`. \ No newline at end of file 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 eff0edb1e2f91..86f23f3002466 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: Learn the `INSPECTION_RESULT` diagnostic result table. -aliases: ['/docs/dev/system-tables/system-table-inspection-result/','/docs/dev/reference/system-databases/inspection-result/'] +aliases: ['/docs/dev/system-tables/system-table-inspection-result/','/docs/dev/reference/system-databases/inspection-result/','/tidb/dev/system-table-inspection-result/'] --- # INSPECTION_RESULT @@ -15,7 +15,8 @@ The structure of the `information_schema.inspection_result` diagnostic result ta {{< copyable "sql" >}} ```sql -desc information_schema.inspection_result; +USE information_schema; +DESC inspection_result; ``` ```sql @@ -59,7 +60,7 @@ Diagnose issues currently existing in the cluster. {{< copyable "sql" >}} ```sql -select * from information_schema.inspection_result\G +SELECT * FROM information_schema.inspection_result\G ``` ```sql @@ -234,7 +235,7 @@ The `version` diagnostic rule checks whether the version hash of the same compon {{< copyable "sql" >}} ```sql -select * from information_schema.inspection_result where rule='version'\G +SELECT * FROM information_schema.inspection_result WHERE rule='version'\G ``` ```sql @@ -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` diagnostic rule diff --git a/information-schema/information-schema-inspection-rules.md b/information-schema/information-schema-inspection-rules.md new file mode 100644 index 0000000000000..ffcb49b95785e --- /dev/null +++ b/information-schema/information-schema-inspection-rules.md @@ -0,0 +1,55 @@ +--- +title: INSPECTION_RULES +summary: Learn the `INSPECTION_RULES` information_schema table. +--- + +# INSPECTION_RULES + +The `INSPECTION_RULES` table provides information about which diagnostic tests are run in an inspection result. See [inspection result](/information-schema/information-schema-inspection-result.md) for example usage. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC inspection_rules; +``` + +``` ++---------+--------------+------+------+---------+-------+ +| 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; +``` + +``` ++-----------------+------------+---------+ +| 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) +``` \ No newline at end of file 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 039735333cae1..73ac020752dbb 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: Learn the `INSPECTION_SUMMARY` inspection summary table. -aliases: ['/docs/dev/system-tables/system-table-inspection-summary/','/docs/dev/reference/system-databases/inspection-summary/'] +aliases: ['/docs/dev/system-tables/system-table-inspection-summary/','/docs/dev/reference/system-databases/inspection-summary/','/tidb/dev/system-table-inspection-summary/'] --- # INSPECTION_SUMMARY @@ -13,7 +13,8 @@ The structure of the `information_schema.inspection_summary` 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) ``` Field description: 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 0000000000000..fced0d73e959f --- /dev/null +++ b/information-schema/information-schema-key-column-usage.md @@ -0,0 +1,86 @@ +--- +title: KEY_COLUMN_USAGE +summary: Learn the `KEY_COLUMN_USAGE` information_schema table. +--- + +# KEY_COLUMN_USAGE + +The `KEY_COLUMN_USAGE` table describes the key constraints of the columns, such as the primary key constraint. + +{{< 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) +``` + +The description of columns in the `KEY_COLUMN_USAGE` table is as follows: + +* `CONSTRAINT_CATALOG`: The name of the catalog to which the constraint belongs. The value is always `def`. +* `CONSTRAINT_SCHEMA`: The name of the schema to which the constraint belongs. +* `CONSTRAINT_NAME`: The name of the constraint. +* `TABLE_CATALOG`: The name of the catalog to which the table belongs. The value is always `def`. +* `TABLE_SCHEMA`: The name of the schema to which the table belongs. +* `TABLE_NAME`: The name of the table with constraints. +* `COLUMN_NAME`: The name of the column with constraints. +* `ORDINAL_POSITION`: The position of the column in the constraint, rather than in the table. The position number starts from `1`. +* `POSITION_IN_UNIQUE_CONSTRAINT`: The unique constraint and the primary key constraint are empty. For foreign key constraints, this column is the position of the referenced table's key. +* `REFERENCED_TABLE_SCHEMA`: The name of the schema referenced by the constraint. Currently in TiDB, the value of this column in all constraints is `nil`, except for the foreign key constraint. +* `REFERENCED_TABLE_NAME`: The name of the table referenced by the constraint. Currently in TiDB, the value of this column in all constraints is `nil`, except for the foreign key constraint. +* `REFERENCED_COLUMN_NAME`: The name of the column referenced by the constraint. Currently in TiDB, the value of this column in all constraints is `nil`, except for the foreign key constraint. 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 fbd82986d359b..a9ef946fcb38a 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: Learn the `METRICS_SUMMARY` system table. -aliases: ['/docs/dev/system-tables/system-table-metrics-summary/','/docs/dev/reference/system-databases/metrics-summary/'] +aliases: ['/docs/dev/system-tables/system-table-metrics-summary/','/docs/dev/reference/system-databases/metrics-summary/',''/tidb/dev/system-table-metrics-summary/''] --- # METRICS_SUMMARY @@ -16,7 +16,8 @@ The two tables summarize all monitoring data for you to check each monitoring me {{< 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) ``` Field description: @@ -49,13 +51,13 @@ To query the three groups of monitoring items with the highest average time cons {{< 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,13 +92,13 @@ Similarly, the following example queries the `metrics_summary_by_label` monitori {{< 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 @@ -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 0000000000000..b49e2378dbd60 --- /dev/null +++ b/information-schema/information-schema-metrics-tables.md @@ -0,0 +1,76 @@ +--- +title: METRICS_TABLES +summary: Learn the `METRICS_TABLES` system table. +aliases: ['/docs/dev/system-tables/system-table-metrics-tables/','/docs/dev/reference/system-databases/metrics-tables/','/tidb/dev/system-table-metrics-tables/'] +--- + +# METRICS_TABLES + +The `METRICS_TABLES` table provides the PromQL (Prometheus Query Language) definition for each of the views in the [metrics_schema](/metrics-schema.md) database. + +{{< 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 | | ++------------+--------------+------+------+---------+-------+ +``` + +Field description: + +* `TABLE_NAME`: Corresponds to the table name in `metrics_schema`. +* `PROMQL`: The working principle of the monitoring table is to map SQL statements to `PromQL` and convert Prometheus results into SQL query results. This field is the expression template of `PromQL`. When you query the data of the monitoring table, the query conditions are used to rewrite the variables in this template to generate the final query expression. +* `LABELS`: The label for the monitoring item. Each label corresponds to a column in the monitoring table. If the SQL statement contains the filter of the corresponding column, the corresponding `PromQL` changes accordingly. +* `QUANTILE`: The percentile. For monitoring data of the histogram type, a default percentile is specified. If the value of this field is `0`, it means that the monitoring item corresponding to the monitoring table is not a histogram. +* `COMMENT`: The comment about the monitoring table. + +{{< 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-partitions.md b/information-schema/information-schema-partitions.md new file mode 100644 index 0000000000000..22b0d7a5b458d --- /dev/null +++ b/information-schema/information-schema-partitions.md @@ -0,0 +1,111 @@ +--- +title: PARTITIONS +summary: Learn the `PARTITIONS` information_schema table. +--- + +# PARTITIONS + +The `PARTITIONS` table provides information about partitioned tables. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC partitions; +``` + +``` ++-------------------------------+--------------+------+------+---------+-------+ +| 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 +``` + +``` +*************************** 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) +``` \ No newline at end of file diff --git a/information-schema/information-schema-processlist.md b/information-schema/information-schema-processlist.md new file mode 100644 index 0000000000000..e6119ccc1866d --- /dev/null +++ b/information-schema/information-schema-processlist.md @@ -0,0 +1,81 @@ +--- +title: PROCESSLIST +summary: Learn the `PROCESSLIST` information_schema table. +--- + +# PROCESSLIST + +`PROCESSLIST`, just like `SHOW PROCESSLIST`, is used to view the requests that are being handled. + +The `PROCESSLIST` table has additional columns not present in `SHOW PROCESSLIST`: + +* A `MEM` column to show memory occupied by the request being handled (in bytes) +* A `TxnStart` column to show the start time of the transaction + +{{< 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) +``` + +## 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 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) | ++-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ +``` \ No newline at end of file diff --git a/information-schema/information-schema-schemata.md b/information-schema/information-schema-schemata.md new file mode 100644 index 0000000000000..78e29db889e45 --- /dev/null +++ b/information-schema/information-schema-schemata.md @@ -0,0 +1,47 @@ +--- +title: SCHEMATA +summary: Learn the `SCHEMATA` information_schema table. +--- + +# SCHEMATA + +The `SCHEMATA` table provides information about databases. The table data is equivalent to the result of the `SHOW DATABASES` statement. + +{{< 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) +``` diff --git a/information-schema/information-schema-sequences.md b/information-schema/information-schema-sequences.md new file mode 100644 index 0000000000000..bd0d75c512800 --- /dev/null +++ b/information-schema/information-schema-sequences.md @@ -0,0 +1,65 @@ +--- +title: SEQUENCES +summary: Learn the `SEQUENCES` information_schema table. +--- + +# SEQUENCES + +The `SEQUENCES` table provides information about sequences. The [sequences feature](/sql-statements/sql-statement-create-sequence.md) is modeled on a similar feature in MariaDB. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC sequences; +``` + +``` ++-----------------+--------------+------+------+---------+-------+ +| 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) +``` \ No newline at end of file diff --git a/information-schema/information-schema-session-variables.md b/information-schema/information-schema-session-variables.md new file mode 100644 index 0000000000000..bc8a786696b20 --- /dev/null +++ b/information-schema/information-schema-session-variables.md @@ -0,0 +1,49 @@ +--- +title: SESSION_VARIABLES +summary: Learn the `SESSION_VARIABLES` information_schema table. +--- + +# SESSION_VARIABLES + +The `SESSION_VARIABLES` table provides information about session variables. The table data is similar to the result of the `SHOW SESSION VARIABLES` statement. + +{{< 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) +``` \ No newline at end of file diff --git a/information-schema/information-schema-slow-query.md b/information-schema/information-schema-slow-query.md new file mode 100644 index 0000000000000..0a9bb468415e3 --- /dev/null +++ b/information-schema/information-schema-slow-query.md @@ -0,0 +1,180 @@ +--- +title: SLOW_QUERY +summary: Learn the `SLOW_QUERY` information_schema table. +--- + +# SLOW_QUERY + +The `SLOW_QUERY` table provides the slow query information of the current node, which is the parsing result of the TiDB slow log file. The column names in the table are corresponding to the field names in the slow log. For how to use this table to identify problematic statements and improve query performance, see [Slow Query Log Document](/identify-slow-queries.md). + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC slow_query; +``` + +``` ++---------------------------+---------------------+------+------+---------+-------+ +| 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 + +The `CLUSTER_SLOW_QUERY` table provides the slow query information of all nodes in the cluster, which is the parsing result of the TiDB slow log files. You can use the `CLUSTER_SLOW_QUERY` table the way you do with `SLOW_QUERY`. The table schema of the `CLUSTER_SLOW_QUERY` table differs from that of the `SLOW_QUERY` table in that an `INSTANCE` column is added to `CLUSTER_SLOW_QUERY`. The `INSTANCE` column represents the TiDB node address of the row information on the slow query. For how to use this table to identify problematic statements and improve query performance, see [Slow Query Log Document](/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) +``` + +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 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 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" >}} + +```sql +SELECT /*+ AGG_TO_COP() */ count(*) FROM cluster_slow_query GROUP BY user; +``` diff --git a/system-tables/system-table-sql-diagnostics.md b/information-schema/information-schema-sql-diagnostics.md similarity index 64% rename from system-tables/system-table-sql-diagnostics.md rename to information-schema/information-schema-sql-diagnostics.md index 0040b2075ffdf..1ed93ba55ded7 100644 --- a/system-tables/system-table-sql-diagnostics.md +++ b/information-schema/information-schema-sql-diagnostics.md @@ -1,7 +1,7 @@ --- title: SQL Diagnostics summary: Understand SQL diagnostics in TiDB. -aliases: ['/docs/dev/system-tables/system-table-sql-diagnostics/','/docs/dev/reference/system-databases/sql-diagnosis/','/docs/dev/system-tables/system-table-sql-diagnosis/'] +aliases: ['/docs/dev/system-tables/system-table-sql-diagnostics/','/docs/dev/reference/system-databases/sql-diagnosis/','/docs/dev/system-tables/system-table-sql-diagnosis/','/tidb/dev/system-table-sql-diagnostics/'] --- # SQL Diagnostics @@ -33,12 +33,12 @@ The SQL diagnostic system consists of three major parts: The cluster information tables bring together the information of all instances and instances in a cluster. With these tables, you can query all cluster information using only one SQL statement. The following is a list of cluster information tables: -+ From the cluster topology table [`information_schema.cluster_info`](/system-tables/system-table-cluster-info.md), you can get the current topology information of the cluster, the version of each instance, the Git Hash corresponding to the version, the starting time of each instance, and the running time of each instance. -+ From the cluster configuration table [`information_schema.cluster_config`](/system-tables/system-table-cluster-config.md), you can get the configuration of all instances in the cluster. For versions earlier than 4.0, you need to access the HTTP API of each instance one by one to get these configuration information. -+ On the cluster hardware table [`information_schema.cluster_hardware`](/system-tables/system-table-cluster-hardware.md), you can quickly query the cluster hardware information. -+ On the cluster load table [`information_schema.cluster_load`](/system-tables/system-table-cluster-load.md), you can query the load information of different instances and hardware types of the cluster. -+ On the kernel parameter table [`information_schema.cluster_systeminfo`](/system-tables/system-table-cluster-systeminfo.md), you can query the kernel configuration information of different instances in the cluster. Currently, TiDB supports querying the sysctl information. -+ On the cluster log table [`information_schema.cluster_log`](/system-tables/system-table-cluster-log.md), you can query cluster logs. By pushing down query conditions to each instance, the impact of the query on cluster performance is less than that of the `grep` command. ++ From the cluster topology table [`information_schema.cluster_info`](/information-schema/information-schema-cluster-info.md), you can get the current topology information of the cluster, the version of each instance, the Git Hash corresponding to the version, the starting time of each instance, and the running time of each instance. ++ From the cluster configuration table [`information_schema.cluster_config`](/information-schema/information-schema-cluster-config.md), you can get the configuration of all instances in the cluster. For versions earlier than 4.0, you need to access the HTTP API of each instance one by one to get these configuration information. ++ On the cluster hardware table [`information_schema.cluster_hardware`](/information-schema/information-schema-cluster-hardware.md), you can quickly query the cluster hardware information. ++ On the cluster load table [`information_schema.cluster_load`](/information-schema/information-schema-cluster-load.md), you can query the load information of different instances and hardware types of the cluster. ++ On the kernel parameter table [`information_schema.cluster_systeminfo`](/information-schema/information-schema-cluster-systeminfo.md), you can query the kernel configuration information of different instances in the cluster. Currently, TiDB supports querying the sysctl information. ++ On the cluster log table [`information_schema.cluster_log`](/information-schema/information-schema-cluster-log.md), you can query cluster logs. By pushing down query conditions to each instance, the impact of the query on cluster performance is less than that of the `grep` command. On the system tables earlier than TiDB v4.0, you can only view the current instance. TiDB v4.0 introduces the corresponding cluster tables and you can have a global view of the entire cluster on a single TiDB instance. These tables are currently in `information_schema`, and the query method is the same as other `information_schema` system tables. @@ -46,16 +46,16 @@ On the system tables earlier than TiDB v4.0, you can only view the current insta To dynamically observe and compare cluster conditions in different time periods, the SQL diagnostic system introduces cluster monitoring system tables. All monitoring tables are in `metrics_schema`, and you can query the monitoring information using SQL statements. Using this method, you can perform correlated queries on all monitoring information of the entire cluster and compare the results of different time periods to quickly identify performance bottlenecks. -+ [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md): Because many system tables exist now, you can query meta-information of these monitoring tables on the `information_schema.metrics_tables` table. ++ [`information_schema.metrics_tables`](/information-schema/information-schema-metrics-tables.md): Because many system tables exist now, you can query meta-information of these monitoring tables on the `information_schema.metrics_tables` table. Because the TiDB cluster has many monitoring metrics, TiDB provides the following monitoring summary tables in v4.0: -+ The monitoring summary table [`information_schema.metrics_summary`](/system-tables/system-table-metrics-summary.md) summarizes all monitoring data to for you to check each monitoring metric with higher efficiency. -+ [`information_schema.metrics_summary_by_label`](/system-tables/system-table-metrics-summary.md) also summarizes all monitoring data. Particularly, this table aggregates statistics using different labels of each monitoring metric. ++ The monitoring summary table [`information_schema.metrics_summary`](/information-schema/information-schema-metrics-summary.md) summarizes all monitoring data to for you to check each monitoring metric with higher efficiency. ++ [`information_schema.metrics_summary_by_label`](/information-schema/information-schema-metrics-summary.md) also summarizes all monitoring data. Particularly, this table aggregates statistics using different labels of each monitoring metric. ## Automatic diagnostics On the cluster information tables and cluster monitoring tables above, you need to manually execute SQL statements to troubleshoot the cluster. TiDB v4.0 supports the automatic diagnostics. You can use diagnostic-related system tables based on the existing basic information tables, so that the diagnostics is automatically executed. The following are the system tables related to the automatic diagnostics: -+ The diagnostic result table [`information_schema.inspection_result`](/system-tables/system-table-inspection-result.md) displays the diagnostic result of the system. The diagnostics is passively triggered. Executing `select * from inspection_result` triggers all diagnostic rules to diagnose the system, and the faults or risks in the system are displayed in the results. -+ The diagnostic summary table [`information_schema.inspection_summary`](/system-tables/system-table-inspection-summary.md) summarizes the monitoring information of a specific link or module. You can troubleshoot and locate problems based on the context of the entire module or link. ++ The diagnostic result table [`information_schema.inspection_result`](/information-schema/information-schema-inspection-result.md) displays the diagnostic result of the system. The diagnostics is passively triggered. Executing `select * from inspection_result` triggers all diagnostic rules to diagnose the system, and the faults or risks in the system are displayed in the results. ++ The diagnostic summary table [`information_schema.inspection_summary`](/information-schema/information-schema-inspection-summary.md) summarizes the monitoring information of a specific link or module. You can troubleshoot and locate problems based on the context of the entire module or link. diff --git a/information-schema/information-schema-statistics.md b/information-schema/information-schema-statistics.md new file mode 100644 index 0000000000000..03a5d5a365ab0 --- /dev/null +++ b/information-schema/information-schema-statistics.md @@ -0,0 +1,53 @@ +--- +title: STATISTICS +summary: Learn the `STATISTICS` information_schema table. +--- + +# STATISTICS + +The `STATISTICS` table provides information about table indexes. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC statistics; +``` + +``` ++---------------+---------------+------+------+---------+-------+ +| 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) +``` + +The following statements are equivalent: + +```sql +SELECT * FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'tbl_name' + AND table_schema = 'db_name' + +SHOW INDEX + FROM tbl_name + FROM db_name +``` \ No newline at end of file diff --git a/information-schema/information-schema-table-constraints.md b/information-schema/information-schema-table-constraints.md new file mode 100644 index 0000000000000..c7b38cad0173c --- /dev/null +++ b/information-schema/information-schema-table-constraints.md @@ -0,0 +1,53 @@ +--- +title: TABLE_CONSTRAINTS +summary: Learn the `TABLE_CONSTRAINTS` information_schema table. +--- + +# TABLE_CONSTRAINTS + +The `TABLE_CONSTRAINTS` table describes which tables have constraints. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC table_constraints; +``` + +``` ++--------------------+--------------+------+------+---------+-------+ +| 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'; +``` + +``` ++--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+ +| 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) +``` + +- The `CONSTRAINT_TYPE` value can be `UNIQUE`, `PRIMARY KEY`, or `FOREIGN KEY`. +- The `UNIQUE` and `PRIMARY KEY` information is similar to the result of the `SHOW INDEX` statement. \ No newline at end of file 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 0000000000000..c45515ed86e28 --- /dev/null +++ b/information-schema/information-schema-table-storage-stats.md @@ -0,0 +1,52 @@ +--- +title: TABLE_STORAGE_STATS +summary: Learn the `TABLE_STORAGE_STATS` information_schema table. +--- + +# TABLE_STORAGE_STATS + +The `TABLE_STORAGE_STATS` table provides information about table sizes as stored by the storage engine (TiKV). + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC table_storage_stats; +``` + +``` ++--------------------+-------------+------+------+---------+-------+ +| 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 +``` + +``` +*************************** 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) +``` \ No newline at end of file diff --git a/information-schema/information-schema-tables.md b/information-schema/information-schema-tables.md new file mode 100644 index 0000000000000..28dca095253fe --- /dev/null +++ b/information-schema/information-schema-tables.md @@ -0,0 +1,102 @@ +--- +title: TABLES +summary: Learn the `TABLES` information_schema table. +--- + +# TABLES + +The `TABLES` table provides information about tables in databases: + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tables; +``` + +``` ++---------------------------+---------------+------+------+----------+-------+ +| 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 +``` + +``` +*************************** 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) +``` + +The following statements are equivalent: + +```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'] +``` + +Most of the information in the table is the same as MySQL. Only two columns are newly defined by TiDB: + +* `TIDB_TABLE_ID`: to indicate the internal ID of a table. This ID is unique in a TiDB cluster. +* `TIDDB_ROW_ID_SHARDING_INFO`: to indicate the sharding type of a table. The possible values are as follows: + - `"NOT_SHARDED"`: the table is not sharded. + - `"NOT_SHARDED(PK_IS_HANDLE)"`: the table that defines an integer Primary Key as its row id is not sharded. + - `"PK_AUTO_RANDOM_BITS={bit_number}"`: the table that defines an integer Primary Key as its row id is sharded because the Primary Key is assigned with `AUTO_RANDOM` attribute. + - `"SHARD_BITS={bit_number}"`: the table is sharded using `SHARD_ROW_ID_BITS={bit_number}`. + - NULL: the table is a system table or view, and thus cannot be sharded. 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 0000000000000..98ead5d7daa1b --- /dev/null +++ b/information-schema/information-schema-tidb-hot-regions.md @@ -0,0 +1,36 @@ +--- +title: TIDB_HOT_REGIONS +summary: Learn the `TIDB_HOT_REGIONS` information_schema table. +--- + +# TIDB_HOT_REGIONS + +The `TIDB_HOT_REGIONS` table provides information about hotspot Regions. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tidb_hot_regions; +``` + +``` ++----------------+-------------+------+------+---------+-------+ +| 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) +``` + +- `TABLE_ID` and `INDEX_ID` are IDs generated for the corresponding table and index in TiDB. +- `TYPE` is the type for a hot Region. Its value can be `READ` or `WRITE`. \ No newline at end of file diff --git a/information-schema/information-schema-tidb-indexes.md b/information-schema/information-schema-tidb-indexes.md new file mode 100644 index 0000000000000..ca62404bd2705 --- /dev/null +++ b/information-schema/information-schema-tidb-indexes.md @@ -0,0 +1,62 @@ +--- +title: TIDB_INDEXES +summary: Learn the `TIDB_INDEXES` information_schema table. +--- + +# TIDB_INDEXES + +The `TIDB_INDEXES` table provides the INDEX information of all tables. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tidb_indexes; +``` + +``` ++---------------+---------------+------+------+---------+-------+ +| 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` is the unique ID that TiDB allocates for each index. It can be used to do a join operation with `INDEX_ID` obtained from another table or API. + +For example, you can obtain `TABLE_ID` and `INDEX_ID` that are involved in some slow query in the [`SLOW_QUERY` table](/information-schema/information-schema-slow-query.md) and then obtain the specific index information using the following SQL statements: + +```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 = ? +``` + +Fields in the `TIDB_INDEXES` table are described as follows: + +* `TABLE_SCHEMA`: The name of the schema to which the index belongs. +* `TABLE_NAME`: The name of the table to which the index belongs. +* `NON_UNIQUE`: If the index is unique, the value is `0`; otherwise, the value is `1`. +* `KEY_NAME`: The index name. If the index is the primary key, the name is `PRIMARY`. +* `SEQ_IN_INDEX`: The sequential number of columns in the index, which starts from `1`. +* `COLUMN_NAME`: The name of the column where the index is located. +* `SUB_PART`: The prefix length of the index. If the the column is partly indexed, the `SUB_PART` value is the count of the indexed characters; otherwise, the value is `NULL`. +* `INDEX_COMMENT`: The comment of the index, which is made when the index is created. +* `INDEX_ID`: The index ID. \ No newline at end of file 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 0000000000000..04de17417489f --- /dev/null +++ b/information-schema/information-schema-tidb-servers-info.md @@ -0,0 +1,50 @@ +--- +title: TIDB_SERVERS_INFO +summary: Learn the `TIDB_SERVERS_INFO` information_schema table. +--- + +# TIDB_SERVERS_INFO + +The `TIDB_SERVERS_INFO` table provides information about TiDB servers in the TiDB Cluster (i.e. tidb-server processes). + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tidb_servers_info; +``` + +``` ++---------------+-------------+------+------+---------+-------+ +| 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 +``` + +``` +*************************** 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) +``` \ No newline at end of file diff --git a/information-schema/information-schema-tiflash-replica.md b/information-schema/information-schema-tiflash-replica.md new file mode 100644 index 0000000000000..38da3a3607da0 --- /dev/null +++ b/information-schema/information-schema-tiflash-replica.md @@ -0,0 +1,30 @@ +--- +title: TIFLASH_REPLICA +summary: Learn the `TIFLASH_REPLICA` information_schema table. +--- + +# TIFLASH_REPLICA + +The `TIFLASH_REPLICA` table provides information about TiFlash replicas available. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tiflash_replica; +``` + +``` ++-----------------+-------------+------+------+---------+-------+ +| 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) +``` 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 0000000000000..0acb64d49f074 --- /dev/null +++ b/information-schema/information-schema-tikv-region-peers.md @@ -0,0 +1,47 @@ +--- +title: TIKV_REGION_PEERS +summary: Learn the `TIKV_REGION_PEERS` information_schema table. +--- + +# TIKV_REGION_PEERS + +The `TIKV_REGION_PEERS` table shows detailed information of a single Region node in TiKV, such as whether it is a learner or leader. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tikv_region_peers; +``` + +``` ++--------------+-------------+------+------+---------+-------+ +| 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) +``` + +For example, you can query the specific TiKV addresses for the top 3 Regions with the maximum value of `WRITTEN_BYTES` using the following SQL statement: + +```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; + ``` \ No newline at end of file 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 0000000000000..0f25f34ab968a --- /dev/null +++ b/information-schema/information-schema-tikv-region-status.md @@ -0,0 +1,48 @@ +--- +title: TIKV_REGION_STATUS +summary: Learn the `TIKV_REGION_STATUS` information_schema table. +--- + +# TIKV_REGION_STATUS + +The `TIKV_REGION_STATUS` table shows some basic information of TiKV Regions via PD's API, like the Region ID, starting and ending key-values, and read and write traffic. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tikv_region_status; +``` + +``` ++---------------------------+-------------+------+------+---------+-------+ +| 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) +``` + +You can implement the `top confver`, `top read` and `top write` operations in pd-ctl via the `ORDER BY X LIMIT Y` operation on the `EPOCH_CONF_VER`, `WRITTEN_BYTES` and `READ_BYTES` columns. + +You can query the top 3 Regions with the most write data using the following SQL statement: + +```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-tikv-store-status.md b/information-schema/information-schema-tikv-store-status.md new file mode 100644 index 0000000000000..98aebdd60b446 --- /dev/null +++ b/information-schema/information-schema-tikv-store-status.md @@ -0,0 +1,42 @@ +--- +title: TIKV_STORE_STATUS +summary: Learn the `TIKV_STORE_STATUS` information_schema table. +--- + +# TIKV_STORE_STATUS + +The `TIKV_STORE_STATUS` table shows some basic information of TiKV nodes via PD's API, like the ID allocated in the cluster, address and port, and status, capacity, and the number of Region leaders of the current node. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC tikv_store_status; +``` + +``` ++-------------------+-------------+------+------+---------+-------+ +| 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) +``` diff --git a/information-schema/information-schema-user-privileges.md b/information-schema/information-schema-user-privileges.md new file mode 100644 index 0000000000000..92d5dabba5d5b --- /dev/null +++ b/information-schema/information-schema-user-privileges.md @@ -0,0 +1,76 @@ +--- +title: USER_PRIVILEGES +summary: Learn the `USER_PRIVILEGES` information_schema table. +--- + +# USER_PRIVILEGES + +The `USER_PRIVILEGES` table provides information about global privileges. This information comes from the `mysql.user` system table: + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC user_privileges; +``` + +``` ++----------------+--------------+------+------+---------+-------+ +| 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; +``` + +``` ++------------+---------------+-------------------------+--------------+ +| 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) +``` + +Fields in the `USER_PRIVILEGES` table are described as follows: + +* `GRANTEE`: The name of the granted user, which is in the format of `'user_name'@'host_name'`. +* `TABLE_CATALOG`: The name of the catalog to which the table belongs. This value is always `def`. +* `PRIVILEGE_TYPE`: The privilege type to be granted. Only one privilege type is shown in each row. +* `IS_GRANTABLE`: If you have the `GRANT OPTION` privilege, the value is `YES`; otherwise, the value is `NO`. \ No newline at end of file diff --git a/information-schema/information-schema-views.md b/information-schema/information-schema-views.md new file mode 100644 index 0000000000000..eac14934e527e --- /dev/null +++ b/information-schema/information-schema-views.md @@ -0,0 +1,68 @@ +--- +title: VIEWS +summary: Learn the `VIEWS` information_schema table. +--- + +# VIEWS + +The `VIEWS` table provides information about SQL views. + +{{< copyable "sql" >}} + +```sql +USE information_schema; +DESC views; +``` + +``` ++----------------------+--------------+------+------+---------+-------+ +| 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 +``` + +``` +*************************** 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) +``` + +Fields in the `VIEWS` table are described as follows: + +* `TABLE_CATALOG`: The name of the catalog to which the view belongs. This value is always `def`. +* `TABLE_SCHEMA`: The name of the schema to which the view belongs. +* `TABLE_NAME`: The view name. +* `VIEW_DEFINITION`: The definition of view, which is made by the `SELECT` statement when the view is created. +* `CHECK_OPTION`: The `CHECK_OPTION` value. The value options are `NONE`, `CASCADE`, and `LOCAL`. +* `IS_UPDATABLE`: Whether `UPDATE`/`INSERT`/`DELETE` is applicable to the view. In TiDB, the value is always `NO`. +* `DEFINER`: The name of the user who creates the view, which is in the format of `'user_name'@'host_name'`. +* `SECURITY_TYPE`: The value of `SQL SECURITY`. The value options are `DEFINER` and `INVOKER`. +* `CHARACTER_SET_CLIENT`: The value of the `character_set_client` session variable when the view is created. +* `COLLATION_CONNECTION`: The value of the `collation_connection` session variable when the view is created. \ No newline at end of file diff --git a/system-tables/system-table-metrics-schema.md b/metrics-schema.md similarity index 76% rename from system-tables/system-table-metrics-schema.md rename to metrics-schema.md index b2cb53e0bc756..203c0514376b3 100644 --- a/system-tables/system-table-metrics-schema.md +++ b/metrics-schema.md @@ -1,14 +1,102 @@ --- title: Metrics Schema summary: Learn the `METRICS_SCHEMA` schema. -aliases: ['/docs/dev/system-tables/system-table-metrics-schema/','/docs/dev/reference/system-databases/metrics-schema/'] +aliases: ['/docs/dev/system-tables/system-table-metrics-schema/','/docs/dev/reference/system-databases/metrics-schema/','/tidb/dev/system-table-metrics-schema/'] --- # Metrics Schema -To dynamically observe and compare cluster conditions of different time ranges, the SQL diagnostic system introduces cluster monitoring system tables. All monitoring tables are in the `metrics_schema` database. You can query the monitoring information using SQL statements in this schema. The data of the three monitoring-related summary tables ([`metrics_summary`](/system-tables/system-table-metrics-summary.md), [`metrics_summary_by_label`](/system-tables/system-table-metrics-summary.md), and `inspection_result`) are all obtained by querying the monitoring tables in the metrics schema. Currently, many system tables are added, so you can query the information of these tables using the [`information_schema.metrics_tables`](/system-tables/system-table-metrics-tables.md) table. +The `METRICS_SCHEMA` is a set of views on top of TiDB metrics that are stored in Prometheus. The source of the PromQL (Prometheus Query Language) for each of the tables is available in [`INFORMATION_SCHEMA.METRICS_TABLES`](/information-schema/information-schema-metrics-tables.md). -## Overview +{{< 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) +``` + +The `METRICS_SCHEMA` is used as a data source for monitoring-related summary tables such as ([`metrics_summary`](/information-schema/information-schema-metrics-summary.md), [`metrics_summary_by_label`](/information-schema/information-schema-metrics-summary.md) and [`inspection_summary`](/information-schema/information-schema-inspection-summary.md). + +## Additional Examples Taking the `tidb_query_duration` monitoring table in `metrics_schema` as an example, this section illustrates how to use this monitoring table and how it works. The working principles of other monitoring tables are similar to `tidb_query_duration`. diff --git a/system-tables/system-table-overview.md b/mysql-schema.md similarity index 70% rename from system-tables/system-table-overview.md rename to mysql-schema.md index b5315e44bac35..baa678c92ed5a 100644 --- a/system-tables/system-table-overview.md +++ b/mysql-schema.md @@ -1,12 +1,12 @@ --- -title: TiDB System Tables -summary: Learn the TiDB system tables. -aliases: ['/docs/dev/system-tables/system-table-overview/','/docs/dev/reference/system-databases/mysql/'] +title: `mysql` schema +summary: Learn about the TiDB system tables. +aliases: ['/docs/dev/system-tables/system-table-overview/','/docs/dev/reference/system-databases/mysql/','/tidb/dev/system-table-overview/'] --- -# TiDB System Tables +# `mysql` schema -This document introduces TiDB system tables. +The `mysql` schema contains TiDB system tables. The design is similar to the `mysql` schema in MySQL, where tables such as `mysql.user` can be edited directly. It also contains a number of tables which are extensions to MySQL. ## Grant system tables diff --git a/sql-statements/sql-statement-show-analyze-status.md b/sql-statements/sql-statement-show-analyze-status.md index 029000c44581a..0f077a374b5e6 100644 --- a/sql-statements/sql-statement-show-analyze-status.md +++ b/sql-statements/sql-statement-show-analyze-status.md @@ -46,4 +46,4 @@ show analyze status; ## See also -* [ANALYZE_STATUS table](/system-tables/system-table-information-schema.md#analyze_status-table) +* [ANALYZE_STATUS table](/information-schema/information-schema-analyze-status.md) diff --git a/system-tables/system-table-information-schema.md b/system-tables/system-table-information-schema.md deleted file mode 100644 index 9dabb4ac72062..0000000000000 --- a/system-tables/system-table-information-schema.md +++ /dev/null @@ -1,1266 +0,0 @@ ---- -title: Information Schema -summary: Learn how to use Information Schema in TiDB. -aliases: ['/docs/dev/system-tables/system-table-information-schema/','/docs/dev/reference/system-databases/information-schema/'] ---- - -# Information Schema - -As part of MySQL compatibility, TiDB supports a number of `INFORMATION_SCHEMA` tables. Many of these tables also have a corresponding `SHOW` command. The benefit of querying `INFORMATION_SCHEMA` is that it is possible to join between tables. - -## Fully Supported Information Schema Tables - -### ANALYZE_STATUS table - -The `ANALYZE_STATUS` table provides information about the running tasks that collect statistics and a limited number of history tasks. - -{{< 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 table - -The `CHARACTER_SETS` table provides information about [character sets](/character-set-and-collation.md). Currently, TiDB only supports some of the character sets. - -{{< 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) -``` - -### COLLATIONS table - -The `COLLATIONS` table provides a list of collations that correspond to character sets in the `CHARACTER_SETS` table. Currently this table is included only for compatibility with MySQL, as TiDB only supports binary collation: - -{{< 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_CHARACTER_SET_APPLICABILITY table - -The `COLLATION_CHARACTER_SET_APPLICABILITY` table maps collations to the applicable character set name. Similar to the `COLLATIONS` table, it is included only for compatibility with MySQL: - -{{< copyable "sql" >}} - -```sql -SELECT * FROM collation_character_set_applicability WHERE character_set_name='utf8mb4'; -``` - -```sql -+------------------------+--------------------+ -| COLLATION_NAME | CHARACTER_SET_NAME | -+------------------------+--------------------+ -| utf8mb4_general_ci | utf8mb4 | -| utf8mb4_bin | utf8mb4 | -| utf8mb4_unicode_ci | utf8mb4 | -| utf8mb4_icelandic_ci | utf8mb4 | -| utf8mb4_latvian_ci | utf8mb4 | -| utf8mb4_romanian_ci | utf8mb4 | -| utf8mb4_slovenian_ci | utf8mb4 | -| utf8mb4_polish_ci | utf8mb4 | -| utf8mb4_estonian_ci | utf8mb4 | -| utf8mb4_spanish_ci | utf8mb4 | -| utf8mb4_swedish_ci | utf8mb4 | -| utf8mb4_turkish_ci | utf8mb4 | -| utf8mb4_czech_ci | utf8mb4 | -| utf8mb4_danish_ci | utf8mb4 | -| utf8mb4_lithuanian_ci | utf8mb4 | -| utf8mb4_slovak_ci | utf8mb4 | -| utf8mb4_spanish2_ci | utf8mb4 | -| utf8mb4_roman_ci | utf8mb4 | -| utf8mb4_persian_ci | utf8mb4 | -| utf8mb4_esperanto_ci | utf8mb4 | -| utf8mb4_hungarian_ci | utf8mb4 | -| utf8mb4_sinhala_ci | utf8mb4 | -| utf8mb4_german2_ci | utf8mb4 | -| utf8mb4_croatian_ci | utf8mb4 | -| utf8mb4_unicode_520_ci | utf8mb4 | -| utf8mb4_vietnamese_ci | utf8mb4 | -+------------------------+--------------------+ -26 rows in set (0.00 sec) -``` - -### COLUMNS table - -The `COLUMNS` table provides detailed information about columns in tables: - -{{< copyable "sql" >}} - -```sql -CREATE TABLE test.t1 (a int); -``` - -```sql -1 row in set (0.01 sec) -``` - -{{< copyable "sql" >}} - -```sql -SELECT * FROM information_schema.columns WHERE table_schema='test' AND TABLE_NAME='t1'; -``` - -```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.01 sec) -``` - -The description of columns in the `COLUMNS` table is as follows: - -* `TABLE_CATALOG`: The name of the catalog to which the table with the column belongs. The value is always `def`. -* `TABLE_SCHEMA`: The name of the schema in which the table with the column is located. -* `TABLE_NAME`: The name of the table with the column. -* `COLUMN_NAME`: The name of the column. -* `ORDINAL_POSITION`: The position of the column in the table. -* `COLUMN_DEFAULT`: The default value of the column. If the explicit default value is `NULL`, or if the column definition does not include the `default` clause, this value is `NULL`. -* `IS_NULLABLE`: Whether the column is nullable. If the column can store null values, this value is `YES`; otherwise, it is `NO`. -* `DATA_TYPE`: The type of data in the column. -* `CHARACTER_MAXIMUM_LENGTH`: For string columns, the maximum length in characters. -* `CHARACTER_OCTET_LENGTH`: For string columns, the maximum length in bytes. -* `NUMERIC_PRECISION`: The numeric precision of a number-type column. -* `NUMERIC_SCALE`: The numeric scale of a number-type column. -* `DATETIME_PRECISION`: For time-type columns, the fractional seconds precision. -* `CHARACTER_SET_NAME`: The name of the character set of a string column. -* `COLLATION_NAME`: The name of the collation of a string column. -* `COLUMN_TYPE`: The column type. -* `COLUMN_KEY`: Whether this column is indexed. This field might have the following values: - * Empty: This column is not indexed, or this column is indexed and is the second column in a multi-column non-unique index. - * `PRI`: This column is the primary key or one of multiple primary keys. - * `UNI`: This column is the first column of the unique index. - * `MUL`: The column is the first column of a non-unique index, in which a given value is allowed to occur for multiple times. -* `EXTRA`: Any additional information of the given column. -* `PRIVILEGES`: The privilege that the current user has on this column. Currently, this value is fixed in TiDB, and is always `select,insert,update,references`. -* `COLUMN_COMMENT`: Comments contained in the column definition. -* `GENERATION_EXPRESSION`: For generated columns, this value displays the expression used to calculate the column value. For non-generated columns, the value is empty. - -The corresponding `SHOW` statement is as follows: - -{{< 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 table - -The `ENGINES` table provides information about storage engines. For compatibility, TiDB will always describe InnoDB as the only supported engine. In addition, other column values in the `ENGINES` table are also fixed values. - -{{< copyable "sql" >}} - -```sql -SELECT * FROM engines; -``` - -```sql -*************************** 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) -``` - -The description of columns in the `ENGINES` table is as follows: - -* `ENGINES`: The name of the storage engine. -* `SUPPORT`: The level of support that the server has on the storage engine. In TiDB, the value is always `DEFAULT`. -* `COMMENT`: The brief comment on the storage engine. -* `TRANSACTIONS`:Whether the storage engine supports transactions. -* `XA`: Whether the storage engine supports XA transactions. -* `SAVEPOINTS`: Whether the storage engine supports `savepoints`. - -### KEY_COLUMN_USAGE table - -The `KEY_COLUMN_USAGE` table describes the key constraints of the columns, such as the primary key constraint: - -{{< copyable "sql" >}} - -```sql -SELECT * FROM key_column_usage WHERE table_schema='mysql' and table_name='user'; -``` - -```sql -*************************** 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) -``` - -The description of columns in the `KEY_COLUMN_USAGE` table is as follows: - -* `CONSTRAINT_CATALOG`: The name of the catalog to which the constraint belongs. The value is always `def`. -* `CONSTRAINT_SCHEMA`: The name of the schema to which the constraint belongs. -* `CONSTRAINT_NAME`: The name of the constraint. -* `TABLE_CATALOG`: The name of the catalog to which the table belongs. The value is always `def`. -* `TABLE_SCHEMA`: The name of the schema to which the table belongs. -* `TABLE_NAME`: The name of the table with constraints. -* `COLUMN_NAME`: The name of the column with constraints. -* `ORDINAL_POSITION`: The position of the column in the constraint, rather than in the table. The position number starts from `1`. -* `POSITION_IN_UNIQUE_CONSTRAINT`: The unique constraint and the primary key constraint are empty. For foreign key constraints, this column is the position of the referenced table's key. -* `REFERENCED_TABLE_SCHEMA`: The name of the schema referenced by the constraint. Currently in TiDB, the value of this column in all constraints is `nil`, except for the foreign key constraint. -* `REFERENCED_TABLE_NAME`: The name of the table referenced by the constraint. Currently in TiDB, the value of this column in all constraints is `nil`, except for the foreign key constraint. -* `REFERENCED_COLUMN_NAME`: The name of the column referenced by the constraint. Currently in TiDB, the value of this column in all constraints is `nil`, except for the foreign key constraint. - -### PROCESSLIST table - -`PROCESSLIST`, just like `show processlist`, is used to view the requests that are being handled. - -The `PROCESSLIST` table has a `MEM` column that `show processlist` does not have. `MEM` means the occupied memory of the requests being handled, and its unit is `byte`. - -```sql -+----+------+------+--------------------+---------+------+-------+---------------------------+-----+ -| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | -+----+------+------+--------------------+---------+------+-------+---------------------------+-----+ -| 1 | root | ::1 | INFORMATION_SCHEMA | Query | 0 | 2 | select * from PROCESSLIST | 0 | -+----+------+------+--------------------+---------+------+-------+---------------------------+-----+ -``` - -### SCHEMATA table - -The `SCHEMATA` table provides information about databases. The table data is equivalent to the result of the `SHOW DATABASES` statement: - -{{< copyable "sql" >}} - -```sql -select * from SCHEMATA; -``` - -```sql -*************************** 1. row *************************** - CATALOG_NAME: def - SCHEMA_NAME: INFORMATION_SCHEMA -DEFAULT_CHARACTER_SET_NAME: utf8mb4 - DEFAULT_COLLATION_NAME: utf8mb4_bin - SQL_PATH: NULL -*************************** 2. row *************************** - CATALOG_NAME: def - SCHEMA_NAME: mysql -DEFAULT_CHARACTER_SET_NAME: utf8mb4 - DEFAULT_COLLATION_NAME: utf8mb4_bin - SQL_PATH: NULL -*************************** 3. row *************************** - CATALOG_NAME: def - SCHEMA_NAME: PERFORMANCE_SCHEMA -DEFAULT_CHARACTER_SET_NAME: utf8mb4 - DEFAULT_COLLATION_NAME: utf8mb4_bin - SQL_PATH: NULL -*************************** 4. row *************************** - CATALOG_NAME: def - SCHEMA_NAME: test -DEFAULT_CHARACTER_SET_NAME: utf8mb4 - DEFAULT_COLLATION_NAME: utf8mb4_bin - SQL_PATH: NULL -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; -``` - -```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) | -+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+ -``` - -### 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: - -{{< 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) -``` - -## SLOW_QUERY table - -The `SLOW_QUERY` table provides the slow query information of the current node, which is the parsing result of the TiDB slow log file. The column names in the table are corresponding to the field names in the slow log. For how to use this table to identify problematic statements and improve query performance, see [Slow Query Log Document](/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 table - -The `CLUSTER_SLOW_QUERY` table provides the slow query information of all nodes in the cluster, which is the parsing result of the TiDB slow log files. You can use the `CLUSTER_SLOW_QUERY` table the way you do with [`SLOW_QUERY`](#slow_query-table). The table schema of the `CLUSTER_SLOW_QUERY` table differs from that of the `SLOW_QUERY` table in that an `INSTANCE` column is added to `CLUSTER_SLOW_QUERY`. The `INSTANCE` column represents the TiDB node address of the row information on the slow query. For how to use this table to identify problematic statements and improve query performance, see [Slow Query Log Document](/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 | | | | -+---------------------------+---------------------+------+-----+---------+-------+ -``` - -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'; -``` - -```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 | -+--------------------------+----------+-----------+--------------------------+------------------------------------------------------+ -``` - -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 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" >}} - -```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: - -{{< 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 | | -+---------------+---------------+------+------+---------+-------+ -``` - -The following statements are equivalent: - -```sql -SELECT * FROM INFORMATION_SCHEMA.STATISTICS - WHERE table_name = 'tbl_name' - AND table_schema = 'db_name' - -SHOW INDEX - FROM tbl_name - FROM db_name -``` - -### TABLES table - -The `TABLES` table provides information about tables in databases: - -{{< copyable "sql" >}} - -```sql -SELECT * FROM tables WHERE table_schema='mysql' AND table_name='user'; -``` - -```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: 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) -``` - -The following statements are equivalent: - -```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'] -``` - -Most of the information in the table is the same as MySQL. Only two columns are newly defined by TiDB: - -* `TIDB_TABLE_ID`: to indicate the internal ID of a table. This ID is unique in a TiDB cluster. -* `TIDDB_ROW_ID_SHARDING_INFO`: to indicate the sharding type of a table. The possible values are as follows: - - `"NOT_SHARDED"`: the table is not sharded. - - `"NOT_SHARDED(PK_IS_HANDLE)"`: the table that defines an integer Primary Key as its row id is not sharded. - - `"PK_AUTO_RANDOM_BITS={bit_number}"`: the table that defines an integer Primary Key as its row id is sharded because the Primary Key is assigned with `AUTO_RANDOM` attribute. - - `"SHARD_BITS={bit_number}"`: the table is sharded using `SHARD_ROW_ID_BITS={bit_number}`. - - NULL: the table is a system table or view, and thus cannot be sharded. - -### TABLE_CONSTRAINTS table - -The `TABLE_CONSTRAINTS` table describes which tables have constraints: - -{{< copyable "sql" >}} - -```sql -SELECT * FROM table_constraints WHERE constraint_type='UNIQUE'; -``` - -```sql -*************************** 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 -6 rows in set (0.00 sec) -``` - -- The `CONSTRAINT_TYPE` value can be `UNIQUE`, `PRIMARY KEY`, or `FOREIGN KEY`. -- The `UNIQUE` and `PRIMARY KEY` information is similar to the result of the `SHOW INDEX` statement. - -### TIDB_HOT_REGIONS table - -The `TIDB_HOT_REGIONS` table provides information about hotspot Regions. - -{{< 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_INDEXES table - -The `TIDB_INDEXES` table provides the INDEX information of all tables. - -{{< 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 | | | | -+---------------+---------------------+------+-----+---------+-------+ -``` - -Fields in the `TIDB_INDEXES` table are described as follows: - -* `TABLE_SCHEMA`: The name of the schema to which the index belongs. -* `TABLE_NAME`: The name of the table to which the index belongs. -* `NON_UNIQUE`: If the index is unique, the value is `0`; otherwise, the value is `1`. -* `KEY_NAME`: The index name. If the index is the primary key, the name is `PRIMARY`. -* `SEQ_IN_INDEX`: The sequential number of columns in the index, which starts from `1`. -* `COLUMN_NAME`: The name of the column where the index is located. -* `SUB_PART`: The prefix length of the index. If the the column is partly indexed, the `SUB_PART` value is the count of the indexed characters; otherwise, the value is `NULL`. -* `INDEX_COMMENT`: The comment of the index, which is made when the index is created. -* `INDEX_ID`: The index ID. - -### TIKV_REGION_PEERS table - -The `TIKV_REGION_PEERS` table provides the peer information of all Regions. - -{{< 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_STATUS table - -The `TIKV_REGION_STATUS` table provides the status information of all Regions. - -{{< copyable "sql" >}} - -```sql -desc TIKV_REGION_STATUS; -``` - -```sql -+------------------+---------------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+------------------+---------------------+------+-----+---------+-------+ -| REGION_ID | bigint(21) unsigned | YES | | | | -| START_KEY | text | YES | | | | -| END_KEY | text | YES | | | | -| EPOCH_CONF_VER | bigint(21) unsigned | YES | | | | -| EPOCH_VERSION | bigint(21) unsigned | YES | | | | -| WRITTEN_BYTES | bigint(21) unsigned | YES | | | | -| READ_BYTES | bigint(21) unsigned | YES | | | | -| APPROXIMATE_SIZE | bigint(21) unsigned | YES | | | | -| APPROXIMATE_KEYS | bigint(21) unsigned | YES | | | | -+------------------+---------------------+------+-----+---------+-------+ -``` - -### TIKV_STORE_STATUS table - -The `TIKV_STORE_STATUS` table provides the status information of all TiKV Stores. - -{{< 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 | | | | -+-------------------+---------------------+------+-----+---------+-------+ -``` - -### USER_PRIVILEGES table - -The `USER_PRIVILEGES` table provides information about global privileges. This information comes from the `mysql.user` system table: - -{{< 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) -``` - -Fields in the `USER_PRIVILEGES` table are described as follows: - -* `GRANTEE`: The name of the granted user, which is in the format of `'user_name'@'host_name'`. -* `TABLE_CATALOG`: The name of the catalog to which the table belongs. This value is always `def`. -* `PRIVILEGE_TYPE`: The privilege type to be granted. Only one privilege type is shown in each row. -* `IS_GRANTABLE`: If you have the `GRANT OPTION` privilege, the value is `YES`; otherwise, the value is `NO`. - -### VIEWS table - -The `VIEWS` table provides information about SQL views: - -{{< copyable "sql" >}} - -```sql -create view test.v1 as select 1; -``` - -```sql -Query OK, 0 rows affected (0.00 sec) -``` - -{{< copyable "sql" >}} - -```sql -select * from views; -``` - -```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: utf8 -COLLATION_CONNECTION: utf8_general_ci -1 row in set (0.00 sec) -``` - -Fields in the `VIEWS` table are described as follows: - -* `TABLE_CATALOG`: The name of the catalog to which the view belongs. This value is always `def`. -* `TABLE_SCHEMA`: The name of the schema to which the view belongs. -* `TABLE_NAME`: The view name. -* `VIEW_DEFINITION`: The definition of view, which is made by the `SELECT` statement when the view is created. -* `CHECK_OPTION`: The `CHECK_OPTION` value. The value options are `NONE`, `CASCADE`, and `LOCAL`. -* `IS_UPDATABLE`: Whether `UPDATE`/`INSERT`/`DELETE` is applicable to the view. In TiDB, the value is always `NO`. -* `DEFINER`: The name of the user who creates the view, which is in the format of `'user_name'@'host_name'`. -* `SECURITY_TYPE`: The value of `SQL SECURITY`. The value options are `DEFINER` and `INVOKER`. -* `CHARACTER_SET_CLIENT`: The value of the `character_set_client` session variable when the view is created. -* `COLLATION_CONNECTION`: The value of the `collation_connection` session variable when the view is created. - -## TIDB\_INDEXES table - -The `TIDB_INDEXES` table provides index-related information. - -{{< copyable "sql" >}} - -```sql -desc tidb_indexes\G -``` - -```sql -*************************** 1. row *************************** - Table: TIDB_INDEXES -Create Table: CREATE TABLE `TIDB_INDEXES` ( - `TABLE_SCHEMA` varchar(64) DEFAULT NULL, - `TABLE_NAME` varchar(64) DEFAULT NULL, - `NON_UNIQUE` bigint(21) unsigned DEFAULT NULL, - `KEY_NAME` varchar(64) DEFAULT NULL, - `SEQ_IN_INDEX` bigint(21) unsigned DEFAULT NULL, - `COLUMN_NAME` varchar(64) DEFAULT NULL, - `SUB_PART` bigint(21) unsigned DEFAULT NULL, - `INDEX_COMMENT` varchar(2048) DEFAULT NULL, - `INDEX_ID` bigint(21) unsigned DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.00 sec) -``` - -`INDEX_ID` is the unique ID that TiDB allocates for each index. It can be used to do a join operation with `INDEX_ID` obtained from another table or API. - -For example, you can obtain `TABLE_ID` and `INDEX_ID` that are involved in some slow query in the [`SLOW_QUERY` table](#slow_query-table) and then obtain the specific index information using the following SQL statements: - -```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\_HOT\_REGIONS table - -The `TIDB_HOT_REGIONS` table provides the hot Region information in the current TiKV instance. - -{{< copyable "sql" >}} - -```sql -desc tidb_hot_regions\G -``` - -```sql -*************************** 1. row *************************** - Table: TIDB_HOT_REGIONS -Create Table: CREATE TABLE `TIDB_HOT_REGIONS` ( - `TABLE_ID` bigint(21) unsigned DEFAULT NULL, - `INDEX_ID` bigint(21) unsigned DEFAULT NULL, - `DB_NAME` varchar(64) DEFAULT NULL, - `TABLE_NAME` varchar(64) DEFAULT NULL, - `INDEX_NAME` varchar(64) DEFAULT NULL, - `TYPE` varchar(64) DEFAULT NULL, - `MAX_HOT_DEGREE` bigint(21) unsigned DEFAULT NULL, - `REGION_COUNT` bigint(21) unsigned DEFAULT NULL, - `FLOW_BYTES` bigint(21) unsigned DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.00 sec) -``` - -- `TABLE_ID` and `INDEX_ID` are IDs generated for the corresponding table and index in TiDB. -- `TYPE` is the type for a hot Region. Its value can be `READ` or `WRITE`. - -## TIKV\_STORE\_STATUS table - -The `TIKV_STORE_STATUS` table shows some basic information of TiKV nodes via PD's API, like the ID allocated in the cluster, address and port, and status, capacity, and the number of Region leaders of the current node. - -{{< copyable "sql" >}} - -```sql -desc tikv_store_status\G -``` - -```sql -*************************** 1. row *************************** - Table: TIKV_STORE_STATUS -Create Table: CREATE TABLE `TIKV_STORE_STATUS` ( - `STORE_ID` bigint(21) unsigned DEFAULT NULL, - `ADDRESS` varchar(64) DEFAULT NULL, - `STORE_STATE` bigint(21) unsigned DEFAULT NULL, - `STORE_STATE_NAME` varchar(64) DEFAULT NULL, - `LABEL` json unsigned DEFAULT NULL, - `VERSION` varchar(64) DEFAULT NULL, - `CAPACITY` varchar(64) DEFAULT NULL, - `AVAILABLE` varchar(64) DEFAULT NULL, - `LEADER_COUNT` bigint(21) unsigned DEFAULT NULL, - `LEADER_WEIGHT` bigint(21) unsigned DEFAULT NULL, - `LEADER_SCORE` bigint(21) unsigned DEFAULT NULL, - `LEADER_SIZE` bigint(21) unsigned DEFAULT NULL, - `REGION_COUNT` bigint(21) unsigned DEFAULT NULL, - `REGION_WEIGHT` bigint(21) unsigned DEFAULT NULL, - `REGION_SCORE` bigint(21) unsigned DEFAULT NULL, - `REGION_SIZE` bigint(21) unsigned DEFAULT NULL, - `START_TS` datetime unsigned DEFAULT NULL, - `LAST_HEARTBEAT_TS` datetime unsigned DEFAULT NULL, - `UPTIME` varchar(64) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.01 sec) -``` - -## TIKV\_REGION\_STATUS table - -The `TIKV_REGION_STATUS` table shows some basic information of TiKV Regions via PD's API, like the Region ID, starting and ending key-values, and read and write traffic. - -{{< copyable "sql" >}} - -```sql -desc tikv_region_status\G -``` - -```sql -*************************** 1. row *************************** - Table: TIKV_REGION_STATUS -Create Table: CREATE TABLE `TIKV_REGION_STATUS` ( - `REGION_ID` bigint(21) unsigned DEFAULT NULL, - `START_KEY` text DEFAULT NULL, - `END_KEY` text DEFAULT NULL, - `EPOCH_CONF_VER` bigint(21) unsigned DEFAULT NULL, - `EPOCH_VERSION` bigint(21) unsigned DEFAULT NULL, - `WRITTEN_BYTES` bigint(21) unsigned DEFAULT NULL, - `READ_BYTES` bigint(21) unsigned DEFAULT NULL, - `APPROXIMATE_SIZE` bigint(21) unsigned DEFAULT NULL, - `APPROXIMATE_KEYS` bigint(21) unsigned DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.00 sec) -``` - -You can implement the `top confver`, `top read` and `top write` operations in pd-ctl via the `ORDER BY X LIMIT Y` operation on the `EPOCH_CONF_VER`, `WRITTEN_BYTES` and `READ_BYTES` columns. - -You can query the top 3 Regions with the most write data using the following SQL statement: - -```sql -select * from tikv_region_status order by written_bytes desc limit 3; -``` - -## TIKV\_REGION\_PEERS table - -The `TIKV_REGION_PEERS` table shows detailed information of a single Region node in TiKV, like whether it is a learner or leader. - -{{< copyable "sql" >}} - -```sql -desc tikv_region_peers\G -``` - -```sql -*************************** 1. row *************************** - Table: TIKV_REGION_PEERS -Create Table: CREATE TABLE `TIKV_REGION_PEERS` ( - `REGION_ID` bigint(21) unsigned DEFAULT NULL, - `PEER_ID` bigint(21) unsigned DEFAULT NULL, - `STORE_ID` bigint(21) unsigned DEFAULT NULL, - `IS_LEARNER` tinyint(1) unsigned DEFAULT NULL, - `IS_LEADER` tinyint(1) unsigned DEFAULT NULL, - `STATUS` varchar(10) DEFAULT NULL, - `DOWN_SECONDS` bigint(21) unsigned DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.00 sec) -``` - -For example, you can query the specific TiKV addresses for the top 3 Regions with the maximum value of `WRITTEN_BYTES` using the following SQL statement: - -```sql -select - address, - tikv.address, - region.region_id, -from - tikv_store_status tikv, - tikv_region_peers peer, - ( - select - * - from - tikv_region_status region - 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.region_id -``` - -## ANALYZE\_STATUS table - -The `ANALYZE_STATUS` table shows the execution status of the `ANALYZE` command in the current cluster. - -{{< copyable "sql" >}} - -```sql -desc analyze_status\G -``` - -```sql -*************************** 1. row *************************** - Table: ANALYZE_STATUS -Create Table: CREATE TABLE `ANALYZE_STATUS` ( - `TABLE_SCHEMA` varchar(64) DEFAULT NULL, - `TABLE_NAME` varchar(64) DEFAULT NULL, - `PARTITION_NAME` varchar(64) DEFAULT NULL, - `JOB_INFO` varchar(64) DEFAULT NULL, - `PROCESSED_ROWS` bigint(20) unsigned DEFAULT NULL, - `START_TIME` datetime unsigned DEFAULT NULL, - `STATE` varchar(64) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.00 sec) -``` - -The `STATE` column shows the execution status of a specific `ANALYZE` task. Its value can be `pending`, `running`,`finished` or `failed`. - -## SLOW\_QUERY table - -The `SLOW_QUERY` table maps slow query logs. Its column names and field names of slow query logs have an one-to-one corresponse relationship. For details, see [Identify Slow Queries](/identify-slow-queries.md#identify-slow-queries). - -{{< copyable "sql" >}} - -```sql -desc slow_query\G -``` - -```sql -*************************** 1. row *************************** - Table: SLOW_QUERY -Create Table: CREATE TABLE `SLOW_QUERY` ( - `Time` timestamp unsigned NULL DEFAULT NULL, - `Txn_start_ts` bigint(20) unsigned DEFAULT NULL, - `User` varchar(64) DEFAULT NULL, - `Host` varchar(64) DEFAULT NULL, - `Conn_ID` bigint(20) unsigned DEFAULT NULL, - `Query_time` double unsigned DEFAULT NULL, - `Process_time` double unsigned DEFAULT NULL, - `Wait_time` double unsigned DEFAULT NULL, - `Backoff_time` double unsigned DEFAULT NULL, - `Request_count` bigint(20) unsigned DEFAULT NULL, - `Total_keys` bigint(20) unsigned DEFAULT NULL, - `Process_keys` bigint(20) unsigned DEFAULT NULL, - `DB` varchar(64) DEFAULT NULL, - `Index_ids` varchar(100) DEFAULT NULL, - `Is_internal` tinyint(1) unsigned DEFAULT NULL, - `Digest` varchar(64) DEFAULT NULL, - `Stats` varchar(512) DEFAULT NULL, - `Cop_proc_avg` double unsigned DEFAULT NULL, - `Cop_proc_p90` double unsigned DEFAULT NULL, - `Cop_proc_max` double unsigned DEFAULT NULL, - `Cop_proc_addr` varchar(64) DEFAULT NULL, - `Cop_wait_avg` double unsigned DEFAULT NULL, - `Cop_wait_p90` double unsigned DEFAULT NULL, - `Cop_wait_max` double unsigned DEFAULT NULL, - `Cop_wait_addr` varchar(64) DEFAULT NULL, - `Mem_max` bigint(20) unsigned DEFAULT NULL, - `Query` varchar(4096) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -1 row in set (0.00 sec) -``` - -## Unsupported Information Schema Tables - -The following `INFORMATION_SCHEMA` tables are present in TiDB, but will always return zero rows: - -* `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` diff --git a/system-tables/system-table-metrics-tables.md b/system-tables/system-table-metrics-tables.md deleted file mode 100644 index 2d032aec37442..0000000000000 --- a/system-tables/system-table-metrics-tables.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: METRICS_TABLES -summary: Learn the `METRICS_TABLES` system table. -aliases: ['/docs/dev/system-tables/system-table-metrics-tables/','/docs/dev/reference/system-databases/metrics-tables/'] ---- - -# METRICS_TABLES - -The `INFORMATION_SCHEMA.METRICS_TABLES` table provides information of all monitoring tables in the [metrics_schema](/system-tables/system-table-metrics-schema.md) database. - -{{< 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 | | -+------------+--------------+------+------+---------+-------+ -``` - -Field description: - -* `TABLE_NAME`: Corresponds to the table name in `metrics_schema`. -* `PROMQL`: The working principle of the monitoring table is to map SQL statements to `PromQL` and convert Prometheus results into SQL query results. This field is the expression template of `PromQL`. When you query the data of the monitoring table, the query conditions are used to rewrite the variables in this template to generate the final query expression. -* `LABELS`: The label for the monitoring item. Each label corresponds to a column in the monitoring table. If the SQL statement contains the filter of the corresponding column, the corresponding `PromQL` changes accordingly. -* `QUANTILE`: The percentile. For monitoring data of the histogram type, a default percentile is specified. If the value of this field is `0`, it means that the monitoring item corresponding to the monitoring table is not a histogram. -* `COMMENT`: The comment about the monitoring table. diff --git a/whats-new-in-tidb-4.0.md b/whats-new-in-tidb-4.0.md index bdbf5cc84a578..580804d7baef8 100644 --- a/whats-new-in-tidb-4.0.md +++ b/whats-new-in-tidb-4.0.md @@ -59,7 +59,7 @@ TiUP is a new package manager tool introduced in v4.0 that is used to manage all - Support using the Index Merge feature to access tables. When you make a query on a single table, the TiDB optimizer automatically reads multiple index data according to the query condition and makes a union of the result, which improves the performance of querying on a single table. See [Index Merge](/index-merge.md) for details. - Support the expression index feature (**experimental**). The expression index is also called the function-based index. When you create an index, the index fields do not have to be a specific column but can be an expression calculated from one or more columns. This feature is useful for quickly accessing the calculation-based tables. See [Expression index](/sql-statements/sql-statement-create-index.md) for details. - Support `AUTO_RANDOM` keys as an extended syntax for the TiDB columnar attribute (**experimental**). `AUTO_RANDOM` is designed to address the hotspot issue caused by the auto-increment column and provides a low-cost migration solution from MySQL for users who work with auto-increment columns. See [`AUTO_RANDOM` Key](/auto-random.md) for details. -- Add system tables that provide information of cluster topology, configuration, logs, hardware, operating systems, and slow queries, which helps DBAs to quickly learn, analyze system metrics. See [SQL Diagnosis](/system-tables/system-table-sql-diagnostics.md) for details. +- Add system tables that provide information of cluster topology, configuration, logs, hardware, operating systems, and slow queries, which helps DBAs to quickly learn, analyze system metrics. See [SQL Diagnosis](/information-schema/information-schema-sql-diagnostics.md) for details. - Add system tables that provide information of cluster topology, configuration, logs, hardware, operating systems to help DBAs quickly learn the cluster configuration and status: - The `cluster_info` table that stores the cluster topology information.