mirror of
https://github.com/postgres/postgres.git
synced 2025-11-16 15:02:33 +03:00
Rewrite btree vacuuming to fold the former bulkdelete and cleanup operations
into a single mostly-physical-order scan of the index. This requires some ticklish interlocking considerations, but should create no material performance impact on normal index operations (at least given the already-committed changes to make scans work a page at a time). VACUUM itself should get significantly faster in any index that's degenerated to a very nonlinear page order. Also, we save one pass over the index entirely, except in the case where there were no deletions to do and so only one pass happened anyway. Original patch by Heikki Linnakangas, rework by Tom Lane.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.96 2006/04/25 22:46:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.97 2006/05/08 00:00:10 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Postgres btree pages look like ordinary relation pages. The opaque
|
||||
@@ -206,6 +206,7 @@ _bt_getroot(Relation rel, int access)
|
||||
rootopaque->btpo_prev = rootopaque->btpo_next = P_NONE;
|
||||
rootopaque->btpo_flags = (BTP_LEAF | BTP_ROOT);
|
||||
rootopaque->btpo.level = 0;
|
||||
rootopaque->btpo_cycleid = 0;
|
||||
|
||||
/* NO ELOG(ERROR) till meta is updated */
|
||||
START_CRIT_SECTION();
|
||||
@@ -544,7 +545,7 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access)
|
||||
* Release the file-extension lock; it's now OK for someone else to
|
||||
* extend the relation some more. Note that we cannot release this
|
||||
* lock before we have buffer lock on the new page, or we risk a race
|
||||
* condition against btvacuumcleanup --- see comments therein.
|
||||
* condition against btvacuumscan --- see comments therein.
|
||||
*/
|
||||
if (needLock)
|
||||
UnlockRelationForExtension(rel, ExclusiveLock);
|
||||
@@ -608,7 +609,7 @@ _bt_pageinit(Page page, Size size)
|
||||
/*
|
||||
* _bt_page_recyclable() -- Is an existing page recyclable?
|
||||
*
|
||||
* This exists to make sure _bt_getbuf and btvacuumcleanup have the same
|
||||
* This exists to make sure _bt_getbuf and btvacuumscan have the same
|
||||
* policy about whether a page is safe to re-use.
|
||||
*/
|
||||
bool
|
||||
@@ -651,6 +652,7 @@ _bt_delitems(Relation rel, Buffer buf,
|
||||
OffsetNumber *itemnos, int nitems)
|
||||
{
|
||||
Page page = BufferGetPage(buf);
|
||||
BTPageOpaque opaque;
|
||||
|
||||
/* No ereport(ERROR) until changes are logged */
|
||||
START_CRIT_SECTION();
|
||||
@@ -658,6 +660,13 @@ _bt_delitems(Relation rel, Buffer buf,
|
||||
/* Fix the page */
|
||||
PageIndexMultiDelete(page, itemnos, nitems);
|
||||
|
||||
/*
|
||||
* We can clear the vacuum cycle ID since this page has certainly
|
||||
* been processed by the current vacuum scan.
|
||||
*/
|
||||
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
opaque->btpo_cycleid = 0;
|
||||
|
||||
MarkBufferDirty(buf);
|
||||
|
||||
/* XLOG stuff */
|
||||
|
||||
Reference in New Issue
Block a user