How to check how many keys are involved in an SQL query?

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

Original topic: 如何查看一个SQL里面涉及到了多少key?

| username: GreenGuan

Which monitoring metric can reflect how many keys or rows are included in an SQL statement?

| username: tidb狂热爱好者 | Original post link

Use EXPLAIN SELECT * FROM a; to see the execution plan.
EXPLAIN ANALYZE

| username: tidb狂热爱好者 | Original post link

See if this is helpful to you.

| username: tidb狂热爱好者 | Original post link

Generally, after adding an index, the number of keys scanned will be relatively fewer.

| username: GreenGuan | Original post link

Sorry, maybe I didn’t express myself clearly. I meant the Grafana monitoring metrics for DML statements like insert, update, delete, not running specific statements.

| username: tidb狂热爱好者 | Original post link

I don’t know about this.

| username: Kongdom | Original post link

Something like this? You can see the traffic visualization on the TiDB Dashboard.

| username: GreenGuan | Original post link

No, this can only show the read and write status of the hotspot table, but it cannot determine how many keys a transaction has affected.

| username: Kongdom | Original post link

If it’s about transactions, then you must be referring to this.

| username: GreenGuan | Original post link

Yes, this is the number of keys involved in a single transaction. What I want to ask is whether Grafana monitoring shows the total number of keys involved in the current period.

| username: Kongdom | Original post link

Is this it?

Transaction

  • Transaction Regions Num: The number of Regions involved in the transaction operation
  • Transaction Write KV Num: The number of KVs involved in the transaction operation

Distsql

  • Scan Keys Num: The number of Keys scanned by each Query
  • Scan Keys Partial Num: The number of Keys scanned by each Partial Result
| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.