Re: \d doesn't show partitioned table foreign keys

Lists: pgsql-hackers
From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: \d doesn't show partitioned table foreign keys
Date: 2018-05-14 02:50:40
Message-ID: a66879e5-636f-d4dd-b4a4-92bdca5a828f@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi.

I just noticed $subject, which attached seems to fix, although not sure if
that's the correct fix for the issue.

create table foo (a int primary key);
create table doo (a int primary key);
create table bar (a int references foo references doo) partition by list (a);
create table bar1 partition of bar for values in (1);

\d bar
Table "public.bar"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Partition key: LIST (a)
Number of partitions: 1 (Use \d+ to list them.)

But can see the key on the partition.

\d bar1
Table "public.bar1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Partition of: bar FOR VALUES IN (1)
Foreign-key constraints:
"bar_a_fkey" FOREIGN KEY (a) REFERENCES foo(a)
"bar_a_fkey1" FOREIGN KEY (a) REFERENCES doo(a)

After applying the patch:

\d bar
Table "public.bar"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Partition key: LIST (a)
Foreign-key constraints:
"bar_a_fkey" FOREIGN KEY (a) REFERENCES foo(a)
"bar_a_fkey1" FOREIGN KEY (a) REFERENCES doo(a)
Number of partitions: 1 (Use \d+ to list them.)

Will add this to open items.

Thanks,
Amit

Attachment Content-Type Size
describe-partitioned-table-fkey-v1.patch text/plain 484 bytes

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: \d doesn't show partitioned table foreign keys
Date: 2018-05-14 02:55:41
Message-ID: f7addac2-4f82-2a8c-d04a-6cf20fdf052c@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2018/05/14 11:50, Amit Langote wrote:
> Hi.
>
> I just noticed $subject, which attached seems to fix, although not sure if
> that's the correct fix for the issue.

I updated the comment above the changed code to explain things as I see them.

Attached updated patch.

Thanks,
Amit

Attachment Content-Type Size
describe-partitioned-table-fkey-v2.patch text/plain 709 bytes

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: \d doesn't show partitioned table foreign keys
Date: 2018-05-14 15:38:39
Message-ID: 20180514153839.lc3yx4mqoj6ua34x@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2018-May-14, Amit Langote wrote:

> Hi.
>
> I just noticed $subject, which attached seems to fix, although not sure if
> that's the correct fix for the issue.

The fix looks good to me. Will push shortly.

A related issue is that \d of the referenced table shows both the
partitioned table as well as all of its partitions, which seems too
repetitive. I think we should only list the partitioned table itself.
Thoughts?

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: \d doesn't show partitioned table foreign keys
Date: 2018-05-14 15:49:23
Message-ID: CA+HiwqF-7zY-Ok45qQ928c0gXZD8Nr0Qf-tWEwcnbCSA_5p83w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, May 15, 2018 at 12:38 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
> On 2018-May-14, Amit Langote wrote:
>
>> Hi.
>>
>> I just noticed $subject, which attached seems to fix, although not sure if
>> that's the correct fix for the issue.
>
> The fix looks good to me. Will push shortly.

Thank you.

> A related issue is that \d of the referenced table shows both the
> partitioned table as well as all of its partitions, which seems too
> repetitive. I think we should only list the partitioned table itself.
> Thoughts?

Yeah, I think showing only the partitioned table makes sense, assuming
that the triggers and constraint entries on the partitions are an
implementation detail. Right?

Thanks,
Amit