Internal Temporary Table Use in MySQL •New data is stored in RAM if space becomes available within the limit defined by  temptable_max_ram . Otherwise, new data is stored in temporary files. •If space becomes available in RAM after some of the data for a table is written to temporary files, it is possible for the remaining table data to be stored in RAM. 1740 When in-memory internal temporary tables are managed by the  TempTable  storage engine, rows that include  VARCHAR  columns,  VARBINARY  columns, and other binary large object type columns (supported as of MySQL 8.0.13) are represented in memory by an array of cells, with each cell containing a NULL flag, the data length, and a data pointer. Column values are placed in consecutive order after the array, in a single region of memory, without padding. Each cell in the array uses 16 bytes of storage. The same In MySQL 8.0.15 and earlier: When using  internal_tmp_disk_storage_engine=INNODB , queries that generate on-disk internal temporary tables that exceed  InnoDB  row or column limits return  Row size too large  or  Too many columns  errors. The workaround is to set internal_tmp_disk_storage_engine  to  MYISAM . In MySQL 8.0.15 and earlier: For common table expressions (CTEs), the storage engine used for on-disk internal temporary tables cannot be  MyISAM . If  internal_tmp_disk_storage_engine=MYISAM , an error occurs for any attempt to materialize a CTE using an on-disk temporary table. In MySQL 8.0.15 and earlier, the  internal_tmp_disk_storage_engine  variable was used to define the storage engine used for on-disk internal temporary tables. This variable was removed in MySQL 8.0.16, and the storage engine used for this purpose is no longer user-configurable. Starting with MySQL 8.0.16, the server always uses the  InnoDB  storage engine for managing internal temporary tables on disk. When using the  MEMORY  storage engine for in-memory temporary tables, MySQL automatically converts an in-memory temporary table to an on-disk table if it becomes too large. The maximum size of an in-memory temporary table is defined by the  tmp_table_size  or  max_heap_table_size  value, whichever is smaller. This differs from  MEMORY  tables explicitly created with  CREATE TABLE . For such tables, only the max_heap_table_size  variable determines how large a table can grow, and there is no conversion to on-disk format. Prior to MySQL 8.0.23,  InnoDB  on-disk internal temporary tables are recommended as the  TempTable overflow mechanism if the TempTable storage engine often exceeds the  temptable_max_ram  limit and uses excessive space in the temporary directory for memory-mapped files. As of MySQL 8.0.23, the  temptable_max_mmap  variable defines a limit on the amount of memory the TempTable storage engine allocates from memory-mapped files, which addresses the risk of those files using too much space. Exceeding the  temptable_max_ram  limit typically occurs due to use of large internal temporary tables or extensive use of internal temporary tables.  InnoDB  on-disk internal temporary tables are created in session temporary tablespaces, which reside in the data directory by default. For more information, see Section 15.6.3.5, “Temporary Tablespaces” . If the  TempTable  storage engine is configured to use  InnoDB  on-disk internal temporary tables as the overflow mechanism ( temptable_use_mmap=OFF  or  temptable_max_mmap =0), an in-memory table that exceeds the  temptable_max_ram  limit is converted to an  InnoDB  on-disk internal temporary table, and any rows belonging to that table are moved from memory to the  InnoDB  on-disk internal temporary table. The  internal_tmp_disk_storage_engine  setting (removed in MySQL 8.0.16) has no affect on the  TempTable  storage engine overflow mechanism. Internal Temporary Table Storage Format Storage Engine for On-Disk Internal Temporary Tables