1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-10 23:02:54 +03:00
Files
mariadb/mysql-test/suite/innodb/r/monitor.result
Marko Mäkelä 685d958e38 MDEV-14425 Improve the redo log for concurrency
The InnoDB redo log used to be formatted in blocks of 512 bytes.
The log blocks were encrypted and the checksum was calculated while
holding log_sys.mutex, creating a serious scalability bottleneck.

We remove the fixed-size redo log block structure altogether and
essentially turn every mini-transaction into a log block of its own.
This allows encryption and checksum calculations to be performed
on local mtr_t::m_log buffers, before acquiring log_sys.mutex.
The mutex only protects a memcpy() of the data to the shared
log_sys.buf, as well as the padding of the log, in case the
to-be-written part of the log would not end in a block boundary of
the underlying storage. For now, the "padding" consists of writing
a single NUL byte, to allow recovery and mariadb-backup to detect
the end of the circular log faster.

Like the previous implementation, we will overwrite the last log block
over and over again, until it has been completely filled. It would be
possible to write only up to the last completed block (if no more
recent write was requested), or to write dummy FILE_CHECKPOINT records
to fill the incomplete block, by invoking the currently disabled
function log_pad(). This would require adjustments to some logic around
log checkpoints, page flushing, and shutdown.

An upgrade after a crash of any previous version is not supported.
Logically empty log files from a previous version will be upgraded.

An attempt to start up InnoDB without a valid ib_logfile0 will be
refused. Previously, the redo log used to be created automatically
if it was missing. Only with with innodb_force_recovery=6, it is
possible to start InnoDB in read-only mode even if the log file
does not exist. This allows the contents of a possibly corrupted
database to be dumped.

Because a prepared backup from an earlier version of mariadb-backup
will create a 0-sized log file, we will allow an upgrade from such
log files, provided that the FIL_PAGE_FILE_FLUSH_LSN in the system
tablespace looks valid.

The 512-byte log checkpoint blocks at 0x200 and 0x600 will be replaced
with 64-byte log checkpoint blocks at 0x1000 and 0x2000.

The start of log records will move from 0x800 to 0x3000. This allows us
to use 4096-byte aligned blocks for all I/O in a future revision.

We extend the MDEV-12353 redo log record format as follows.

(1) Empty mini-transactions or extra NUL bytes will not be allowed.
(2) The end-of-minitransaction marker (a NUL byte) will be replaced
with a 1-bit sequence number, which will be toggled each time when the
circular log file wraps back to the beginning.
(3) After the sequence bit, a CRC-32C checksum of all data
(excluding the sequence bit) will written.
(4) If the log is encrypted, 8 bytes will be written before
the checksum and included in it. This is part of the
initialization vector (IV) of encrypted log data.
(5) File names, page numbers, and checkpoint information will not be
encrypted. Only the payload bytes of page-level log will be encrypted.
The tablespace ID and page number will form part of the IV.
(6) For padding, arbitrary-length FILE_CHECKPOINT records may be written,
with all-zero payload, and with the normal end marker and checksum.
The minimum size is 7 bytes, or 7+8 with innodb_encrypt_log=ON.

In mariadb-backup and in Galera snapshot transfer (SST) scripts, we will
no longer remove ib_logfile0 or create an empty ib_logfile0. Server startup
will require a valid log file. When resizing the log, we will create
a logically empty ib_logfile101 at the current LSN and use an atomic rename
to replace ib_logfile0 with it. See the test innodb.log_file_size.

Because there is no mandatory padding in the log file, we are able
to create a dummy log file as of an arbitrary log sequence number.
See the test mariabackup.huge_lsn.

The parameter innodb_log_write_ahead_size and the
INFORMATION_SCHEMA.INNODB_METRICS counter log_padded will be removed.

The minimum value of innodb_log_buffer_size will be increased to 2MiB
(because log_sys.buf will replace recv_sys.buf) and the increment
adjusted to 4096 bytes (the maximum log block size).

The following INFORMATION_SCHEMA.INNODB_METRICS counters will be removed:

os_log_fsyncs
os_log_pending_fsyncs
log_pending_log_flushes
log_pending_checkpoint_writes

The following status variables will be removed:

Innodb_os_log_fsyncs (this is included in Innodb_data_fsyncs)
Innodb_os_log_pending_fsyncs (this was limited to at most 1 by design)

log_sys.get_block_size(): Return the physical block size of the log file.
This is only implemented on Linux and Microsoft Windows for now, and for
the power-of-2 block sizes between 64 and 4096 bytes (the minimum and
maximum size of a checkpoint block). If the block size is anything else,
the traditional 512-byte size will be used via normal file system
buffering.

