1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00
Files
Thirunarayanan Balathandayuthapani 1bb1738271 MDEV-32067 InnoDB linear read-ahead had better be logical
The traditional linear read-ahead, enabled by
innodb_read_ahead_threshold, only helps when consecutively
accessed pages have adjacent page numbers.

That is rarely true for B-tree leaf pages: after splits,
merges and page reuse, the logical order of leaves has
nothing to do with their physical page numbers. So for a
scan of scattered leaves the old read-ahead either did nothing
or read the wrong pages.

This replaces linear read-ahead of index pages with a logical
read-ahead that prefetches the actual leaf pages a scan is
going to visit, discovered from the B-tree during traversal.
After this change, the exact nonzero value of
innodb_read_ahead_threshold matters only for the read-ahead of undo
log pages.

buf_read_ahead_undo(): Renamed from buf_read_ahead_linear(). Now
invoked only for undo log pages, whose page numbers are
sequential. It is no longer called on BLOB pages or index pages.

buf_read_ahead_one(): Read ahead a single leaf page.

buf_read_ahead_pages(): Read ahead a set of known B-tree leaf pages.
Stops at the first page that is already resident or fails.

buf_read_ahead_random(): Split into a decision part(which extent
to read) and action part (issue the reads)

The pending read throttle now compares the
os_aio_pending_reads_approx() with buf_pool.curr_size() instead of
current pool bytes, which had made the throttle a no-op.

buf_read_ahead_pages() releases the tablespace reference
on a failed/corrupted page.

btr_ra_latch: A caller-owned buffer of leaf page numbers, which also
records the level-1 page and the child page number of the last node
pointer collected, so read-ahead can be resumed later.

btr_ra_collect(): Scan the node pointers of PAGE_LEVEL=1 page from
the given record in scan order, appending child page numbers

btr_cur_t::search_leaf(), btr_cur_t::open_leaf(): At PAGE_LEVEL=1,
after the descent has located the child to follow, harvest leaf page
numbers starting at that child in the scan direction. These are
exactly the leaves the cursor will visit, so prefetch is precise
regardless of physical page numbers.

btr_ra_resume_rec(): Locate the record from which read-ahead should
resume, by re-finding the last harvested child by value. It walks only
genuine records, so a concurrent page reorganization cannot cause
an invalid read

btr_pcur_move_to_next_page(): Prefetch the sibling after the
one being entered, with buf_read_ahead_one().

btr_pcur_move_backward_from_page(): Add a no-wait fast path that
latches the previous page if it is resident
(validating it against the current page), and prefetch
the one before it.

btr_copy_blob_prefix(): Simplified; no longer relies on
FIL_PAGE_PREV/NEXT, which are not initialized on BLOB pages.

records_in_range() reports the first and last leaf page of a
range, and the optimizer forwards that extent to the engine through
handler::advise_page_range().

multi_range_read_info_const() takes a page_range parameter;
the default MRR implementation aggregates the
per-range extents, and opt_range.cc carries the result through the
chosen QUICK_RANGE_SELECT, whose reset() calls advise_page_range()
before multi_range_read_init(). The extent only sizes and bounds
read-ahead; it never gates the pages the scan actually reads.
The LIMIT is converted in multi_range_read_info_const() to a
leaf count (m_ra_limit_pages).

mrr_readahead_from_scan_range() derives the read-ahead ceiling
from the advised extent, falling back to that LIMIT-based estimate.
The ceiling is capped by init_readahead_window() at 1/256 of
the buffer pool (but at least 4 pages), because every prefetched
page occupies a buffer pool frame as soon as its read is issued.

The window ramps up: a positioning read harvests at most 4 leaves
and resets the window to 4, and readahead_refill() doubles it
toward the ceiling. Single-row probes such as index_first()
for MIN()/MAX(), and every range of a multi-range read,
therefore prefetch only a few leaves while long scans reach
full depth.

search_with_readahead(): Position the cursor while collecting the leaf
pages, then call start_readahead(). It is used by
index_read() and by the first general_fetch() only when
read-ahead is armed, so the other paths carry no read-ahead locals.

start_readahead(): For a just-positioned scan, prefetch the collected
batch and set up the rolling cursor.

readahead_refill(): As the scan advances (general_fetch()),
resume the level-1 harvest under an index S-latch, chain across
level-1 siblings, and prefetch the next batch bounded by the
advised last leaf, or to the end of the index when the extent
is unknown. The reads are issued after the latches are released.

