Re: Bug in MergeAttributesIntoExisting() function.

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: amul sul <sul_amul(at)yahoo(dot)co(dot)in>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Bug in MergeAttributesIntoExisting() function.
Date: 2016-01-04 14:43:03
Message-ID: CA+HiwqFta2rPuOcaMzXw3mnWdGu0-6hXOd7oike6Au9HKxturA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Jan 4, 2016 at 8:11 PM, amul sul <sul_amul(at)yahoo(dot)co(dot)in> wrote:
> Hi,
>
> In inheritance, child column's pg_attribute.attislocal flag not getting updated, if it is inherited using ALTER TABLE <child> INHERIT <parent>.
>
> Due to this, if we try to drop column(s) from parent table, which are not getting drop from child.
> Attached herewith is quick patch fixing this issue.
>
>
> ----------------------Demonstration:
> ----------------------
> CREATE TABLE p1 (a int , b int, c int, d int);
>
> CREATE TABLE c1 () inherits (p1);CREATE TABLE c2 (a int , b int, c int, d int);
>
>
> --Drop parent's column
> ALTER TABLE p1 DROP COLUMN b;
> ALTER TABLE p1 DROP COLUMN c;
> ALTER TABLE p1 DROP COLUMN d;
>
>
> postgres=# \d p1
> Table "public.p1"
> Column | Type | Modifiers
> --------+---------+-----------
> a | integer |
> Number of child tables: 2 (Use \d+ to list them.)
>
> postgres=# \d c1
> Table "public.c1"
> Column | Type | Modifiers
> --------+---------+-----------
> a | integer |
> Inherits: p1
>
> postgres=# \d c2
> Table "public.c2"
> Column | Type | Modifiers
> --------+---------+-----------
> a | integer |
> b | integer |
> c | integer |
> d | integer |
> Inherits: p1
>
>
> ----------------------
> You can see columns are not dropped from child c2 table, which we have inherited using ALTER command.

I'm afraid the patched behavior of MergeAttributeIntoExisting() would
be inconsistent with MergeAttributes(). For example, try with the
following:

CREATE TABLE c1(b int) INHERITS(p1);

In this case, MergeAttributes() would cause 'b' to be defined to be a
local attribute (ie, with attislocal = true) and hence would not be
dropped unlike c2 which the patched behavior would cause to be
dropped.

Am I missing something?

Thanks,
Amit

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-01-04 14:47:59 Re: Bug in MergeAttributesIntoExisting() function.
Previous Message Greg Stark 2016-01-04 14:33:28 Re: pgsql: Further tweaking of print_aligned_vertical().