If the file system buffers can be bypassed, a message like the following
will be issued:

InnoDB: File system buffers for log disabled (block size=512 bytes)
InnoDB: File system buffers for log disabled (block size=4096 bytes)

This has been tested on Linux and Microsoft Windows with both sizes.

On Linux, only enable O_DIRECT on the log for innodb_flush_method=O_DSYNC.
Tests in 3 different environments where the log is stored in a device
with a physical block size of 512 bytes are yielding better throughput
without O_DIRECT. This could be due to the fact that in the event the
last log block is being overwritten (if multiple transactions would
become durable at the same time, and each of will write a small
number of bytes to the last log block), it should be faster to re-copy
data from log_sys.buf or log_sys.flush_buf to the kernel buffer,
to be finally written at fdatasync() time.

The parameter innodb_flush_method=O_DSYNC will imply O_DIRECT for
data files. This option will enable O_DIRECT on the log file on Linux.
It may be unsafe to use when the storage device does not support
FUA (Force Unit Access) mode.

When the server is compiled WITH_PMEM=ON, we will use memory-mapped
I/O for the log file if the log resides on a "mount -o dax" device.
We will identify PMEM in a start-up message:

InnoDB: log sequence number 0 (memory-mapped); transaction id 3

On Linux, we will also invoke mmap() on any ib_logfile0 that resides
in /dev/shm, effectively treating the log file as persistent memory.
This should speed up "./mtr --mem" and increase the test coverage of
PMEM on non-PMEM hardware. It also allows users to estimate how much
the performance would be improved by installing persistent memory.
On other tmpfs file systems such as /run, we will not use mmap().

mariadb-backup: Eliminated several variables. We will refer
directly to recv_sys and log_sys.

backup_wait_for_lsn(): Detect non-progress of
xtrabackup_copy_logfile(). In this new log format with
arbitrary-sized blocks, we can only detect log file overrun
indirectly, by observing that the scanned log sequence number
is not advancing.

xtrabackup_copy_logfile(): On PMEM, do not modify the sequence bit,
because we are not allowed to modify the server's log file, and our
memory mapping is read-only.

trx_flush_log_if_needed_low(): Do not use the callback on pmem.
Using neither flush_lock nor write_lock around PMEM writes seems
to yield the best performance. The pmem_persist() calls may
still be somewhat slower than the pwrite() and fdatasync() based
interface (PMEM mounted without -o dax).

recv_sys_t::buf: Remove. We will use log_sys.buf for parsing.

recv_sys_t::MTR_SIZE_MAX: Replaces RECV_SCAN_SIZE.

recv_sys_t::file_checkpoint: Renamed from mlog_checkpoint_lsn.

recv_sys_t, log_sys_t: Removed many data members.

recv_sys.lsn: Renamed from recv_sys.recovered_lsn.
recv_sys.offset: Renamed from recv_sys.recovered_offset.
log_sys.buf_size: Replaces srv_log_buffer_size.

recv_buf: A smart pointer that wraps log_sys.buf[recv_sys.offset]
when the buffer is being allocated from the memory heap.

recv_ring: A smart pointer that wraps a circular log_sys.buf[] that is
backed by ib_logfile0. The pointer will wrap from recv_sys.len
(log_sys.file_size) to log_sys.START_OFFSET. For the record that
wraps around, we may copy file name or record payload data to
the auxiliary buffer decrypt_buf in order to have a contiguous
block of memory. The maximum size of a record is less than
innodb_page_size bytes.

recv_sys_t::parse(): Take the smart pointer as a template parameter.
Do not temporarily add a trailing NUL byte to FILE_ records, because
we are not supposed to modify the memory-mapped log file. (It is
attached in read-write mode already during recovery.)

recv_sys_t::parse_mtr(): Wrapper for recv_sys_t::parse().

recv_sys_t::parse_pmem(): Like parse_mtr(), but if PREMATURE_EOF would be
returned on PMEM, use recv_ring to wrap around the buffer to the start.

mtr_t::finish_write(), log_close(): Do not enforce log_sys.max_buf_free
on PMEM, because it has no meaning on the mmap-based log.

log_sys.write_to_buf: Count writes to log_sys.buf. Replaces
srv_stats.log_write_requests and export_vars.innodb_log_write_requests.
Protected by log_sys.mutex. Updated consistently in log_close().
Previously, mtr_t::commit() conditionally updated the count,
which was inconsistent.

