Commit df3f5dfd authored by Tom Lane's avatar Tom Lane

In DeleteAttributeTuples, use a single indexscan instead of the multiple

scans that will most likely be caused by SearchSysCache probes.  Also,
share some code between index deletion and table deletion.
parent 942a2e94
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.182 2002/07/12 18:43:13 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.183 2002/07/14 21:08:08 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -789,10 +789,7 @@ index_drop(Oid indexId) ...@@ -789,10 +789,7 @@ index_drop(Oid indexId)
Relation userHeapRelation; Relation userHeapRelation;
Relation userIndexRelation; Relation userIndexRelation;
Relation indexRelation; Relation indexRelation;
Relation relationRelation;
Relation attributeRelation;
HeapTuple tuple; HeapTuple tuple;
int16 attnum;
int i; int i;
Assert(OidIsValid(indexId)); Assert(OidIsValid(indexId));
...@@ -818,53 +815,27 @@ index_drop(Oid indexId) ...@@ -818,53 +815,27 @@ index_drop(Oid indexId)
/* /*
* fix RELATION relation * fix RELATION relation
*/ */
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock); DeleteRelationTuple(indexId);
/* Remove the pg_class tuple for the index itself */
tuple = SearchSysCacheCopy(RELOID,
ObjectIdGetDatum(indexId),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "index_drop: cache lookup failed for index %u",
indexId);
simple_heap_delete(relationRelation, &tuple->t_self);
heap_freetuple(tuple);
heap_close(relationRelation, RowExclusiveLock);
/* /*
* fix ATTRIBUTE relation * fix ATTRIBUTE relation
*/ */
attributeRelation = heap_openr(AttributeRelationName, RowExclusiveLock); DeleteAttributeTuples(indexId);
attnum = 1; /* indexes start at 1 */
while (HeapTupleIsValid(tuple = SearchSysCacheCopy(ATTNUM,
ObjectIdGetDatum(indexId),
Int16GetDatum(attnum),
0, 0)))
{
simple_heap_delete(attributeRelation, &tuple->t_self);
heap_freetuple(tuple);
attnum++;
}
heap_close(attributeRelation, RowExclusiveLock);
/* /*
* fix INDEX relation * fix INDEX relation
*/ */
indexRelation = heap_openr(IndexRelationName, RowExclusiveLock); indexRelation = heap_openr(IndexRelationName, RowExclusiveLock);
tuple = SearchSysCacheCopy(INDEXRELID, tuple = SearchSysCache(INDEXRELID,
ObjectIdGetDatum(indexId), ObjectIdGetDatum(indexId),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "index_drop: cache lookup failed for index %u", elog(ERROR, "index_drop: cache lookup failed for index %u",
indexId); indexId);
simple_heap_delete(indexRelation, &tuple->t_self); simple_heap_delete(indexRelation, &tuple->t_self);
heap_freetuple(tuple);
ReleaseSysCache(tuple);
heap_close(indexRelation, RowExclusiveLock); heap_close(indexRelation, RowExclusiveLock);
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: heap.h,v 1.52 2002/07/12 18:43:19 tgl Exp $ * $Id: heap.h,v 1.53 2002/07/14 21:08:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,6 +61,9 @@ extern Node *cookDefault(ParseState *pstate, ...@@ -61,6 +61,9 @@ extern Node *cookDefault(ParseState *pstate,
extern int RemoveRelConstraints(Relation rel, const char *constrName, extern int RemoveRelConstraints(Relation rel, const char *constrName,
DropBehavior behavior); DropBehavior behavior);
extern void DeleteRelationTuple(Oid relid);
extern void DeleteAttributeTuples(Oid relid);
extern Form_pg_attribute SystemAttributeDefinition(AttrNumber attno, extern Form_pg_attribute SystemAttributeDefinition(AttrNumber attno,
bool relhasoids); bool relhasoids);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment