Why does BitmapPrefetch() skip fetch based on current block recheck flag - Mailing list pgsql-hackers

From Melanie Plageman
Subject Why does BitmapPrefetch() skip fetch based on current block recheck flag
Date
Msg-id CAAKRu_bxrXeZ2rCnY8LyeC2Ls88KpjWrQ+opUrXDRXdcfwFZGA@mail.gmail.com
Whole thread Raw
List 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



pgsql-hackers by date:

Previous
From: "Amonson, Paul D"
Date:
Subject: RE: Popcount optimization using AVX512
Next
From: Andres Freund
Date:
Subject: Re: Improve WALRead() to suck data directly from WAL buffers when possible