log_sys.write_to_log: Count swaps of log_sys.buf and log_sys.flush_buf,
for writing to log_sys.log (the ib_logfile0). Replaces
srv_stats.log_writes and export_vars.innodb_log_writes.
Protected by log_sys.mutex.

log_sys.waits: Count waits in append_prepare(). Replaces
srv_stats.log_waits and export_vars.innodb_log_waits.

recv_recover_page(): Do not unnecessarily acquire
log_sys.flush_order_mutex. We are inserting the blocks in arbitary
order anyway, to be adjusted in recv_sys.apply(true).

We will change the definition of flush_lock and write_lock to
avoid potential false sharing. Depending on sizeof(log_sys) and
CPU_LEVEL1_DCACHE_LINESIZE, the flush_lock and write_lock could
share a cache line with each other or with the last data members
of log_sys.

Thanks to Matthias Leich for providing https://rr-project.org traces
for various failures during the development, and to
Thirunarayanan Balathandayuthapani for his help in debugging
some of the recovery code. And thanks to the developers of the
rr debugger for a tool without which extensive changes to InnoDB
would be very challenging to get right.

Thanks to Vladislav Vaintroub for useful feedback and
to him, Axel Schwenke and Krunal Bauskar for testing the performance.
2022-01-21 16:03:47 +02:00

742 lines
26 KiB
Plaintext

