88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.48 2002/10/19 03:01:09 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.49 2002/10/21 20:31:51 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -1584,7 +1584,6 @@ update_ri_trigger_args(Oid relid,
15841584void
15851585AlterTableAddColumn (Oid myrelid ,
15861586bool recurse ,
1587- bool recursing ,
15881587ColumnDef * colDef )
15891588{
15901589Relation rel ,
@@ -1643,22 +1642,50 @@ AlterTableAddColumn(Oid myrelid,
16431642colDefChild -> inhcount = 1 ;
16441643colDefChild -> is_local = false;
16451644
1646- /*this routine is actually in the planner */
1647- children = find_all_inheritors (myrelid );
1645+ /*We only want direct inheritors */
1646+ children = find_inheritance_children (myrelid );
16481647
1649- /*
1650- * find_all_inheritors does the recursive search of the
1651- * inheritance hierarchy, so all we have to do is process all of
1652- * the relids in the list that it returns.
1653- */
16541648foreach (child ,children )
16551649{
16561650Oid childrelid = lfirsti (child );
1651+ HeapTuple tuple ;
1652+ Form_pg_attribute childatt ;
1653+ Relation childrel ;
16571654
16581655if (childrelid == myrelid )
16591656continue ;
16601657
1661- AlterTableAddColumn (childrelid , false, true,colDefChild );
1658+ attrdesc = heap_openr (AttributeRelationName ,RowExclusiveLock );
1659+ tuple = SearchSysCacheCopyAttName (childrelid ,colDef -> colname );
1660+ if (!HeapTupleIsValid (tuple ))
1661+ {
1662+ heap_close (attrdesc ,RowExclusiveLock );
1663+ AlterTableAddColumn (childrelid , true,colDefChild );
1664+ continue ;
1665+ }
1666+ childatt = (Form_pg_attribute )GETSTRUCT (tuple );
1667+
1668+ typeTuple = typenameType (colDef -> typename );
1669+
1670+ if (HeapTupleGetOid (typeTuple )!= childatt -> atttypid ||
1671+ colDef -> typename -> typmod != childatt -> atttypmod )
1672+ elog (ERROR ,"ALTER TABLE: child table %u has different "
1673+ "type for column \"%s\"" ,
1674+ childrelid ,colDef -> colname );
1675+
1676+ childatt -> attinhcount ++ ;
1677+ simple_heap_update (attrdesc ,& tuple -> t_self ,tuple );
1678+ CatalogUpdateIndexes (attrdesc ,tuple );
1679+
1680+ childrel = RelationIdGetRelation (childrelid );
1681+ elog (NOTICE ,"ALTER TABLE: merging definition of column "
1682+ "\"%s\" for child %s" ,colDef -> colname ,
1683+ RelationGetRelationName (childrel ));
1684+ RelationClose (childrel );
1685+
1686+ heap_close (attrdesc ,RowExclusiveLock );
1687+ heap_freetuple (tuple );
1688+ ReleaseSysCache (typeTuple );
16621689}
16631690}
16641691else
@@ -1667,8 +1694,7 @@ AlterTableAddColumn(Oid myrelid,
16671694 * If we are told not to recurse, there had better not be any
16681695 * child tables; else the addition would put them out of step.
16691696 */
1670- if (!recursing &&
1671- find_inheritance_children (myrelid )!= NIL )
1697+ if (find_inheritance_children (myrelid )!= NIL )
16721698elog (ERROR ,"Attribute must be added to child tables too" );
16731699}
16741700