Why does BitmapPrefetch() skip fetch based on current block recheck flag

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Why does BitmapPrefetch() skip fetch based on current block recheck flag
Date: 2024-02-12 20:17:32
Message-ID: CAAKRu_bxrXeZ2rCnY8LyeC2Ls88KpjWrQ+opUrXDRXdcfwFZGA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I noticed that in the following code in BitmapPrefetch(), we use the
current block's TBMIterateResult->recheck when deciding whether or not
to prefetch the block returned by tbm_iterate() (which is very likely
a different block). Why not use TBMIterateResult->recheck for the
block we are considering prefetching?

I see a note that the skip fetch logic here depends on the assumption
that the index AM will report the same recheck flag for this future
heap page as it did for the current heap page. But why would we depend
on that assumption instead of just using the TBMIterateResult just
populated by tbm_iterate() for the block we are about to prefetch?
That is the block we pass to PrefetchBuffer() afterward.

/*
* If we expect not to have to actually read this heap page,
* skip this prefetch call, but continue to run the prefetch
* logic normally. (Would it be better not to increment
* prefetch_pages?)
*
* This depends on the assumption that the index AM will
* report the same recheck flag for this future heap page as
* it did for the current heap page; which is not a certainty
* but is true in many cases.
*/
skip_fetch = (node->can_skip_fetch &&
(node->tbmres ? !node->tbmres->recheck : false) &&
VM_ALL_VISIBLE(node->ss.ss_currentRelation,
tbmpre->blockno,
&node->pvmbuffer));

if (!skip_fetch)
PrefetchBuffer(scan->rs_rd, MAIN_FORKNUM, tbmpre->blockno);

- Melanie

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-02-12 20:18:53 Re: Improve WALRead() to suck data directly from WAL buffers when possible
Previous Message Amonson, Paul D 2024-02-12 20:14:06 RE: Popcount optimization using AVX512