Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJrlt-0004Wd-1x for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Dec 2016 01:02:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cJrls-0005up-Dv for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Dec 2016 01:02:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cJrkS-0004Kx-T7 for pgsql-hackers@postgresql.org; Thu, 22 Dec 2016 01:00:45 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJrkO-00062q-NA for pgsql-hackers@postgresql.org; Thu, 22 Dec 2016 01:00:43 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id uBM10UJd030846; Thu, 22 Dec 2016 10:00:31 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id AEB7E5F63F; Thu, 22 Dec 2016 10:00:30 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 9707B5F631; Thu, 22 Dec 2016 10:00:30 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTP id 5F769400AF8; Thu, 22 Dec 2016 10:00:30 +0900 (JST) Subject: Re: [COMMITTERS] pgsql: Implement table partitioning. References: <20161220172214.xjgratgkhqhsp7gk@alvherre.pgsql> From: Amit Langote Message-ID: Date: Thu, 22 Dec 2016 10:00:18 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------DC53DAC0D6C2CE1579EE106D" To: Robert Haas , Alvaro Herrera Cc: "pgsql-hackers@postgresql.org" X-TM-AS-MML: disable X-Pg-Spam-Score: -5.7 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------DC53DAC0D6C2CE1579EE106D Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 2016/12/22 0:31, Robert Haas wrote: > On Tue, Dec 20, 2016 at 12:22 PM, Alvaro Herrera > 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 --------------DC53DAC0D6C2CE1579EE106D Content-Type: text/x-diff; name="ATExecAttachPartition-improvements-1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ATExecAttachPartition-improvements-1.patch" 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) --------------DC53DAC0D6C2CE1579EE106D Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------DC53DAC0D6C2CE1579EE106D--