Skip to content

Commit a160d82

Browse files
0xPoeti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#18499
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 190d96a commit a160d82

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: SHOW STATS_BUCKETS
3+
summary: An overview of the usage of SHOW STATS_BUCKETS for TiDB database.
4+
---
5+
6+
# SHOW STATS_BUCKETS
7+
8+
The `SHOW STATS_BUCKETS` statement shows the bucket information in [statistics](/statistics.md).
9+
10+
Currently, the `SHOW STATS_BUCKETS` statement returns the following columns:
11+
12+
| Column name | Description |
13+
| :-------- | :------------- |
14+
| `Db_name` | The database name |
15+
| `Table_name` | The table name |
16+
| `Partition_name` | The partition name |
17+
| `Column_name` | The column name (when `is_index` is `0`) or the index name (when `is_index` is `1`) |
18+
| `Is_index` | Whether it is an index column or not |
19+
| `Bucket_id` | The ID of a bucket |
20+
| `Count` | The number of all the values that falls on the bucket and the previous buckets |
21+
| `Repeats` | The occurrence number of the maximum value |
22+
| `Lower_bound` | The minimum value |
23+
| `Upper_bound` | The maximum value |
24+
| `Ndv` | The number of distinct values in the bucket. This field is deprecated and always shows `0` due to its inaccurate value. |
25+
26+
## Synopsis
27+
28+
```ebnf+diagram
29+
ShowStatsBucketsStmt ::=
30+
"SHOW" "STATS_BUCKETS" ShowLikeOrWhere?
31+
32+
ShowLikeOrWhere ::=
33+
"LIKE" SimpleExpr
34+
| "WHERE" Expression
35+
```
36+
37+
## Examples
38+
39+
```sql
40+
SHOW STATS_BUCKETS WHERE Table_name='t';
41+
```
42+
43+
```
44+
+---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+
45+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv |
46+
+---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+
47+
| test | t | | a | 0 | 0 | 1 | 1 | 2023-12-27 00:00:00 | 2023-12-27 00:00:00 | 0 |
48+
| test | t | | a | 0 | 1 | 2 | 1 | 2023-12-28 00:00:00 | 2023-12-28 00:00:00 | 0 |
49+
| test | t | | ia | 1 | 0 | 1 | 1 | (NULL, 2) | (NULL, 2) | 0 |
50+
| test | t | | ia | 1 | 1 | 2 | 1 | (NULL, 4) | (NULL, 4) | 0 |
51+
| test | t | | ia | 1 | 2 | 3 | 1 | (2023-12-27 00:00:00, 1) | (2023-12-27 00:00:00, 1) | 0 |
52+
| test | t | | ia | 1 | 3 | 4 | 1 | (2023-12-28 00:00:00, 3) | (2023-12-28 00:00:00, 3) | 0 |
53+
+---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+
54+
6 rows in set (0.00 sec)
55+
```
56+
57+
## MySQL compatibility
58+
59+
This statement is a TiDB extension to MySQL syntax.
60+
61+
## See also
62+
63+
* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md)
64+
* [Introduction to Statistics](/statistics.md)

system-variables.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a
11131113
11141114
### tidb_analyze_distsql_scan_concurrency <span class="version-mark">New in v7.6.0</span>
11151115
1116-
- Scope: GLOBAL
1116+
- Scope: SESSION | GLOBAL
11171117
- Persists to cluster: Yes
11181118
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
11191119
- Type: Integer
@@ -1359,7 +1359,7 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1;
13591359

13601360
### tidb_build_sampling_stats_concurrency <span class="version-mark">New in v7.5.0</span>
13611361

1362-
- Scope: GLOBAL
1362+
- Scope: SESSION | GLOBAL
13631363
- Persists to cluster: Yes
13641364
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
13651365
- Type: Integer
@@ -4274,7 +4274,7 @@ mysql> desc select count(distinct a) from test.t;
42744274
+-----------------------------------+---------+-----------+-----------------------+---------------------------------+
42754275
```
42764276
4277-
- The second example uses `0`, which assumes that 0% of rows will be scanned before the qualified rows are found.
4277+
- The second example uses `0`, which assumes that 0% of rows will be scanned before the qualified rows are found.
42784278
42794279
```sql
42804280
> SET SESSION tidb_opt_ordering_index_selectivity_ratio = 0;

0 commit comments

Comments
 (0)