diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-01-24 11:18:35 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-01-24 11:25:29 -0300 |
commit | 19184fcc09739abf75ccdada965ed6135c6d07c3 (patch) | |
tree | 40be6ce34a7f7be7c23aa63855166f25ff8f1f94 | |
parent | fd1afdbafd4fbb0ce23a3f319adc177e4cf8fe99 (diff) | |
download | postgresql-19184fcc09739abf75ccdada965ed6135c6d07c3.tar.gz postgresql-19184fcc09739abf75ccdada965ed6135c6d07c3.zip |
Simplify coding to detach constraints when detaching partition
The original coding was too baroque and led to an use-after-release
mistake, noticed by buildfarm member prion.
Discussion: https://postgr.es/m/21693.1548305934@sss.pgh.pa.us
-rw-r--r-- | src/backend/commands/tablecmds.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 738c1781078..887c19c3eff 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -15106,24 +15106,14 @@ ATExecDetachPartition(Relation rel, RangeVar *name) idx = index_open(idxid, AccessExclusiveLock); IndexSetParentIndex(idx, InvalidOid); update_relispartition(classRel, idxid, false); - index_close(idx, NoLock); - - /* - * Detach any constraints associated with the index too. Only UNIQUE - * and PRIMARY KEY index constraints can be inherited, so no need - * to check for others. - */ - if (!idx->rd_index->indisprimary && !idx->rd_index->indisunique) - continue; + /* If there's a constraint associated with the index, detach it too */ constrOid = get_relation_idx_constraint_oid(RelationGetRelid(partRel), idxid); - if (!OidIsValid(constrOid)) - elog(ERROR, "missing pg_constraint entry of index \"%s\" of partition \"%s\"", - RelationGetRelationName(idx), - RelationGetRelationName(partRel)); + if (OidIsValid(constrOid)) + ConstraintSetParentConstraint(constrOid, InvalidOid); - ConstraintSetParentConstraint(constrOid, InvalidOid); + index_close(idx, NoLock); } table_close(classRel, RowExclusiveLock); |