Quick revision
The short answer
A history list length of 48 million means purge has fallen far behind: undo from millions of committed transactions cannot be removed because some old transaction still holds an open read view that might need it. The usual cause is a long-running or forgotten open transaction, such as an idle session after BEGIN or a backup holding a consistent snapshot. We find it in information_schema.innodb_trx ordered by trx_started, end it, and prevent a repeat with transaction timeouts and monitoring of transaction age and history list length.
What to remember
In this answer, we saw that the history list length counts committed transactions whose undo has not been purged yet. Purge cannot remove versions newer than the oldest open read view, so one forgotten transaction or a long backup snapshot makes history pile up. Readers then walk long undo chains and scan dead entries, the buffer pool fills with undo, and queries slow down through the day. We find the culprit in information_schema.innodb_trx ordered by trx_started, kill it and fix the client, and prevent a repeat with transaction timeouts, leak detection and alerts on transaction age and history list length.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A history list length of 48 million means purge has fallen far behind: undo from millions of committed transactions cannot be removed because some old transaction still holds an open read view that might need it. The usual cause is a long-running or forgotten open transaction, such as an idle session after BEGIN or a backup holding a consistent snapshot. We find it in information_schema.innodb_trx ordered by trx_started, end it, and prevent a repeat with transaction timeouts and monitoring of transaction age and history list length.
Why this question is asked
This problem is sneaky because nothing is broken in the usual sense: there are no errors, no deadlocks, just a database that gets a little slower every hour until someone restarts something and it recovers. Interviewers like it because the cause is usually not the slow query at all but a quiet session somewhere else, and finding it requires knowing how MVCC and purge work together. In this answer, we will recap undo, read views and purge, see what blocks purge, explain why queries slow down, find the culprit with a few queries, and then fix and prevent it.
1A Quick Recap of Undo, Read Views and Purge
Every time InnoDB updates or deletes a row, it keeps the old version in the undo log, linked from the new version, so that transactions which started earlier can still see the row as it was. A deleted row is not removed at once either; it is only marked as deleted.
A consistent read in InnoDB uses a read view, a record of which transactions had committed when the snapshot was taken. At REPEATABLE READ, the default, a transaction creates its read view at its first read and keeps it until it ends. Any row version newer than the read view is invisible to it and is rebuilt from undo.
Purge is the background work that cleans up: it removes undo records and physically deletes delete-marked rows and index entries once no read view could need them. The history list length counts the undo logs of committed transactions waiting for purge, roughly one per transaction. A healthy busy server shows hundreds or a few thousand. 48 million means purge has been blocked for a long time.
2What Holds Purge Back
Purge can only remove versions older than the oldest read view still open. So a single transaction that started at 02:00 and never ended forces InnoDB to keep every version created since 02:00, for every table, even tables that transaction never touched. The common culprits are mundane: a connection that ran BEGIN and a SELECT and then went idle because of a bug or an exception path that skipped commit, a pooled connection with autocommit turned off, a developer's console session left open, or a logical backup such as mysqldump --single-transaction that holds one snapshot for hours.
6 messages in order. Play them, or step through them one at a time.
Purge waits for the oldest read view, whoever owns it.
Notice that the blocking session does not need to be doing anything. A session in the Sleep state with an open transaction is the most common cause, and it is invisible in a list of slow queries.
3Why Queries Get Slower Through the Day
The slowdown has several sources, all caused by the versions purge cannot remove. A reader whose read view is old must walk back through the undo chain of each row it reads to find the version it may see; on a hot row updated thousands of times, that chain is long. Every scan, including scans by new transactions, also has to step over delete-marked rows and index entries that purge would normally have removed, so an index range that should hold 1,000 live entries may hold 50,000 dead ones as well. And the undo pages compete with table data for space in the buffer pool, so more reads go to disk.
Meanwhile the undo tablespaces grow to hold the history, which consumes disk space and makes the problem visible to whoever watches storage before anyone watches latency.
4Finding the Transaction
We start with SHOW ENGINE INNODB STATUS to confirm the symptom, then look for the oldest open transaction and who owns it.
Notice that trx_query is NULL: the session is not running anything, it just never committed. The performance_schema join tells us which service and host own the connection and the last statements it ran, which is what we need to find the code path. The first column of the innodb_trx result is also the number to watch as a metric: the age of the oldest transaction.
5Resolving It Now
Once we know the owner, we end the transaction, usually with KILL 88123. If the transaction only read, it ends at once. If it wrote a lot, the rollback can take a while, and it must finish before purge advances. After that, purge works through the backlog; with 48 million entries this can take tens of minutes, and we can watch the history list length fall. On a server where purge regularly struggles even without a blocker, more purge threads (innodb_purge_threads, 4 by default, set at startup) can help, and in MySQL 8.0 undo tablespaces are truncated automatically once purge has freed them (innodb_undo_log_truncate, on by default; check your version).
Then we fix the client. The useful question is why the transaction stayed open: a missing commit in an error path, a Spring method that does slow remote calls inside @Transactional, or a pool configuration that leaves autocommit off.
6Preventing It From Coming Back
In the application, we keep transactions short and give them a limit. Spring's @Transactional(timeout = 30) rolls back a transaction that runs too long, and HikariCP's leakDetectionThreshold logs a stack trace when a connection is held longer than expected, which points straight at the leaking code. In MySQL, max_execution_time limits SELECT statements, but nothing ends an idle open transaction for us, so monitoring has to catch it.
We alert on two numbers: the age of the oldest transaction from innodb_trx (for example over 5 minutes), and the history list length, also available as trx_rseg_history_len in information_schema.INNODB_METRICS (for example over 1 million). And we take logical backups from a replica, or use a physical backup tool, so a long snapshot never sits on the primary.
- History list length keeps risingSHOW ENGINE INNODB STATUS
- Oldest entry in innodb_trxorder by trx_started
- Is it a backup or a known job?YesMove it to a replicaNoFind the owner via performance_schema
- KILL the sessionwait for any rollback
- Fix the code pathcommit in every path, add timeouts
- Alert on age and length5 minutes, 1 million
6 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Does READ COMMITTED avoid the problem?
It reduces it a lot. At READ COMMITTED each statement gets a fresh read view, so an idle session between statements holds no read view at all. But a single long-running statement still holds one for its duration, and so does a session that explicitly started a consistent snapshot, so long queries can still block purge.
Why does a transaction on an unrelated table block purge of my table?
Because a read view is not tied to tables. InnoDB cannot know which tables the old transaction will read next, so it must keep every version newer than that read view, everywhere.
Can we just add more purge threads?
Not for this cause. More purge threads help when purge cannot keep up with the write rate, but when the oldest read view blocks it, there is nothing purge is allowed to remove, however many threads it has.
8Conclusion
In this answer, we saw that the history list length counts committed transactions whose undo has not been purged yet. Purge cannot remove versions newer than the oldest open read view, so one forgotten transaction or a long backup snapshot makes history pile up. Readers then walk long undo chains and scan dead entries, the buffer pool fills with undo, and queries slow down through the day. We find the culprit in information_schema.innodb_trx ordered by trx_started, kill it and fix the client, and prevent a repeat with transaction timeouts, leak detection and alerts on transaction age and history list length.
Open with
The history list length is the backlog of undo from committed transactions that purge has not removed yet. Normally it is in the thousands; 48 million means purge has been blocked for hours.
Then, if they want more
Purge can only remove row versions older than the oldest open read view, so one long or forgotten transaction, like a session that ran BEGIN and then sat idle, or a mysqldump with single-transaction, makes InnoDB keep every version since it started, across all tables.
Queries slow down because readers walk longer version chains, scans step over delete-marked entries purge would have removed, and undo pages crowd the buffer pool, while the undo tablespaces grow.
To resolve it, I would query information_schema.innodb_trx ordered by trx_started to find the oldest transaction, join to performance_schema threads to see the user, host and last statements, and kill it, then fix the client code path, often a missing commit or slow remote calls inside a transaction.
To prevent it, I would set transaction timeouts in Spring, enable HikariCP leak detection, run logical backups on a replica, and alert on the age of the oldest transaction and on the history list length. More purge threads only help when purge cannot keep up, not when it is blocked.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- MySQL 8.0
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "SHOW ENGINE INNODB STATUS reports 'History list length 48000000' and queries on a hot...": https://scrivio-interview-library.netlify.app/databases/mysql/7f85949299/