Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan. - Mailing list pgsql-hackers

From Andy Fan
Subject Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.
Date
Msg-id CAKU4AWroeWHn3hbN2gRjyyid+2jdfAiVS6DCMri3_LV5DDLpDA@mail.gmail.com
Whole thread Raw
Responses Re: Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.
Re: Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.
List 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

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Skipping logical replication transactions on subscriber side
Next
From: Amit Kapila
Date:
Subject: Re: Parallel Inserts in CREATE TABLE AS