Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions TOC-tidb-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@
- [`SHOW BUILTINS`](/sql-statements/sql-statement-show-builtins.md)
- [`SHOW CHARACTER SET`](/sql-statements/sql-statement-show-character-set.md)
- [`SHOW COLLATION`](/sql-statements/sql-statement-show-collation.md)
- [`SHOW [FULL] COLUMNS FROM`](/sql-statements/sql-statement-show-columns-from.md)
- [`SHOW COLUMN_STATS_USAGE`](/sql-statements/sql-statement-show-column-stats-usage.md)
- [`SHOW COLUMNS FROM`](/sql-statements/sql-statement-show-columns-from.md)
- [`SHOW CREATE DATABASE`](/sql-statements/sql-statement-show-create-database.md)
- [`SHOW CREATE PLACEMENT POLICY`](/sql-statements/sql-statement-show-create-placement-policy.md)
- [`SHOW CREATE RESOURCE GROUP`](/sql-statements/sql-statement-show-create-resource-group.md)
Expand All @@ -461,7 +462,7 @@
- [`SHOW DATABASES`](/sql-statements/sql-statement-show-databases.md)
- [`SHOW ENGINES`](/sql-statements/sql-statement-show-engines.md)
- [`SHOW ERRORS`](/sql-statements/sql-statement-show-errors.md)
- [`SHOW [FULL] FIELDS FROM`](/sql-statements/sql-statement-show-fields-from.md)
- [`SHOW FIELDS FROM`](/sql-statements/sql-statement-show-fields-from.md)
- [`SHOW GRANTS`](/sql-statements/sql-statement-show-grants.md)
- [`SHOW IMPORT JOB`](/sql-statements/sql-statement-show-import-job.md)
- [`SHOW INDEXES [FROM|IN]`](/sql-statements/sql-statement-show-indexes.md)
Expand All @@ -471,18 +472,20 @@
- [`SHOW PLACEMENT LABELS`](/sql-statements/sql-statement-show-placement-labels.md)
- [`SHOW PLUGINS`](/sql-statements/sql-statement-show-plugins.md)
- [`SHOW PRIVILEGES`](/sql-statements/sql-statement-show-privileges.md)
- [`SHOW [FULL] PROCESSSLIST`](/sql-statements/sql-statement-show-processlist.md)
- [`SHOW PROCESSSLIST`](/sql-statements/sql-statement-show-processlist.md)
- [`SHOW PROFILES`](/sql-statements/sql-statement-show-profiles.md)
- [`SHOW SCHEMAS`](/sql-statements/sql-statement-show-schemas.md)
- [`SHOW STATS_BUCKETS`](/sql-statements/sql-statement-show-stats-buckets.md)
- [`SHOW STATS_HEALTHY`](/sql-statements/sql-statement-show-stats-healthy.md)
- [`SHOW STATS_HISTOGRAMS`](/sql-statements/sql-statement-show-stats-histograms.md)
- [`SHOW STATS_LOCKED`](/sql-statements/sql-statement-show-stats-locked.md)
- [`SHOW STATS_META`](/sql-statements/sql-statement-show-stats-meta.md)
- [`SHOW STATS_TOPN`](/sql-statements/sql-statement-show-stats-topn.md)
- [`SHOW STATUS`](/sql-statements/sql-statement-show-status.md)
- [`SHOW TABLE NEXT_ROW_ID`](/sql-statements/sql-statement-show-table-next-rowid.md)
- [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md)
- [`SHOW TABLE STATUS`](/sql-statements/sql-statement-show-table-status.md)
- [`SHOW [FULL] TABLES`](/sql-statements/sql-statement-show-tables.md)
- [`SHOW TABLES`](/sql-statements/sql-statement-show-tables.md)
- [`SHOW [GLOBAL|SESSION] VARIABLES`](/sql-statements/sql-statement-show-variables.md)
- [`SHOW WARNINGS`](/sql-statements/sql-statement-show-warnings.md)
- [`SPLIT REGION`](/sql-statements/sql-statement-split-region.md)
Expand Down
3 changes: 3 additions & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@
- [`SHOW BUILTINS`](/sql-statements/sql-statement-show-builtins.md)
- [`SHOW CHARACTER SET`](/sql-statements/sql-statement-show-character-set.md)
- [`SHOW COLLATION`](/sql-statements/sql-statement-show-collation.md)
- [`SHOW COLUMN_STATS_USAGE`](/sql-statements/sql-statement-show-column-stats-usage.md)
- [`SHOW COLUMNS FROM`](/sql-statements/sql-statement-show-columns-from.md)
- [`SHOW CONFIG`](/sql-statements/sql-statement-show-config.md)
- [`SHOW CREATE DATABASE`](/sql-statements/sql-statement-show-create-database.md)
Expand All @@ -850,10 +851,12 @@
- [`SHOW PROFILES`](/sql-statements/sql-statement-show-profiles.md)
- [`SHOW PUMP STATUS`](/sql-statements/sql-statement-show-pump-status.md)
- [`SHOW SCHEMAS`](/sql-statements/sql-statement-show-schemas.md)
- [`SHOW STATS_BUCKETS`](/sql-statements/sql-statement-show-stats-buckets.md)
- [`SHOW STATS_HEALTHY`](/sql-statements/sql-statement-show-stats-healthy.md)
- [`SHOW STATS_HISTOGRAMS`](/sql-statements/sql-statement-show-stats-histograms.md)
- [`SHOW STATS_LOCKED`](/sql-statements/sql-statement-show-stats-locked.md)
- [`SHOW STATS_META`](/sql-statements/sql-statement-show-stats-meta.md)
- [`SHOW STATS_TOPN`](/sql-statements/sql-statement-show-stats-topn.md)
- [`SHOW STATUS`](/sql-statements/sql-statement-show-status.md)
- [`SHOW TABLE NEXT_ROW_ID`](/sql-statements/sql-statement-show-table-next-rowid.md)
- [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md)
Expand Down
53 changes: 37 additions & 16 deletions sql-statements/sql-statement-drop-stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,59 @@ The `DROP STATS` statement is used to delete the statistics of the selected tabl

