1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Use full 64-bit XID for checking if a deleted GiST page is old enough.

Otherwise, after a deleted page gets even older, it becomes unrecyclable
again. B-tree has the same problem, and has had since time immemorial,
but let's at least fix this in GiST, where this is new.

Backpatch to v12, where GiST page deletion was introduced.

Reviewed-by: Andrey Borodin
Discussion: https://www.postgresql.org/message-id/835A15A5-F1B4-4446-A711-BF48357EB602%40yandex-team.ru
This commit is contained in:
Heikki Linnakangas
2019-07-24 20:24:07 +03:00
parent 9eb5607e69
commit 6655a7299d
9 changed files with 134 additions and 28 deletions

View File

@@ -882,9 +882,27 @@ gistNewBuffer(Relation r)
bool
gistPageRecyclable(Page page)
{
return PageIsNew(page) ||
(GistPageIsDeleted(page) &&
TransactionIdPrecedes(GistPageGetDeleteXid(page), RecentGlobalXmin));
if (PageIsNew(page))
return true;
if (GistPageIsDeleted(page))
{
/*
* The page was deleted, but when? If it was just deleted, a scan
* might have seen the downlink to it, and will read the page later.
* As long as that can happen, we must keep the deleted page around as
* a tombstone.
*
* Compare the deletion XID with RecentGlobalXmin. If deleteXid <
* RecentGlobalXmin, then no scan that's still in progress could have
* seen its downlink, and we can recycle it.
*/
FullTransactionId deletexid_full = GistPageGetDeleteXid(page);
FullTransactionId recentxmin_full = GetFullRecentGlobalXmin();
if (FullTransactionIdPrecedes(deletexid_full, recentxmin_full))
return true;
}
return false;
}
bytea *