@@ -7919,10 +7919,12 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
7919
7919
ReleaseSysCache (partcontup );
7920
7920
7921
7921
/*
7922
- * Looks good! Attach this constraint. Note that the action
7923
- * triggers are no longer needed, so remove them. We identify
7924
- * them because they have our constraint OID, as well as being
7925
- * on the referenced rel.
7922
+ * Looks good! Attach this constraint. The action triggers in
7923
+ * the new partition become redundant -- the parent table already
7924
+ * has equivalent ones, and those will be able to reach the
7925
+ * partition. Remove the ones in the partition. We identify them
7926
+ * because they have our constraint OID, as well as being on the
7927
+ * referenced rel.
7926
7928
*/
7927
7929
trigrel = heap_open (TriggerRelationId , RowExclusiveLock );
7928
7930
ScanKeyInit (& key ,
@@ -7935,17 +7937,30 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
7935
7937
while ((trigtup = systable_getnext (scan )) != NULL )
7936
7938
{
7937
7939
Form_pg_trigger trgform = (Form_pg_trigger ) GETSTRUCT (trigtup );
7940
+ ObjectAddress trigger ;
7938
7941
7939
7942
if (trgform -> tgconstrrelid != fk -> conrelid )
7940
7943
continue ;
7941
7944
if (trgform -> tgrelid != fk -> confrelid )
7942
7945
continue ;
7943
7946
7944
- deleteDependencyRecordsForClass (TriggerRelationId ,
7945
- trgform -> oid ,
7946
- ConstraintRelationId ,
7947
- DEPENDENCY_INTERNAL );
7948
- CatalogTupleDelete (trigrel , & trigtup -> t_self );
7947
+ /*
7948
+ * The constraint is originally set up to contain this trigger
7949
+ * as an implementation object, so there's a dependency record
7950
+ * that links the two; however, since the trigger is no longer
7951
+ * needed, we remove the dependency link in order to be able
7952
+ * to drop the trigger while keeping the constraint intact.
7953
+ */
7954
+ deleteDependencyRecordsFor (TriggerRelationId ,
7955
+ trgform -> oid ,
7956
+ false);
7957
+ /* make dependency deletion visible to performDeletion */
7958
+ CommandCounterIncrement ();
7959
+ ObjectAddressSet (trigger , TriggerRelationId ,
7960
+ trgform -> oid );
7961
+ performDeletion (& trigger , DROP_RESTRICT , 0 );
7962
+ /* make trigger drop visible, in case the loop iterates */
7963
+ CommandCounterIncrement ();
7949
7964
}
7950
7965
7951
7966
systable_endscan (scan );
0 commit comments