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
2 changes: 2 additions & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@
+ [`SHOW [FULL] PROCESSSLIST`](/sql-statements/sql-statement-show-processlist.md)
+ [`SHOW PUMP STATUS`](/sql-statements/sql-statement-show-pump-status.md)
+ [`SHOW SCHEMAS`](/sql-statements/sql-statement-show-schemas.md)
+ [`SHOW STATS_HISTOGRAMS`](/sql-statements/sql-statement-show-histograms.md)
+ [`SHOW STATES_META`](/sql-statements/sql-statement-show-stats-meta.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
Binary file modified media/sqlgram/ShowLikeOrWhereOpt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions sql-statements/sql-statement-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ The `SELECT` statement is used to read data from TiDB.

![SelectLockOpt](/media/sqlgram/SelectLockOpt.png)

**WindowClauseOptional**

![WindowClauseOptional](/media/sqlgram/WindowClauseOptional.png)

## Description of the syntax elements

|Syntax Element|Description|
|:--------------------- | :-------------------------------------------------- |
|`TableOptimizerHints`| This is the hint to control the behavior of TiDB's optimizer. For more information, refer to [Optimizer Hints](/optimizer-hints.md). |
|`ALL`, `DISTINCT`, `DISTINCTROW` | The `ALL`, `DISTINCT`/`DISTINCTROW` modifiers specify whether duplicate rows should be returned. ALL (the default) specifies that all matching rows should be returned.|
|`HIGH_PRIORITY` | `HIGH_PRIORITY` gives the current statement higher priority than other statements. |
|`SQL_CALC_FOUND_ROWS`| To guarantee compatibility with MySQL, TiDB parses this syntax, but will ignore it. |
Expand All @@ -75,6 +80,7 @@ The `SELECT` statement is used to read data from TiDB.
|`HAVING where_condition` | The `HAVING` clause and the `WHERE` clause are both used to filter the results. The `HAVING` clause filters the results of `GROUP BY`, while the `WHERE` clause filter the results before aggregation. |
|`ORDER BY` | The `ORDER BY` clause is used to sort the data in ascending or descending order, based on columns, expressions or items in the `select_expr` list.|
|`LIMIT` | The `LIMIT` clause can be used to constrain the number of rows. `LIMIT` takes one or two numeric arguments. With one argument, the argument specifies the maximum number of rows to return, the first row to return is the first row of the table by default; with two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.|
|`Window window_definition`| This is the syntax for window function, which is usually used to do some analytical computation. For more information, refer to [Window Function](/functions-and-operators/window-functions.md). |
| `FOR UPDATE` | The `SELECT FOR UPDATE` clause locks all the data in the result sets to detect concurrent updates from other transactions. Data that match the query conditions but do not exist in the result sets are not read-locked, such as the row data written by other transactions after the current transaction is started. TiDB uses the [Optimistic Transaction Model](/optimistic-transaction.md). The transaction conflicts are not detected in the statement execution phase. Therefore, the current transaction does not block other transactions from executing `UPDATE`, `DELETE` or `SELECT FOR UPDATE` like other databases such as PostgreSQL. In the committing phase, the rows read by `SELECT FOR UPDATE` are committed in two phases, which means they can also join the conflict detection. If write conflicts occur, the commit fails for all transactions that include the `SELECT FOR UPDATE` clause. If no conflict is detected, the commit succeeds. And a new version is generated for the locked rows, so that write conflicts can be detected when other uncommitted transactions are being committed later. When using pessimistic transaction model, the behavior is basically the same as other databases. Refer to [Difference with MySQL InnoDB](/pessimistic-transaction.md#difference-with-mysql-innodb) to see the details. |
|`LOCK IN SHARE MODE` | To guarantee compatibility, TiDB parses these three modifiers, but will ignore them. |

Expand Down
67 changes: 67 additions & 0 deletions sql-statements/sql-statement-show-histograms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: SHOW STATS_HISTOGRAMS
summary: An overview of the usage of SHOW HISTOGRAMS for TiDB database。
category: reference
---

# SHOW STATS_HISTOGRAMS

This statement shows the histogram information collected by the `ANALYZE` statement.

## Synopsis

**ShowStmt**

![ShowStmt](/media/sqlgram/ShowStmt.png)

**ShowTargetFiltertable**

![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png)

**ShowLikeOrWhereOpt**

![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png)

## Examples

{{< copyable "sql" >}}

```sql
show stats_histograms;
```

```sql
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time | Distinct_count | Null_count | Avg_col_size | Correlation |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
| test | t | | a | 0 | 2020-05-25 19:20:00 | 7 | 0 | 1 | 1 |
| test | t2 | | a | 0 | 2020-05-25 19:20:01 | 6 | 0 | 8 | 0 |
| test | t2 | | b | 0 | 2020-05-25 19:20:01 | 6 | 0 | 1.67 | 1 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
3 rows in set (0.00 sec)
```

{{< copyable "sql" >}}

```sql
show stats_histograms where table_name = 't2';
```

```sql
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time | Distinct_count | Null_count | Avg_col_size | Correlation |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
| test | t2 | | b | 0 | 2020-05-25 19:20:01 | 6 | 0 | 1.67 | 1 |
| test | t2 | | a | 0 | 2020-05-25 19:20:01 | 6 | 0 | 8 | 0 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
2 rows in set (0.00 sec)
```

## MySQL compatibility

`SHOW STATS_HISTOGRAMS` is a TiDB specific syntax, and thus not compatible with MySQL.

## See also

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

# SHOW STATS_META

You can use `SHOW STATS_META` to view how many rows are in a table and how many rows are changed in that table. When using this statement, you can filter the needed information by the `ShowLikeOrWhere` clause.

Currently, the `SHOW STATS_META` statement outputs 6 columns:

| Syntax element | Description |
| -------- | ------------- |
| db_name | Database name |
| table_name | Table name |
| partition_name| Partition name |
| update_time | Last updated time |
| modify_count | The number of rows modified |
| row_count | The total row count |

> **注意:**
>
> The `update_time` is updated when TiDB updates the `modify_count` and `row_count` fields according to DML statements. So `update_time` is not the last execution time of the `ANALYZE` statement.

## Synopsis

**ShowStmt**

![ShowStmt](/media/sqlgram/ShowStmt.png)

**ShowTargetFiltertable**

![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png)

**ShowLikeOrWhereOpt**

![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png)

## Examples

{{< copyable "sql" >}}

```sql
show stats_meta;
```

```sql
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test | t0 | | 2020-05-15 16:58:00 | 0 | 0 |
| test | t1 | | 2020-05-15 16:58:04 | 0 | 0 |
| test | t2 | | 2020-05-15 16:58:11 | 0 | 0 |
| test | s | | 2020-05-22 19:46:43 | 0 | 0 |
| test | t | | 2020-05-25 12:04:21 | 0 | 0 |
+---------+------------+----------------+---------------------+--------------+-----------+
5 rows in set (0.00 sec)
```

{{< copyable "sql" >}}

```sql
show stats_meta where table_name = 't2';
```

```sql
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test | t2 | | 2020-05-15 16:58:11 | 0 | 0 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)
```

## MySQL compatibility

`SHOW STATS_META` is a TiDB specific syntax, and thus not compatible with MySQL.

## See also

* [ANALYZE](/sql-statements/sql-statement-analyze-table.md)
* [Introduction to Statistics](/statistics.md)
4 changes: 1 addition & 3 deletions statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,14 @@ You can view the statistics status using the following statements.

You can use the `SHOW STATS_META` statement to view the total number of rows and the number of updated rows.

Syntax as follows:
The syntax of `ShowLikeOrWhereOpt` is as follows:

{{< copyable "sql" >}}

```sql
SHOW STATS_META [ShowLikeOrWhere]
```

This statement returns the total number of all the rows in all the tables and the number of updated rows. You can use `ShowLikeOrWhere` to filter the information you need.

Currently, the `SHOW STATS_META` statement returns the following 6 columns:

| Syntax Element | Description |
Expand Down