diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-09-18 19:08:25 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-09-18 19:08:25 +0000 |
commit | bd272cace63effa23d68a6b344a07e326b6a41e2 (patch) | |
tree | 3026c545c238bd38eadc7fb1fac89d636cf51673 /src/backend/access/gist/gist.c | |
parent | 6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff) | |
download | postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.tar.gz postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.zip |
Mega-commit to make heap_open/heap_openr/heap_close take an
additional argument specifying the kind of lock to acquire/release (or
'NoLock' to do no lock processing). Ensure that all relations are locked
with some appropriate lock level before being examined --- this ensures
that relevant shared-inval messages have been processed and should prevent
problems caused by concurrent VACUUM. Fix several bugs having to do with
mismatched increment/decrement of relation ref count and mismatched
heap_open/close (which amounts to the same thing). A bogus ref count on
a relation doesn't matter much *unless* a SI Inval message happens to
arrive at the wrong time, which is probably why we got away with this
sloppiness for so long. Repair missing grab of AccessExclusiveLock in
DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi.
Recommend 'make clean all' after pulling this update; I modified the
Relation struct layout slightly.
Will post further discussion to pghackers list shortly.
Diffstat (limited to 'src/backend/access/gist/gist.c')
-rw-r--r-- | src/backend/access/gist/gist.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index 32111347423..0535fd6278d 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.44 1999/07/19 02:06:15 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.45 1999/09/18 19:05:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -20,6 +20,7 @@ #include "catalog/index.h" #include "catalog/pg_index.h" #include "executor/executor.h" +#include "miscadmin.h" #include "utils/syscache.h" @@ -88,8 +89,6 @@ gistbuild(Relation heap, TupleTableSlot *slot; #endif - Oid hrelid, - irelid; Node *pred, *oldPred; GISTSTATE giststate; @@ -271,28 +270,31 @@ gistbuild(Relation heap, } /* - * Since we just inted the tuples in the heap, we update its stats in - * pg_relation to guarantee that the planner takes advantage of the - * index we just created. UpdateStats() does a - * CommandinterIncrement(), which flushes changed entries from the - * system relcache. The act of constructing an index changes these - * heap and index tuples in the system catalogs, so they need to be - * flushed. We close them to guarantee that they will be. + * Since we just counted the tuples in the heap, we update its stats + * in pg_class to guarantee that the planner takes advantage of the + * index we just created. But, only update statistics during + * normal index definitions, not for indices on system catalogs + * created during bootstrap processing. We must close the relations + * before updating statistics to guarantee that the relcache entries + * are flushed when we increment the command counter in UpdateStats(). + * But we do not release any locks on the relations; those will be + * held until end of transaction. */ - - hrelid = RelationGetRelid(heap); - irelid = RelationGetRelid(index); - heap_close(heap); - index_close(index); - - UpdateStats(hrelid, nh, true); - UpdateStats(irelid, ni, false); - - if (oldPred != NULL) + if (IsNormalProcessingMode()) { - if (ni == nh) - pred = NULL; - UpdateIndexPredicate(irelid, oldPred, pred); + Oid hrelid = RelationGetRelid(heap); + Oid irelid = RelationGetRelid(index); + + heap_close(heap, NoLock); + index_close(index); + UpdateStats(hrelid, nh, true); + UpdateStats(irelid, ni, false); + if (oldPred != NULL) + { + if (ni == nh) + pred = NULL; + UpdateIndexPredicate(irelid, oldPred, pred); + } } /* be tidy */ |