This topic describes the logical prefetch feature of RDS for MySQL.
- MySQL 5.7 version, and the kernel minor version is MySQL 5.7.44_20260215 and above.
- MySQL 8.0 with a kernel version of MySQL 8.0.43_20251215 or later.
- MySQL 8.4 version, and the kernel minor version is MySQL 8.4.7_20260415 and above.
MySQL natively supports linear prefetching. It predicts the pages that need to be read based on their physical location and asynchronously loads them into the buffer pool. This allows subsequent read requests from user threads to directly hit the buffer pool, reducing the I/O latency of user SQL queries. However, for instances that use volumes, adjacent data pages may not be contiguous in the actual storage. As a result, the native linear prefetching mechanism of MySQL provides suboptimal optimization.
RDS for MySQL introduces a logical prefetching feature. This feature accurately predicts the pages that need to be read based on user SQL queries to reduce the I/O latency of SQL queries for instances that use volumes.
The logical pre-read capability scans indexes through a background thread, accurately predicts the pages that user threads need to read based on the index, and asynchronously loads them into the buffer pool.
Logical pre-read supports the following scenarios:
- Primary key range scan (Suitable for scenarios with a high volume of primary key index scans)
- Secondary index range scan (Suitable for scenarios with a high volume of secondary covering index scans)
- Covering index scan (Suitable for scenarios with a high volume of secondary covering index scans)
- Secondary index range scan with primary key lookup (Suitable for scenarios with a poor secondary index filtering rate)
To optimize the read performance of BLOB data, this iteration of MySQL 8.0 also implements the prefetching capability for BLOB objects.
RDS for MySQL provides the following modifiable parameters to configure the logical prefetch feature.
Before application, you can use Database Workshop to manually connect to the secondary instance and execute prefetch SQL to test the optimization effect. This avoids putting heavy pressure on the primary instance from large-scale scans.
After enabling IO metric observation by running SET SESSION loose_enable_track_index_io=ON, you can execute SELECT * FROM information_schema.rds_io_trace_stats WHERE thread_id = connection_Id() to check whether the current thread performed a logical prefetch, the details of the logical prefetch, and the possible reason for not supporting it:
- Enabling the logical prefetch feature increases IO/CPU resource consumption due to prefetch threads, which might impact other concurrent SQL operations. Therefore, enable this feature selectively only for the required SQL statements.
- Logical prefetch is not currently supported for compressed tables, partitioned tables, or non-InnoDB tables.
- Logical prefetch is not currently supported for multi-valued indexes, virtual generated column indexes, spatial indexes, full-text indexes, or vector indexes.
- In MySQL 5.7, BLOB data can only be read sequentially, so prefetching for BLOB objects is not currently supported.
An RDS for MySQL 8.0 instance with a 2C4G node specification and a 10 TB cloud disk.
Use `sysbench prepare` to insert data that is five times the number of rows in the test range.
Restart the MySQL process before each test to ensure that the memory `buffer_pool` contains no cached data, which allows for testing the actual improvement in execution efficiency.