Identify long-running queries
Use theSHOW STATEMENTS statement to list details about currently active SQL queries, including each query’s start timestamp:
Cancel long-running queries
Once you’ve identified a long-running query viaSHOW STATEMENTS, note the query_id and use it with the CANCEL QUERY statement:
query execution canceled error to the client that issued the query.
- If the canceled query was a single, stand-alone statement, no further action is required by the client.
- If the canceled query was part of a larger, multi-statement transaction, the client should then issue a
ROLLBACKstatement.
Improve query performance
After cancelling a long-running query, use theEXPLAIN statement to examine it. It’s possible that the query was slow because it performs a full-table scan. In these cases, you can likely improve the query’s performance by adding an index.

