Thread States
The following list describes thread State values that are associated with general query processing and not more specialized activities such as replication. Many of these are useful only for finding bugs in the server.
-
After createThis occurs when the thread creates a table (including internal temporary tables), at the end of the function that creates the table. This state is used even if the table could not be created due to some error.
-
altering tableThe server is in the process of executing an in-place
ALTER TABLE. -
AnalyzingThe thread is calculating a
MyISAMtable key distributions (for example, forANALYZE TABLE). -
checking permissionsThe thread is checking whether the server has the required privileges to execute the statement.
-
Checking tableThe thread is performing a table check operation.
-
cleaning upThe thread has processed one command and is preparing to free memory and reset certain state variables.
-
closing tablesThe thread is flushing the changed table data to disk and closing the used tables. This should be a fast operation. If not, verify that you do not have a full disk and that the disk is not in very heavy use.
-
committing alter table to storage engineThe server has finished an in-place
ALTER TABLEand is committing the result. -
converting HEAP to ondiskThe thread is converting an internal temporary table from a
MEMORYtable to an on-disk table. -
copy to tmp tableThe thread is processing an
ALTER TABLEstatement. This state occurs after the table with the new structure has been created but before rows are copied into it.For a thread in this state, the Performance Schema can be used to obtain about the progress of the copy operation. See Section 29.12.5, "Performance Schema Stage Event Tables".
-
Copying to group tableIf a statement has different
ORDER BYandGROUP BYcriteria, the rows are sorted by group and copied to a temporary table. -
Copying to tmp tableThe server is copying to a temporary table in memory.
-
Copying to tmp table on diskThe server is copying to a temporary table on disk. The temporary result set has become too large (see Section 10.4.4, "Internal Temporary Table Use in MySQL"). Consequently, the thread is changing the temporary table from in-memory to disk-based format to save memory.
-
Creating indexThe thread is processing
ALTER TABLE ... ENABLE KEYSfor aMyISAMtable. -
Creating sort indexThe thread is processing a
SELECTthat is resolved using an internal temporary table. -
creating tableThe thread is creating a table. This includes creation of temporary tables.
-
Creating tmp tableThe thread is creating a temporary table in memory or on disk. If the table is created in memory but later is converted to an on-disk table, the state during that operation is
Copying to tmp table on disk. -
deleting from main tableThe server is executing the first part of a multiple-table delete. It is deleting only from the first table, and saving columns and offsets to be used for deleting from the other (reference) tables.
-
deleting from reference tablesThe server is executing the second part of a multiple-table delete and deleting the matched rows from the other tables.
-
discard_or_import_tablespaceThe thread is processing an
ALTER TABLE ... DISCARD TABLESPACEorALTER TABLE ... IMPORT TABLESPACEstatement. -
endThis occurs at the end but before the cleanup of
ALTER TABLE,CREATE VIEW,DELETE,INSERT,SELECT, orUPDATEstatements.For the
endstate, the following operations could be happening:-
Writing an event to the binary log
-
Freeing memory buffers, including for blobs
-
-
executingThe thread has begun executing a statement.
-
Execution of init_commandThe thread is executing statements in the value of the
init_commandsystem variable. -
freeing itemsThe thread has executed a command. This state is usually followed by
cleaning up. -
FULLTEXT initializationThe server is preparing to perform a natural-language full-text search.
-
initThis occurs before the initialization of
ALTER TABLE,DELETE,INSERT,SELECT, orUPDATEstatements. Actions taken by the server in this state include flushing the binary log and theInnoDBlog. -
KilledSomeone has sent a
KILLstatement to the thread and it should abort next time it checks the kill flag. The flag is checked in each major loop in MySQL, but in some cases it might still take a short time for the thread to die. If the thread is locked by some other thread, the kill takes effect as soon as the other thread releases its lock. -
Locking system tablesThe thread is trying to lock a system table (for example, a time zone or log table).
-
logging slow queryThe thread is writing a statement to the slow-query log.
-
loginThe initial state for a connection thread until the client has been authenticated successfully.
-
manage keysThe server is enabling or disabling a table index.
-
Opening system tablesThe thread is trying to open a system table (for example, a time zone or log table).
-
Opening tablesThe thread is trying to open a table. This is should be very fast procedure, unless something prevents opening. For example, an
ALTER TABLEor aLOCK TABLEstatement can prevent opening a table until the statement is finished. It is also worth checking that yourtable_open_cachevalue is large enough.For system tables, the
Opening system tablesstate is used instead. -
optimizingThe server is performing initial optimizations for a query.
-
preparingThis state occurs during query optimization.
-
preparing for alter tableThe server is preparing to execute an in-place
ALTER TABLE. -
Purging old relay logsThe thread is removing unneeded relay log files.
-
query endThis state occurs after processing a query but before the
freeing itemsstate. -
Receiving from clientThe server is reading a packet from the client.
-
Removing duplicatesThe query was using
SELECT DISTINCTin such a way that MySQL could not optimize away the distinct operation at an early stage. Because of this, MySQL requires an extra stage to remove all duplicated rows before sending the result to the client. -
removing tmp tableThe thread is removing an internal temporary table after processing a
SELECTstatement. This state is not used if no temporary table was created. -
renameThe thread is renaming a table.
-
rename result tableThe thread is processing an
ALTER TABLEstatement, has created the new table, and is renaming it to replace the original table. -
Reopen tablesThe thread got a lock for the table, but noticed after getting the lock that the underlying table structure changed. It has freed the lock, closed the table, and is trying to reopen it.
-
Repair by sortingThe repair code is using a sort to create indexes.
-
Repair doneThe thread has completed a multithreaded repair for a
MyISAMtable. -
Repair with keycacheThe repair code is using creating keys one by one through the key cache. This is much slower than
Repair by sorting. -
Rolling backThe thread is rolling back a transaction.
-
Saving stateFor
MyISAMtable operations such as repair or analysis, the thread is saving the new table state to the.MYIfile header. State includes information such as number of rows, theAUTO_INCREMENTcounter, and key distributions. -
Searching rows for updateThe thread is doing a first phase to find all matching rows before updating them. This has to be done if the
UPDATEis changing the index that is used to find the involved rows. -
Sending dataPrior to MySQL 8.0.17: The thread is reading and processing rows for a
SELECTstatement, and sending data to the client. Because operations occurring during this state tend to perform large amounts of disk access (reads), it is often the longest-running state over the lifetime of a given query. MySQL 8.0.17 and later: This state is no longer indicated separately, but rather is included in theExecutingstate. -
Sending to clientThe server is writing a packet to the client.
-
setupThe thread is beginning an
ALTER TABLEoperation. -
Sorting for groupThe thread is doing a sort to satisfy a
GROUP BY. -
Sorting for orderThe thread is doing a sort to satisfy an
ORDER BY. -
Sorting indexThe thread is sorting index pages for more efficient access during a
MyISAMtable optimization operation. -
Sorting resultFor a
SELECTstatement, this is similar toCreating sort index, but for nontemporary tables. -
startingThe first stage at the beginning of statement execution.
-
statisticsThe server is calculating statistics to develop a query execution plan. If a thread is in this state for a long time, the server is probably disk-bound performing other work.
-
System lockThe thread has called
mysql_lock_tables()and the thread state has not been updated since. This is a very general state that can occur for many reasons.For example, the thread is going to request or is waiting for an internal or external system lock for the table. This can occur when
InnoDBwaits for a table-level lock during execution ofLOCK TABLES. If this state is being caused by requests for external locks and you are not using multiple mysqld servers that are accessing the sameMyISAMtables, you can disable external system locks with the--skip-external-lockingoption. However, external locking is disabled by default, so it is likely that this option has no effect. ForSHOW PROFILE, this state means the thread is requesting the lock (not waiting for it).For system tables, the
Locking system tablesstate is used instead. -
updateThe thread is getting ready to start updating the table.
-
UpdatingThe thread is searching for rows to update and is updating them.
-
updating main tableThe server is executing the first part of a multiple-table update. It is updating only the first table, and saving columns and offsets to be used for updating the other (reference) tables.
-
updating reference tablesThe server is executing the second part of a multiple-table update and updating the matched rows from the other tables.
-
User lockThe thread is going to request or is waiting for an advisory lock requested with a
GET_LOCK()call. ForSHOW PROFILE, this state means the thread is requesting the lock (not waiting for it). -
User sleepThe thread has invoked a
SLEEP()call. -
Waiting for commit lockFLUSH TABLES WITH READ LOCKis waiting for a commit lock. -
waiting for handler commitThe thread is waiting for a transaction to commit versus other parts of query processing.
-
Waiting for tablesThe thread got a notification that the underlying structure for a table has changed and it needs to reopen the table to get the new structure. However, to reopen the table, it must wait until all other threads have closed the table in question.
This notification takes place if another thread has used
FLUSH TABLESor one of the following statements on the table in question:FLUSH TABLES _`tbl_name`_,ALTER TABLE,RENAME TABLE,REPAIR TABLE,ANALYZE TABLE, orOPTIMIZE TABLE. -
Waiting for table flushThe thread is executing
FLUSH TABLESand is waiting for all threads to close their tables, or the thread got a notification that the underlying structure for a table has changed and it needs to reopen the table to get the new structure. However, to reopen the table, it must wait until all other threads have closed the table in question.This notification takes place if another thread has used
FLUSH TABLESor one of the following statements on the table in question:FLUSH TABLES _`tbl_name`_,ALTER TABLE,RENAME TABLE,REPAIR TABLE,ANALYZE TABLE, orOPTIMIZE TABLE. -
Waiting for _`lock_type`_ lockThe server is waiting to acquire a
THR_LOCKlock or a lock from the metadata locking subsystem, wherelock_typeindicates the type of lock.This state indicates a wait for a
THR_LOCK:Waiting for table level lock
These states indicate a wait for a metadata lock:
Waiting for event metadata lockWaiting for global read lockWaiting for schema metadata lockWaiting for stored function metadata lockWaiting for stored procedure metadata lockWaiting for table metadata lockWaiting for trigger metadata lock
-
Waiting on condA generic state in which the thread is waiting for a condition to become true. No specific state information is available.
-
Writing to netThe server is writing a packet to the network.