aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2006-02-11 16:59:09 +0000
committerBruce Momjian <bruce@momjian.us>2006-02-11 16:59:09 +0000
commitbf324946b32736da1b128b1e742515879b42a4e8 (patch)
treed1a9560e621c4423a40dfef2fc5dcfda183dfbeb /src/backend/access
parent85d8ee846b6b645cdf07d948aabc807aa755deac (diff)
downloadpostgresql-bf324946b32736da1b128b1e742515879b42a4e8.tar.gz
postgresql-bf324946b32736da1b128b1e742515879b42a4e8.zip
Allow VACUUM to complete faster by avoiding scanning the indexes when no
rows were removed from the heap by the VACUUM. Simon Riggs
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/gist/gistvacuum.c19
-rw-r--r--src/backend/access/hash/hash.c18
-rw-r--r--src/backend/access/index/indexam.c7
-rw-r--r--src/backend/access/nbtree/nbtree.c21
4 files changed, 46 insertions, 19 deletions
diff --git a/src/backend/access/gist/gistvacuum.c b/src/backend/access/gist/gistvacuum.c
index 31c560a83ad..10bd6cb4dc1 100644
--- a/src/backend/access/gist/gistvacuum.c
+++ b/src/backend/access/gist/gistvacuum.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.11 2005/11/22 18:17:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.12 2006/02/11 16:59:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -125,7 +125,7 @@ gistVacuumUpdate(GistVacuum *gv, BlockNumber blkno, bool needunion)
if (chldtuple.ituplen > 1)
{
/*
- * child was splitted, so we need mark completion
+ * child was split, so we need mark completion
* insert(split)
*/
int j;
@@ -329,9 +329,9 @@ gistVacuumUpdate(GistVacuum *gv, BlockNumber blkno, bool needunion)
}
/*
- * For usial vacuum just update FSM, for full vacuum
+ * For usual vacuum just update FSM, for full vacuum
* reforms parent tuples if some of childs was deleted or changed,
- * update invalid tuples (they can exsist from last crash recovery only),
+ * update invalid tuples (they can exist from last crash recovery only),
* tries to get smaller index
*/
@@ -505,10 +505,15 @@ gistbulkdelete(PG_FUNCTION_ARGS)
*ptr;
bool needLock;
- stack = (GistBDItem *) palloc0(sizeof(GistBDItem));
+ if (callback_state)
+ {
+ stack = (GistBDItem *) palloc0(sizeof(GistBDItem));
- stack->blkno = GIST_ROOT_BLKNO;
- needFullVacuum = false;
+ stack->blkno = GIST_ROOT_BLKNO;
+ needFullVacuum = false;
+ }
+ else
+ stack = NULL;
while (stack)
{
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 3a01109125f..548901a9be4 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.83 2006/01/25 23:26:11 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.84 2006/02/11 16:59:09 momjian Exp $
*
* NOTES
* This file contains only the public interface routines.
@@ -496,6 +496,17 @@ hashbulkdelete(PG_FUNCTION_ARGS)
tuples_removed = 0;
num_index_tuples = 0;
+ /* return statistics */
+ num_pages = RelationGetNumberOfBlocks(rel);
+
+ result = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
+ result->num_pages = num_pages;
+
+ if (!callback_state)
+ {
+ PG_RETURN_POINTER(result);
+ }
+
/*
* Read the metapage to fetch original bucket and tuple counts. Also, we
* keep a copy of the last-seen metapage so that we can use its
@@ -644,11 +655,6 @@ loop_top:
_hash_wrtbuf(rel, metabuf);
- /* return statistics */
- num_pages = RelationGetNumberOfBlocks(rel);
-
- result = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
- result->num_pages = num_pages;
result->num_index_tuples = num_index_tuples;
result->tuples_removed = tuples_removed;
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index c1e61ff2bda..0365ae79424 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.87 2005/12/03 05:51:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.88 2006/02/11 16:59:09 momjian Exp $
*
* INTERFACE ROUTINES
* index_open - open an index relation by relation OID
@@ -685,6 +685,11 @@ index_getmulti(IndexScanDesc scan,
* callback routine tells whether a given main-heap tuple is
* to be deleted
*
+ * passing NULL callback_state can be interpreted by the
+ * index access method as meaning that the index does not need
+ * to be scanned in logical sequence to remove rows for this call
+ * index_vacuum_cleanup is always required after this, however.
+ *
* return value is an optional palloc'd struct of statistics
* ----------------
*/
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 45f49c0b2bd..e757c4adad1 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.136 2006/01/25 23:04:20 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.137 2006/02/11 16:59:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -543,8 +543,9 @@ btbulkdelete(PG_FUNCTION_ARGS)
double num_index_tuples;
OffsetNumber deletable[MaxOffsetNumber];
int ndeletable;
- Buffer buf;
+ Buffer buf = NULL;
BlockNumber num_pages;
+ bool scanindex = true;
tuples_removed = 0;
num_index_tuples = 0;
@@ -565,8 +566,15 @@ btbulkdelete(PG_FUNCTION_ARGS)
* skip obtaining exclusive lock on empty pages though, since no indexscan
* could be stopped on those.
*/
- buf = _bt_get_endpoint(rel, 0, false);
- if (BufferIsValid(buf)) /* check for empty index */
+ if (callback_state)
+ {
+ buf = _bt_get_endpoint(rel, 0, false);
+ scanindex = BufferIsValid(buf); /* check for empty index */
+ }
+ else
+ scanindex = false;
+
+ if (scanindex)
{
for (;;)
{
@@ -649,7 +657,10 @@ btbulkdelete(PG_FUNCTION_ARGS)
result = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
result->num_pages = num_pages;
- result->num_index_tuples = num_index_tuples;
+ if (scanindex)
+ result->num_index_tuples = num_index_tuples;
+ else
+ result->num_index_tuples = -1;
result->tuples_removed = tuples_removed;
PG_RETURN_POINTER(result);