Re: Minor inheritance/check bug: Inconsistent behavior

From: Chris Travers <chris(at)metatrontech(dot)com>
To: Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Minor inheritance/check bug: Inconsistent behavior
Date: 2012-08-24 14:18:15
Message-ID: CAPKNUtcm_4G+ybJsu-hA9qs9oe0CCi=9GWyTGgJ2NjjvupiKcQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Aug 24, 2012 at 3:52 AM, Amit Kapila <amit(dot)kapila(at)huawei(dot)com> wrote:
> From: pgsql-bugs-owner(at)postgresql(dot)org
> [mailto:pgsql-bugs-owner(at)postgresql(dot)org] On Behalf Of Tom Lane
> Sent: Friday, August 24, 2012 10:33 AM
> Chris Travers <chris(at)metatrontech(dot)com> writes:
>>> My guess is that tableoid is not known when the check constraint is
>>> checked.
>
>>None of the system columns are set at the time check constraints are
>>checked.
>
> Is there any problem if set tableOID before calling ExecConstarints()?
> I am not sure may be this is not so important problem for which we don't
> want to
> change existing code.

Just to be sure my initial concern is this:

Table inheritance would be easier if there was a way to declare a
constraint such that it prevents insert for some rows on the parent
but not for a child and/or vice versa. This can be used to partition
the primary key between a parent and child tables to avoid some key
overlap issues. My concern was that this was the "clever" solution
that someone would try, insufficiently test, and find out that their
clever solution in fact did nothing except preventing the constraint
from being dropped and later re-applied.

As for the ideal way of looking at addressing this possibility:

I am further not going to speak for the developers here but I do
wonder about system columns generally and check constraints, and
whether the same solution is just to check the check constraint and
error if a system column is checked. Some things seem obvious but
what happens if someone says "this table cannot grow beyind 5 pages
and we will do this by checking against ctid"? If we start pulling
out some system columns for special treatment I am not sure where it
ends. I am assuming that ctid cannot be safely known before the row
is formally stored on disk.

I think the cleanest fix interface-wise is to prevent check
constraints from being added to tables in this case. I don't see it
as a high priority though.

My larger priority is to flag this as a possible thing someone is
likely to try to get around the issues storing rows in both parent and
child tables.

Best Wishes,
Chris Travers

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Euler Taveira 2012-08-24 14:22:33 Re: BUG #7504: corrupted statistics file "pg_stat_tmp/pgstat.stat"
Previous Message Tom Lane 2012-08-24 14:15:44 Re: Minor inheritance/check bug: Inconsistent behavior