SHOW QUERY STATS
更新时间:2025-10-16
描述
该语句用于展示数据库中历史查询命中的库表列的情况
语法
SQL
1SHOW QUERY STATS [ { [FOR <db_name>] | [FROM <table_name>] } ] [ALL] [VERBOSE]];
可选参数
1. <db_name>
若填写表示展示数据库的命中情况
2. <table_name>
若填写表示查询某表的查询命中情况
3. ALL
ALL 可以指定是否展示所有 index 的查询命中情况
4. VERBOSE
VERBOSE 可以展示更详细的命中情况
权限控制
执行此 SQL 命令的用户必须至少具有以下权限:
| 权限(Privilege) | 对象(Object) | 说明(Notes) |
|---|---|---|
| SELECT_PRIV | DATABASE | 需要对查询的数据库有 SELECT 权限 |
注意事项
- 支持查询数据库和表的历史查询命中情况,重启 fe 后数据会重置,每个 fe 单独统计。
- 通过 FOR DATABASE 和 FROM TABLE 可以指定查询数据库或者表的命中情况,后面分别接数据库名或者表名。
- ALL 和 VERBOSE 可以展示更详细的命中情况,这两个参数可以单独使用,也可以一起使用,但是必须放在最后 而且只能用在表的查询上。
- 如果没有 use 任何数据库那么直接执行
SHOW QUERY STATS将展示所有数据库的命中情况。 - 命中结果中可能有两列:QueryCount 表示该列被查询次数,FilterCount 表示该列作为 where 条件被查询的次数。
示例
SQL
1show query stats from baseall
Text
1 +-------+------------+-------------+
2 | Field | QueryCount | FilterCount |
3 +-------+------------+-------------+
4 | k0 | 0 | 0 |
5 | k1 | 0 | 0 |
6 | k2 | 0 | 0 |
7 | k3 | 0 | 0 |
8 | k4 | 0 | 0 |
9 | k5 | 0 | 0 |
10 | k6 | 0 | 0 |
11 | k10 | 0 | 0 |
12 | k11 | 0 | 0 |
13 | k7 | 0 | 0 |
14 | k8 | 0 | 0 |
15 | k9 | 0 | 0 |
16 | k12 | 0 | 0 |
17 | k13 | 0 | 0 |
18 +-------+------------+-------------+
SQL
1select k0, k1,k2, sum(k3) from baseall where k9 > 1 group by k0,k1,k2
Text
1 +------+------+--------+-------------+
2 | k0 | k1 | k2 | sum(`k3`) |
3 +------+------+--------+-------------+
4 | 0 | 6 | 32767 | 3021 |
5 | 1 | 12 | 32767 | -2147483647 |
6 | 0 | 3 | 1989 | 1002 |
7 | 0 | 7 | -32767 | 1002 |
8 | 1 | 8 | 255 | 2147483647 |
9 | 1 | 9 | 1991 | -2147483647 |
10 | 1 | 11 | 1989 | 25699 |
11 | 1 | 13 | -32767 | 2147483647 |
12 | 1 | 14 | 255 | 103 |
13 | 0 | 1 | 1989 | 1001 |
14 | 0 | 2 | 1986 | 1001 |
15 | 1 | 15 | 1992 | 3021 |
16 +------+------+--------+-------------+
SQL
1show query stats from baseall;
Text
1 +-------+------------+-------------+
2 | Field | QueryCount | FilterCount |
3 +-------+------------+-------------+
4 | k0 | 1 | 0 |
5 | k1 | 1 | 0 |
6 | k2 | 1 | 0 |
7 | k3 | 1 | 0 |
8 | k4 | 0 | 0 |
9 | k5 | 0 | 0 |
10 | k6 | 0 | 0 |
11 | k10 | 0 | 0 |
12 | k11 | 0 | 0 |
13 | k7 | 0 | 0 |
14 | k8 | 0 | 0 |
15 | k9 | 1 | 1 |
16 | k12 | 0 | 0 |
17 | k13 | 0 | 0 |
18 +-------+------------+-------------+
SQL
1show query stats from baseall all
Text
1 +-----------+------------+
2 | IndexName | QueryCount |
3 +-----------+------------+
4 | baseall | 1 |
5 +-----------+------------+
SQL
1show query stats from baseall all verbose
Text
1 +-----------+-------+------------+-------------+
2 | IndexName | Field | QueryCount | FilterCount |
3 +-----------+-------+------------+-------------+
4 | baseall | k0 | 1 | 0 |
5 | | k1 | 1 | 0 |
6 | | k2 | 1 | 0 |
7 | | k3 | 1 | 0 |
8 | | k4 | 0 | 0 |
9 | | k5 | 0 | 0 |
10 | | k6 | 0 | 0 |
11 | | k10 | 0 | 0 |
12 | | k11 | 0 | 0 |
13 | | k7 | 0 | 0 |
14 | | k8 | 0 | 0 |
15 | | k9 | 1 | 1 |
16 | | k12 | 0 | 0 |
17 | | k13 | 0 | 0 |
18 +-----------+-------+------------+-------------+
SQL
1show query stats for test_query_db
Text
1 +----------------------------+------------+
2 | TableName | QueryCount |
3 +----------------------------+------------+
4 | compaction_tbl | 0 |
5 | bigtable | 0 |
6 | empty | 0 |
7 | tempbaseall | 0 |
8 | test | 0 |
9 | test_data_type | 0 |
10 | test_string_function_field | 0 |
11 | baseall | 1 |
12 | nullable | 0 |
13 +----------------------------+------------+
SQL
1show query stats
Text
1 +-----------------+------------+
2 | Database | QueryCount |
3 +-----------------+------------+
4 | test_query_db | 1 |
5 +-----------------+------------+
