@ -9844,6 +9844,9 @@ addFkRecurseReferenced(Constraint *fkconstraint, Relation rel,
Oid deleteTriggerOid ,
Oid deleteTriggerOid ,
updateTriggerOid ;
updateTriggerOid ;
Assert ( CheckRelationLockedByMe ( pkrel , ShareRowExclusiveLock , true ) ) ;
Assert ( CheckRelationLockedByMe ( rel , ShareRowExclusiveLock , true ) ) ;
/*
/*
* Create the action triggers that enforce the constraint .
* Create the action triggers that enforce the constraint .
*/
*/
@ -9870,6 +9873,7 @@ addFkRecurseReferenced(Constraint *fkconstraint, Relation rel,
Oid partIndexId ;
Oid partIndexId ;
ObjectAddress address ;
ObjectAddress address ;
/* XXX would it be better to acquire these locks beforehand? */
partRel = table_open ( pd - > oids [ i ] , ShareRowExclusiveLock ) ;
partRel = table_open ( pd - > oids [ i ] , ShareRowExclusiveLock ) ;
/*
/*
@ -9970,7 +9974,9 @@ addFkRecurseReferencing(List **wqueue, Constraint *fkconstraint, Relation rel,
Oid insertTriggerOid ,
Oid insertTriggerOid ,
updateTriggerOid ;
updateTriggerOid ;
AssertArg ( OidIsValid ( parentConstr ) ) ;
Assert ( OidIsValid ( parentConstr ) ) ;
Assert ( CheckRelationLockedByMe ( rel , ShareRowExclusiveLock , true ) ) ;
Assert ( CheckRelationLockedByMe ( pkrel , ShareRowExclusiveLock , true ) ) ;
if ( rel - > rd_rel - > relkind = = RELKIND_FOREIGN_TABLE )
if ( rel - > rd_rel - > relkind = = RELKIND_FOREIGN_TABLE )
ereport ( ERROR ,
ereport ( ERROR ,
@ -10259,13 +10265,8 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
continue ;
continue ;
}
}
/*
/* We need the same lock level that CreateTrigger will acquire */
* Because we ' re only expanding the key space at the referenced side ,
fkRel = table_open ( constrForm - > conrelid , ShareRowExclusiveLock ) ;
* we don ' t need to prevent any operation in the referencing table , so
* AccessShareLock suffices ( assumes that dropping the constraint
* acquires AccessExclusiveLock ) .
*/
fkRel = table_open ( constrForm - > conrelid , AccessShareLock ) ;
indexOid = constrForm - > conindid ;
indexOid = constrForm - > conindid ;
DeconstructFkConstraintRow ( tuple ,
DeconstructFkConstraintRow ( tuple ,
@ -18822,8 +18823,7 @@ DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent,
foreach ( cell , fks )
foreach ( cell , fks )
{
{
ForeignKeyCacheInfo * fk = lfirst ( cell ) ;
ForeignKeyCacheInfo * fk = lfirst ( cell ) ;
HeapTuple contup ,
HeapTuple contup ;
parentConTup ;
Form_pg_constraint conform ;
Form_pg_constraint conform ;
Oid insertTriggerOid ,
Oid insertTriggerOid ,
updateTriggerOid ;
updateTriggerOid ;
@ -18841,13 +18841,6 @@ DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent,
continue ;
continue ;
}
}
Assert ( OidIsValid ( conform - > conparentid ) ) ;
parentConTup = SearchSysCache1 ( CONSTROID ,
ObjectIdGetDatum ( conform - > conparentid ) ) ;
if ( ! HeapTupleIsValid ( parentConTup ) )
elog ( ERROR , " cache lookup failed for constraint %u " ,
conform - > conparentid ) ;
/*
/*
* The constraint on this table must be marked no longer a child of
* The constraint on this table must be marked no longer a child of
* the parent ' s constraint , as do its check triggers .
* the parent ' s constraint , as do its check triggers .
@ -18888,7 +18881,6 @@ DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent,
Oid conffeqop [ INDEX_MAX_KEYS ] ;
Oid conffeqop [ INDEX_MAX_KEYS ] ;
int numfkdelsetcols ;
int numfkdelsetcols ;
AttrNumber confdelsetcols [ INDEX_MAX_KEYS ] ;
AttrNumber confdelsetcols [ INDEX_MAX_KEYS ] ;
AttrMap * attmap ;
Relation refdRel ;
Relation refdRel ;
DeconstructFkConstraintRow ( contup ,
DeconstructFkConstraintRow ( contup ,
@ -18921,19 +18913,19 @@ DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent,
fkconstraint - > old_pktable_oid = InvalidOid ;
fkconstraint - > old_pktable_oid = InvalidOid ;
fkconstraint - > location = - 1 ;
fkconstraint - > location = - 1 ;
attmap = build_attrmap_by_name ( RelationGetDescr ( partRel ) ,
/* set up colnames, used to generate the constraint name */
RelationGetDescr ( rel ) ) ;
for ( int i = 0 ; i < numfks ; i + + )
for ( int i = 0 ; i < numfks ; i + + )
{
{
Form_pg_attribute att ;
Form_pg_attribute att ;
att = TupleDescAttr ( RelationGetDescr ( partRel ) ,
att = TupleDescAttr ( RelationGetDescr ( partRel ) ,
attmap - > attnums [ conkey [ i ] - 1 ] - 1 ) ;
conkey [ i ] - 1 ) ;
fkconstraint - > fk_attrs = lappend ( fkconstraint - > fk_attrs ,
fkconstraint - > fk_attrs = lappend ( fkconstraint - > fk_attrs ,
makeString ( NameStr ( att - > attname ) ) ) ;
makeString ( NameStr ( att - > attname ) ) ) ;
}
}
refdRel = table_open ( fk - > confrelid , Access ShareLock) ;
refdRel = table_open ( fk - > confrelid , ShareRowExclusiv eLock ) ;
addFkRecurseReferenced ( fkconstraint , partRel ,
addFkRecurseReferenced ( fkconstraint , partRel ,
refdRel ,
refdRel ,
@ -18949,11 +18941,10 @@ DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent,
confdelsetcols ,
confdelsetcols ,
true ,
true ,
InvalidOid , InvalidOid ) ;
InvalidOid , InvalidOid ) ;
table_close ( refdRel , AccessShare Lock) ;
table_close ( refdRel , No Lock) ; /* keep lock till end of xact */
}
}
ReleaseSysCache ( contup ) ;
ReleaseSysCache ( contup ) ;
ReleaseSysCache ( parentConTup ) ;
}
}
list_free_deep ( fks ) ;
list_free_deep ( fks ) ;
if ( trigrel )
if ( trigrel )