8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.272 2004/07/11 19:52:48 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.273 2004/08/28 21:05:26 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
@@ -71,7 +71,7 @@ static void AddNewRelationType(const char *typeName,
71
71
Oid new_rel_oid ,
72
72
char new_rel_kind ,
73
73
Oid new_type_oid );
74
- static void RelationRemoveInheritance (Relation relation );
74
+ static void RelationRemoveInheritance (Oid relid );
75
75
static void StoreRelCheck (Relation rel , char * ccname , char * ccbin );
76
76
static void StoreConstraints (Relation rel , TupleDesc tupdesc );
77
77
static void SetRelationNumChecks (Relation rel , int numchecks );
@@ -836,7 +836,7 @@ heap_create_with_catalog(const char *relname,
836
836
* linking this relation to its parent(s).
837
837
*/
838
838
static void
839
- RelationRemoveInheritance (Relation relation )
839
+ RelationRemoveInheritance (Oid relid )
840
840
{
841
841
Relation catalogRelation ;
842
842
SysScanDesc scan ;
@@ -848,7 +848,7 @@ RelationRemoveInheritance(Relation relation)
848
848
ScanKeyInit (& key ,
849
849
Anum_pg_inherits_inhrelid ,
850
850
BTEqualStrategyNumber , F_OIDEQ ,
851
- ObjectIdGetDatum (RelationGetRelid ( relation ) ));
851
+ ObjectIdGetDatum (relid ));
852
852
853
853
scan = systable_beginscan (catalogRelation , InheritsRelidSeqnoIndex , true,
854
854
SnapshotNow , 1 , & key );
@@ -1015,7 +1015,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
1015
1015
heap_close (attr_rel , RowExclusiveLock );
1016
1016
1017
1017
if (attnum > 0 )
1018
- RemoveStatistics (rel , attnum );
1018
+ RemoveStatistics (relid , attnum );
1019
1019
1020
1020
relation_close (rel , NoLock );
1021
1021
}
@@ -1147,33 +1147,24 @@ RemoveAttrDefaultById(Oid attrdefId)
1147
1147
relation_close (myrel , NoLock );
1148
1148
}
1149
1149
1150
- /* ----------------------------------------------------------------
1151
- * heap_drop_with_catalog - removes specified relation from catalogs
1152
- *
1153
- * 1) open relation, acquire exclusive lock.
1154
- * 2) flush relation buffers from bufmgr
1155
- * 3) remove inheritance information
1156
- * 4) remove pg_statistic tuples
1157
- * 5) remove pg_attribute tuples
1158
- * 6) remove pg_class tuple
1159
- * 7) unlink relation file
1150
+ /*
1151
+ * heap_drop_with_catalog - removes specified relation from catalogs
1160
1152
*
1161
1153
* Note that this routine is not responsible for dropping objects that are
1162
1154
* linked to the pg_class entry via dependencies (for example, indexes and
1163
1155
* constraints). Those are deleted by the dependency-tracing logic in
1164
1156
* dependency.c before control gets here. In general, therefore, this routine
1165
1157
* should never be called directly; go through performDeletion() instead.
1166
- * ----------------------------------------------------------------
1167
1158
*/
1168
1159
void
1169
- heap_drop_with_catalog (Oid rid )
1160
+ heap_drop_with_catalog (Oid relid )
1170
1161
{
1171
1162
Relation rel ;
1172
1163
1173
1164
/*
1174
1165
* Open and lock the relation.
1175
1166
*/
1176
- rel = relation_open (rid , AccessExclusiveLock );
1167
+ rel = relation_open (relid , AccessExclusiveLock );
1177
1168
1178
1169
/*
1179
1170
* Release all buffers that belong to this relation, after writing any
@@ -1182,53 +1173,57 @@ heap_drop_with_catalog(Oid rid)
1182
1173
FlushRelationBuffers (rel , (BlockNumber ) 0 );
1183
1174
1184
1175
/*
1185
- * remove inheritance information
1176
+ * Schedule unlinking of the relation's physical file at commit.
1186
1177
*/
1187
- RelationRemoveInheritance (rel );
1178
+ if (rel -> rd_rel -> relkind != RELKIND_VIEW &&
1179
+ rel -> rd_rel -> relkind != RELKIND_COMPOSITE_TYPE )
1180
+ {
1181
+ if (rel -> rd_smgr == NULL )
1182
+ rel -> rd_smgr = smgropen (rel -> rd_node );
1183
+ smgrscheduleunlink (rel -> rd_smgr , rel -> rd_istemp );
1184
+ rel -> rd_smgr = NULL ;
1185
+ }
1188
1186
1189
1187
/*
1190
- * delete statistics
1188
+ * Close relcache entry, but *keep* AccessExclusiveLock on the
1189
+ * relation until transaction commit. This ensures no one else will
1190
+ * try to do something with the doomed relation.
1191
1191
*/
1192
- RemoveStatistics (rel , 0 );
1192
+ relation_close (rel , NoLock );
1193
1193
1194
1194
/*
1195
- * delete attribute tuples
1195
+ * Forget any ON COMMIT action for the rel
1196
1196
*/
1197
- DeleteAttributeTuples ( RelationGetRelid ( rel ) );
1197
+ remove_on_commit_action ( relid );
1198
1198
1199
1199
/*
1200
- * delete relation tuple
1200
+ * Flush the relation from the relcache. We want to do this before
1201
+ * starting to remove catalog entries, just to be certain that no
1202
+ * relcache entry rebuild will happen partway through. (That should
1203
+ * not really matter, since we don't do CommandCounterIncrement here,
1204
+ * but let's be safe.)
1201
1205
*/
1202
- DeleteRelationTuple ( RelationGetRelid ( rel ) );
1206
+ RelationForgetRelation ( relid );
1203
1207
1204
1208
/*
1205
- * forget any ON COMMIT action for the rel
1209
+ * remove inheritance information
1206
1210
*/
1207
- remove_on_commit_action ( rid );
1211
+ RelationRemoveInheritance ( relid );
1208
1212
1209
1213
/*
1210
- * unlink the relation's physical file and finish up.
1214
+ * delete statistics
1211
1215
*/
1212
- if (rel -> rd_rel -> relkind != RELKIND_VIEW &&
1213
- rel -> rd_rel -> relkind != RELKIND_COMPOSITE_TYPE )
1214
- {
1215
- if (rel -> rd_smgr == NULL )
1216
- rel -> rd_smgr = smgropen (rel -> rd_node );
1217
- smgrscheduleunlink (rel -> rd_smgr , rel -> rd_istemp );
1218
- rel -> rd_smgr = NULL ;
1219
- }
1216
+ RemoveStatistics (relid , 0 );
1220
1217
1221
1218
/*
1222
- * Close relcache entry, but *keep* AccessExclusiveLock on the
1223
- * relation until transaction commit. This ensures no one else will
1224
- * try to do something with the doomed relation.
1219
+ * delete attribute tuples
1225
1220
*/
1226
- relation_close ( rel , NoLock );
1221
+ DeleteAttributeTuples ( relid );
1227
1222
1228
1223
/*
1229
- * flush the relation from the relcache
1224
+ * delete relation tuple
1230
1225
*/
1231
- RelationForgetRelation ( rid );
1226
+ DeleteRelationTuple ( relid );
1232
1227
}
1233
1228
1234
1229
@@ -1884,7 +1879,7 @@ RemoveRelConstraints(Relation rel, const char *constrName,
1884
1879
* for that column.
1885
1880
*/
1886
1881
void
1887
- RemoveStatistics (Relation rel , AttrNumber attnum )
1882
+ RemoveStatistics (Oid relid , AttrNumber attnum )
1888
1883
{
1889
1884
Relation pgstatistic ;
1890
1885
SysScanDesc scan ;
@@ -1897,7 +1892,7 @@ RemoveStatistics(Relation rel, AttrNumber attnum)
1897
1892
ScanKeyInit (& key [0 ],
1898
1893
Anum_pg_statistic_starelid ,
1899
1894
BTEqualStrategyNumber , F_OIDEQ ,
1900
- ObjectIdGetDatum (RelationGetRelid ( rel ) ));
1895
+ ObjectIdGetDatum (relid ));
1901
1896
1902
1897
if (attnum == 0 )
1903
1898
nkeys = 1 ;
0 commit comments