@@ -8008,10 +8008,12 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
80088008ReleaseSysCache (partcontup );
80098009
80108010/*
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.
80158017 */
80168018trigrel = heap_open (TriggerRelationId ,RowExclusiveLock );
80178019ScanKeyInit (& key ,
@@ -8024,17 +8026,30 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
80248026while ((trigtup = systable_getnext (scan ))!= NULL )
80258027{
80268028Form_pg_trigger trgform = (Form_pg_trigger )GETSTRUCT (trigtup );
8029+ ObjectAddress trigger ;
80278030
80288031if (trgform -> tgconstrrelid != fk -> conrelid )
80298032continue ;
80308033if (trgform -> tgrelid != fk -> confrelid )
80318034continue ;
80328035
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 ();
80388053}
80398054
80408055systable_endscan (scan );