aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-09-18 19:08:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-09-18 19:08:25 +0000
commitbd272cace63effa23d68a6b344a07e326b6a41e2 (patch)
tree3026c545c238bd38eadc7fb1fac89d636cf51673 /src/backend/utils/adt
parent6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff)
downloadpostgresql-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/utils/adt')
-rw-r--r--src/backend/utils/adt/not_in.c13
-rw-r--r--src/backend/utils/adt/regproc.c33
-rw-r--r--src/backend/utils/adt/selfuncs.c8
-rw-r--r--src/backend/utils/adt/sets.c8
4 files changed, 23 insertions, 39 deletions
diff --git a/src/backend/utils/adt/not_in.c b/src/backend/utils/adt/not_in.c
index 2ef45f63e42..1a851cf7e5f 100644
--- a/src/backend/utils/adt/not_in.c
+++ b/src/backend/utils/adt/not_in.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.20 1999/07/17 20:17:58 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.21 1999/09/18 19:07:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -58,12 +58,7 @@ int4notin(int32 not_in_arg, char *relation_and_attr)
/* Open the relation and get a relation descriptor */
- relation_to_scan = heap_openr(relation);
- if (!RelationIsValid(relation_to_scan))
- {
- elog(ERROR, "int4notin: unknown relation %s",
- relation);
- }
+ relation_to_scan = heap_openr(relation, AccessShareLock);
/* Find the column to search */
@@ -95,7 +90,9 @@ int4notin(int32 not_in_arg, char *relation_and_attr)
}
/* close the relation */
- heap_close(relation_to_scan);
+ heap_endscan(scan_descriptor);
+ heap_close(relation_to_scan, AccessShareLock);
+
return retval;
}
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 754eea3a96e..b3179e864c1 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.42 1999/07/17 20:17:59 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.43 1999/09/18 19:07:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -78,7 +78,7 @@ regprocin(char *pro_name_or_oid)
(RegProcedure) F_NAMEEQ,
PointerGetDatum(pro_name_or_oid));
- hdesc = heap_openr(ProcedureRelationName);
+ hdesc = heap_openr(ProcedureRelationName, AccessShareLock);
idesc = index_openr(ProcedureNameIndex);
sd = index_beginscan(idesc, false, 1, skey);
@@ -102,6 +102,7 @@ regprocin(char *pro_name_or_oid)
index_endscan(sd);
pfree(sd);
index_close(idesc);
+ heap_close(hdesc, AccessShareLock);
if (matches > 1)
elog(ERROR, "There is more than one procedure named %s.\n\tSupply the pg_proc oid inside single quotes.", pro_name_or_oid);
@@ -116,13 +117,7 @@ regprocin(char *pro_name_or_oid)
ScanKeyData key;
bool isnull;
- proc = heap_openr(ProcedureRelationName);
- if (!RelationIsValid(proc))
- {
- elog(ERROR, "regprocin: could not open %s",
- ProcedureRelationName);
- return 0;
- }
+ proc = heap_openr(ProcedureRelationName, AccessShareLock);
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) 1,
@@ -132,8 +127,8 @@ regprocin(char *pro_name_or_oid)
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{
- heap_close(proc);
- elog(ERROR, "regprocin: could not being scan of %s",
+ heap_close(proc, AccessShareLock);
+ elog(ERROR, "regprocin: could not begin scan of %s",
ProcedureRelationName);
return 0;
}
@@ -151,7 +146,7 @@ regprocin(char *pro_name_or_oid)
result = (RegProcedure) 0;
heap_endscan(procscan);
- heap_close(proc);
+ heap_close(proc, AccessShareLock);
}
return (int32) result;
@@ -193,12 +188,7 @@ regprocout(RegProcedure proid)
HeapScanDesc procscan;
ScanKeyData key;
- proc = heap_openr(ProcedureRelationName);
- if (!RelationIsValid(proc))
- {
- elog(ERROR, "regprocout: could not open %s", ProcedureRelationName);
- return 0;
- }
+ proc = heap_openr(ProcedureRelationName, AccessShareLock);
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) ObjectIdAttributeNumber,
@@ -208,8 +198,8 @@ regprocout(RegProcedure proid)
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{
- heap_close(proc);
- elog(ERROR, "regprocout: could not being scan of %s",
+ heap_close(proc, AccessShareLock);
+ elog(ERROR, "regprocout: could not begin scan of %s",
ProcedureRelationName);
return 0;
}
@@ -232,8 +222,7 @@ regprocout(RegProcedure proid)
result[1] = '\0';
}
heap_endscan(procscan);
- heap_close(proc);
- return result;
+ heap_close(proc, AccessShareLock);
}
return result;
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 1b2d58c075e..e14e5375553 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.40 1999/09/09 02:35:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.41 1999/09/18 19:07:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -598,7 +598,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid typid, int32 typmod,
HeapTuple typeTuple;
FmgrInfo inputproc;
- rel = heap_openr(StatisticRelationName);
+ rel = heap_openr(StatisticRelationName, AccessShareLock);
key[0].sk_argument = ObjectIdGetDatum(relid);
key[1].sk_argument = Int16GetDatum((int16) attnum);
@@ -609,7 +609,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid typid, int32 typmod,
{
/* no such stats entry */
heap_endscan(scan);
- heap_close(rel);
+ heap_close(rel, AccessShareLock);
return false;
}
@@ -694,7 +694,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid typid, int32 typmod,
}
heap_endscan(scan);
- heap_close(rel);
+ heap_close(rel, AccessShareLock);
return true;
}
diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c
index 05bc16b92af..46dbca9d698 100644
--- a/src/backend/utils/adt/sets.c
+++ b/src/backend/utils/adt/sets.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.25 1999/07/17 20:18:00 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.26 1999/09/18 19:07:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -100,8 +100,7 @@ SetDefine(char *querystr, char *typename)
replNull[i] = ' ';
/* change the pg_proc tuple */
- procrel = heap_openr(ProcedureRelationName);
- LockRelation(procrel, AccessExclusiveLock);
+ procrel = heap_openr(ProcedureRelationName, RowExclusiveLock);
tup = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(setoid),
@@ -131,8 +130,7 @@ SetDefine(char *querystr, char *typename)
CatalogIndexInsert(idescs, Num_pg_proc_indices, procrel, newtup);
CatalogCloseIndices(Num_pg_proc_indices, idescs);
}
- UnlockRelation(procrel, AccessExclusiveLock);
- heap_close(procrel);
+ heap_close(procrel, RowExclusiveLock);
}
return setoid;
}