The sql query data of the tidb INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY table is inaccurate

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY 表 sql查询数据不准

| username: 超7成网友

I want to count the number of slow queries for a specific user.

select Time from INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY where user = 'app' and time < '2024-04-25 18:05:00';

The result shows 112 entries.

select count(Time) from INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY where user = 'app';

It shows 63 entries. This is very strange; when the condition is relaxed, the count is actually lower.

| username: TIDB-Learner | Original post link

The statistics are inaccurate. Will try it when I have time.

| username: TiDBer_JUi6UvZm | Original post link

Indeed magical. What if you run select Time from INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY where user = 'app';?

| username: DBAER | Original post link

Is this the reason that the corresponding slow logs are parsed when a specific time period is specified, but only the current slow logs are parsed when not specified? Why don’t you try specifying the time and see if the result is correct?

| username: zhang_2023 | Original post link

I’ve encountered this issue before. Recollecting the statistics will solve it.

| username: 小龙虾爱大龙虾 | Original post link

When querying this, you must include a time range condition.

| username: 超7成网友 | Original post link

Learned, thank you.

| username: xiaoqiao | Original post link

Include the scope.