88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.67 2002/03/3106:26 :30 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.68 2002/03/3107:49 :30 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -69,8 +69,8 @@ static void update_ri_trigger_args(Oid relid,
6969 */
7070void
7171renameatt (Oid relid ,
72- char * oldattname ,
73- char * newattname ,
72+ const char * oldattname ,
73+ const char * newattname ,
7474bool recurse )
7575{
7676Relation targetrelation ;
@@ -250,51 +250,36 @@ renameatt(Oid relid,
250250 *renamerel- change the name of a relation
251251 */
252252void
253- renamerel (const RangeVar * relation ,const char * newrelname )
253+ renamerel (Oid relid ,const char * newrelname )
254254{
255255Relation targetrelation ;
256256Relation relrelation ;/* for RELATION relation */
257257HeapTuple reltup ;
258258Oid namespaceId ;
259- Oid reloid ;
260259char relkind ;
261260bool relhastriggers ;
262261Relation irelations [Num_pg_class_indices ];
263262
264- if (!allowSystemTableMods && IsSystemRelationName (relation -> relname ))
265- elog (ERROR ,"renamerel: system relation \"%s\" may not be renamed" ,
266- relation -> relname );
267-
268- if (!allowSystemTableMods && IsSystemRelationName (newrelname ))
269- elog (ERROR ,"renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs" ,
270- newrelname );
271-
272263/*
273264 * Grab an exclusive lock on the target table or index, which we will
274265 * NOT release until end of transaction.
275266 */
276- targetrelation = relation_openrv ( relation ,AccessExclusiveLock );
267+ targetrelation = relation_open ( relid ,AccessExclusiveLock );
277268
278269namespaceId = RelationGetNamespace (targetrelation );
279- reloid = RelationGetRelid (targetrelation );
280- relkind = targetrelation -> rd_rel -> relkind ;
281- relhastriggers = (targetrelation -> rd_rel -> reltriggers > 0 );
282270
283- /*
284- * Close rel, but keep exclusive lock!
285- */
286- relation_close (targetrelation ,NoLock );
271+ /* Validity checks */
272+ if (!allowSystemTableMods &&
273+ IsSystemRelationName (RelationGetRelationName (targetrelation )))
274+ elog (ERROR ,"renamerel: system relation \"%s\" may not be renamed" ,
275+ RelationGetRelationName (targetrelation ));
287276
288- /*
289- * Flush the relcache entry (easier than trying to change it at
290- * exactly the right instant).It'll get rebuilt on next access to
291- * relation.
292- *
293- * XXX What if relation is myxactonly?
294- *
295- * XXX this is probably not necessary anymore?
296- */
297- RelationIdInvalidateRelationCacheByRelationId (reloid );
277+ if (!allowSystemTableMods && IsSystemRelationName (newrelname ))
278+ elog (ERROR ,"renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs" ,
279+ newrelname );
280+
281+ relkind = targetrelation -> rd_rel -> relkind ;
282+ relhastriggers = (targetrelation -> rd_rel -> reltriggers > 0 );
298283
299284/*
300285 * Find relation's pg_class tuple, and make sure newrelname isn't in
@@ -303,11 +288,11 @@ renamerel(const RangeVar *relation, const char *newrelname)
303288relrelation = heap_openr (RelationRelationName ,RowExclusiveLock );
304289
305290reltup = SearchSysCacheCopy (RELOID ,
306- PointerGetDatum (reloid ),
291+ PointerGetDatum (relid ),
3072920 ,0 ,0 );
308293if (!HeapTupleIsValid (reltup ))
309294elog (ERROR ,"renamerel: relation \"%s\" does not exist" ,
310- relation -> relname );
295+ RelationGetRelationName ( targetrelation ) );
311296
312297if (get_relname_relid (newrelname ,namespaceId )!= InvalidOid )
313298elog (ERROR ,"renamerel: relation \"%s\" exists" ,newrelname );
@@ -332,7 +317,8 @@ renamerel(const RangeVar *relation, const char *newrelname)
332317 * Also rename the associated type, if any.
333318 */
334319if (relkind != RELKIND_INDEX )
335- TypeRename (relation -> relname ,namespaceId ,newrelname );
320+ TypeRename (RelationGetRelationName (targetrelation ),namespaceId ,
321+ newrelname );
336322
337323/*
338324 * If it's a view, must also rename the associated ON SELECT rule.
@@ -342,7 +328,7 @@ renamerel(const RangeVar *relation, const char *newrelname)
342328char * oldrulename ,
343329* newrulename ;
344330
345- oldrulename = MakeRetrieveViewRuleName (relation -> relname );
331+ oldrulename = MakeRetrieveViewRuleName (RelationGetRelationName ( targetrelation ) );
346332newrulename = MakeRetrieveViewRuleName (newrelname );
347333RenameRewriteRule (oldrulename ,newrulename );
348334}
@@ -353,14 +339,21 @@ renamerel(const RangeVar *relation, const char *newrelname)
353339if (relhastriggers )
354340{
355341/* update tgargs where relname is primary key */
356- update_ri_trigger_args (reloid ,
357- relation -> relname ,newrelname ,
342+ update_ri_trigger_args (relid ,
343+ RelationGetRelationName (targetrelation ),
344+ newrelname ,
358345 false, true);
359346/* update tgargs where relname is foreign key */
360- update_ri_trigger_args (reloid ,
361- relation -> relname ,newrelname ,
347+ update_ri_trigger_args (relid ,
348+ RelationGetRelationName (targetrelation ),
349+ newrelname ,
362350 true, true);
363351}
352+
353+ /*
354+ * Close rel, but keep exclusive lock!
355+ */
356+ relation_close (targetrelation ,NoLock );
364357}
365358
366359/*