From d67fac574abb085db33e00711ded0515d71d99eb Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 1 Aug 2017 10:12:39 +0900 Subject: [PATCH 1/4] Cosmetic fixes for code in ATExecAttachPartition --- src/backend/commands/tablecmds.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index bb00858ad1..1307dc5893 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -13421,7 +13421,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) { Relation attachRel, catalog; - List *childrels; + List *attachRel_children; TupleConstr *attachRel_constr; List *partConstraint, *existConstraint; @@ -13490,9 +13490,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) * Prevent circularity by seeing if rel is a partition of attachRel. (In * particular, this disallows making a rel a partition of itself.) */ - childrels = find_all_inheritors(RelationGetRelid(attachRel), - AccessShareLock, NULL); - if (list_member_oid(childrels, RelationGetRelid(rel))) + attachRel_children = find_all_inheritors(RelationGetRelid(attachRel), + AccessShareLock, NULL); + if (list_member_oid(attachRel_children, RelationGetRelid(rel))) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), errmsg("circular inheritance not allowed"), @@ -13684,19 +13684,16 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) skip_validate = true; } - /* It's safe to skip the validation scan after all */ if (skip_validate) + { + /* No need to scan the table after all. */ ereport(INFO, (errmsg("partition constraint for table \"%s\" is implied by existing constraints", RelationGetRelationName(attachRel)))); - - /* - * Set up to have the table be scanned to validate the partition - * constraint (see partConstraint above). If it's a partitioned table, we - * instead schedule its leaf partitions to be scanned. - */ - if (!skip_validate) + } + else { + /* Constraints proved insufficient, so we need to scan the table. */ List *all_parts; ListCell *lc; @@ -13721,17 +13718,17 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) part_rel = attachRel; /* - * Skip if it's a partitioned table. Only RELKIND_RELATION - * relations (ie, leaf partitions) need to be scanned. + * Skip if the partition is itself a partitioned table. We can + * only ever scan RELKIND_RELATION relations. */ - if (part_rel != attachRel && - part_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + if (part_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) { - heap_close(part_rel, NoLock); + if (part_rel != attachRel) + heap_close(part_rel, NoLock); continue; } - /* Grab a work queue entry */ + /* Grab a work queue entry. */ tab = ATGetQueueEntry(wqueue, part_rel); /* Adjust constraint to match this partition */ -- 2.11.0