From 0fb7996c09a91d3c54deb5a386fe11e9b4298cfe Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Fri, 7 Oct 2011 22:50:11 -0400 Subject: [PATCH] Stuff. Need to rip out hppo crap. --- src/backend/access/heap/heapam.c | 3 +- src/backend/access/heap/pruneheap.c | 35 ++++++++++++++++++----- src/backend/access/index/indexam.c | 3 +- src/backend/executor/nodeBitmapHeapscan.c | 3 +- src/backend/storage/ipc/snaparray.c | 2 +- src/include/access/heapam.h | 3 +- src/include/storage/bufpage.h | 6 ++-- 7 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 88829bf866..dc1e5db3f1 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -233,8 +233,7 @@ heapgetpage(HeapScanDesc scan, BlockNumber page) /* * Prune and repair fragmentation for the whole page, if possible. */ - Assert(TransactionIdIsValid(RecentGlobalXmin)); - heap_page_prune_opt(scan->rs_rd, buffer, RecentGlobalXmin); + heap_page_prune_opt(scan->rs_rd, buffer); /* * We must hold share lock on the buffer content while examining tuple diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index 61f2ce4cde..510bb02b3c 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -19,7 +19,9 @@ #include "miscadmin.h" #include "pgstat.h" #include "storage/bufmgr.h" +#include "storage/procarray.h" #include "utils/rel.h" +#include "utils/snapmgr.h" #include "utils/tqual.h" @@ -51,6 +53,7 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +uint64 hppo1, hppo2, hppo3, hppo4, hppo5; /* * Optionally prune and repair fragmentation in the specified page. @@ -68,18 +71,18 @@ static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); * or RECENTLY_DEAD (see HeapTupleSatisfiesVacuum). */ void -heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) +heap_page_prune_opt(Relation relation, Buffer buffer) { Page page = BufferGetPage(buffer); Size minfree; /* - * Let's see if we really need pruning. - * - * Forget it if page is not hinted to contain something prunable that's - * older than OldestXmin. + * If the page isn't hinted to contain something prunable, or if the hint + * is for an XID that's still too new, exit quickly. */ - if (!PageIsPrunable(page, OldestXmin)) + ++hppo1; + if (!TransactionIdIsValid(PagePruneXid(page)) + || !TransactionIdPrecedes(PagePruneXid(page), TransactionXmin)) return; /* @@ -89,6 +92,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) */ if (RecoveryInProgress()) return; + ++hppo2; /* * We prune when a previous UPDATE failed to find enough space on the page @@ -108,6 +112,22 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree) { + /* + * If RecentGlobalXmin is too old to prune the page, update it and + * recheck. + */ + ++hppo3; + if (!PageIsPrunable(page, RecentGlobalXmin)) + { + RecentGlobalXmin = GetOldestXmin(true, false); + if (!PageIsPrunable(page, RecentGlobalXmin)) + { + ++hppo4; + return; + } + } + ++hppo5; + /* OK, try to get exclusive buffer lock */ if (!ConditionalLockBufferForCleanup(buffer)) return; @@ -124,7 +144,8 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) * needed */ /* OK to prune */ - (void) heap_page_prune(relation, buffer, OldestXmin, true, &ignore); + (void) heap_page_prune(relation, buffer, RecentGlobalXmin, true, + &ignore); } /* And release buffer lock */ diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index 6d423a7d68..e1823e876e 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -512,8 +512,7 @@ index_fetch_heap(IndexScanDesc scan) * Prune page, but only if we weren't already on this page */ if (prev_buf != scan->xs_cbuf) - heap_page_prune_opt(scan->heapRelation, scan->xs_cbuf, - RecentGlobalXmin); + heap_page_prune_opt(scan->heapRelation, scan->xs_cbuf); } /* Obtain share-lock on the buffer so we can examine visibility */ diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c index 4a8920e6ce..aed435988c 100644 --- a/src/backend/executor/nodeBitmapHeapscan.c +++ b/src/backend/executor/nodeBitmapHeapscan.c @@ -325,8 +325,7 @@ bitgetpage(HeapScanDesc scan, TBMIterateResult *tbmres) /* * Prune and repair fragmentation for the whole page, if possible. */ - Assert(TransactionIdIsValid(RecentGlobalXmin)); - heap_page_prune_opt(scan->rs_rd, buffer, RecentGlobalXmin); + heap_page_prune_opt(scan->rs_rd, buffer); /* * We must hold share lock on the buffer content while examining tuple diff --git a/src/backend/storage/ipc/snaparray.c b/src/backend/storage/ipc/snaparray.c index 1c71d5bf32..160b054785 100644 --- a/src/backend/storage/ipc/snaparray.c +++ b/src/backend/storage/ipc/snaparray.c @@ -624,7 +624,7 @@ retry: * that shouldn't matter, since we never allow the real global_xmin to * go backward. */ - if (!TransactionIdIsValid(TransactionXmin)) + if (!TransactionIdIsValid(MyProc->xmin)) { /* Advertise new xmin. */ MyProc->xmin = TransactionXmin = xmin; diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 776ea5c4cc..589199207b 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -143,8 +143,7 @@ extern XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blk, Page page); /* in heap/pruneheap.c */ -extern void heap_page_prune_opt(Relation relation, Buffer buffer, - TransactionId OldestXmin); +extern void heap_page_prune_opt(Relation relation, Buffer buffer); extern int heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, bool report_stats, TransactionId *latestRemovedXid); diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index 42d6b10dda..7a158a95f7 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -345,11 +345,13 @@ typedef PageHeaderData *PageHeader; #define PageClearAllVisible(page) \ (((PageHeader) (page))->pd_flags &= ~PD_ALL_VISIBLE) +#define PagePruneXid(page) \ + (((PageHeader) (page))->pd_prune_xid) #define PageIsPrunable(page, oldestxmin) \ ( \ AssertMacro(TransactionIdIsNormal(oldestxmin)), \ - TransactionIdIsValid(((PageHeader) (page))->pd_prune_xid) && \ - TransactionIdPrecedes(((PageHeader) (page))->pd_prune_xid, oldestxmin) \ + TransactionIdIsValid(PagePruneXid(page)) && \ + TransactionIdPrecedes(PagePruneXid(page), oldestxmin) \ ) #define PageSetPrunable(page, xid) \ do { \ -- 2.39.5