summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2023-05-11 13:21:57 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2023-05-11 13:21:57 +0300
commit279d0120f5769462c3418fb32387c3e3b7f0ce4b (patch)
tree263c7275e87a892553b66bf901b39abd90bdfcf6
parentd4dd63452935cb790bfaabfcbdb7fec80b64136a (diff)
downloadmariadb-git-279d0120f5769462c3418fb32387c3e3b7f0ce4b.tar.gz
MDEV-29967 innodb_read_ahead_threshold (linear read-ahead) does not work
buf_read_ahead_linear(): Correct some calculations that were broken in commit b1ab211dee599eabd9a5b886fafa3adea29ae041 (MDEV-15053). Thanks to Daniel Black for providing a test case and initial debugging. Tested by: Matthias Leich
-rw-r--r--storage/innobase/buf/buf0rea.cc25
1 files changed, 17 insertions, 8 deletions
diff --git a/storage/innobase/buf/buf0rea.cc b/storage/innobase/buf/buf0rea.cc
index ff163f74b08..26a84939306 100644
--- a/storage/innobase/buf/buf0rea.cc
+++ b/storage/innobase/buf/buf0rea.cc
@@ -582,7 +582,7 @@ buf_read_ahead_linear(const page_id_t page_id, ulint zip_size, bool ibuf)
/* We will check that almost all pages in the area have been accessed
in the desired order. */
- const bool descending= page_id == low;
+ const bool descending= page_id != low;
if (!descending && page_id != high_1)
/* This is not a border page of the area */
@@ -612,7 +612,7 @@ fail:
uint32_t{buf_pool.read_ahead_area});
page_id_t new_low= low, new_high_1= high_1;
unsigned prev_accessed= 0;
- for (page_id_t i= low; i != high_1; ++i)
+ for (page_id_t i= low; i <= high_1; ++i)
{
const ulint fold= i.fold();
page_hash_latch *hash_lock= buf_pool.page_hash.lock<false>(fold);
@@ -647,12 +647,21 @@ hard_fail:
if (prev == FIL_NULL || next == FIL_NULL)
goto hard_fail;
page_id_t id= page_id;
- if (descending && next - 1 == page_id.page_no())
- id.set_page_no(prev);
- else if (!descending && prev + 1 == page_id.page_no())
- id.set_page_no(next);
+ if (descending)
+ {
+ if (id == high_1)
+ ++id;
+ else if (next - 1 != page_id.page_no())
+ goto hard_fail;
+ else
+ id.set_page_no(prev);
+ }
else
- goto hard_fail; /* Successor or predecessor not in the right order */
+ {
+ if (prev + 1 != page_id.page_no())
+ goto hard_fail;
+ id.set_page_no(next);
+ }
new_low= id - (id.page_no() % buf_read_ahead_area);
new_high_1= new_low + (buf_read_ahead_area - 1);
@@ -693,7 +702,7 @@ failed:
/* If we got this far, read-ahead can be sensible: do it */
count= 0;
for (ulint ibuf_mode= ibuf ? BUF_READ_IBUF_PAGES_ONLY : BUF_READ_ANY_PAGE;
- new_low != new_high_1; ++new_low)
+ new_low <= new_high_1; ++new_low)
{
if (ibuf_bitmap_page(new_low, zip_size))
continue;