On 2016/12/22 0:31, Robert Haas wrote: > On Tue, Dec 20, 2016 at 12:22 PM, Alvaro Herrera > <alvhe...@2ndquadrant.com> wrote: >> Robert Haas wrote: >>> Implement table partitioning. >> >> I thought it was odd to use rd_rel->reloftype as a boolean in >> ATExecAttachPartition, but apparently we do it elsewhere too, so let's >> leave that complaint for another day. > > Ugh. I agree - that's bad style.
Agreed, fixed in the attached patch. >> What I also found off in the same function is that we use >> SearchSysCacheCopyAttName() on each attribute and then don't free the >> result, and don't ever use the returned tuple either. A simple fix, I >> thought, just remove the "Copy" and add a ReleaseSysCache(). > > Or use SearchSysCachExists. Done, too. >> But then I >> noticed this whole thing is rather strange -- why not pass a boolean >> flag down to CreateInheritance() and from there to >> MergeAttributesIntoExisting() to implement the check? That seems less >> duplicative. > > Hmm, that would be another way to do it. MergeAttributesIntoExisting() is called by ATExecAddInherit() as well, where we don't want to check that. Sure, we can only check if child_is_partition, but I thought it'd be better to keep the shared code (between regular inheritance and partitioning) as close to the old close as possible. Attached patch also fixes a couple of other minor issues. Thanks, Amit
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 115b98313e..ee79b726f2 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -12996,7 +12996,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) *existConstraint; SysScanDesc scan; ScanKeyData skey; - HeapTuple tuple; AttrNumber attno; int natts; TupleDesc tupleDesc; @@ -13018,7 +13017,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) errmsg("\"%s\" is already a partition", RelationGetRelationName(attachRel)))); - if (attachRel->rd_rel->reloftype) + if (OidIsValid(attachRel->rd_rel->reloftype)) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot attach a typed table as partition"))); @@ -13119,9 +13118,10 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) if (attribute->attisdropped) continue; - /* Find same column in parent (matching on column name). */ - tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), attributeName); - if (!HeapTupleIsValid(tuple)) + /* Try to find the column in parent (matching on column name) */ + if (!SearchSysCacheExists2(ATTNAME, + ObjectIdGetDatum(RelationGetRelid(rel)), + CStringGetDatum(attributeName))) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("table \"%s\" contains column \"%s\" not found in parent \"%s\"", @@ -13167,7 +13167,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) * There is a case in which we cannot rely on just the result of the * proof. */ - tupleDesc = RelationGetDescr(attachRel); attachRel_constr = tupleDesc->constr; existConstraint = NIL; if (attachRel_constr != NULL)
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers