Skip to content

Commit b70b786

Browse files
committed
Tweak CreateTrigger() so that the OID used in the name of an
RI_ConstraintTrigger is the same OID assigned to the pg_trigger row. This reduces consumption of OIDs and may ease debugging.
1 parent 17b2850 commit b70b786

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/backend/commands/trigger.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.122 2002/07/20 05:16:57 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.123 2002/07/20 19:55:38 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -50,6 +50,14 @@ static void DeferredTriggerExecute(DeferredTriggerEvent event, int itemno,
5050
MemoryContext per_tuple_context);
5151

5252

53+
/*
54+
* Create a trigger. Returns the OID of the created trigger.
55+
*
56+
* forConstraint, if true, says that this trigger is being created to
57+
* implement a constraint. The caller will then be expected to make
58+
* a pg_depend entry linking the trigger to that constraint (and thereby
59+
* to the owning relation(s)).
60+
*/
5361
Oid
5462
CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
5563
{
@@ -94,6 +102,12 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
94102
if (aclresult != ACLCHECK_OK)
95103
aclcheck_error(aclresult, RelationGetRelationName(rel));
96104

105+
/*
106+
* Generate the trigger's OID now, so that we can use it in the name
107+
* if needed.
108+
*/
109+
trigoid = newoid();
110+
97111
/*
98112
* If trigger is an RI constraint, use specified trigger name as
99113
* constraint name and build a unique trigger name instead.
@@ -103,7 +117,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
103117
if (stmt->isconstraint)
104118
{
105119
snprintf(constrtrigname, sizeof(constrtrigname),
106-
"RI_ConstraintTrigger_%u", newoid());
120+
"RI_ConstraintTrigger_%u", trigoid);
107121
trigname = constrtrigname;
108122
constrname = stmt->trigname;
109123
}
@@ -279,10 +293,14 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
279293

280294
tuple = heap_formtuple(tgrel->rd_att, values, nulls);
281295

296+
/* force tuple to have the desired OID */
297+
AssertTupleDescHasOid(tgrel->rd_att);
298+
HeapTupleSetOid(tuple, trigoid);
299+
282300
/*
283301
* Insert tuple into pg_trigger.
284302
*/
285-
trigoid = simple_heap_insert(tgrel, tuple);
303+
simple_heap_insert(tgrel, tuple);
286304

287305
CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
288306
CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);

0 commit comments

Comments
 (0)