diff --git a/TOC-tidb-cloud.md b/TOC-tidb-cloud.md index b50aae1a4cdce..7fb4dcaede862 100644 --- a/TOC-tidb-cloud.md +++ b/TOC-tidb-cloud.md @@ -601,6 +601,9 @@ - PERFORMANCE_SCHEMA - [Overview](/performance-schema/performance-schema.md) - [`SESSION_CONNECT_ATTRS`](/performance-schema/performance-schema-session-connect-attrs.md) + - SYS + - [Overview](/sys-schema/sys-schema.md) + - [`schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md) - [Metadata Lock](/metadata-lock.md) - [Use UUIDs](/best-practices/uuid.md) - [TiDB Accelerated Table Creation](/accelerated-table-creation.md) diff --git a/TOC.md b/TOC.md index 9235ac7a68fcb..acd4231a2f519 100644 --- a/TOC.md +++ b/TOC.md @@ -981,7 +981,9 @@ - PERFORMANCE_SCHEMA - [Overview](/performance-schema/performance-schema.md) - [`SESSION_CONNECT_ATTRS`](/performance-schema/performance-schema-session-connect-attrs.md) - - [`SYS`](/sys-schema.md) + - SYS + - [Overview](/sys-schema/sys-schema.md) + - [`schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md) - [Metadata Lock](/metadata-lock.md) - [TiDB Accelerated Table Creation](/accelerated-table-creation.md) - UI diff --git a/information-schema/information-schema-tidb-index-usage.md b/information-schema/information-schema-tidb-index-usage.md index 00e57aa9cd906..a98f23667c2e2 100644 --- a/information-schema/information-schema-tidb-index-usage.md +++ b/information-schema/information-schema-tidb-index-usage.md @@ -101,3 +101,7 @@ The output is as follows: - The data in the `TIDB_INDEX_USAGE` table might be delayed by up to 5 minutes. - After TiDB restarts, the data in the `TIDB_INDEX_USAGE` table is cleared. + +## Read more + +- [`sys.schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md) \ No newline at end of file diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index d90951aa5889d..63965b57dceaf 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -13,7 +13,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi <CustomContent platform="tidb"> -| Table Name | Description | +| Table name | Description | |-----------------------------------------------------------------------------------------|-----------------------------| | [`CHARACTER_SETS`](/information-schema/information-schema-character-sets.md) | Provides a list of character sets the server supports. | | [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) | Provides information about [`CHECK` constraints](/constraints.md#check) on tables. | @@ -56,7 +56,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi <CustomContent platform="tidb-cloud"> -| Table Name | Description | +| Table name | Description | |-----------------------------------------------------------------------------------------|-----------------------------| | [`CHARACTER_SETS`](/information-schema/information-schema-character-sets.md) | Provides a list of character sets the server supports. | | [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) | Provides information about [`CHECK` constraints](/constraints.md#check) on tables. | @@ -104,7 +104,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi > > Some of the following tables are only supported on TiDB Self-Hosted and not supported on TiDB Cloud. To get a full list of unsupported tables on TiDB Cloud, see [System tables](https://docs.pingcap.com/tidbcloud/limited-sql-features#system-tables). -| Table Name | Description | +| Table name | Description | |-----------------------------------------------------------------------------------------|-------------| | [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md) | Provides information about tasks to collect statistics. | | [`CLIENT_ERRORS_SUMMARY_BY_HOST`](/information-schema/client-errors-summary-by-host.md) | Provides a summary of errors and warnings generated by client requests and returned to clients. | @@ -157,7 +157,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi <CustomContent platform="tidb-cloud"> -| Table Name | Description | +| Table name | Description | |-----------------------------------------------------------------------------------------|-------------| | [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md) | Provides information about tasks to collect statistics. | | [`CLIENT_ERRORS_SUMMARY_BY_HOST`](/information-schema/client-errors-summary-by-host.md) | Provides a summary of errors and warnings generated by client requests and returned to clients. | diff --git a/performance-schema/performance-schema.md b/performance-schema/performance-schema.md index 3a3fa419010dc..9dcb97e7c1536 100644 --- a/performance-schema/performance-schema.md +++ b/performance-schema/performance-schema.md @@ -9,7 +9,7 @@ TiDB implements performance schema tables for MySQL compatibility. ## Tables for MySQL compatibility -| Table Name | Description | +| Table name | Description | |--------------------------------------------------------------------------------------------------|-----------------------------------------------------------| | `events_stages_current` | | | `events_stages_history` | | @@ -33,7 +33,7 @@ TiDB implements performance schema tables for MySQL compatibility. ## Tables that are TiDB extensions -| Table Name | Description | +| Table name | Description | |--------------------------------------------------------------------------------------------------|-----------------------------------------------------------| | `pd_profile_allocs` | | | `pd_profile_block` | | diff --git a/releases/release-8.0.0.md b/releases/release-8.0.0.md index e8d58fadfde52..a1ab05d19248a 100644 --- a/releases/release-8.0.0.md +++ b/releases/release-8.0.0.md @@ -47,7 +47,7 @@ Quick access: [Quick start](https://docs.pingcap.com/tidb/v8.0/quick-start-with- <tr> <td rowspan="1">DB Operations and Observability</td> <td>Support monitoring index usage statistics </td> - <td>Proper index design is a crucial prerequisite to maintaining database performance. TiDB v8.0.0 introduces the <a href="https://docs.pingcap.com/tidb/v8.0/information-schema-tidb-index-usage"><code>INFORMATION_SCHEMA.TIDB_INDEX_USAGE</code></a> table and the <a href="https://docs.pingcap.com/tidb/v8.0/sys-schema"><code>sys.schema_unused_index</code></a> view to provide usage statistics of indexes. This feature helps you assess the efficiency of indexes in the database and optimize the index design.</td> + <td>Proper index design is a crucial prerequisite to maintaining database performance. TiDB v8.0.0 introduces the <a href="https://docs.pingcap.com/tidb/v8.0/information-schema-tidb-index-usage"><code>INFORMATION_SCHEMA.TIDB_INDEX_USAGE</code></a> table and the <a href="https://docs.pingcap.com/tidb/v8.0/sys-schema-unused-indexes"><code>sys.schema_unused_indexes</code></a> view to provide usage statistics of indexes. This feature helps you assess the efficiency of indexes in the database and optimize the index design.</td> </tr> <tr> <td rowspan="2">Data Migration</td> @@ -236,7 +236,7 @@ Quick access: [Quick start](https://docs.pingcap.com/tidb/v8.0/quick-start-with- With this information, you can identify indexes that are not used by the optimizer and indexes with poor selectivity, thereby optimizing index design to improve database performance. - Additionally, TiDB v8.0.0 introduces a view [`sys.schema_unused_index`](/sys-schema.md), which is compatible with MySQL. This view shows indexes that have not been used since the last start of TiDB instances. For clusters upgraded from versions earlier than v8.0.0, the `sys` schema and the views are not created automatically. You can manually create them by referring to [`sys`](/sys-schema.md). + Additionally, TiDB v8.0.0 introduces a view [`sys.schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md), which is compatible with MySQL. This view shows indexes that have not been used since the last start of TiDB instances. For clusters upgraded from versions earlier than v8.0.0, the `sys` schema and the views are not created automatically. You can manually create them by referring to [`sys.schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md#manually-create-the-schema_unused_indexes-view). For more information, see [documentation](/information-schema/information-schema-tidb-index-usage.md). @@ -362,7 +362,7 @@ Quick access: [Quick start](https://docs.pingcap.com/tidb/v8.0/quick-start-with- ### System tables * Add new system tables [`INFORMATION_SCHEMA.TIDB_INDEX_USAGE`](/information-schema/information-schema-tidb-index-usage.md) and [`INFORMATION_SCHEMA.CLUSTER_TIDB_INDEX_USAGE`](/information-schema/information-schema-tidb-index-usage.md#cluster_tidb_index_usage) to record index usage statistics on TiDB nodes. -* Add a new system schema [`sys`](/sys-schema.md) and a new view [`sys.schema_unused_index`](/sys-schema.md#schema_unused_index), which records indexes that have not been used since the last start of TiDB. +* Add a new system schema [`sys`](/sys-schema/sys-schema.md) and a new view [`sys.schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md), which records indexes that have not been used since the last start of TiDB. ## Deprecated features diff --git a/sys-schema.md b/sys-schema/sys-schema-unused-indexes.md similarity index 70% rename from sys-schema.md rename to sys-schema/sys-schema-unused-indexes.md index 4c3beda035e2a..1c9b7dec764df 100644 --- a/sys-schema.md +++ b/sys-schema/sys-schema-unused-indexes.md @@ -1,35 +1,11 @@ --- -title: sys Schema -summary: Learn about the system tables in the `sys` schema. +title: schema_unused_indexes +summary: Learn about the `schema_unused_indexes` table in the `sys` schema. --- -# `sys` Schema +# `schema_unused_indexes` -Starting from v8.0.0, TiDB provides the `sys` schema. You can use the views in `sys` schema to understand the data in the system tables, [`INFORMATION_SCHEMA`](/information-schema/information-schema.md), and [`PERFORMANCE SCHEMA`](/performance-schema/performance-schema.md) of TiDB. - -## Manually create the `sys` schema and views - -For clusters upgraded from versions earlier than v8.0.0, the `sys` schema and the views in it are not created automatically. You can manually create them using the following SQL statements: - -```sql -CREATE DATABASE IF NOT EXISTS sys; -CREATE OR REPLACE VIEW sys.schema_unused_indexes AS - SELECT - table_schema as object_schema, - table_name as object_name, - index_name - FROM information_schema.cluster_tidb_index_usage - WHERE - table_schema not in ('sys', 'mysql', 'INFORMATION_SCHEMA', 'PERFORMANCE_SCHEMA') and - index_name != 'PRIMARY' - GROUP BY table_schema, table_name, index_name - HAVING - sum(last_access_time) is null; -``` - -## `schema_unused_index` - -`schema_unused_index` records indexes that have not been used since the last start of TiDB. It includes the following columns: +`schema_unused_indexes` records indexes that have not been used since the last start of TiDB. It includes the following columns: - `OBJECT_SCHEMA`: The name of the database to which the table containing the index belongs. - `OBJECT_NAME`: The name of the table containing the index. @@ -51,4 +27,28 @@ The output is as follows: | index_name | varchar(64) | YES | | NULL | | +---------------+-------------+------+------+---------+-------+ 3 rows in set (0.00 sec) -``` \ No newline at end of file +``` + +## Manually create the `schema_unused_indexes` view + +For clusters upgraded from versions earlier than v8.0.0, the `sys` schema and the views in it are not created automatically. You can manually create them using the following SQL statements: + +```sql +CREATE DATABASE IF NOT EXISTS sys; +CREATE OR REPLACE VIEW sys.schema_unused_indexes AS + SELECT + table_schema as object_schema, + table_name as object_name, + index_name + FROM information_schema.cluster_tidb_index_usage + WHERE + table_schema not in ('sys', 'mysql', 'INFORMATION_SCHEMA', 'PERFORMANCE_SCHEMA') and + index_name != 'PRIMARY' + GROUP BY table_schema, table_name, index_name + HAVING + sum(last_access_time) is null; +``` + +## Read more + +- [`INFORMATION_SCHEMA.TIDB_INDEX_USAGE`](/information-schema/information-schema-tidb-index-usage.md) \ No newline at end of file diff --git a/sys-schema/sys-schema.md b/sys-schema/sys-schema.md new file mode 100644 index 0000000000000..cc4f0d79495d3 --- /dev/null +++ b/sys-schema/sys-schema.md @@ -0,0 +1,14 @@ +--- +title: sys Schema +summary: Learn about the system tables in the `sys` schema. +--- + +# `sys` Schema + +Starting from v8.0.0, TiDB provides the `sys` schema. You can use the views in `sys` schema to understand the data in the system tables, [`INFORMATION_SCHEMA`](/information-schema/information-schema.md), and [`PERFORMANCE SCHEMA`](/performance-schema/performance-schema.md) of TiDB. + +## Tables for MySQL compatibility + +| Table name | Description | +|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------| +| [`schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md) | Records indexes that have not been used since the last start of TiDB. | \ No newline at end of file