*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.272 2004/07/11 19:52:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.273 2004/08/28 21:05:26 tgl Exp $
*
*
* INTERFACE ROUTINES
Oid new_rel_oid,
char new_rel_kind,
Oid new_type_oid);
-static void RelationRemoveInheritance(Relation relation);
+static void RelationRemoveInheritance(Oid relid);
static void StoreRelCheck(Relation rel, char *ccname, char *ccbin);
static void StoreConstraints(Relation rel, TupleDesc tupdesc);
static void SetRelationNumChecks(Relation rel, int numchecks);
* linking this relation to its parent(s).
*/
static void
-RelationRemoveInheritance(Relation relation)
+RelationRemoveInheritance(Oid relid)
{
Relation catalogRelation;
SysScanDesc scan;
ScanKeyInit(&key,
Anum_pg_inherits_inhrelid,
BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(RelationGetRelid(relation)));
+ ObjectIdGetDatum(relid));
scan = systable_beginscan(catalogRelation, InheritsRelidSeqnoIndex, true,
SnapshotNow, 1, &key);
heap_close(attr_rel, RowExclusiveLock);
if (attnum > 0)
- RemoveStatistics(rel, attnum);
+ RemoveStatistics(relid, attnum);
relation_close(rel, NoLock);
}
relation_close(myrel, NoLock);
}
-/* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes specified relation from catalogs
- *
- * 1) open relation, acquire exclusive lock.
- * 2) flush relation buffers from bufmgr
- * 3) remove inheritance information
- * 4) remove pg_statistic tuples
- * 5) remove pg_attribute tuples
- * 6) remove pg_class tuple
- * 7) unlink relation file
+/*
+ * heap_drop_with_catalog - removes specified relation from catalogs
*
* Note that this routine is not responsible for dropping objects that are
* linked to the pg_class entry via dependencies (for example, indexes and
* constraints). Those are deleted by the dependency-tracing logic in
* dependency.c before control gets here. In general, therefore, this routine
* should never be called directly; go through performDeletion() instead.
- * ----------------------------------------------------------------
*/
void
-heap_drop_with_catalog(Oid rid)
+heap_drop_with_catalog(Oid relid)
{
Relation rel;
/*
* Open and lock the relation.
*/
- rel = relation_open(rid, AccessExclusiveLock);
+ rel = relation_open(relid, AccessExclusiveLock);
/*
* Release all buffers that belong to this relation, after writing any
FlushRelationBuffers(rel, (BlockNumber) 0);
/*
- * remove inheritance information
+ * Schedule unlinking of the relation's physical file at commit.
*/
- RelationRemoveInheritance(rel);
+ if (rel->rd_rel->relkind != RELKIND_VIEW &&
+ rel->rd_rel->relkind != RELKIND_COMPOSITE_TYPE)
+ {
+ if (rel->rd_smgr == NULL)
+ rel->rd_smgr = smgropen(rel->rd_node);
+ smgrscheduleunlink(rel->rd_smgr, rel->rd_istemp);
+ rel->rd_smgr = NULL;
+ }
/*
- * delete statistics
+ * Close relcache entry, but *keep* AccessExclusiveLock on the
+ * relation until transaction commit. This ensures no one else will
+ * try to do something with the doomed relation.
*/
- RemoveStatistics(rel, 0);
+ relation_close(rel, NoLock);
/*
- * delete attribute tuples
+ * Forget any ON COMMIT action for the rel
*/
- DeleteAttributeTuples(RelationGetRelid(rel));
+ remove_on_commit_action(relid);
/*
- * delete relation tuple
+ * Flush the relation from the relcache. We want to do this before
+ * starting to remove catalog entries, just to be certain that no
+ * relcache entry rebuild will happen partway through. (That should
+ * not really matter, since we don't do CommandCounterIncrement here,
+ * but let's be safe.)
*/
- DeleteRelationTuple(RelationGetRelid(rel));
+ RelationForgetRelation(relid);
/*
- * forget any ON COMMIT action for the rel
+ * remove inheritance information
*/
- remove_on_commit_action(rid);
+ RelationRemoveInheritance(relid);
/*
- * unlink the relation's physical file and finish up.
+ * delete statistics
*/
- if (rel->rd_rel->relkind != RELKIND_VIEW &&
- rel->rd_rel->relkind != RELKIND_COMPOSITE_TYPE)
- {
- if (rel->rd_smgr == NULL)
- rel->rd_smgr = smgropen(rel->rd_node);
- smgrscheduleunlink(rel->rd_smgr, rel->rd_istemp);
- rel->rd_smgr = NULL;
- }
+ RemoveStatistics(relid, 0);
/*
- * Close relcache entry, but *keep* AccessExclusiveLock on the
- * relation until transaction commit. This ensures no one else will
- * try to do something with the doomed relation.
+ * delete attribute tuples
*/
- relation_close(rel, NoLock);
+ DeleteAttributeTuples(relid);
/*
- * flush the relation from the relcache
+ * delete relation tuple
*/
- RelationForgetRelation(rid);
+ DeleteRelationTuple(relid);
}
* for that column.
*/
void
-RemoveStatistics(Relation rel, AttrNumber attnum)
+RemoveStatistics(Oid relid, AttrNumber attnum)
{
Relation pgstatistic;
SysScanDesc scan;
ScanKeyInit(&key[0],
Anum_pg_statistic_starelid,
BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(RelationGetRelid(rel)));
+ ObjectIdGetDatum(relid));
if (attnum == 0)
nkeys = 1;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.235 2004/08/01 17:32:14 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.236 2004/08/28 21:05:26 tgl Exp $
*
*
* INTERFACE ROUTINES
HeapTuple tuple;
bool hasexprs;
- Assert(OidIsValid(indexId));
-
/*
* To drop an index safely, we must grab exclusive lock on its parent
* table; otherwise there could be other backends using the index!
LockRelation(userIndexRelation, AccessExclusiveLock);
/*
- * fix RELATION relation
+ * flush buffer cache and schedule physical removal of the file
*/
- DeleteRelationTuple(indexId);
+ FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
+
+ if (userIndexRelation->rd_smgr == NULL)
+ userIndexRelation->rd_smgr = smgropen(userIndexRelation->rd_node);
+ smgrscheduleunlink(userIndexRelation->rd_smgr,
+ userIndexRelation->rd_istemp);
+ userIndexRelation->rd_smgr = NULL;
/*
- * fix ATTRIBUTE relation
+ * Close and flush the index's relcache entry, to ensure relcache
+ * doesn't try to rebuild it while we're deleting catalog entries.
+ * We keep the lock though.
*/
- DeleteAttributeTuples(indexId);
+ index_close(userIndexRelation);
+
+ RelationForgetRelation(indexId);
/*
* fix INDEX relation, and check for expressional index
* statistics about them.
*/
if (hasexprs)
- RemoveStatistics(userIndexRelation, 0);
+ RemoveStatistics(indexId, 0);
/*
- * flush buffer cache and physically remove the file
+ * fix ATTRIBUTE relation
*/
- FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
+ DeleteAttributeTuples(indexId);
- if (userIndexRelation->rd_smgr == NULL)
- userIndexRelation->rd_smgr = smgropen(userIndexRelation->rd_node);
- smgrscheduleunlink(userIndexRelation->rd_smgr,
- userIndexRelation->rd_istemp);
- userIndexRelation->rd_smgr = NULL;
+ /*
+ * fix RELATION relation
+ */
+ DeleteRelationTuple(indexId);
/*
* We are presently too lazy to attempt to compute the new correct
CacheInvalidateRelcache(userHeapRelation);
/*
- * Close rels, but keep locks
+ * Close owning rel, but keep lock
*/
- index_close(userIndexRelation);
heap_close(userHeapRelation, NoLock);
-
- RelationForgetRelation(indexId);
}
/* ----------------------------------------------------------------