Re: [PATCHES] ADD/DROPS inherits

2006-06-13 Thread Greg Stark

Simon Riggs <[EMAIL PROTECTED]> writes:

> On Mon, 2006-06-12 at 17:39 -0400, Greg Stark wrote:
> 
> > Points I'm uncertain about:
> > 
> > . I throw an elog() error if there's a null conbin for a CHECK constraint. 
> > Is
> >   it possible for a valid CHECK constraint structure to have a null conbin?
> 
> ruleutils shows: elog(ERROR, "null conbin for constraint %u"

I'm unclear what you mean by this. This doesn't look like what I would expect
the error to look like if it was triggered. And the "%u" makes it appear as if
the name of the constraint it "%u" which is passing strange too.

How do I reproduce this?

> > I added some basic (very basic) regression tests 
> 
> Should we fail if columns in the wrong order from the parent? I thought
> that was one of the restrictions you discovered?

I don't think we can complain about wrongly ordered columns. Tom pointed out
something as simple as adding more columns to the parent can create a
non-standard ordering since it adds them after the local columns. And in any
case verifying the order in complicated cases involving multiple parents and
locally defined columns would be nigh impossible anyways.

> Can we test for
>   ALTER TABLE child NO INHERIT parent1 INHERIT parent2
> That was on Hannu's wish list.
> 
> Is INHERIT allowed or disallowed with other ALTER TABLE options?
> If it is allowed, can we test for something that will fail and something
> that would pass, e.g. ALTER TABLE DROP column1 INHERITS parent -- where
> the parent passes on column1.

Both those two cases both work, so you just want more regression tests? 
No problem.

Note that operations aren't done in a strictly left-to-right order. For
instance ADD/DROP columns are done before INHERIT/NO INHERIT.

And "ALTER TABLE child NO INHERIT parent 1, INHERIT parent2" will treat
attislocal subtly different from the reverse.


> When I read those tests, it makes me think this should be INHERITS and
> NOT INHERITS (not great English, but then neither is NO INHERIT).
> ISTM it might become confusing between INHERITS and INHERIT.
> Waddyathink?

None of these syntaxes are particularly more or less appealing than any other
to me. I'm still trying to think of something better.

-- 
greg


---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [PATCHES] ADD/DROPS inherits

2006-06-13 Thread Simon Riggs
On Mon, 2006-06-12 at 17:39 -0400, Greg Stark wrote:

> Points I'm uncertain about:
> 
> . I throw an elog() error if there's a null conbin for a CHECK constraint. Is
>   it possible for a valid CHECK constraint structure to have a null conbin?

ruleutils shows: elog(ERROR, "null conbin for constraint %u"

> I added some basic (very basic) regression tests 

Should we fail if columns in the wrong order from the parent? I thought
that was one of the restrictions you discovered?

Can we test for
ALTER TABLE child NO INHERIT parent1 INHERIT parent2
That was on Hannu's wish list.

Is INHERIT allowed or disallowed with other ALTER TABLE options?
If it is allowed, can we test for something that will fail and something
that would pass, e.g. ALTER TABLE DROP column1 INHERITS parent -- where
the parent passes on column1.

When I read those tests, it makes me think this should be INHERITS and
NOT INHERITS (not great English, but then neither is NO INHERIT).
ISTM it might become confusing between INHERITS and INHERIT.
Waddyathink?

-- 
  Simon Riggs
  EnterpriseDB  http://www.enterprisedb.com


---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[PATCHES] ADD/DROPS inherits

2006-06-12 Thread Greg Stark

I couldn't figure out how to make use of the predigested constraints in the
relcache, so I continued on the tack I was on. I just stuf the entire
HeapTuple in a list and decompiled the constraint source only if I find a
constraint with a matching name.

Points I'm uncertain about:

. I throw an elog() error if there's a null conbin for a CHECK constraint. Is
  it possible for a valid CHECK constraint structure to have a null conbin?

. Memory management. Do I need the heap_copytuple or is that unnecessary?
  Would it be ok to simply store the actual HeapTuples as the scan proceeds?

. Locking -- all of it :) 

I added some basic (very basic) regression tests and documentation. Did I find
the right places? Is that enough or should I add more?


Index: doc/src/sgml/ref/alter_table.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v
retrieving revision 1.84
diff -u -p -c -r1.84 alter_table.sgml
cvs diff: conflicting specifications of output style
*** doc/src/sgml/ref/alter_table.sgml   12 Feb 2006 19:11:00 -  1.84
--- doc/src/sgml/ref/alter_table.sgml   12 Jun 2006 21:30:54 -
*** where act
*** 46,51 
--- 46,53 
  CLUSTER ON index_name
  SET WITHOUT CLUSTER
  SET WITHOUT OIDS
+ INHERIT parent_table
+ NO INHERIT parent_table
  OWNER TO new_owner
  SET TABLESPACE new_tablespace
  
*** where act
*** 250,255 
--- 252,303 
 
  
 
+ INHERIT parent_table
+ 
+  
+ 
+   This form adds a new parent table to the table. This won't add new
+   columns to the child table, instead all columns of the parent table must
+   already exist in the child table. They must have matching data types,
+   and if they have NOT NULL constraints in the parent
+   then they must also have NOT NULL constraints in the
+   child.
+ 
+ 
+ 
+ 
+   There must also be matching table constraints for all
+   CHECK table constraints of the parent. Currently
+   UNIQUE, PRIMARY KEY, and
+   FOREIGN KEY constraints are ignored however this may
+   change in the future.
+ 
+ 
+ 
+ 
+   The easiest way to create a suitable table is to create a table using
+   INHERITS and then remove it via NO
+   INHERIT. Alternatively create a table using
+   LIKE however note that LIKE does
+   not create the necessary constraints.
+ 
+  
+ 
+ 
+
+ 
+
+ NO INHERIT parent_table
+ 
+  
+This form removes a parent table from the list of parents of the table.
+Queries against the parent table will no longer include records drawn
+from the target table.
+  
+ 
+
+ 
+
  OWNER
  
   
Index: src/backend/commands/tablecmds.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/commands/tablecmds.c,v
retrieving revision 1.184
diff -u -p -c -r1.184 tablecmds.c
cvs diff: conflicting specifications of output style
*** src/backend/commands/tablecmds.c10 May 2006 23:18:39 -  1.184
--- src/backend/commands/tablecmds.c12 Jun 2006 21:30:54 -
*** typedef struct NewColumnValue
*** 159,166 
--- 159,168 
  static void truncate_check_rel(Relation rel);
  static List *MergeAttributes(List *schema, List *supers, bool istemp,
List **supOids, List **supconstr, int 
*supOidCount);
+ static void MergeAttributesIntoExisting(Relation rel, Relation relation);
  static bool change_varattnos_of_a_node(Node *node, const AttrNumber 
*newattno);
  static void StoreCatalogInheritance(Oid relationId, List *supers);
+ static void StoreCatalogInheritance1(Oid relationId, Oid parentOid, int16 
seqNumber, Relation catalogRelation);
  static intfindAttrByName(const char *attributeName, List *schema);
  static void setRelhassubclassInRelation(Oid relationId, bool relhassubclass);
  static bool needs_toast_table(Relation rel);
*** static void ATPrepSetTableSpace(AlteredT
*** 246,251 
--- 248,255 
  static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace);
  static void ATExecEnableDisableTrigger(Relation rel, char *trigname,
   bool enable, bool 
skip_system);
+ static void ATExecAddInherits(Relation rel, RangeVar *parent);
+ static void ATExecDropInherits(Relation rel, RangeVar *parent);
  static void copy_relation_data(Relation rel, SMgrRelation dst);
  static void update_ri_trigger_args(Oid relid,
   const char *oldname,
*** static void
*** 1156,1165 
  StoreCatalogInheritance(Oid relationId, List *supers)
  {
Relationrelation;
-   TupleDesc   desc;
int16   seqNumber;
ListCell   *entry;
-   HeapTuple   tuple;
  
/*