set global innodb_monitor_disable = All;
select name, if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics;
name status
metadata_table_handles_opened disabled
lock_deadlocks disabled
lock_timeouts disabled
lock_rec_lock_waits disabled
lock_table_lock_waits disabled
lock_rec_lock_requests disabled
lock_rec_lock_created disabled
lock_rec_lock_removed disabled
lock_rec_locks disabled
lock_table_lock_created disabled
lock_table_lock_removed disabled
lock_table_locks disabled
lock_row_lock_current_waits disabled
lock_row_lock_time disabled
lock_row_lock_time_max disabled
lock_row_lock_waits disabled
lock_row_lock_time_avg disabled
buffer_pool_size disabled
buffer_pool_reads disabled
buffer_pool_read_requests disabled
buffer_pool_write_requests disabled
buffer_pool_wait_free disabled
buffer_pool_read_ahead disabled
buffer_pool_read_ahead_evicted disabled
buffer_pool_pages_total disabled
buffer_pool_pages_misc disabled
buffer_pool_pages_data disabled
buffer_pool_bytes_data disabled
buffer_pool_pages_dirty disabled
buffer_pool_bytes_dirty disabled
buffer_pool_pages_free disabled
buffer_pages_created disabled
buffer_pages_written disabled
buffer_index_pages_written disabled
buffer_non_index_pages_written disabled
buffer_pages_read disabled
buffer_index_sec_rec_cluster_reads disabled
buffer_index_sec_rec_cluster_reads_avoided disabled
buffer_data_reads disabled
buffer_data_written disabled
buffer_flush_batch_scanned disabled
buffer_flush_batch_num_scan disabled
buffer_flush_batch_scanned_per_call disabled
buffer_flush_batch_total_pages disabled
buffer_flush_batches disabled
buffer_flush_batch_pages disabled
buffer_flush_neighbor_total_pages disabled
buffer_flush_neighbor disabled
buffer_flush_neighbor_pages disabled
buffer_flush_n_to_flush_requested disabled
buffer_flush_n_to_flush_by_age disabled
buffer_flush_adaptive_avg_time disabled
buffer_flush_adaptive_avg_pass disabled
buffer_LRU_get_free_loops disabled
buffer_LRU_get_free_waits disabled
buffer_flush_avg_page_rate disabled
buffer_flush_lsn_avg_rate disabled
buffer_flush_pct_for_dirty disabled
buffer_flush_pct_for_lsn disabled
buffer_flush_sync_waits disabled
buffer_flush_adaptive_total_pages disabled
buffer_flush_adaptive disabled
buffer_flush_adaptive_pages disabled
buffer_flush_sync_total_pages disabled
buffer_flush_sync disabled
buffer_flush_sync_pages disabled
buffer_flush_background_total_pages disabled
buffer_flush_background disabled
buffer_flush_background_pages disabled
buffer_LRU_batch_scanned disabled
buffer_LRU_batch_num_scan disabled
buffer_LRU_batch_scanned_per_call disabled
buffer_LRU_batch_flush_total_pages disabled
buffer_LRU_batch_evict_total_pages disabled
buffer_LRU_single_flush_failure_count disabled
buffer_LRU_get_free_search disabled
buffer_LRU_search_scanned disabled
buffer_LRU_search_num_scan disabled
buffer_LRU_search_scanned_per_call disabled
buffer_LRU_unzip_search_scanned disabled
buffer_LRU_unzip_search_num_scan disabled
buffer_LRU_unzip_search_scanned_per_call disabled
buffer_page_read_index_leaf disabled
buffer_page_read_index_non_leaf disabled
buffer_page_read_index_ibuf_leaf disabled
buffer_page_read_index_ibuf_non_leaf disabled
buffer_page_read_undo_log disabled
buffer_page_read_index_inode disabled
buffer_page_read_ibuf_free_list disabled
buffer_page_read_ibuf_bitmap disabled
buffer_page_read_system_page disabled
buffer_page_read_trx_system disabled
buffer_page_read_fsp_hdr disabled
buffer_page_read_xdes disabled
buffer_page_read_blob disabled
buffer_page_read_zblob disabled
buffer_page_read_zblob2 disabled
buffer_page_read_other disabled
buffer_page_written_index_leaf disabled
buffer_page_written_index_non_leaf disabled
buffer_page_written_index_ibuf_leaf disabled
buffer_page_written_index_ibuf_non_leaf disabled
buffer_page_written_undo_log disabled
buffer_page_written_index_inode disabled
buffer_page_written_ibuf_free_list disabled
buffer_page_written_ibuf_bitmap disabled
buffer_page_written_system_page disabled
buffer_page_written_trx_system disabled
buffer_page_written_fsp_hdr disabled
buffer_page_written_xdes disabled
buffer_page_written_blob disabled
buffer_page_written_zblob disabled
buffer_page_written_zblob2 disabled
buffer_page_written_other disabled
os_data_reads disabled
os_data_writes disabled
os_data_fsyncs disabled
os_pending_reads disabled
os_pending_writes disabled
os_log_bytes_written disabled
trx_rw_commits disabled
trx_ro_commits disabled
trx_nl_ro_commits disabled
trx_commits_insert_update disabled
trx_rollbacks disabled
trx_rollbacks_savepoint disabled
trx_rseg_history_len disabled
trx_undo_slots_used disabled
trx_undo_slots_cached disabled
trx_rseg_current_size disabled
purge_del_mark_records disabled
purge_upd_exist_or_extern_records disabled
purge_invoked disabled
purge_undo_log_pages disabled
purge_dml_delay_usec disabled
purge_stop_count disabled
purge_resume_count disabled
log_checkpoints disabled
log_lsn_last_flush disabled
log_lsn_last_checkpoint disabled
log_lsn_current disabled
log_lsn_checkpoint_age disabled
log_lsn_buf_pool_oldest disabled
log_max_modified_age_async disabled
log_num_log_io disabled
log_waits disabled
log_write_requests disabled
log_writes disabled
compress_pages_compressed disabled
compress_pages_decompressed disabled
compression_pad_increments disabled
compression_pad_decrements disabled
compress_saved disabled
compress_pages_page_compressed disabled
compress_page_compressed_trim_op disabled
compress_pages_page_decompressed disabled
compress_pages_page_compression_error disabled
compress_pages_encrypted disabled
compress_pages_decrypted disabled
index_page_splits disabled
index_page_merge_attempts disabled
index_page_merge_successful disabled
index_page_reorg_attempts disabled
index_page_reorg_successful disabled
index_page_discards disabled
adaptive_hash_searches disabled
adaptive_hash_searches_btree disabled
adaptive_hash_pages_added disabled
adaptive_hash_pages_removed disabled
adaptive_hash_rows_added disabled
adaptive_hash_rows_removed disabled
adaptive_hash_rows_deleted_no_hash_entry disabled
adaptive_hash_rows_updated disabled
file_num_open_files disabled
ibuf_merges_insert disabled
ibuf_merges_delete_mark disabled
ibuf_merges_delete disabled
ibuf_merges_discard_insert disabled
ibuf_merges_discard_delete_mark disabled
ibuf_merges_discard_delete disabled
ibuf_merges disabled
ibuf_size disabled
innodb_master_thread_sleeps disabled
innodb_activity_count disabled
innodb_master_active_loops disabled
innodb_master_idle_loops disabled
innodb_log_flush_usec disabled
innodb_dict_lru_usec disabled
innodb_dict_lru_count_active disabled
innodb_dict_lru_count_idle disabled
innodb_dblwr_writes disabled
innodb_dblwr_pages_written disabled
innodb_page_size disabled
dml_reads disabled
dml_inserts disabled
dml_deletes disabled
dml_updates disabled
dml_system_reads disabled
dml_system_inserts disabled
dml_system_deletes disabled
dml_system_updates disabled
ddl_background_drop_indexes disabled
ddl_online_create_index disabled
ddl_pending_alter_table disabled
ddl_sort_file_alter_table disabled
ddl_log_file_alter_table disabled
icp_attempts disabled
icp_no_match disabled
icp_out_of_range disabled
icp_match disabled
set global innodb_monitor_enable = all;
select name from information_schema.innodb_metrics where not enabled;
name
set global innodb_monitor_enable = aaa;
ERROR 42000: Variable 'innodb_monitor_enable' can't be set to the value of 'aaa'
set global innodb_monitor_disable = All;
select name from information_schema.innodb_metrics where enabled;
name
set global innodb_monitor_reset_all = all;
select name from information_schema.innodb_metrics where count!=0;
name
set global innodb_monitor_enable = "%lock%";
select name from information_schema.innodb_metrics
where enabled != (name like "%lock%");
name
set global innodb_monitor_disable = "%lock%";
select name, if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "%lock%";
name status
lock_deadlocks disabled
lock_timeouts disabled
lock_rec_lock_waits disabled
lock_table_lock_waits disabled
lock_rec_lock_requests disabled
lock_rec_lock_created disabled
lock_rec_lock_removed disabled
lock_rec_locks disabled
lock_table_lock_created disabled
lock_table_lock_removed disabled
lock_table_locks disabled
lock_row_lock_current_waits disabled
lock_row_lock_time disabled
lock_row_lock_time_max disabled
lock_row_lock_waits disabled
lock_row_lock_time_avg disabled
set global innodb_monitor_enable = "%lock*";
ERROR 42000: Variable 'innodb_monitor_enable' can't be set to the value of '%lock*'
set global innodb_monitor_enable="%%%%%%%%%%%%%%%%%%%%%%%%%%%";
select name from information_schema.innodb_metrics where not enabled;
name
set global innodb_monitor_disable="%%%%%";
select name from information_schema.innodb_metrics where enabled;
name
set global innodb_monitor_enable="%";
select name from information_schema.innodb_metrics where not enabled;
name
set global innodb_monitor_disable="%_%";
select name from information_schema.innodb_metrics where enabled;
name
set global innodb_monitor_enable="log%%%%";
select name from information_schema.innodb_metrics
where enabled != (name like "log%");
name
set global innodb_monitor_enable="os_%a_fs_ncs";
set global innodb_monitor_enable="os%pending%";
select name, if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "os%";
name status
os_data_reads disabled
os_data_writes disabled
os_data_fsyncs enabled
os_pending_reads enabled
os_pending_writes enabled
os_log_bytes_written disabled
set global innodb_monitor_enable="";
ERROR 42000: Variable 'innodb_monitor_enable' can't be set to the value of ''
set global innodb_monitor_enable="_";
ERROR 42000: Variable 'innodb_monitor_enable' can't be set to the value of '_'
SET global innodb_monitor_disable = module_metadata;
SET global innodb_monitor_reset_all = module_metadata;
set global innodb_monitor_enable = metadata_table_handles_opened;
create table monitor_test(col int) engine = innodb;
select * from monitor_test;
col
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 1 NULL 1 1 NULL 1 enabled
set global innodb_monitor_reset = metadata_table_handles_opened;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 1 NULL 1 NULL NULL 0 enabled
drop table monitor_test;
create table monitor_test(col int) engine = innodb;
select * from monitor_test;
col
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 2 NULL 2 1 NULL 1 enabled
set global innodb_monitor_reset_all = metadata_table_handles_opened;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 2 NULL 2 1 NULL 1 enabled
set global innodb_monitor_disable = metadata_table_handles_opened;
set global innodb_monitor_reset = metadata_table_handles_opened;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 2 NULL 2 NULL NULL 0 disabled
drop table monitor_test;
create table monitor_test(col int) engine = innodb;
select * from monitor_test;
col
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 2 NULL 2 NULL NULL 0 disabled
set global innodb_monitor_reset_all = metadata_table_handles_opened;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name = "metadata_table_handles_opened";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened NULL NULL 0 NULL NULL 0 disabled
set global innodb_monitor_enable = metadata_table_handles_opened;
drop table monitor_test;
create table monitor_test(col int) engine = innodb stats_persistent=0;
select * from monitor_test;
col
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "metadata%";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 1 NULL 1 1 NULL 1 enabled
set global innodb_monitor_disable = module_metadata;
set global innodb_monitor_reset = module_metadata;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "metadata%";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened 1 NULL 1 NULL NULL 0 disabled
set global innodb_monitor_reset_all = module_metadata;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "metadata%";
name max_count min_count count max_count_reset min_count_reset count_reset status
metadata_table_handles_opened NULL NULL 0 NULL NULL 0 disabled
set global innodb_monitor_enable = module_trx;
begin;
insert into monitor_test values(9);
commit;
begin;
insert into monitor_test values(9);
rollback;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name='trx_rollbacks';
name max_count min_count count max_count_reset min_count_reset count_reset status
trx_rollbacks 1 NULL 1 1 NULL 1 enabled
set global innodb_monitor_disable = module_trx;
set global innodb_monitor_enable = module_dml;
insert into monitor_test values(9);
update monitor_test set col = 10 where col = 9;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads 2 NULL 2 2 NULL 2 enabled
dml_inserts 1 NULL 1 1 NULL 1 enabled
dml_deletes 0 NULL 0 0 NULL 0 enabled
dml_updates 2 NULL 2 2 NULL 2 enabled
dml_system_reads 0 NULL 0 0 NULL 0 enabled
dml_system_inserts 0 NULL 0 0 NULL 0 enabled
dml_system_deletes 0 NULL 0 0 NULL 0 enabled
dml_system_updates 0 NULL 0 0 NULL 0 enabled
delete from monitor_test;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads 4 NULL 4 4 NULL 4 enabled
dml_inserts 1 NULL 1 1 NULL 1 enabled
dml_deletes 2 NULL 2 2 NULL 2 enabled
dml_updates 2 NULL 2 2 NULL 2 enabled
dml_system_reads 0 NULL 0 0 NULL 0 enabled
dml_system_inserts 0 NULL 0 0 NULL 0 enabled
dml_system_deletes 0 NULL 0 0 NULL 0 enabled
dml_system_updates 0 NULL 0 0 NULL 0 enabled
set global innodb_monitor_reset = module_dml;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads 4 NULL 4 0 NULL 0 enabled
dml_inserts 1 NULL 1 0 NULL 0 enabled
dml_deletes 2 NULL 2 0 NULL 0 enabled
dml_updates 2 NULL 2 0 NULL 0 enabled
dml_system_reads 0 NULL 0 0 NULL 0 enabled
dml_system_inserts 0 NULL 0 0 NULL 0 enabled
dml_system_deletes 0 NULL 0 0 NULL 0 enabled
dml_system_updates 0 NULL 0 0 NULL 0 enabled
insert into monitor_test values(9);
insert into monitor_test values(1);
delete from monitor_test;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads 6 NULL 6 2 NULL 2 enabled
dml_inserts 3 NULL 3 2 NULL 2 enabled
dml_deletes 4 NULL 4 2 NULL 2 enabled
dml_updates 2 NULL 2 0 NULL 0 enabled
dml_system_reads 0 NULL 0 0 NULL 0 enabled
dml_system_inserts 0 NULL 0 0 NULL 0 enabled
dml_system_deletes 0 NULL 0 0 NULL 0 enabled
dml_system_updates 0 NULL 0 0 NULL 0 enabled
set global innodb_monitor_reset_all = module_dml;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads 6 NULL 6 2 NULL 2 enabled
dml_inserts 3 NULL 3 2 NULL 2 enabled
dml_deletes 4 NULL 4 2 NULL 2 enabled
dml_updates 2 NULL 2 0 NULL 0 enabled
dml_system_reads 0 NULL 0 0 NULL 0 enabled
dml_system_inserts 0 NULL 0 0 NULL 0 enabled
dml_system_deletes 0 NULL 0 0 NULL 0 enabled
dml_system_updates 0 NULL 0 0 NULL 0 enabled
set global innodb_monitor_disable = module_dml;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads 6 NULL 6 2 NULL 2 disabled
dml_inserts 3 NULL 3 2 NULL 2 disabled
dml_deletes 4 NULL 4 2 NULL 2 disabled
dml_updates 2 NULL 2 0 NULL 0 disabled
dml_system_reads 0 NULL 0 0 NULL 0 disabled
dml_system_inserts 0 NULL 0 0 NULL 0 disabled
dml_system_deletes 0 NULL 0 0 NULL 0 disabled
dml_system_updates 0 NULL 0 0 NULL 0 disabled
set global innodb_monitor_reset_all = module_dml;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads NULL NULL 0 NULL NULL 0 disabled
dml_inserts NULL NULL 0 NULL NULL 0 disabled
dml_deletes NULL NULL 0 NULL NULL 0 disabled
dml_updates NULL NULL 0 NULL NULL 0 disabled
dml_system_reads NULL NULL 0 NULL NULL 0 disabled
dml_system_inserts NULL NULL 0 NULL NULL 0 disabled
dml_system_deletes NULL NULL 0 NULL NULL 0 disabled
dml_system_updates NULL NULL 0 NULL NULL 0 disabled
set global innodb_monitor_enable = dml_inserts;
insert into monitor_test values(9);
insert into monitor_test values(1);
delete from monitor_test;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "dml%";
name max_count min_count count max_count_reset min_count_reset count_reset status
dml_reads NULL NULL 0 NULL NULL 0 disabled
dml_inserts 2 NULL 2 2 NULL 2 enabled
dml_deletes NULL NULL 0 NULL NULL 0 disabled
dml_updates NULL NULL 0 NULL NULL 0 disabled
dml_system_reads NULL NULL 0 NULL NULL 0 disabled
dml_system_inserts NULL NULL 0 NULL NULL 0 disabled
dml_system_deletes NULL NULL 0 NULL NULL 0 disabled
dml_system_updates NULL NULL 0 NULL NULL 0 disabled
set global innodb_monitor_disable = module_dml;
drop table monitor_test;
set global innodb_monitor_enable = file_num_open_files;
select name, max_count, min_count, count,
max_count_reset, min_count_reset, count_reset,
if(enabled,'enabled','disabled') status
from information_schema.innodb_metrics
where name like "file_num_open_files";
name max_count min_count count max_count_reset min_count_reset count_reset status
file_num_open_files # # # # # # enabled
set global innodb_monitor_disable = file_num_open_files;
set global innodb_monitor_enable = "icp%";
create table monitor_test(a char(3), b int, c char(2),
primary key (a(1), c(1)), key(b)) engine = innodb;
insert into monitor_test values("13", 2, "aa");
select a from monitor_test where b < 1 for update;
a
select name, count from information_schema.innodb_metrics
where name like "icp%";
name count
icp_attempts 1
icp_no_match 0
icp_out_of_range 1
icp_match 0
select a from monitor_test where b < 3 for update;
a
13
select name, count from information_schema.innodb_metrics
where name like "icp%";
name count
icp_attempts 2
icp_no_match 0
icp_out_of_range 1
icp_match 1
drop table monitor_test;
set global innodb_monitor_disable = All;
set global innodb_monitor_reset_all = all;
select 1 from `information_schema`.`INNODB_METRICS`
where case (1) when (1) then (AVG_COUNT_RESET) else (1) end;
1
set global innodb_monitor_enable = default;
set global innodb_monitor_disable = default;
set global innodb_monitor_reset = default;
set global innodb_monitor_reset_all = default;
#
# Bug#22576241 SETTING INNODB_MONITOR_ENABLE TO ALL DOES NOT ENABLE ALL
# MONITORS
#
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=0;
SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
LIKE 'buffer_page_written_index_leaf';
NAME COUNT > 0
buffer_page_written_index_leaf 0
SET GLOBAL innodb_monitor_enable='module_buffer_page';
INSERT INTO t1 VALUES (1), (2), (3), (4);
FLUSH TABLES t1 FOR EXPORT;
UNLOCK TABLES;
SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
LIKE 'buffer_page_written_index_leaf';
NAME COUNT > 0
buffer_page_written_index_leaf 1
SET GLOBAL innodb_monitor_disable='module_buffer_page';
SET GLOBAL innodb_monitor_reset_all='module_buffer_page';
SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
LIKE 'buffer_page_written_index_leaf';
NAME COUNT > 0
buffer_page_written_index_leaf 0
SET GLOBAL innodb_monitor_enable='%';
INSERT INTO t1 VALUES (5), (6), (7), (8);
FLUSH TABLES t1 FOR EXPORT;
UNLOCK TABLES;
SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
LIKE 'buffer_page_written_index_leaf';
NAME COUNT > 0
buffer_page_written_index_leaf 1
SET GLOBAL innodb_monitor_disable='%';
SET GLOBAL innodb_monitor_reset_all='%';
SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
LIKE 'buffer_page_written_index_leaf';
NAME COUNT > 0
buffer_page_written_index_leaf 0
SET GLOBAL innodb_monitor_enable='ALL';
INSERT INTO t1 VALUES (9), (10), (11), (12);
FLUSH TABLES t1 FOR EXPORT;
UNLOCK TABLES;
SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
LIKE 'buffer_page_written_index_leaf';
NAME COUNT > 0
buffer_page_written_index_leaf 1
DROP TABLE t1;
CREATE TABLE fl0 (
id INT NOT NULL PRIMARY KEY
) ENGINE = InnoDB;
CREATE TABLE fl1 (
id INT NOT NULL PRIMARY KEY,
fl0_id INT,
CONSTRAINT `fkl0`
FOREIGN KEY (fl0_id) REFERENCES fl0 (id)
ON DELETE CASCADE
ON UPDATE RESTRICT
) ENGINE = InnoDB;
CREATE TABLE fl2 (
id INT NOT NULL PRIMARY KEY,
fl1_id INT,
CONSTRAINT `fkl1`
FOREIGN KEY (fl1_id) REFERENCES fl1 (id)
ON DELETE CASCADE
ON UPDATE SET NULL
) ENGINE = InnoDB;
INSERT INTO fl0 VALUES (1000);
INSERT INTO fl1 VALUES (500, 1000), (1500, 1000);
INSERT INTO fl2 VALUES (200, 500), (800, 500), (1200, 1500), (1800, 1500);
CREATE TABLE t1(id INT PRIMARY KEY, a INT, b CHAR(1), UNIQUE KEY u(a,b))
ENGINE=InnoDB;
SET @start = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
= 'lock_rec_lock_created');
BEGIN;
INSERT INTO t1 VALUES(1,1,'a'),(2,9999,'b'),(3,10000,'c'),(4,4,'d');
DELETE FROM t1 WHERE a = 9999 AND b='b';
COMMIT;
SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
= 'lock_rec_lock_created');
SELECT @end - @start;
@end - @start
0
# Records must not be S/X-locked if a table is X-locked.
SET @start = @end;
SET autocommit = 0;
BEGIN;
LOCK TABLE t1 WRITE;
SELECT * FROM t1;
id a b
1 1 a
4 4 d
3 10000 c
SELECT * FROM t1 WHERE a>=10000;
id a b
3 10000 c
SELECT * FROM t1 FOR UPDATE;
id a b
1 1 a
4 4 d
3 10000 c
SELECT * FROM t1 WHERE a>=10000 FOR UPDATE;
id a b
3 10000 c
UPDATE t1 SET b = 'b' WHERE id = 4;
UPDATE t1 SET b = 'b' WHERE a = 10000;
REPLACE INTO t1 VALUES (4,3,'a');
INSERT INTO t1 VALUES (3,1,'e') ON DUPLICATE KEY UPDATE b = 'b';
INSERT INTO t1 VALUES (5,5,'e');
DELETE FROM t1 WHERE a = 1 AND b='a';
DELETE FROM t1;
COMMIT;
UNLOCK TABLES;
SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
SELECT @end - @start;
@end - @start
0
# Records must not be S-locked if a table is S-locked.
SET @start = @end;
BEGIN;
LOCK TABLE t1 WRITE;
INSERT INTO t1 VALUES(1,1,'a'),(2,9999,'b'),(3,10000,'c'),(4,4,'d');
DELETE FROM t1 WHERE a = 9999 AND b='b';
COMMIT;
UNLOCK TABLES;
BEGIN;
LOCK TABLE t1 READ;
SELECT * FROM t1 LOCK IN SHARE MODE;
id a b
1 1 a
4 4 d
3 10000 c
SELECT * FROM t1 WHERE a>=10000 LOCK IN SHARE MODE;
id a b
3 10000 c
COMMIT;
UNLOCK TABLES;
SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
SELECT @end - @start;
@end - @start
0
# Records must not be S-locked for foreign keys enforcement
SET @start = @end;
BEGIN;
LOCK TABLE fl0 READ, fl1 READ, fl2 WRITE;
INSERT INTO fl2 VALUES (300, 500), (700, 500), (1300, 1500), (1700, 1500);
SELECT * FROM fl1 LOCK IN SHARE MODE;
id fl0_id
500 1000
1500 1000
COMMIT;
UNLOCK TABLES;
SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
SELECT @end - @start;
@end - @start
0
# Records must not be X-locked for foreign keys cascade
SET @start = @end;
BEGIN;
LOCK TABLE fl0 READ, fl1 WRITE, fl2 WRITE;
DELETE FROM fl1 WHERE id = 1500;
UPDATE fl1 SET id = 2500 WHERE id = 500;
COMMIT;
UNLOCK TABLES;
SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
SELECT @end - @start;
@end - @start
0
SET autocommit = default;
DROP TABLE t1;
DROP TABLE fl2;
DROP TABLE fl1;
DROP TABLE fl0;
SET GLOBAL innodb_monitor_enable=default;
SET GLOBAL innodb_monitor_disable=default;
SET GLOBAL innodb_monitor_reset_all=default;