Re: A bug in mapping attributes in ATExecAttachPartition()

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Amit Langote <amitlangote09(at)gmail(dot)com>
Subject: Re: A bug in mapping attributes in ATExecAttachPartition()
Date: 2017-08-02 01:23:06
Message-ID: 1ec44ca5-ffa3-72a4-2323-0edc3fc284f1@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for reviewing.

On 2017/08/02 2:54, Robert Haas wrote:
> On Mon, Jul 31, 2017 at 11:10 PM, Amit Langote
> <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> wrote:
>> OK, these cosmetic changes are now in attached patch 0001.
>
> Regarding 0001:
>
> - List *childrels;
> + List *attachRel_children;
>
> I sorta don't see why this is necessary, or better.

Since ATExecAttachPartition() deals with the possibility that the table
being attached itself might be partitioned, someone reading the code might
find it helpful to get some clue about whose partitions/children a
particular piece of code is dealing with - AT's target table's (rel's) or
those of the table being attached (attachRel's)? IMHO, attachRel_children
makes it abundantly clear that it is in fact the partitions of the table
being attached that are being manipulated.

> /* It's safe to skip the validation scan after all */
> if (skip_validate)
> + {
> + /* No need to scan the table after all. */
>
> The existing comment should be removed along with adding the new one, I think.

Oops, fixed.

> - 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);
>
> This works out to a cosmetic change, I guess, but it makes it worse...

Not sure what you mean by "makes it worse". The comment above says that
we should skip partitioned tables from being scheduled for heap scan. The
new code still does that. We should close part_rel before continuing to
consider the next partition, but mustn't do that if part_rel is really
attachRel. The new code does that too. Stylistically worse?

Thanks,
Amit

Attachment Content-Type Size
0001-Cosmetic-fixes-for-code-in-ATExecAttachPartition.patch text/plain 3.0 KB
0002-Fix-lock-upgrade-deadlock-hazard-in-ATExecAttachPart.patch text/plain 2.8 KB
0003-Cope-with-differing-attnos-in-ATExecAttachPartition-.patch text/plain 7.9 KB
0004-Teach-ATExecAttachPartition-to-skip-validation-in-mo.patch text/plain 11.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2017-08-02 01:23:24 Re: BUG #14758: Segfault with logical replication on a function index
Previous Message Noah Misch 2017-08-02 00:52:04 Re: pg_stop_backup(wait_for_archive := true) on standby server