88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.62 2001/11/1200:46:36 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.63 2001/11/1201:34:50 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
4141#include "utils/temprel.h"
4242
4343
44- #define RI_TRIGGER_PK 1/* is a trigger on the PK relation */
45- #define RI_TRIGGER_FK 2/* is a trigger on the FK relation */
44+ #define RI_TRIGGER_PK 1/* is a trigger on the PK relation */
45+ #define RI_TRIGGER_FK 2/* is a trigger on the FK relation */
4646#define RI_TRIGGER_NONE 0/* is not an RI trigger function */
4747
48- static int ri_trigger_type (Oid tgfoid );
48+ static int ri_trigger_type (Oid tgfoid );
4949static void update_ri_trigger_args (Oid relid ,
50- const char * oldname ,
51- const char * newname ,
52- bool fk_scan ,
53- bool update_relname );
50+ const char * oldname ,
51+ const char * newname ,
52+ bool fk_scan ,
53+ bool update_relname );
5454
5555
5656/*
@@ -251,7 +251,7 @@ renameatt(char *relname,
251251if (targetrelation -> rd_rel -> reltriggers > 0 )
252252{
253253/* update tgargs column reference where att is primary key */
254- update_ri_trigger_args (RelationGetRelid (targetrelation ),
254+ update_ri_trigger_args (RelationGetRelid (targetrelation ),
255255oldattname ,newattname ,
256256 false, false);
257257/* update tgargs column reference where att is foreign key */
@@ -425,49 +425,49 @@ ri_trigger_type(Oid tgfoid)
425425 */
426426static void
427427update_ri_trigger_args (Oid relid ,
428- const char * oldname ,
429- const char * newname ,
430- bool fk_scan ,
431- bool update_relname )
428+ const char * oldname ,
429+ const char * newname ,
430+ bool fk_scan ,
431+ bool update_relname )
432432{
433- Relation tgrel ;
434- Relation irel ;
435- ScanKeyData skey [1 ];
436- IndexScanDesc idxtgscan ;
433+ Relation tgrel ;
434+ Relation irel ;
435+ ScanKeyData skey [1 ];
436+ IndexScanDesc idxtgscan ;
437437RetrieveIndexResult idxres ;
438- Datum values [Natts_pg_trigger ];
439- char nulls [Natts_pg_trigger ];
440- char replaces [Natts_pg_trigger ];
438+ Datum values [Natts_pg_trigger ];
439+ char nulls [Natts_pg_trigger ];
440+ char replaces [Natts_pg_trigger ];
441441
442442tgrel = heap_openr (TriggerRelationName ,RowExclusiveLock );
443443if (fk_scan )
444444irel = index_openr (TriggerConstrRelidIndex );
445445else
446446irel = index_openr (TriggerRelidIndex );
447447
448- ScanKeyEntryInitialize (& skey [0 ],0x0 ,
448+ ScanKeyEntryInitialize (& skey [0 ],0x0 ,
4494491 ,/* always column 1 of index */
450450F_OIDEQ ,
451451ObjectIdGetDatum (relid ));
452452idxtgscan = index_beginscan (irel , false,1 ,skey );
453-
453+
454454while ((idxres = index_getnext (idxtgscan ,ForwardScanDirection ))!= NULL )
455455{
456- HeapTupleData tupledata ;
457- Buffer buffer ;
458- HeapTuple tuple ;
459- Form_pg_trigger pg_trigger ;
460- bytea * val ;
461- bytea * newtgargs ;
462- bool isnull ;
463- int tg_type ;
464- bool examine_pk ;
465- bool changed ;
466- int tgnargs ;
467- int i ;
468- int newlen ;
469- const char * arga [RI_MAX_ARGUMENTS ];
470- const char * argp ;
456+ HeapTupleData tupledata ;
457+ Buffer buffer ;
458+ HeapTuple tuple ;
459+ Form_pg_trigger pg_trigger ;
460+ bytea * val ;
461+ bytea * newtgargs ;
462+ bool isnull ;
463+ int tg_type ;
464+ bool examine_pk ;
465+ bool changed ;
466+ int tgnargs ;
467+ int i ;
468+ int newlen ;
469+ const char * arga [RI_MAX_ARGUMENTS ];
470+ const char * argp ;
471471
472472tupledata .t_self = idxres -> heap_iptr ;
473473heap_fetch (tgrel ,SnapshotNow ,& tupledata ,& buffer ,idxtgscan );
@@ -487,8 +487,8 @@ update_ri_trigger_args(Oid relid,
487487/*
488488 * It is an RI trigger, so parse the tgargs bytea.
489489 *
490- * NB: we assume the field will never be compressed or moved
491- *out of line; so does trigger.c ...
490+ * NB: we assume the field will never be compressed or moved out of
491+ * line; so does trigger.c ...
492492 */
493493tgnargs = pg_trigger -> tgnargs ;
494494val = (bytea * )fastgetattr (tuple ,
@@ -505,15 +505,15 @@ update_ri_trigger_args(Oid relid,
505505for (i = 0 ;i < tgnargs ;i ++ )
506506{
507507arga [i ]= argp ;
508- argp += strlen (argp )+ 1 ;
508+ argp += strlen (argp )+ 1 ;
509509}
510510
511511/*
512512 * Figure out which item(s) to look at. If the trigger is
513- * primary-key type and attached to my rel, I should look at
514- *the PK fields; if it is foreign-key type and attached to my
515- *rel, I should look at the FK fields. But the opposite rule
516- *holds when examining triggers found by tgconstrrel search.
513+ * primary-key type and attached to my rel, I should look at the
514+ * PK fields; if it is foreign-key type and attached to my rel, I
515+ * should look at the FK fields. But the opposite rule holds when
516+ * examining triggers found by tgconstrrel search.
517517 */
518518examine_pk = (tg_type == RI_TRIGGER_PK )== (!fk_scan );
519519
@@ -590,27 +590,27 @@ update_ri_trigger_args(Oid relid,
590590simple_heap_update (tgrel ,& tuple -> t_self ,tuple );
591591
592592{
593- Relation irelations [Num_pg_attr_indices ];
593+ Relation irelations [Num_pg_attr_indices ];
594+
595+ CatalogOpenIndices (Num_pg_trigger_indices ,Name_pg_trigger_indices ,irelations );
596+ CatalogIndexInsert (irelations ,Num_pg_trigger_indices ,tgrel ,tuple );
597+ CatalogCloseIndices (Num_pg_trigger_indices ,irelations );
598+ }
594599
595- CatalogOpenIndices (Num_pg_trigger_indices ,Name_pg_trigger_indices ,irelations );
596- CatalogIndexInsert (irelations ,Num_pg_trigger_indices ,tgrel ,tuple );
597- CatalogCloseIndices (Num_pg_trigger_indices ,irelations );
598- }
599-
600600/* free up our scratch memory */
601601pfree (newtgargs );
602602heap_freetuple (tuple );
603603}
604604
605- index_endscan (idxtgscan );
606- index_close (irel );
605+ index_endscan (idxtgscan );
606+ index_close (irel );
607607
608608heap_close (tgrel ,RowExclusiveLock );
609609
610610/*
611- * Increment cmd counter to make updates visible; this is needed
612- *in case the same tuple has to be updated again by next pass
613- *(can happen in case of a self-referential FK relationship).
611+ * Increment cmd counter to make updates visible; this is needed in
612+ * case the same tuple has to be updated again by next pass (can
613+ * happen in case of a self-referential FK relationship).
614614 */
615- CommandCounterIncrement ();
615+ CommandCounterIncrement ();
616616}