pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Robert Haas <robertmhaas@gmail.com>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: [COMMITTERS] pgsql: Implement table partitioning.
Date: Thu, 22 Dec 2016 10:00:18 +0900
Message-ID: <fc87efc2-ee69-d18b-ecb7-b0cc1ad6f045@lab.ntt.co.jp> (raw)
In-Reply-To: <CA+TgmoaQLDUAdjBNe1hfSCj5SW+8HnsnDwTbGZUkSmHygG-V9w@mail.gmail.com>
References: <E1cEgoz-0001H4-UP@gemulon.postgresql.org>
	<20161220172214.xjgratgkhqhsp7gk@alvherre.pgsql>
	<CA+TgmoaQLDUAdjBNe1hfSCj5SW+8HnsnDwTbGZUkSmHygG-V9w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 2016/12/22 0:31, Robert Haas wrote:
> On Tue, Dec 20, 2016 at 12:22 PM, Alvaro Herrera
> <alvherre@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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

ATExecAttachPartition-improvements-1.patch (text/x-diff, 1.8K) download 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)

view thread (36+ messages)  latest in thread

Message-ID: <fc87efc2-ee69-d18b-ecb7-b0cc1ad6f045@lab.ntt.co.jp>
Permalink:  ../fc87efc2-ee69-d18b-ecb7-b0cc1ad6f045@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/fc87efc2-ee69-d18b-ecb7-b0cc1ad6f045@lab.ntt.co.jp

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: Langote_Amit_f8@lab.ntt.co.jp, robertmhaas@gmail.com, alvherre@2ndquadrant.com, pgsql-hackers@postgresql.org
  Subject: Re: [COMMITTERS] pgsql: Implement table partitioning.
  In-Reply-To: <fc87efc2-ee69-d18b-ecb7-b0cc1ad6f045@lab.ntt.co.jp>
  References: <E1cEgoz-0001H4-UP@gemulon.postgresql.org> <20161220172214.xjgratgkhqhsp7gk@alvherre.pgsql> <CA+TgmoaQLDUAdjBNe1hfSCj5SW+8HnsnDwTbGZUkSmHygG-V9w@mail.gmail.com> <fc87efc2-ee69-d18b-ecb7-b0cc1ad6f045@lab.ntt.co.jp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox