Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0ea71c9

Browse files
Notice that heap page has dead items during VACUUM.
Consistently set a flag variable that tracks whether the current heap page has a dead item during lazy vacuum's heap scan. We missed the common case where there is an preexisting (or even a new) LP_DEAD heap line pointer. Also make it clear that the variable might be affected by an existing line pointer, say from an earlier opportunistic pruning operation. This distinction is important because it's the main reason why we can't just use the nearby tups_vacuumed variable instead. No backpatch. In theory failing to set the page level flag variable had no consequences. Currently it is only used to defensively check if a page marked all visible has dead items, which should never happen anyway (if it does then the table must be corrupt). Author: Masahiko Sawada <sawada.mshk@gmail.com> Diagnosed-By: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/CAD21AoAtZb4+HJT_8RoOXvu4HM-Zd4HKS3YSMCH6+-W=bDyh-w@mail.gmail.com
1 parent 58f5749 commit 0ea71c9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
945945
bool all_visible_according_to_vm = false;
946946
bool all_visible;
947947
bool all_frozen = true; /* provided all_visible is also true */
948-
bool has_dead_tuples;
948+
bool has_dead_items; /* includes existing LP_DEAD items */
949949
TransactionId visibility_cutoff_xid = InvalidTransactionId;
950950

951951
/* see note above about forcing scanning of last page */
@@ -1248,7 +1248,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
12481248
* requiring freezing.
12491249
*/
12501250
all_visible = true;
1251-
has_dead_tuples = false;
1251+
has_dead_items = false;
12521252
nfrozen = 0;
12531253
hastup = false;
12541254
prev_dead_count = dead_tuples->num_tuples;
@@ -1300,6 +1300,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
13001300
{
13011301
lazy_record_dead_tuple(dead_tuples, &(tuple.t_self));
13021302
all_visible = false;
1303+
has_dead_items = true;
13031304
continue;
13041305
}
13051306

@@ -1448,7 +1449,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
14481449
HeapTupleHeaderAdvanceLatestRemovedXid(tuple.t_data,
14491450
&vacrelstats->latestRemovedXid);
14501451
tups_vacuumed += 1;
1451-
has_dead_tuples = true;
1452+
has_dead_items = true;
14521453
}
14531454
else
14541455
{
@@ -1527,7 +1528,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
15271528
/* Remove tuples from heap if the table has no index */
15281529
lazy_vacuum_page(onerel, blkno, buf, 0, vacrelstats, &vmbuffer);
15291530
vacuumed_pages++;
1530-
has_dead_tuples = false;
1531+
has_dead_items = false;
15311532
}
15321533
else
15331534
{
@@ -1625,7 +1626,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
16251626
* There should never be dead tuples on a page with PD_ALL_VISIBLE
16261627
* set, however.
16271628
*/
1628-
else if (PageIsAllVisible(page) && has_dead_tuples)
1629+
else if (PageIsAllVisible(page) && has_dead_items)
16291630
{
16301631
elog(WARNING, "page containing dead tuples is marked as all-visible in relation \"%s\" page %u",
16311632
vacrelstats->relname, blkno);

0 commit comments

Comments
 (0)