Is it possible to check which regions a SQL statement has accessed?

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

Original topic: 请问可否查看 SQL 语句访问了哪些region吗?

| username: GreenGuan

Background:
A slow SQL with a specific id

Full table group by takes 3 seconds
SELECT col_id, sum(money) as money FROM t where logtime >= ‘2022-08-23’ group by col_id;
18 rows in set (3.20 sec)

id 127 is slow:
SELECT col_id, sum(money) as money FROM t WHERE col_id = 127 AND logtime >= ‘2022-08-23’ group by col_id;
1 row in set (59.00 sec)
Rewritten query is even slower
select * from (SELECT col_id, sum(money) as money FROM t where logtime >= ‘2022-08-23’ group by col_id) as tmp_a where tmp_a.col_id = 127;
1 row in set (1 min 11.29 sec)

id 100 is fast:
SELECT col_id, sum(money) as money FROM t WHERE col_id = 100 AND logtime >= ‘2022-08-23’ group by col_id;
1 row in set (3.40 sec)

Table t is a partitioned table, and the number of entries with id 100 is more than that with id 127. There is an index on col_id and the query utilizes this index. This cluster does not have TiFlash or similar components, only pd, tidb, and tikv.

Therefore, I suspect it might be a hardware performance issue and want to check which store the region with col_id = 127 is distributed on.

| username: h5n1 | Original post link

trace select …

| username: GreenGuan | Original post link

I tried it and it seems that I can’t see the region information, I can only see which function was executed and for how long. The current TiDB version is 4.0.13.

| username: h5n1 | Original post link

Post it and take a look.

| username: GreenGuan | Original post link

I’m sorry, but I can’t access attachments. Please provide the text you need translated directly in the chat.

| username: h5n1 | Original post link

That means the 4.0 version does not have region_id.