Copying to tmp table is a common thread state within MySQL which occurs when the MySQL server is copying to a temporary table in memory.
MySQL will need to create temporary tables under certain circumstances e.g.:
- Sorting operations e.g. if a query contains an “Order By” clause, or “Group By” clause
- If the query contains “distinct”
To determine whether a query requires a temporary table, use EXPLAIN and check the Extra column to see whether it says “Using temporary“.
According to the MySQL site:
Some conditions prevent the use of an in-memory temporary table, in which case the server uses an on-disk table instead:
- Presence of a BLOB or TEXT column in the table
- Presence of any column in a GROUP BY or DISTINCT clause larger than 512 bytes
- Presence of any column larger than 512 bytes in the SELECT list, if UNION or UNION ALL is used
Queries which involve disk based Temporary tables are often slow, and a large number of queries of this type can result in a serious performance bottleneck.
taken from
http://www.dbtuna.com/article/55/Copying_to_tmp_table_-_MySQL_thread_states