8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1584,7 +1584,6 @@ update_ri_trigger_args(Oid relid,
1584
1584
void
1585
1585
AlterTableAddColumn (Oid myrelid ,
1586
1586
bool recurse ,
1587
- bool recursing ,
1588
1587
ColumnDef * colDef )
1589
1588
{
1590
1589
Relation rel ,
@@ -1643,22 +1642,50 @@ AlterTableAddColumn(Oid myrelid,
1643
1642
colDefChild -> inhcount = 1 ;
1644
1643
colDefChild -> is_local = false;
1645
1644
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 );
1648
1647
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
- */
1654
1648
foreach (child , children )
1655
1649
{
1656
1650
Oid childrelid = lfirsti (child );
1651
+ HeapTuple tuple ;
1652
+ Form_pg_attribute childatt ;
1653
+ Relation childrel ;
1657
1654
1658
1655
if (childrelid == myrelid )
1659
1656
continue ;
1660
1657
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 );
1662
1689
}
1663
1690
}
1664
1691
else
@@ -1667,8 +1694,7 @@ AlterTableAddColumn(Oid myrelid,
1667
1694
* If we are told not to recurse, there had better not be any
1668
1695
* child tables; else the addition would put them out of step.
1669
1696
*/
1670
- if (!recursing &&
1671
- find_inheritance_children (myrelid ) != NIL )
1697
+ if (find_inheritance_children (myrelid ) != NIL )
1672
1698
elog (ERROR , "Attribute must be added to child tables too" );
1673
1699
}
1674
1700
0 commit comments