@@ -8008,10 +8008,12 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
8008
8008
ReleaseSysCache (partcontup );
8009
8009
8010
8010
/*
8011
- * Looks good! Attach this constraint. Note that the action
8012
- * triggers are no longer needed, so remove them. We identify
8013
- * them because they have our constraint OID, as well as being
8014
- * on the referenced rel.
8011
+ * Looks good! Attach this constraint. The action triggers in
8012
+ * the new partition become redundant -- the parent table already
8013
+ * has equivalent ones, and those will be able to reach the
8014
+ * partition. Remove the ones in the partition. We identify them
8015
+ * because they have our constraint OID, as well as being on the
8016
+ * referenced rel.
8015
8017
*/
8016
8018
trigrel = heap_open (TriggerRelationId , RowExclusiveLock );
8017
8019
ScanKeyInit (& key ,
@@ -8024,17 +8026,30 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
8024
8026
while ((trigtup = systable_getnext (scan )) != NULL )
8025
8027
{
8026
8028
Form_pg_trigger trgform = (Form_pg_trigger ) GETSTRUCT (trigtup );
8029
+ ObjectAddress trigger ;
8027
8030
8028
8031
if (trgform -> tgconstrrelid != fk -> conrelid )
8029
8032
continue ;
8030
8033
if (trgform -> tgrelid != fk -> confrelid )
8031
8034
continue ;
8032
8035
8033
- deleteDependencyRecordsForClass (TriggerRelationId ,
8034
- HeapTupleGetOid (trigtup ),
8035
- ConstraintRelationId ,
8036
- DEPENDENCY_INTERNAL );
8037
- CatalogTupleDelete (trigrel , & trigtup -> t_self );
8036
+ /*
8037
+ * The constraint is originally set up to contain this trigger
8038
+ * as an implementation object, so there's a dependency record
8039
+ * that links the two; however, since the trigger is no longer
8040
+ * needed, we remove the dependency link in order to be able
8041
+ * to drop the trigger while keeping the constraint intact.
8042
+ */
8043
+ deleteDependencyRecordsFor (TriggerRelationId ,
8044
+ HeapTupleGetOid (trigtup ),
8045
+ false);
8046
+ /* make dependency deletion visible to performDeletion */
8047
+ CommandCounterIncrement ();
8048
+ ObjectAddressSet (trigger , TriggerRelationId ,
8049
+ HeapTupleGetOid (trigtup ));
8050
+ performDeletion (& trigger , DROP_RESTRICT , 0 );
8051
+ /* make trigger drop visible, in case the loop iterates */
8052
+ CommandCounterIncrement ();
8038
8053
}
8039
8054
8040
8055
systable_endscan (scan );
0 commit comments