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

Поиск
Список
Период
Сортировка
От Andy Fan
Тема Re: Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.
Дата
Msg-id CAKU4AWr_AfHXtrzc8Gy9V3JD2m0SGXROMEQV=CJraRkFcZJFJg@mail.gmail.com
обсуждение исходный текст
Ответ на Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.  (Andy Fan <zhihui.fan1213@gmail.com>)
Список 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.fzh@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

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thomas Munro
Дата:
Сообщение: O_DIRECT on macOS
Следующее
От: Fabien COELHO
Дата:
Сообщение: Re: Clear empty space in a page.