diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/indexcmds.c | 36 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 24 | ||||
-rw-r--r-- | src/backend/commands/trigger.c | 16 |
3 files changed, 42 insertions, 34 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index bd85099c286..7352b9e341d 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -971,7 +971,8 @@ DefineIndex(Oid relationId, IndexSetParentIndex(cldidx, indexRelationId); if (createdConstraintId != InvalidOid) ConstraintSetParentConstraint(cldConstrOid, - createdConstraintId); + createdConstraintId, + childRelid); if (!cldidx->rd_index->indisvalid) invalidate_parent = true; @@ -2622,35 +2623,34 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid) if (fix_dependencies) { - ObjectAddress partIdx; - /* - * Insert/delete pg_depend rows. If setting a parent, add an - * INTERNAL_AUTO dependency to the parent index; if making standalone, - * remove all existing rows and put back the regular dependency on the - * table. + * Insert/delete pg_depend rows. If setting a parent, add PARTITION + * dependencies on the parent index and the table; if removing a + * parent, delete PARTITION dependencies. */ - ObjectAddressSet(partIdx, RelationRelationId, partRelid); - if (OidIsValid(parentOid)) { + ObjectAddress partIdx; ObjectAddress parentIdx; + ObjectAddress partitionTbl; + ObjectAddressSet(partIdx, RelationRelationId, partRelid); ObjectAddressSet(parentIdx, RelationRelationId, parentOid); - recordDependencyOn(&partIdx, &parentIdx, DEPENDENCY_INTERNAL_AUTO); + ObjectAddressSet(partitionTbl, RelationRelationId, + partitionIdx->rd_index->indrelid); + recordDependencyOn(&partIdx, &parentIdx, + DEPENDENCY_PARTITION_PRI); + recordDependencyOn(&partIdx, &partitionTbl, + DEPENDENCY_PARTITION_SEC); } else { - ObjectAddress partitionTbl; - - ObjectAddressSet(partitionTbl, RelationRelationId, - partitionIdx->rd_index->indrelid); - deleteDependencyRecordsForClass(RelationRelationId, partRelid, RelationRelationId, - DEPENDENCY_INTERNAL_AUTO); - - recordDependencyOn(&partIdx, &partitionTbl, DEPENDENCY_AUTO); + DEPENDENCY_PARTITION_PRI); + deleteDependencyRecordsForClass(RelationRelationId, partRelid, + RelationRelationId, + DEPENDENCY_PARTITION_SEC); } /* make our updates visible */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b66d194b80d..715c6a221cf 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7825,7 +7825,8 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, bool attach_it; Oid constrOid; ObjectAddress parentAddr, - childAddr; + childAddr, + childTableAddr; ListCell *cell; int i; @@ -7966,7 +7967,8 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, systable_endscan(scan); table_close(trigrel, RowExclusiveLock); - ConstraintSetParentConstraint(fk->conoid, parentConstrOid); + ConstraintSetParentConstraint(fk->conoid, parentConstrOid, + RelationGetRelid(partRel)); CommandCounterIncrement(); attach_it = true; break; @@ -8013,8 +8015,14 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, 1, false, true); subclone = lappend_oid(subclone, constrOid); + /* Set up partition dependencies for the new constraint */ ObjectAddressSet(childAddr, ConstraintRelationId, constrOid); - recordDependencyOn(&childAddr, &parentAddr, DEPENDENCY_INTERNAL_AUTO); + recordDependencyOn(&childAddr, &parentAddr, + DEPENDENCY_PARTITION_PRI); + ObjectAddressSet(childTableAddr, RelationRelationId, + RelationGetRelid(partRel)); + recordDependencyOn(&childAddr, &childTableAddr, + DEPENDENCY_PARTITION_SEC); fkconstraint = makeNode(Constraint); /* for now this is all we need */ @@ -14893,7 +14901,8 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel) /* bingo. */ IndexSetParentIndex(attachrelIdxRels[i], idx); if (OidIsValid(constraintOid)) - ConstraintSetParentConstraint(cldConstrOid, constraintOid); + ConstraintSetParentConstraint(cldConstrOid, constraintOid, + RelationGetRelid(attachrel)); update_relispartition(NULL, cldIdxId, true); found = true; break; @@ -15151,7 +15160,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name) constrOid = get_relation_idx_constraint_oid(RelationGetRelid(partRel), idxid); if (OidIsValid(constrOid)) - ConstraintSetParentConstraint(constrOid, InvalidOid); + ConstraintSetParentConstraint(constrOid, InvalidOid, InvalidOid); index_close(idx, NoLock); } @@ -15183,7 +15192,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name) } /* unset conparentid and adjust conislocal, coninhcount, etc. */ - ConstraintSetParentConstraint(fk->conoid, InvalidOid); + ConstraintSetParentConstraint(fk->conoid, InvalidOid, InvalidOid); /* * Make the action triggers on the referenced relation. When this was @@ -15419,7 +15428,8 @@ ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name) /* All good -- do it */ IndexSetParentIndex(partIdx, RelationGetRelid(parentIdx)); if (OidIsValid(constraintOid)) - ConstraintSetParentConstraint(cldConstrId, constraintOid); + ConstraintSetParentConstraint(cldConstrId, constraintOid, + RelationGetRelid(partTbl)); update_relispartition(NULL, partIdxId, true); pfree(attmap); diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 0b245a613e0..409bee24f89 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -1012,17 +1012,11 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, * User CREATE TRIGGER, so place dependencies. We make trigger be * auto-dropped if its relation is dropped or if the FK relation is * dropped. (Auto drop is compatible with our pre-7.3 behavior.) - * - * Exception: if this trigger comes from a parent partitioned table, - * then it's not separately drop-able, but goes away if the partition - * does. */ referenced.classId = RelationRelationId; referenced.objectId = RelationGetRelid(rel); referenced.objectSubId = 0; - recordDependencyOn(&myself, &referenced, OidIsValid(parentTriggerOid) ? - DEPENDENCY_INTERNAL_AUTO : - DEPENDENCY_AUTO); + recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO); if (OidIsValid(constrrelid)) { @@ -1046,11 +1040,15 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, recordDependencyOn(&referenced, &myself, DEPENDENCY_INTERNAL); } - /* Depends on the parent trigger, if there is one. */ + /* + * If it's a partition trigger, create the partition dependencies. + */ if (OidIsValid(parentTriggerOid)) { ObjectAddressSet(referenced, TriggerRelationId, parentTriggerOid); - recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL_AUTO); + recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_PRI); + ObjectAddressSet(referenced, RelationRelationId, RelationGetRelid(rel)); + recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_SEC); } } |