[mysql] What does it mean when MySQL is in the state "Sending data"?

What does it mean if the Mysql query:

SHOW PROCESSLIST;

returns "Sending data" in the State column?

I imagine it means the query has been executed and MySQL is sending “result” Data to the client but I'm wondering why its taking so much time (up to an hour).

Thank you.

This question is related to mysql

The answer is


This is quite a misleading status. It should be called "reading and filtering data".

This means that MySQL has some data stored on the disk (or in memory) which is yet to be read and sent over. It may be the table itself, an index, a temporary table, a sorted output etc.

If you have a 1M records table (without an index) of which you need only one record, MySQL will still output the status as "sending data" while scanning the table, despite the fact it has not sent anything yet.


In this state:

The thread is reading and processing rows for a SELECT statement, and sending data to the client.

Because operations occurring during this this state tend to perform large amounts of disk access (reads).

That's why it takes more time to complete and so is the longest-running state over the lifetime of a given query.