Bhushan Bhushan - 4 months ago 11x
SQL Question

How to get query plan for a running process in mysql

I can see currently running processes using

show processlist;
. It gives me partial text of the query which is running.
I want to know how can I see the query plan for this process using the Id.

"Explain" command of mysql accepts table name or a full query, but it doesn't accept a running query's id.


You have to write function something like this.

select info into @query from information_schema.processlist where id=3206933;
SET @stmt = CONCAT('explain ', @query);
use `database`
PREPARE stmt FROM @stmt;