Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.
Date: 2021-05-29 03:23:31
Message-ID: CAKU4AWroeWHn3hbN2gRjyyid+2jdfAiVS6DCMri3_LV5DDLpDA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi:

I'm always confused about the following codes.

static void
initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
{
ParallelBlockTableScanDesc bpscan = NULL;
bool allow_strat;
bool allow_sync;

/*
* Determine the number of blocks we have to scan.
*
* It is sufficient to do this once at scan start, since any tuples added
* while the scan is in progress will be invisible to my snapshot anyway.
* (That is not true when using a non-MVCC snapshot. However, we couldn't
* guarantee to return tuples added after scan start anyway, since they
* might go into pages we already scanned. To guarantee consistent
* results for a non-MVCC snapshot, the caller must hold some higher-level
* lock that ensures the interesting tuple(s) won't change.)
*/
if (scan->rs_base.rs_parallel != NULL)
{
bpscan = (ParallelBlockTableScanDesc) scan->rs_base.rs_parallel;
scan->rs_nblocks = bpscan->phs_nblocks;
}
else
scan->rs_nblocks = RelationGextNumberOfBlocks(scan->rs_base.rs_rd);

..
}

1. Why do we need scan->rs_nblocks =
RelationGextNumberOfBlocks(scan->rs_base.rs_rd) for every rescan, which
looks
mismatched with the comments along the code. and the comments looks
reasonable to me.
2. For the heap scan after an IndexScan, we don't need to know the heap
size, then why do we need to get the nblocks for bitmap heap scan? I
think the
similarity between the 2 is that both of them can get a "valid"
CTID/pages number
from index scan. To be clearer, I think for bitmap heap scan, we even
don't
need check the RelationGextNumberOfBlocks for the initscan.
3. If we need to check nblocks every time, why Parallel Scan doesn't
change it
every time?

shall we remove the RelationGextNumberOfBlocks for bitmap heap scan totally
and the rescan for normal heap scan?

--
Best Regards
Andy Fan (https://www.aliyun.com/)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Gibson (DB Administrator) 2021-05-29 04:08:28 Re: AWS forcing PG upgrade from v9.6 a disaster
Previous Message Masahiko Sawada 2021-05-29 02:56:39 Re: Skipping logical replication transactions on subscriber side