Symptoms
- Queries fail with
ERROR 1114 (HY000): The table '/tmp/#sql...' is full(the path varies), often only under concurrency. - Disk usage in
tmpdiror the InnoDB temporary tablespace (ibtmp1and#innodb_temp/) jumps during reporting jobs. GROUP BY,DISTINCT,UNION, window functions or derived tables get much slower at certain data sizes.Created_tmp_disk_tablesclimbs.
How MySQL 8 stores internal temporary tables
Since 8.0, internal temp tables default to the TempTable engine (internal_tmp_mem_storage_engine = TempTable):
- Rows go into TempTable memory, up to the global
temptable_max_ramshared by all sessions. - Past that, TempTable can use memory-mapped temporary files, up to
temptable_max_mmap(8.0.23+), if mmap is enabled. - Past that, the table is converted to an InnoDB on-disk temp table in the session temporary tablespaces.
- Since 8.0.28,
tmp_table_sizealso caps each in-memory TempTable table, after which that table goes to disk.
Defaults changed in 8.4:
| Variable | 8.0 default | 8.4 default |
|---|---|---|
temptable_max_ram | 1 GiB | 3% of physical memory, clamped to 1–4 GiB |
temptable_use_mmap | ON (deprecated 8.0.26) | OFF (deprecated) |
temptable_max_mmap | 1 GiB | 0 (mmap disabled) |
So an upgrade from 8.0 to 8.4 changes where overflow goes. Check your build: SHOW VARIABLES LIKE 'temptable%';
Warning
On 8.0 with mmap enabled, mmap files are created in
tmpdirand are deleted but still open.lswon't show them, butdfwill. Atmpdiron a small root volume can fill and break unrelated processes. On 8.0.x, error 1114 is often this path running out oftemptable_max_mmap(or of disk).
Checks
1. How often do temp tables reach disk?
SHOW GLOBAL STATUS WHERE Variable_name IN
('Created_tmp_tables','Created_tmp_disk_tables','Created_tmp_files','Uptime');
Take two samples a few minutes apart and compare the rates. A rising disk/total ratio during a particular job is your lead. Overflow into TempTable mmap files is not counted as a disk table, so look at memory instrumentation as well.
2. How much TempTable memory and mmap is in use now?
SELECT event_name,
current_number_of_bytes_used/1024/1024 AS current_mb,
high_number_of_bytes_used/1024/1024 AS high_water_mb
FROM performance_schema.memory_summary_global_by_event_name
WHERE event_name IN ('memory/temptable/physical_ram','memory/temptable/physical_disk');
physical_ramhigh water neartemptable_max_rammeans sessions are competing for the global pool.physical_disk> 0 means mmap overflow is in use.
3. Which queries create them?
SELECT digest_text,
count_star,
sum_created_tmp_tables AS tmp_tables,
sum_created_tmp_disk_tables AS tmp_disk_tables,
round(sum_timer_wait/1e12, 1) AS total_s
FROM performance_schema.events_statements_summary_by_digest
WHERE sum_created_tmp_disk_tables > 0
ORDER BY sum_created_tmp_disk_tables DESC
LIMIT 15;
Or with the sys schema:
SELECT query, exec_count, disk_tmp_tables, tmp_tables_to_disk_pct
FROM sys.statements_with_temp_tables
ORDER BY disk_tmp_tables DESC LIMIT 15;
4. Why does the query need a temp table?
EXPLAIN FORMAT=TREE
SELECT customer_id, COUNT(DISTINCT product_id)
FROM order_lines
WHERE order_date >= '2026-10-01'
GROUP BY customer_id
ORDER BY 2 DESC;
Look for Temporary table, Temporary table with deduplication or Materialize. EXPLAIN ANALYZE shows the row counts going into them.
5. Where is on-disk space going?
SELECT * FROM information_schema.INNODB_SESSION_TEMP_TABLESPACES; -- per-session .ibt files
SELECT file_name, total_extents*extent_size/1024/1024 AS mb
FROM information_schema.FILES WHERE tablespace_name = 'innodb_temporary'; -- ibtmp1 (user temp tables)
In 8.0.16+ internal on-disk temp tables use the session temporary tablespaces. Space returns to the pool when the session disconnects. Long-lived pooled connections can hold large .ibt files indefinitely.
Symptom → cause → fix
| Symptom | Likely cause | Fix |
|---|---|---|
Error 1114 on 8.0, physical_disk high | mmap overflow hit temptable_max_mmap or tmpdir filled | Raise temptable_max_mmap and point tmpdir at a large volume, or disable mmap so overflow goes to InnoDB |
| Error 1114 with low disk usage | InnoDB temp tablespace capped (innodb_temp_data_file_path with :max:) or a file-system limit | Raise the cap or remove the limit; check INNODB_SESSION_TEMP_TABLESPACES |
| Many disk tables, each small | Per-table cap tmp_table_size (8.0.28+) too low | Raise tmp_table_size carefully, globally or per session for batch jobs |
| Many disk tables only under concurrency | Global temptable_max_ram exhausted by many sessions | Raise temptable_max_ram within memory budget, or reduce concurrency of the reporting job |
| Disk tables after 8.0→8.4 upgrade | mmap disabled by default in 8.4 | Expected; size temptable_max_ram and the temp tablespace volume, or re-enable mmap after testing |
| One query creates GBs of temp data | GROUP BY/DISTINCT/UNION on many rows without a usable index | Add an index that delivers the grouping order, use UNION ALL, pre-aggregate, or filter earlier |
Large .ibt files that never shrink | Pooled sessions keep their temp tablespace | Recycle pool connections periodically (max lifetime) |
Fixes in order of preference
Fix the query first
- An index on
(customer_id, product_id)lets the example above group with an index scan and skip the temp table. - Replace
UNIONwithUNION ALLwhen duplicates are impossible. - Don't select wide
TEXT/BLOBcolumns into a grouped result. TempTable handles them, but they inflate memory per row. - Push filters into derived tables. Check with
EXPLAINthat derived tables are merged rather than materialised.
Then size the engine
-- Session-level for a known heavy batch job (8.0.28+ honours tmp_table_size for TempTable)
SET SESSION tmp_table_size = 512*1024*1024;
-- Global pool: dynamic, no restart
SET PERSIST temptable_max_ram = 4*1024*1024*1024;
Caution
temptable_max_ramis a ceiling, not a reservation. It still competes with the buffer pool, per-session buffers and the OS. On a box where the buffer pool is already 75–80% of RAM, adding gigabytes of TempTable headroom is how you get an OOM kill of mysqld. Check total memory first and change one setting at a time.
On managed services (RDS, Aurora, Azure Flexible Server) these are parameter-group or server-parameter settings. Some are fixed or bounded by the provider, so check the current documentation for your engine version. Aurora MySQL 3 has its own behaviour for temporary tables on readers. Read the Aurora docs before tuning a reader.
Then the storage
- Put
tmpdiron a volume sized for your worst report. - Monitor free space on the temp volume and the size of
#innodb_temp.
Prevent it next time
- Alert on the rate of
Created_tmp_disk_tables, on thememory/temptable/physical_diskhigh water mark, and on free space in the temp volume. - Review
sys.statements_with_temp_tablesweekly alongside your slow-query review. - Add the TempTable default changes to your 8.0 → 8.4 upgrade checklist, and load-test the reporting workload on 8.4 before cut-over.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get