From 92dd62acabc7dd7a81988dcf0b8af99cab044d28 Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:49:03 -0600 Subject: [PATCH 1/2] cherry pick #3388 to release-4.0 Signed-off-by: ti-srebot --- TOC.md | 1 + .../sql-statement-show-stats-healthy.md | 89 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 sql-statements/sql-statement-show-stats-healthy.md diff --git a/TOC.md b/TOC.md index 382b2cbe4d7ff..4668160ca9759 100644 --- a/TOC.md +++ b/TOC.md @@ -322,6 +322,7 @@ + [`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_HEALTHY`](/sql-statements/sql-statement-show-stats-healthy.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) diff --git a/sql-statements/sql-statement-show-stats-healthy.md b/sql-statements/sql-statement-show-stats-healthy.md new file mode 100644 index 0000000000000..22e214cf61497 --- /dev/null +++ b/sql-statements/sql-statement-show-stats-healthy.md @@ -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) From d968f552da7a6138c72ce9edf48bdaa629e32686 Mon Sep 17 00:00:00 2001 From: yikeke Date: Fri, 24 Jul 2020 10:34:24 +0800 Subject: [PATCH 2/2] add 6 aliases from https://github.com/pingcap/docs/pull/3396/ --- sql-statements/sql-statement-show-table-regions.md | 2 +- sql-statements/sql-statement-split-region.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-show-table-regions.md b/sql-statements/sql-statement-show-table-regions.md index 35edb9e76a5a5..ec7d6a2ec9d83 100644 --- a/sql-statements/sql-statement-show-table-regions.md +++ b/sql-statements/sql-statement-show-table-regions.md @@ -1,7 +1,7 @@ --- title: SHOW TABLE REGIONS summary: Learn how to use SHOW TABLE REGIONS in TiDB. -aliases: ['/docs/stable/sql-statements/sql-statement-show-table-regions/','/docs/v4.0/sql-statements/sql-statement-show-table-regions/','/docs/stable/reference/sql/statements/show-table-regions/'] +aliases: ['/docs/stable/sql-statements/sql-statement-show-table-regions/','/docs/v4.0/sql-statements/sql-statement-show-table-regions/','/docs/stable/reference/sql/statements/show-table-regions/','/tidb/v2.1/sql-statements/sql-statement-show-table-regions','/docs/v2.1/sql-statements/sql-statement-show-table-regions/','/docs/v2.1/reference/sql/statements/show-table-regions/'] --- # SHOW TABLE REGIONS diff --git a/sql-statements/sql-statement-split-region.md b/sql-statements/sql-statement-split-region.md index 300a550f2d678..955e8c9b0ad18 100644 --- a/sql-statements/sql-statement-split-region.md +++ b/sql-statements/sql-statement-split-region.md @@ -1,7 +1,7 @@ --- title: Split Region summary: An overview of the usage of Split Region for the TiDB database. -aliases: ['/docs/stable/sql-statements/sql-statement-split-region/','/docs/v4.0/sql-statements/sql-statement-split-region/','/docs/stable/reference/sql/statements/split-region/'] +aliases: ['/docs/stable/sql-statements/sql-statement-split-region/','/docs/v4.0/sql-statements/sql-statement-split-region/','/docs/stable/reference/sql/statements/split-region/','/tidb/v2.1/sql-statements/sql-statement-split-region','/docs/v2.1/sql-statements/sql-statement-split-region/','/docs/v2.1/reference/sql/statements/split-region/'] --- # Split Region