pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Naoya Anzai <anzai-naoya@mxu.nes.nec.co.jp>
To: pgsql-bugs@postgresql.org
Subject: BUG #5856: pg_attribute.attinhcount is not correct.
Date: Mon, 31 Jan 2011 11:42:31 GMT
Message-ID: <201101311142.p0VBgVGd019556@wwwmaster.postgresql.org> (raw)


The following bug has been logged online:

Bug reference:      5856
Logged by:          Naoya Anzai
Email address:      anzai-naoya@mxu.nes.nec.co.jp
PostgreSQL version: 8.4.5
Operating system:   Red Hat Enterprise Linux Server release 5.5
Description:        pg_attribute.attinhcount is not correct.
Details: 

In PostgreSQL8.4.5, I found that the catalog pg_attribute.attinhcount is not
correct.

I executed the following queries.

--------------------------------------------------------------------------
create table "3_grandchild"();
create table "2_child"();
create table "1_parent"();

alter table "3_grandchild" inherit "2_child";
alter table "2_child" inherit "1_parent";

alter table "3_grandchild" add column c1 text;
alter table "2_child" add column c1 text;
alter table "1_parent" add column c1 text;

select c.relname,a.attname,a.attinhcount from pg_attribute a,pg_class c 
where a.attrelid=c.oid 
and relname in ('1_parent','2_child','3_grandchild') 
and attname not in('xmax','xmin','cmin','cmax','tableoid','ctid') 
order by relname;

    relname    | attname | attinhcount
 --------------+---------+-------------
  1_parent     | c1      |           0
  2_child      | c1      |           1
  3_grandchild | c1      |           2
 (3 rows)
--------------------------------------------------------------------------

"3_grandchild"'s attinhcount should be 1.

When column "c1" is added  to "1_parent", "ATExecAddColumn" is 
executed for "2_child" and "3_grandchild" too.
If column "c1" already exists on "2_child" and "3_grandchild", 
"ATExecAddColumn" increment pg_attribute.attinhcount of "c1".

 childatt->attinhcount++;     # src/backend/commands/tablecmds.c:3560

But pg_attribute.attinhcount should be the number of parent table (column) 
that inherited directly.
So pg_attribute.attinhcount of "3_grandchild"."c1" should not be
incremented.

In this case,an error occurs when the following operations are
executed.

--------------------------------------------------------------------------
alter table "1_parent" drop column c1;
alter table "2_child" drop column c1;
alter table "3_grandchild" drop column c1;
 ERROR:  cannot drop inherited column "c1"

select c.relname,a.attname,a.attinhcount from pg_attribute a,pg_class c 
where a.attrelid=c.oid 
and relname in ('1_parent','2_child','3_grandchild') 
and attname not in('xmax','xmin','cmin','cmax','tableoid','ctid') 
order by relname;

    relname    | attname | attinhcount
 --------------+---------+-------------
  1_parent     | c1      |           0
  2_child      | c1      |           0
  3_grandchild | c1      |           1
 (3 rows)
--------------------------------------------------------------------------



view thread (13+ messages)  latest in thread

Message-ID: <201101311142.p0VBgVGd019556@wwwmaster.postgresql.org>
Permalink:  ../201101311142.p0VBgVGd019556@wwwmaster.postgresql.org/
Also on:    postgresql.org/message-id/201101311142.p0VBgVGd019556@wwwmaster.postgresql.org

 · 

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-bugs@postgresql.org
  Cc: anzai-naoya@mxu.nes.nec.co.jp
  Subject: Re: BUG #5856: pg_attribute.attinhcount is not correct.
  In-Reply-To: <201101311142.p0VBgVGd019556@wwwmaster.postgresql.org>
  References: <201101311142.p0VBgVGd019556@wwwmaster.postgresql.org>

* 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