-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql-statements: add SHOW STATS_HEALTHY (#3388)
* sql-statements: ADD SHOW STATS_HEALTHY * Update sql-statements/sql-statement-show-stats-healthy.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> * Update sql-statements/sql-statement-show-stats-healthy.md Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
- Loading branch information
1 parent
c5acf0a
commit bc0fb25
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: SHOW STATS_HEALTHY | ||
summary: An overview of the usage of SHOW STATS_HEALTHY for TiDB database. | ||
--- | ||
|
||
# SHOW STATS_HEALTHY | ||
|
||
The `SHOW STATS_HEALTHY` statement shows an estimation of how accurate statistics are believed to be. Tables with a low percentage health may generate sub-optimal query execution plans. | ||
|
||
The health of a table can be improved by running the `ANALYZE` table command. `ANALYZE` runs automatically when the health drops below the [`tidb_auto_analyze_ratio`](/system-variables.md#tidb_auto_analyze_ratio) threshold. | ||
|
||
## Synopsis | ||
|
||
**ShowStmt** | ||
|
||
![ShowStmt](/media/sqlgram/ShowStmt.png) | ||
|
||
**ShowTargetFiltertable** | ||
|
||
![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png) | ||
|
||
**ShowLikeOrWhereOpt** | ||
|
||
![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png) | ||
|
||
## Examples | ||
|
||
Load example data and run `ANALYZE`: | ||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
CREATE TABLE t1 ( | ||
id INT NOT NULL PRIMARY KEY auto_increment, | ||
b INT NOT NULL, | ||
pad VARBINARY(255), | ||
INDEX(b) | ||
); | ||
|
||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM dual; | ||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; | ||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; | ||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; | ||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; | ||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; | ||
INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; | ||
SELECT SLEEP(1); | ||
ANALYZE TABLE t1; | ||
SHOW STATS_HEALTHY; # should be 100% healthy | ||
``` | ||
|
||
```sql | ||
... | ||
mysql> SHOW STATS_HEALTHY; | ||
+---------+------------+----------------+---------+ | ||
| Db_name | Table_name | Partition_name | Healthy | | ||
+---------+------------+----------------+---------+ | ||
| test | t1 | | 100 | | ||
+---------+------------+----------------+---------+ | ||
1 row in set (0.00 sec) | ||
``` | ||
|
||
Perform a bulk update deleting approximately 30% of the records. Check the health of the statistics: | ||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
DELETE FROM t1 WHERE id BETWEEN 101010 AND 201010; # delete about 30% of records | ||
SHOW STATS_HEALTHY; | ||
``` | ||
|
||
```sql | ||
mysql> SHOW STATS_HEALTHY; | ||
+---------+------------+----------------+---------+ | ||
| Db_name | Table_name | Partition_name | Healthy | | ||
+---------+------------+----------------+---------+ | ||
| test | t1 | | 50 | | ||
+---------+------------+----------------+---------+ | ||
1 row 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) |