aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execUtils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-07-15 22:48:19 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-07-15 22:48:19 +0000
commitc8076f09d2eb82a28f27f97230be470fffe7a1e0 (patch)
tree1e357e7e28313386f9d2e789d3905b37ce2d58f6 /src/backend/executor/execUtils.c
parent997439f59e1d487cb2bfa1384f6479fda0c4dd4c (diff)
downloadpostgresql-c8076f09d2eb82a28f27f97230be470fffe7a1e0.tar.gz
postgresql-c8076f09d2eb82a28f27f97230be470fffe7a1e0.zip
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in different AMs' ambuild routines has been moved out to a common routine in index.c; this means that all index types now do the right things about inserting recently-dead tuples, etc. (I also removed support for EXTEND INDEX in the ambuild routines, since that's about to go away anyway, and it cluttered the code a lot.) The retail indextuple deletion routines have been replaced by a "bulk delete" routine in which the indexscan is inside the access method. I haven't pushed this change as far as it should go yet, but it should allow considerable simplification of the internal bookkeeping for deletions. Also, add flag columns to pg_am to eliminate various hardcoded tests on AM OIDs, and remove unused pg_am columns. Fix rtree and gist index types to not attempt to store NULLs; before this, gist usually crashed, while rtree managed not to crash but computed wacko bounding boxes for NULL entries (which might have had something to do with the performance problems we've heard about occasionally). Add AtEOXact routines to hash, rtree, and gist, all of which have static state that needs to be reset after an error. We discovered this need long ago for btree, but missed the other guys. Oh, one more thing: concurrent VACUUM is now the default.
Diffstat (limited to 'src/backend/executor/execUtils.c')
-rw-r--r--src/backend/executor/execUtils.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 72aceb35f0f..9465604b584 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.75 2001/03/22 06:16:12 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.76 2001/07/15 22:48:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -504,25 +504,26 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo)
/*
* Open (and lock, if necessary) the index relation
*
- * Hack for not btree and hash indices: they use relation level
- * exclusive locking on update (i.e. - they are not ready for
- * MVCC) and so we have to exclusively lock indices here to
- * prevent deadlocks if we will scan them - index_beginscan places
- * AccessShareLock, indices update methods don't use locks at all.
- * We release this lock in ExecCloseIndices. Note, that hashes use
- * page level locking - i.e. are not deadlock-free - let's them be
- * on their way -:)) vadim 03-12-1998
+ * If the index AM is not safe for concurrent updates, obtain
+ * an exclusive lock on the index to lock out other updaters as
+ * well as readers (index_beginscan places AccessShareLock).
+ * We will release this lock in ExecCloseIndices.
*
- * If there are multiple not-btree-or-hash indices, all backends must
- * lock the indices in the same order or we will get deadlocks
- * here during concurrent updates. This is now guaranteed by
+ * If the index AM supports concurrent updates, we obtain no lock
+ * here at all, which is a tad weird, but safe since any critical
+ * operation on the index (like deleting it) will acquire exclusive
+ * lock on the parent table. Perhaps someday we should acquire
+ * RowExclusiveLock on the index here?
+ *
+ * If there are multiple not-concurrent-safe indexes, all backends
+ * must lock the indexes in the same order or we will get deadlocks
+ * here during concurrent updates. This is guaranteed by
* RelationGetIndexList(), which promises to return the index list
- * in OID order. tgl 06-19-2000
+ * in OID order.
*/
indexDesc = index_open(indexOid);
- if (indexDesc->rd_rel->relam != BTREE_AM_OID &&
- indexDesc->rd_rel->relam != HASH_AM_OID)
+ if (! indexDesc->rd_am->amconcurrent)
LockRelation(indexDesc, AccessExclusiveLock);
/*
@@ -560,24 +561,21 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
{
int i;
int numIndices;
- RelationPtr relationDescs;
+ RelationPtr indexDescs;
numIndices = resultRelInfo->ri_NumIndices;
- relationDescs = resultRelInfo->ri_IndexRelationDescs;
+ indexDescs = resultRelInfo->ri_IndexRelationDescs;
for (i = 0; i < numIndices; i++)
{
- if (relationDescs[i] == NULL)
+ if (indexDescs[i] == NULL)
continue;
- /*
- * See notes in ExecOpenIndices.
- */
- if (relationDescs[i]->rd_rel->relam != BTREE_AM_OID &&
- relationDescs[i]->rd_rel->relam != HASH_AM_OID)
- UnlockRelation(relationDescs[i], AccessExclusiveLock);
+ /* Drop lock, if one was acquired by ExecOpenIndices */
+ if (! indexDescs[i]->rd_am->amconcurrent)
+ UnlockRelation(indexDescs[i], AccessExclusiveLock);
- index_close(relationDescs[i]);
+ index_close(indexDescs[i]);
}
/*