Read-ahead is started from index_read() (range and full index scans),
rnd_init()/general_fetch() (full table scans), and, at one-page depth,
from row_merge_read_clustered_index() (OPTIMIZE/ALTER rebuild).
general_fetch() sets active_handler_stats before issuing
read-ahead so prefetched pages are attributed to the query.

dict_stats_analyze_index_for_n_prefix(): Choose the records to dive
below first, prefetch their child pages in one batch with
buf_read_ahead_pages(), and then dive below the same records.

Undo/system tablespace shrinking holds fil_space_t::latch exclusively
(x_lock_space()), and buf_read_ahead_undo() holds it shared,
via the new fil_space_t::s_lock_try() that never waits,
while it checks the size and issues the reads.
If the latch is not available, the read-ahead is skipped.

trx_undo_get_prev_rec(), trx_undo_get_prev_rec_from_prev_page():
take the trx_undo_t object instead of a long parameter list and
always latch shared.
2026-10-12 11:02:47 +05:30
..
2026-06-16 12:24:32 +02:00
2026-06-15 16:53:03 +02:00
…
2025-07-28 21:29:29 +02:00
2024-11-05 14:00:48 -08:00
2025-09-29 18:25:09 +03:00
…
2025-03-14 12:08:56 +04:00
2026-02-16 21:55:18 +01:00
2025-03-14 12:08:56 +04:00
…
2024-12-02 11:35:34 +02:00
2024-12-02 17:51:17 +02:00
2026-01-31 14:08:54 +01:00
2024-10-30 15:11:17 +01:00
…
2026-01-31 14:08:54 +01:00
2026-06-29 07:41:06 +03:00
2024-12-02 11:35:34 +02:00
2026-05-26 21:15:58 +02:00
2026-03-24 09:49:17 +02:00
2026-03-24 09:49:17 +02:00
…
…
2026-06-15 16:53:03 +02:00
2026-05-26 21:15:58 +02:00
2024-11-29 13:43:17 +02:00
…
…
2026-05-26 21:15:58 +02:00
2024-12-05 10:11:58 +01:00
2026-06-29 07:40:04 +03:00
2026-02-03 14:53:15 +01:00
2026-06-29 07:40:04 +03:00
2026-05-26 21:15:58 +02:00
2026-02-03 14:53:15 +01:00
2026-02-03 14:53:15 +01:00
2026-02-03 14:53:15 +01:00
2026-06-23 12:52:39 +02:00
2026-06-29 07:41:06 +03:00
2026-03-24 09:49:17 +02:00
2026-01-31 14:08:54 +01:00
2026-04-01 15:03:59 +03:00
2026-04-02 09:15:17 +03:00
2026-01-08 12:02:45 +01:00
2024-07-08 22:40:16 +02:00
2026-05-26 21:15:58 +02:00
2026-06-16 12:24:32 +02:00
…
2026-06-16 12:24:32 +02:00
2026-06-15 16:53:03 +02:00
2026-06-16 12:44:36 +02:00
2026-06-16 15:03:05 +02:00
2026-05-26 21:15:58 +02:00
…
2025-03-14 12:08:56 +04:00
…
2024-10-03 15:59:20 +10:00
…
2025-03-14 12:08:56 +04:00
2026-05-26 21:15:58 +02:00
2026-06-29 08:38:07 +03:00
2026-05-26 21:15:58 +02:00
2025-04-02 14:07:01 +03:00
2026-05-26 21:15:58 +02:00
2026-02-03 14:53:15 +01:00
2024-06-24 13:09:47 +03:00
2026-05-08 08:00:01 +02:00
2026-03-27 14:15:54 +01:00
2026-01-31 14:08:54 +01:00
2026-05-26 21:15:58 +02:00
2026-02-03 14:53:15 +01:00
2025-09-29 18:25:09 +03:00
2024-07-22 15:14:50 +02:00
2026-05-26 21:15:58 +02:00
2026-05-26 21:15:58 +02:00
2026-02-07 22:06:40 +01:00
2026-05-26 21:15:58 +02:00
2026-06-16 12:24:32 +02:00
2025-07-31 20:55:47 +02:00
2026-05-08 08:00:01 +02:00
2026-02-07 22:06:40 +01:00
2026-06-16 12:24:32 +02:00
2026-06-15 16:53:03 +02:00
2026-06-15 16:53:03 +02:00
2025-03-14 12:08:56 +04:00
2026-04-02 09:15:17 +03:00
2026-05-26 21:15:58 +02:00
2026-05-26 21:15:58 +02:00
2026-06-16 12:24:32 +02:00
2026-02-06 17:46:50 +01:00
2025-11-04 12:39:27 +01:00
2026-06-16 12:24:32 +02:00
2026-06-16 12:24:32 +02:00
2026-05-26 21:15:58 +02:00
2026-06-16 12:24:32 +02:00
2026-02-06 17:46:51 +01:00
2026-06-29 07:40:04 +03:00
2026-01-08 12:02:45 +01:00
2025-09-04 18:08:39 +03:00
2026-05-26 21:15:58 +02:00
2026-02-16 21:55:18 +01:00
2026-05-26 21:15:58 +02:00
2024-06-24 13:09:47 +03:00
2026-05-26 21:15:58 +02:00
2026-06-15 15:15:10 +02:00
2026-06-15 15:15:10 +02:00
2026-01-08 21:41:40 +01:00
2026-05-26 21:15:58 +02:00
2026-04-02 09:15:17 +03:00
2026-01-31 14:08:54 +01:00
2026-01-05 20:34:44 +01:00
2026-06-24 12:27:13 +02:00
2026-03-24 09:49:17 +02:00
2026-06-29 07:40:04 +03:00
2026-01-08 12:02:45 +01:00
2026-05-26 21:15:58 +02:00
2026-02-06 17:46:51 +01:00
2026-03-17 18:57:42 +01:00
2026-06-29 07:40:04 +03:00
…
2026-02-06 17:46:51 +01:00
2026-02-06 17:46:51 +01:00
2025-09-29 18:25:09 +03:00
2024-06-27 10:26:09 +03:00
2025-08-04 12:05:53 +02:00
2024-12-02 17:51:17 +02:00
2026-05-27 12:49:36 +02:00
2025-09-19 12:31:14 +03:00
2026-06-16 12:24:32 +02:00
2026-05-26 21:15:58 +02:00
2025-03-14 12:08:56 +04:00
2026-05-26 21:15:58 +02:00
2024-07-03 12:45:30 +02:00
2026-06-15 16:53:03 +02:00
2026-04-17 09:31:38 +10:00
2026-05-26 21:15:58 +02:00
2025-01-09 09:41:38 +02:00
2026-05-26 21:15:58 +02:00
2024-12-02 17:51:17 +02:00
2026-02-03 14:53:15 +01:00
2026-06-29 07:41:06 +03:00
2026-05-27 12:49:36 +02:00
2026-05-26 21:15:58 +02:00
2026-05-26 21:15:58 +02:00
2026-03-24 09:49:17 +02:00
2026-05-27 12:49:36 +02:00
2026-04-01 10:49:05 +03:00
2026-05-27 12:49:36 +02:00
2026-02-07 22:12:32 +01:00
2025-04-29 11:18:00 +10:00
2026-05-26 21:15:58 +02:00
…
2026-05-22 09:52:05 +02:00
2026-05-22 09:52:05 +02:00
2026-05-22 09:52:05 +02:00
2026-06-16 15:03:05 +02:00
2025-03-14 12:08:56 +04:00
2024-12-02 17:51:17 +02:00
2026-05-26 21:15:58 +02:00
2026-05-26 21:15:58 +02:00
2026-05-26 21:15:58 +02:00
2026-06-15 16:53:03 +02:00
2026-06-29 08:38:07 +03:00
2026-05-26 21:15:58 +02:00
2026-06-24 12:27:13 +02:00
2026-05-26 21:15:58 +02:00
2026-05-26 21:15:58 +02:00
2025-04-29 11:18:00 +10:00
2026-03-24 09:49:17 +02:00
2025-09-04 18:08:39 +03:00
2024-06-24 13:09:47 +03:00
2025-03-14 12:08:56 +04:00
2026-05-22 09:52:05 +02:00
2024-12-02 17:51:17 +02:00
2024-12-02 11:35:34 +02:00
2025-03-14 12:08:56 +04:00
2026-06-16 12:24:32 +02:00
2025-11-28 12:56:27 +02:00
2024-06-27 10:26:09 +03:00
2026-06-16 15:03:05 +02:00
2026-06-21 15:32:20 +02:00
2026-06-15 16:53:03 +02:00
2026-04-02 09:15:17 +03:00
2024-10-03 13:24:43 +03:00
2024-09-09 13:50:38 +03:00
2026-06-25 14:49:32 +02:00
2026-02-07 22:12:32 +01:00
2026-06-23 12:52:39 +02:00
2026-06-23 12:52:39 +02:00
2026-06-25 14:49:32 +02:00