88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.1 2002/07/12 18:43:15 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.2 2002/07/16 05:53:33 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
3838recordDependencyOn (const ObjectAddress * depender ,
3939 const ObjectAddress * referenced ,
4040 DependencyType behavior )
41+ {
42+ recordMultipleDependencies (depender , referenced , 1 , behavior );
43+ }
44+
45+ /*
46+ * Record multiple dependencies (of the same kind) for a single dependent
47+ * object. This has a little less overhead than recording each separately.
48+ */
49+ void
50+ recordMultipleDependencies (const ObjectAddress * depender ,
51+ const ObjectAddress * referenced ,
52+ int nreferenced ,
53+ DependencyType behavior )
4154{
4255 Relation dependDesc ;
4356 HeapTuple tup ;
4457 int i ;
4558 char nulls [Natts_pg_depend ];
4659 Datum values [Natts_pg_depend ];
4760 Relation idescs [Num_pg_depend_indices ];
61+ bool indices_opened = false;
62+
63+ if (nreferenced <= 0 )
64+ return ; /* nothing to do */
4865
4966 /*
5067 * During bootstrap, do nothing since pg_depend may not exist yet.
@@ -55,44 +72,51 @@ recordDependencyOn(const ObjectAddress *depender,
5572
5673 dependDesc = heap_openr (DependRelationName , RowExclusiveLock );
5774
58- /*
59- * If the referenced object is pinned by the system, there's no real
60- * need to record dependencies on it. This saves lots of space in
61- * pg_depend, so it's worth the time taken to check.
62- */
63- if (!isObjectPinned (referenced , dependDesc ))
75+ memset (nulls , ' ' , sizeof (nulls ));
76+
77+ for (i = 0 ; i < nreferenced ; i ++ , referenced ++ )
6478 {
6579 /*
66- * Record the Dependency. Note we don't bother to check for
67- * duplicate dependencies; there's no harm in them.
80+ * If the referenced object is pinned by the system, there's no real
81+ * need to record dependencies on it. This saves lots of space in
82+ * pg_depend, so it's worth the time taken to check.
6883 */
69- for ( i = 0 ; i < Natts_pg_depend ; ++ i )
84+ if (! isObjectPinned ( referenced , dependDesc ) )
7085 {
71- nulls [i ] = ' ' ;
72- values [i ] = (Datum ) 0 ;
86+ /*
87+ * Record the Dependency. Note we don't bother to check for
88+ * duplicate dependencies; there's no harm in them.
89+ */
90+ values [Anum_pg_depend_classid - 1 ] = ObjectIdGetDatum (depender -> classId );
91+ values [Anum_pg_depend_objid - 1 ] = ObjectIdGetDatum (depender -> objectId );
92+ values [Anum_pg_depend_objsubid - 1 ] = Int32GetDatum (depender -> objectSubId );
93+
94+ values [Anum_pg_depend_refclassid - 1 ] = ObjectIdGetDatum (referenced -> classId );
95+ values [Anum_pg_depend_refobjid - 1 ] = ObjectIdGetDatum (referenced -> objectId );
96+ values [Anum_pg_depend_refobjsubid - 1 ] = Int32GetDatum (referenced -> objectSubId );
97+
98+ values [Anum_pg_depend_deptype - 1 ] = CharGetDatum ((char ) behavior );
99+
100+ tup = heap_formtuple (dependDesc -> rd_att , values , nulls );
101+
102+ simple_heap_insert (dependDesc , tup );
103+
104+ /*
105+ * Keep indices current
106+ */
107+ if (!indices_opened )
108+ {
109+ CatalogOpenIndices (Num_pg_depend_indices , Name_pg_depend_indices , idescs );
110+ indices_opened = true;
111+ }
112+ CatalogIndexInsert (idescs , Num_pg_depend_indices , dependDesc , tup );
113+
114+ heap_freetuple (tup );
73115 }
116+ }
74117
75- values [Anum_pg_depend_classid - 1 ] = ObjectIdGetDatum (depender -> classId );
76- values [Anum_pg_depend_objid - 1 ] = ObjectIdGetDatum (depender -> objectId );
77- values [Anum_pg_depend_objsubid - 1 ] = Int32GetDatum (depender -> objectSubId );
78-
79- values [Anum_pg_depend_refclassid - 1 ] = ObjectIdGetDatum (referenced -> classId );
80- values [Anum_pg_depend_refobjid - 1 ] = ObjectIdGetDatum (referenced -> objectId );
81- values [Anum_pg_depend_refobjsubid - 1 ] = Int32GetDatum (referenced -> objectSubId );
82-
83- values [Anum_pg_depend_deptype - 1 ] = CharGetDatum ((char ) behavior );
84-
85- tup = heap_formtuple (dependDesc -> rd_att , values , nulls );
86-
87- simple_heap_insert (dependDesc , tup );
88-
89- /*
90- * Keep indices current
91- */
92- CatalogOpenIndices (Num_pg_depend_indices , Name_pg_depend_indices , idescs );
93- CatalogIndexInsert (idescs , Num_pg_depend_indices , dependDesc , tup );
118+ if (indices_opened )
94119 CatalogCloseIndices (Num_pg_depend_indices , idescs );
95- }
96120
97121 heap_close (dependDesc , RowExclusiveLock );
98122}
0 commit comments