From: | Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan. |
Date: | 2021-05-30 04:51:40 |
Message-ID: | CAKU4AWr_AfHXtrzc8Gy9V3JD2m0SGXROMEQV=CJraRkFcZJFJg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> 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?
>
>
yizhi(dot)fzh(at)e18c07352 /u/y/g/postgres> git diff
diff --git a/src/backend/access/heap/heapam.c
b/src/backend/access/heap/heapam.c
index 6ac07f2fda..6df096fb46 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -246,7 +246,7 @@ initscan(HeapScanDesc scan, ScanKey key, bool
keep_startblock)
bpscan = (ParallelBlockTableScanDesc)
scan->rs_base.rs_parallel;
scan->rs_nblocks = bpscan->phs_nblocks;
}
- else
+ else if (scan->rs_nblocks == -1 && !(scan->rs_base.rs_flags &
SO_TYPE_BITMAPSCAN))
scan->rs_nblocks =
RelationGetNumberOfBlocks(scan->rs_base.rs_rd);
/*
@@ -1209,6 +1209,7 @@ heap_beginscan(Relation relation, Snapshot snapshot,
scan->rs_base.rs_flags = flags;
scan->rs_base.rs_parallel = parallel_scan;
scan->rs_strategy = NULL; /* set in initscan */
+ scan->rs_nblocks = -1;
I did the above hacks, and all the existing tests passed.
>
--
Best Regards
Andy Fan (https://www.aliyun.com/)
From | Date | Subject | |
---|---|---|---|
Next Message | Fabien COELHO | 2021-05-30 05:22:28 | Re: Clear empty space in a page. |
Previous Message | Thomas Munro | 2021-05-30 04:39:48 | O_DIRECT on macOS |