Internal Temporary Table Use in MySQL •Evaluation of some views, such those that use the  TEMPTABLE  algorithm,  UNION , or aggregation. •Evaluation of derived tables (see Section 13.2.11.8, “Derived Tables” ). •Evaluation of common table expressions (see Section 13.2.15, “WITH (Common Table Expressions)” ). •Tables created for subquery or semijoin materialization (see Section 8.2.2, “Optimizing Subqueries, Derived Tables, View References, and Common Table Expressions” ). •Evaluation of statements that contain an  ORDER BY  clause and a different  GROUP BY  clause, or for which the  ORDER BY  or  GROUP BY  contains columns from tables other than the first table in the join queue. •Evaluation of  DISTINCT  combined with  ORDER BY  may require a temporary table. •For queries that use the  SQL_SMALL_RESULT  modifier, MySQL uses an in-memory temporary table, unless the query also contains elements (described later) that require on-disk storage. •To evaluate  INSERT ... SELECT  statements that select from and insert into the same table, MySQL creates an internal temporary table to hold the rows from the  SELECT , then inserts those rows into the target table. See Section 13.2.6.1, “INSERT ... SELECT Statement” . •Evaluation of multiple-table  UPDATE  statements. •Evaluation of  GROUP_CONCAT()  or  COUNT(DISTINCT)  expressions. •Evaluation of window functions (see Section 12.21, “Window Functions” ) uses temporary tables as necessary. •Presence of a  BLOB  or  TEXT  column in the table. However, the  TempTable  storage engine, which is the default storage engine for in-memory internal temporary tables in MySQL 8.0, supports binary large object types as of MySQL 8.0.13. See Internal Temporary Table Storage Engine. •Presence of any string column with a maximum length larger than 512 (bytes for binary strings, characters for nonbinary strings) in the  SELECT  list, if  UNION  or  UNION ALL  is used. •The  SHOW COLUMNS  and  DESCRIBE  statements use  BLOB  as the type for some columns, thus the temporary table used for the results is an on-disk table. 1738 The server does not use a temporary table for  UNION  statements that meet certain qualifications. Instead, it retains from temporary table creation only the data structures necessary to perform result column typecasting. The table is not fully instantiated and no rows are written to or read from it; rows are sent directly to the client. The result is reduced memory and disk requirements, and smaller delay before the first row is sent to the client because the server need not wait until the last query block is executed. EXPLAIN  and optimizer trace output reflects this execution strategy: The  UNION RESULT  query block is not present because that block corresponds to the part that reads from the temporary table. These conditions qualify a  UNION  for evaluation without a temporary table: Some query conditions prevent the use of an in-memory temporary table, in which case the server uses an on-disk table instead: To determine whether a statement requires a temporary table, use  EXPLAIN  and check the  Extra  column to see whether it says  Using temporary  (see Section 8.8.1, “Optimizing Queries with EXPLAIN” ). EXPLAIN  does not necessarily say  Using temporary  for derived or materialized temporary tables. For statements that use window functions,  EXPLAIN  with  FORMAT=JSON  always provides information about the windowing steps. If the windowing functions use temporary tables, it is indicated for each step.