Re: Bug in MergeAttributesIntoExisting() function. - Mailing list pgsql-hackers

From Rushabh Lathia
Subject Re: Bug in MergeAttributesIntoExisting() function.
Date
Msg-id CAGPqQf3T1mC_1-rm2QrEr6z6ujuO9+zFUodA_p3kz_S8pD8SNA@mail.gmail.com
Whole thread Raw
In response to Bug in MergeAttributesIntoExisting() function.  (amul sul <sul_amul@yahoo.co.in>)
Responses Re: Bug in MergeAttributesIntoExisting() function.  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers


On Mon, Jan 4, 2016 at 4:41 PM, amul sul <sul_amul@yahoo.co.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


----------------------

Seems like you missed following command in the demonstration test:

ALTER TABLE c2 INHERIT p1;
 
You can see columns are not dropped from child c2 table, which we have inherited using ALTER command.


I took a quick look at this and did some testing. Patch looks good to me.
ALTER TABLE INHERIT missing the attislocal = false check.


Regards,
Amul Sul

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




--
Rushabh Lathia

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Keyword classifications
Next
From: Andreas Karlsson
Date:
Subject: Re: \x auto and EXPLAIN