Skip to content

Commit

Permalink
ebnf show stats healthy (#17072)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Apr 18, 2024
1 parent adec738 commit 21cc128
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions sql-statements/sql-statement-show-stats-healthy.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@ summary: An overview of the usage of SHOW STATS_HEALTHY for TiDB database.

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.
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.

## Synopsis

**ShowStmt**
```ebnf+diagram
ShowStatsHealthyStmt ::=
"SHOW" "STATS_HEALTHY" ShowLikeOrWhere?
![ShowStmt](/media/sqlgram/ShowStmt.png)

**ShowTargetFiltertable**

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

**ShowLikeOrWhereOpt**

![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png)
ShowLikeOrWhere ::=
"LIKE" SimpleExpr
| "WHERE" Expression
```

## Examples

Load example data and run `ANALYZE`:

{{< copyable "sql" >}}

```sql
CREATE TABLE t1 (
id INT NOT NULL PRIMARY KEY auto_increment,
Expand Down Expand Up @@ -62,8 +57,6 @@ mysql> SHOW STATS_HEALTHY;

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;
Expand Down

0 comments on commit 21cc128

Please sign in to comment.