All pages
Powered by GitBook
1 of 1

Loading...

InnoDB Undo Log

The undo log stores the "before" image of data modified by active transactions, supporting rollbacks and consistent read views.

Overview

When a transaction writes data, it always inserts them in the table indexes or data (in the buffer pool or in physical files). No private copies are created. The old versions of data being modified by active InnoDB transactions are stored in the undo log. The original data can then be restored, or viewed by a consistent read.

Implementation Details

Before a row is modified, a diff is copied into the undo log. Each normal row contains a pointer to the most recent version of the same row in the undo log. Each row in the undo log contains a pointer to previous version, if any. So, each modified row has a history chain.

Rows are never physically deleted until a transaction ends. If they were deleted, the restore in ROLLBACK would be impossible. Thus, rows are simply marked for deletion.

Each transaction uses a view of the records. The determines how this view is created. For example, READ UNCOMMITTED usually uses the current version of rows, even if they are not committed (dirty reads). Other isolation levels require that the most recent committed version of rows is searched in the undo log. READ COMMITTED uses a different view for each table, while REPEATABLE READ and SERIALIZABLE use the same view for all tables.

There is also a global history list of the data. When a transaction is committed, its history is added to this history list. The order of the list is the chronological order of the commits.

The purge thread deletes the rows in the undo log which are not needed by any existing view. The rows for which a most recent version exists are deleted, as well as the delete-marked rows.

If InnoDB needs to restore an old version, it will simply replace the newer version with the older one. When a transaction inserts a new row, there is no older version. However, in that case, the restore can be done by deleting the inserted rows.

Effects of Long-Running Transactions

Understanding how the undo log works helps with understanding the negative effects long transactions.

  • Long transactions generate several old versions of the rows in the undo log. Those rows will probably be needed for a longer time, because other long transactions will need them. Since those transactions will generate more modified rows, a sort of combinatorial explosion can be observed. Thus, the undo log requires more space.

  • Transaction may need to read very old versions of the rows in the history list, thus their performance will degrade.

Of course read-only transactions do not write more entries in the undo log; however, they delay the purging of existing entries.

Also, long transactions can more likely result in deadlocks, but this problem is not related to the undo log.

Feature Summary

Feature
Detail
Resources

Configuration

System variables affecting undo logs include:

The undo log is not a log file that can be viewed on disk in the usual sense, such as the or , but rather an area of storage.

Before , the undo log is usually part of the physical system tablespace, but from , the and system variables can be used to split into different tablespaces and store in a different location (perhaps on a different storage device). From , multiple undo tablespaces are enabled by default, and the default is changed to 3 so that the space occupied by possible bursts of undo log records can be reclaimed after is set.

Each insert or update portion of the undo log is known as a rollback segment. The system variable allowed to reduce the number of rollback segments from the usual 128, to limit the number of concurrently active write transactions. was deprecated and ignored in and removed in , as it always makes sense to use the maximum number of rollback segments.

The related status variable stores the total number of available InnoDB undo logs.

This page is licensed: CC BY-SA / Gnu FDL

Location

By default, located in InnoDB system tablespace When

innodb_undo_tablespaces is set, located in directory set by (Defaults to )

Quantity

Set by

Size

10 MB per tablespace by default (grows as needed)

innodb_undo_tablespaces
  • innodb_purge_batch_size

  • innodb_purge_rseg_truncate_frequency

  • Transaction Log

    InnoDB Undo Log

    Storage Engine

    InnoDB

    Purpose

    Multi-Version Concurrency Control (MVCC)

    Availability

    All ES and CS versions

    MariaDB Enterprise Server

    transaction isolation level
    innodb_max_undo_log_size
    innodb_undo_directory
    innodb_undo_log_truncate
    innodb_undo_logs
    error log
    slow query log
    innodb_undo_directory
    innodb_undo_tablespaces
    innodb_undo_tablespaces
    innodb_undo_log_truncate
    innodb_undo_logs
    innodb_undo_logs
    MariaDB 10.6
    innodb_available_undo_logs
    innodb_undo_tablespaces
    innodb_undo_directory
    datadir
    innodb_undo_tablespaces
    Configure the InnoDB Undo Log
    MariaDB 11.0
    MariaDB 10.0
    MariaDB 11.0
    MariaDB 10.5