Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 060f420

Browse files
Simplify vacuum VM update logging counters
We can simplify the VM counters added in dc6acfd to lazy_vacuum_heap_page() and lazy_scan_new_or_empty(). We won't invoke lazy_vacuum_heap_page() unless there are dead line pointers, so we know the page can't be all-visible. In lazy_scan_new_or_empty(), we only update the VM if the page-level hint PD_ALL_VISIBLE is clear, and the VM bit cannot be set if the page level bit is clear because a subsequent page update would fail to clear the visibility map bit. Simplify the logic for determining which log counters to increment based on this knowledge. Doing so is worthwhile because the old logic was confusing and misguided. Author: Melanie Plageman <[email protected]> Reviewed-by: Nazir Bilal Yavuz <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Discussion: https://postgr.es/m/flat/CAAKRu_a9w_n2mwY%3DG4LjfWTvRTJtjbfvnYAKi4WjO8QXHHrA0g%40mail.gmail.com
1 parent a3994ec commit 060f420

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,6 @@ lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno,
18721872
*/
18731873
if (!PageIsAllVisible(page))
18741874
{
1875-
uint8 old_vmbits;
1876-
18771875
START_CRIT_SECTION();
18781876

18791877
/* mark buffer dirty before writing a WAL record */
@@ -1893,24 +1891,16 @@ lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno,
18931891
log_newpage_buffer(buf, true);
18941892

18951893
PageSetAllVisible(page);
1896-
old_vmbits = visibilitymap_set(vacrel->rel, blkno, buf,
1897-
InvalidXLogRecPtr,
1898-
vmbuffer, InvalidTransactionId,
1899-
VISIBILITYMAP_ALL_VISIBLE |
1900-
VISIBILITYMAP_ALL_FROZEN);
1894+
visibilitymap_set(vacrel->rel, blkno, buf,
1895+
InvalidXLogRecPtr,
1896+
vmbuffer, InvalidTransactionId,
1897+
VISIBILITYMAP_ALL_VISIBLE |
1898+
VISIBILITYMAP_ALL_FROZEN);
19011899
END_CRIT_SECTION();
19021900

1903-
/*
1904-
* If the page wasn't already set all-visible and/or all-frozen in
1905-
* the VM, count it as newly set for logging.
1906-
*/
1907-
if ((old_vmbits & VISIBILITYMAP_ALL_VISIBLE) == 0)
1908-
{
1909-
vacrel->vm_new_visible_pages++;
1910-
vacrel->vm_new_visible_frozen_pages++;
1911-
}
1912-
else if ((old_vmbits & VISIBILITYMAP_ALL_FROZEN) == 0)
1913-
vacrel->vm_new_frozen_pages++;
1901+
/* Count the newly all-frozen pages for logging */
1902+
vacrel->vm_new_visible_pages++;
1903+
vacrel->vm_new_visible_frozen_pages++;
19141904
}
19151905

19161906
freespace = PageGetHeapFreeSpace(page);
@@ -2915,7 +2905,6 @@ lazy_vacuum_heap_page(LVRelState *vacrel, BlockNumber blkno, Buffer buffer,
29152905
if (heap_page_is_all_visible(vacrel, buffer, &visibility_cutoff_xid,
29162906
&all_frozen))
29172907
{
2918-
uint8 old_vmbits;
29192908
uint8 flags = VISIBILITYMAP_ALL_VISIBLE;
29202909

29212910
if (all_frozen)
@@ -2925,25 +2914,15 @@ lazy_vacuum_heap_page(LVRelState *vacrel, BlockNumber blkno, Buffer buffer,
29252914
}
29262915

29272916
PageSetAllVisible(page);
2928-
old_vmbits = visibilitymap_set(vacrel->rel, blkno, buffer,
2929-
InvalidXLogRecPtr,
2930-
vmbuffer, visibility_cutoff_xid,
2931-
flags);
2917+
visibilitymap_set(vacrel->rel, blkno, buffer,
2918+
InvalidXLogRecPtr,
2919+
vmbuffer, visibility_cutoff_xid,
2920+
flags);
29322921

2933-
/*
2934-
* If the page wasn't already set all-visible and/or all-frozen in the
2935-
* VM, count it as newly set for logging.
2936-
*/
2937-
if ((old_vmbits & VISIBILITYMAP_ALL_VISIBLE) == 0)
2938-
{
2939-
vacrel->vm_new_visible_pages++;
2940-
if (all_frozen)
2941-
vacrel->vm_new_visible_frozen_pages++;
2942-
}
2943-
2944-
else if ((old_vmbits & VISIBILITYMAP_ALL_FROZEN) == 0 &&
2945-
all_frozen)
2946-
vacrel->vm_new_frozen_pages++;
2922+
/* Count the newly set VM page for logging */
2923+
vacrel->vm_new_visible_pages++;
2924+
if (all_frozen)
2925+
vacrel->vm_new_visible_frozen_pages++;
29472926
}
29482927

29492928
/* Revert to the previous phase information for error traceback */

0 commit comments

Comments
 (0)