Re: patch for check constraints using multiple inheritance

Yeb Havinga <yebhavinga@gmail.com>

From: Yeb Havinga <yebhavinga@gmail.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Henk Enting <h.d.enting@mgrid.net>, pgsql-hackers@postgresql.org
Date: 2010-08-02T13:20:47Z
Lists: pgsql-hackers

Attachments

Robert Haas wrote:
> I agree that's the crux of the problem, but I can't see solving it
> with a global variable.  I realize you were just testing...
>   
Yes it was just a test. However, somewhere information must be kept or 
altered so it can be detected that a relation has already been visited, 
i.e. it is a multiple inheriting child. The other solutions I could 
think of are more intrusive (i.e. definitionin ATController and passing 
as parameter).

The attached patch uses the globally defined list. After ATPrepCmd the 
list pointer is reset to NIL, the list not freed since the allocs are 
done in a memory context soon to be deleted (PortalHeapMemory). It 
passes regression as well as the script below.

regards,
Yeb Havinga


DROP SCHEMA IF EXISTS test_inheritance CASCADE;
CREATE SCHEMA test_inheritance;
SET search_path TO test_inheritance;

CREATE TABLE top (i int);
CREATE TABLE mid1 () INHERITS (top);
CREATE TABLE mid2 () INHERITS (top);
CREATE TABLE bottom () INHERITS (mid1, mid2);
CREATE TABLE basement () INHERITS (bottom);

ALTER TABLE top
ADD COLUMN a_table_column integer,
ADD COLUMN a_table_column2 integer;

ALTER TABLE top
ADD COLUMN a_table_column3 integer;

ALTER TABLE top
ADD CONSTRAINT  a_check_constraint CHECK (i IN (0,1)),
ADD CONSTRAINT  a_check_constraint2 CHECK (i IN (0,1));

ALTER TABLE top
ADD CONSTRAINT  a_check_constraint3 CHECK (i IN (0,1));

SELECT t.oid, t.relname, a.attinhcount
FROM pg_class t
JOIN pg_attribute a ON (a.attrelid = t.oid)
JOIN pg_namespace n ON (t.relnamespace = n.oid)
WHERE n.nspname = 'test_inheritance' AND a.attname LIKE 'a_table_column%'
ORDER BY oid;

SELECT t.oid, t.relname, c.coninhcount
FROM pg_class t
JOIN pg_constraint c ON (c.conrelid = t.oid)
JOIN pg_namespace n ON (t.relnamespace = n.oid)
WHERE n.nspname = 'test_inheritance'
ORDER BY oid;