```ebnf+diagram
DropStatsStmt ::=
'DROP' 'STATS' TableNameList

TableNameList ::=
TableName ( ',' TableName )*
'DROP' 'STATS' TableName ("PARTITION" partition | "GLOBAL")? ( ',' TableName )*

TableName ::=
Identifier ('.' Identifier)?
```

## Examples
## Usage

{{< copyable "sql" >}}
The following statement deletes all statistics of `TableName`. If a partitioned table is specified, this statement deletes statistics of all partitions in this table as well as [GlobalStats generated in dynamic pruning mode](/statistics.md#collect-statistics-of-partitioned-tables-in-dynamic-pruning-mode).

```sql
CREATE TABLE t(a INT);
DROP STATS TableName
```

```
Query OK, 0 rows affected (0.00 sec)
```

The following statement only deletes statistics of the specified partitions in `PartitionNameList`.

```sql
Query OK, 0 rows affected (0.01 sec)
DROP STATS TableName PARTITION PartitionNameList;
```

{{< copyable "sql" >}}
```
Query OK, 0 rows affected (0.00 sec)
```

The following statement only deletes GlobalStats generated in dynamic pruning mode of the specified table.

```sql
SHOW STATS_META WHERE db_name='test' and table_name='t';
DROP STATS TableName GLOBAL;
```

```
Query OK, 0 rows affected (0.00 sec)
```

## Examples

```sql
CREATE TABLE t(a INT);
```

```
Query OK, 0 rows affected (0.01 sec)
```

```sql
SHOW STATS_META WHERE db_name='test' and table_name='t';
```

```
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
Expand All @@ -47,23 +72,19 @@ SHOW STATS_META WHERE db_name='test' and table_name='t';
1 row in set (0.00 sec)
```

{{< copyable "sql" >}}

```sql
DROP STATS t;
```

```sql
```
Query OK, 0 rows affected (0.00 sec)
```

{{< copyable "sql" >}}

```sql
SHOW STATS_META WHERE db_name='test' and table_name='t';
```

```sql
```
Empty set (0.00 sec)
```

Expand Down
17 changes: 16 additions & 1 deletion sql-statements/sql-statement-show-analyze-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ Starting from TiDB v6.1.0, you can view the history tasks within the last 7 days

Starting from TiDB v7.3.0, you can view the progress of the current `ANALYZE` task through the system table `mysql.analyze_jobs` or `SHOW ANALYZE STATUS`.

Currently, the `SHOW ANALYZE STATUS` statement returns the following columns:

| Column name | Description |
| :--------------- | :------------- |
| `Table_schema` | The database name |
| `Table_name` | The table name |
| `Partition_name` | The partition name |
| `Job_info` | The task information. If an index is analyzed, this information will include the index name. When `tidb_analyze_version =2`, this information will include configuration items such as sample rate. |
| `Processed_rows` | The number of rows that have been analyzed |
| `Start_time` | The time at which the task starts |
| `State` | The state of a task, including `pending`, `running`, `finished`, and `failed` |
| `Fail_reason` | The reason why the task fails. If the execution is successful, the value is `NULL`. |
| `Instance` | The TiDB instance that executes the task |
| `Process_id` | The process ID that executes the task |

## Synopsis

```ebnf+diagram
Expand Down Expand Up @@ -71,4 +86,4 @@ This statement is a TiDB extension to MySQL syntax.

## See also

* [ANALYZE_STATUS table](/information-schema/information-schema-analyze-status.md)
* [ANALYZE_STATUS table](/information-schema/information-schema-analyze-status.md)
58 changes: 58 additions & 0 deletions sql-statements/sql-statement-show-column-stats-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: SHOW COLUMN_STATS_USAGE
summary: An overview of the usage of SHOW COLUMN_STATS_USAGE for TiDB database.
---

# SHOW COLUMN_STATS_USAGE

The `SHOW COLUMN_STATS_USAGE` statement shows the last usage time and collection time of column statistics. You can also use it to locate `PREDICATE COLUMNS` and columns on which statistics have been collected.

Currently, the `SHOW COLUMN_STATS_USAGE` statement returns the following columns:

| Column name | Description |
| -------- | ------------- |
| `Db_name` | The database name |
| `Table_name` | The table name |
| `Partition_name` | The partition name |
| `Column_name` | The column name |
| `Last_used_at` | The last time when the column statistics were used in the query optimization |
| `Last_analyzed_at` | The last time when the column statistics were collected |

## Synopsis

```ebnf+diagram
ShowColumnStatsUsageStmt ::=
"SHOW" "COLUMN_STATS_USAGE" ShowLikeOrWhere?

ShowLikeOrWhere ::=
"LIKE" SimpleExpr
| "WHERE" Expression
```

## Examples

```sql
SHOW COLUMN_STATS_USAGE;
```

```
+---------+------------+----------------+-------------+--------------+---------------------+
| Db_name | Table_name | Partition_name | Column_name | Last_used_at | Last_analyzed_at |
+---------+------------+----------------+-------------+--------------+---------------------+
| test | t1 | | id | NULL | 2024-05-10 11:04:23 |
| test | t1 | | b | NULL | 2024-05-10 11:04:23 |
| test | t1 | | pad | NULL | 2024-05-10 11:04:23 |
| test | t | | a | NULL | 2024-05-10 11:37:06 |
| test | t | | b | NULL | 2024-05-10 11:37:06 |
+---------+------------+----------------+-------------+--------------+---------------------+
5 rows in set (0.00 sec)
```

## MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

## See also

* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md)
* [Introduction to Statistics](/statistics.md)
64 changes: 64 additions & 0 deletions sql-statements/sql-statement-show-stats-buckets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: SHOW STATS_BUCKETS
summary: An overview of the usage of SHOW STATS_BUCKETS for TiDB database.
---

# SHOW STATS_BUCKETS

The `SHOW STATS_BUCKETS` statement shows the bucket information in [statistics](/statistics.md).

Currently, the `SHOW STATS_BUCKETS` statement returns the following columns:

| Column name | Description |
| :-------- | :------------- |
| `Db_name` | The database name |
| `Table_name` | The table name |
| `Partition_name` | The partition name |
| `Column_name` | The column name (when `is_index` is `0`) or the index name (when `is_index` is `1`) |
| `Is_index` | Whether it is an index column or not |
| `Bucket_id` | The ID of a bucket |
| `Count` | The number of all the values that falls on the bucket and the previous buckets |
| `Repeats` | The occurrence number of the maximum value |
| `Lower_bound` | The minimum value |
| `Upper_bound` | The maximum value |
| `Ndv` | The number of different values in the bucket. When `tidb_analyze_version` = `1`, `Ndv` is always `0`, which has no actual meaning. |

## Synopsis

```ebnf+diagram
ShowStatsBucketsStmt ::=
"SHOW" "STATS_BUCKETS" ShowLikeOrWhere?

ShowLikeOrWhere ::=
"LIKE" SimpleExpr
| "WHERE" Expression
```

## Examples

```sql
SHOW STATS_BUCKETS WHERE Table_name='t';
```

```
+---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+
| test | t | | a | 0 | 0 | 1 | 1 | 2023-12-27 00:00:00 | 2023-12-27 00:00:00 | 0 |
| test | t | | a | 0 | 1 | 2 | 1 | 2023-12-28 00:00:00 | 2023-12-28 00:00:00 | 0 |
| test | t | | ia | 1 | 0 | 1 | 1 | (NULL, 2) | (NULL, 2) | 0 |
| test | t | | ia | 1 | 1 | 2 | 1 | (NULL, 4) | (NULL, 4) | 0 |
| test | t | | ia | 1 | 2 | 3 | 1 | (2023-12-27 00:00:00, 1) | (2023-12-27 00:00:00, 1) | 0 |
| test | t | | ia | 1 | 3 | 4 | 1 | (2023-12-28 00:00:00, 3) | (2023-12-28 00:00:00, 3) | 0 |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+
6 rows in set (0.00 sec)
```

## MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

## See also

* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md)
* [Introduction to Statistics](/statistics.md)
9 changes: 9 additions & 0 deletions sql-statements/sql-statement-show-stats-healthy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ The `SHOW STATS_HEALTHY` statement shows an estimation of how accurate statistic

The health of a table can be improved by running the [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md) statement. `ANALYZE` runs automatically when the health drops below the [`tidb_auto_analyze_ratio`](/system-variables.md#tidb_auto_analyze_ratio) threshold.

Currently, the `SHOW STATS_HEALTHY` statement returns the following columns:

| Column name | Description |
| -------- | ------------- |
| `Db_name` | The database name |
| `Table_name` | The table name |
| `Partition_name` | The partition name |
| `Healthy` | The healthy percentage between 0 and 100 |

## Synopsis

```ebnf+diagram
Expand Down
20 changes: 20 additions & 0 deletions sql-statements/sql-statement-show-stats-histograms.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ summary: An overview of the usage of SHOW HISTOGRAMS for TiDB database.

This statement shows the histogram information collected by the [`ANALYZE` statement](/sql-statements/sql-statement-analyze-table.md) as part of database [statistics](/statistics.md).

Currently, the `SHOW STATS_HISTOGRAMS` statement returns the following columns:

| Column name | Description |
| -------- | ------------- |
| Db_name | Database name |
| `Table_name` | The table name |
| `Partition_name` | The partition name |
| `Column_name` | The column name |
| `Is_index` | Whether it is an index column or not |
| `Update_time` | The update time |
| `Distinct_count` | The distinct count |
| `Null_count` | NULL count |
| `Avg_col_size` | The average col size |
| `Correlation` | Correlation |
| `Load_status` | Load status, such as `allEvicted` and `allLoaded` |
| `Total_mem_usage` | The total memory usage |
| `Hist_mem_usage` | The historical memory usage |
| `Topn_mem_usage` | The TopN memory usage |
| `Cms_mem_usage` | The CMS memory usage |

## Synopsis

```ebnf+diagram
Expand Down
9 changes: 9 additions & 0 deletions sql-statements/sql-statement-show-stats-locked.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ summary: An overview of the usage of SHOW STATS_LOCKED for the TiDB database.

`SHOW STATS_LOCKED` shows the tables whose statistics are locked.

Currently, the `SHOW STATS_LOCKED` statement returns the following columns:

| Column name | Description |
| -------- | ------------- |
| `Db_name` | The database name |
| `Table_name` | The table name |
| `Partition_name` | The partition name |
| `Status` | The statistics status, such as `locked` |

## Synopsis

```ebnf+diagram
Expand Down
Loading