10bet网址
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr)- 41.6Mb
PDF (A4)- 41.7Mb
Man Pages (TGZ)- 262.2Kb
Man Pages (Zip)- 372.3Kb
Info (Gzip)- 4.0Mb
Info (Zip)- 4.0Mb
Excerpts from this Manual

15.8.9 Purge Configuration

InnoDBdoes not physically remove a row from the database immediately when you delete it with an SQL statement. A row and its index records are only physically removed whenInnoDBdiscards the undo log record written for the deletion. This removal operation, which only occurs after the row is no longer required for multi-version concurrency control (MVCC) or rollback, is called a purge.

Purge runs on a periodic schedule. It parses and processes undo log pages from the history list, which is a list of undo log pages for committed transactions that is maintained by theInnoDBtransaction system. Purge frees the undo log pages from the history list after processing them.

Configuring Purge Threads

Purge operations are performed in the background by one or more purge threads. The number of purge threads is controlled by theinnodb_purge_threads弗吉尼亚州riable. The default value is 4.

If DML action is concentrated on a single table, purge operations for the table are performed by a single purge thread, which can result in slowed purge operations, increased purge lag, and increased tablespace file size if the DML operations involve large object values. From MySQL 8.0.26, if theinnodb_max_purge_lagsetting is exceeded, purge work is automatically redistributed among available purge threads. Too many active purge threads in this scenario can cause contention with user threads, so manage theinnodb_purge_threadssetting accordingly. Theinnodb_max_purge_lag弗吉尼亚州riable is set to 0 by default, which means that there is no maximum purge lag by default.

If DML action is concentrated on few tables, keep theinnodb_purge_threadssetting low so that the threads do not contend with each other for access to the busy tables. If DML operations are spread across many tables, consider a higherinnodb_purge_threadssetting. The maximum number of purge threads is 32.

Theinnodb_purge_threadssetting is the maximum number of purge threads permitted. The purge system automatically adjusts the number of purge threads that are used.

Configuring Purge Batch Size

Theinnodb_purge_batch_size弗吉尼亚州riable defines the number of undo log pages that purge parses and processes in one batch from the history list. The default value is 300. In a multithreaded purge configuration, the coordinator purge thread dividesinnodb_purge_batch_sizebyinnodb_purge_threadsand assigns that number of pages to each purge thread.

The purge system also frees the undo log pages that are no longer required. It does so every 128 iterations through the undo logs. In addition to defining the number of undo log pages parsed and processed in a batch, theinnodb_purge_batch_size弗吉尼亚州riable defines the number of undo log pages that purge frees every 128 iterations through the undo logs.

Theinnodb_purge_batch_size弗吉尼亚州riable is intended for advanced performance tuning and experimentation. Most users need not changeinnodb_purge_batch_sizefrom its default value.

Configuring the Maximum Purge Lag

Theinnodb_max_purge_lag弗吉尼亚州riable defines the desired maximum purge lag. When the purge lag exceeds theinnodb_max_purge_lagthreshold, a delay is imposed onINSERT,UPDATE, andDELETEoperations to allow time for purge operations to catch up. The default value is 0, which means there is no maximum purge lag and no delay.

TheInnoDBtransaction system maintains a list of transactions that have index records delete-marked byUPDATEorDELETEoperations. The length of the list is the purge lag. Prior to MySQL 8.0.14, the purge lag delay is calculated by the following formula, which results in a minimum delay of 5000 microseconds:

(purge lag/innodb_max_purge_lag - 0.5) * 10000

As of MySQL 8.0.14, the purge lag delay is calculated by the following revised formula, which reduces the minimum delay to 5 microseconds. A delay of 5 microseconds is more appropriate for modern systems.

(purge_lag/innodb_max_purge_lag - 0.9995) * 10000

The delay is calculated at the beginning of a purge batch.

A typicalinnodb_max_purge_lagsetting for a problematic workload might be 1000000 (1 million), assuming that transactions are small, only 100 bytes in size, and it is permissible to have 100MB of unpurged table rows.

The purge lag is presented as theHistory list length弗吉尼亚州lue in theTRANSACTIONSsection ofSHOW ENGINE INNODB STATUSoutput.

mysql> SHOW ENGINE INNODB STATUS; ... ------------ TRANSACTIONS ------------ Trx id counter 0 290328385 Purge done for trx's n:o < 0 290315608 undo n:o < 0 17 History list length 20

TheHistory list lengthis typically a low value, usually less than a few thousand, but a write-heavy workload or long running transactions can cause it to increase, even for transactions that are read only. The reason that a long running transaction can cause theHistory list lengthto increase is that under a consistent read transaction isolation level such asREPEATABLE READ, a transaction must return the same result as when the read view for that transaction was created. Consequently, theInnoDBmulti-version concurrency control (MVCC) system must keep a copy of the data in the undo log until all transactions that depend on that data have completed. The following are examples of long running transactions that could cause theHistory list lengthto increase:

To prevent excessive delays in extreme situations where the purge lag becomes huge, you can limit the delay by setting theinnodb_max_purge_lag_delay弗吉尼亚州riable. Theinnodb_max_purge_lag_delay弗吉尼亚州riable specifies the maximum delay in microseconds for the delay imposed when theinnodb_max_purge_lagthreshold is exceeded. The specifiedinnodb_max_purge_lag_delay弗吉尼亚州lue is an upper limit on the delay period calculated by theinnodb_max_purge_lagformula.

Purge and Undo Tablespace Truncation

als净化系统o responsible for truncating undo tablespaces. You can configure theinnodb_purge_rseg_truncate_frequency弗吉尼亚州riable to control the frequency with which the purge system looks for undo tablespaces to truncate. For more information, seeTruncating Undo Tablespaces.