14
14
*
15
15
*
16
16
* IDENTIFICATION
17
- * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.103 2003/08/04 02:40:01 momjian Exp $
17
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.104 2003/08/11 23:04:49 tgl Exp $
18
18
*
19
19
*-------------------------------------------------------------------------
20
20
*/
@@ -64,7 +64,7 @@ static bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK);
64
64
static Node * adjust_inherited_attrs_mutator (Node * node ,
65
65
adjust_inherited_attrs_context * context );
66
66
static Relids adjust_relid_set (Relids relids ,Index oldrelid ,Index newrelid );
67
- static List * adjust_inherited_tlist (List * tlist ,Oid new_relid );
67
+ static List * adjust_inherited_tlist (List * tlist ,Oid old_relid , Oid new_relid );
68
68
69
69
70
70
/*
@@ -787,6 +787,7 @@ adjust_inherited_attrs(Node *node,
787
787
if (newnode -> commandType == CMD_UPDATE )
788
788
newnode -> targetList =
789
789
adjust_inherited_tlist (newnode -> targetList ,
790
+ old_relid ,
790
791
new_relid );
791
792
}
792
793
return (Node * )newnode ;
@@ -812,9 +813,10 @@ adjust_inherited_attrs_mutator(Node *node,
812
813
var -> varnoold = context -> new_rt_index ;
813
814
if (var -> varattno > 0 )
814
815
{
815
- char * attname = get_attname (context -> old_relid ,
816
- var -> varattno );
816
+ char * attname ;
817
817
818
+ attname = get_relid_attribute_name (context -> old_relid ,
819
+ var -> varattno );
818
820
var -> varattno = get_attnum (context -> new_relid ,attname );
819
821
if (var -> varattno == InvalidAttrNumber )
820
822
elog (ERROR ,"attribute \"%s\" of relation \"%s\" does not exist" ,
@@ -976,7 +978,7 @@ adjust_relid_set(Relids relids, Index oldrelid, Index newrelid)
976
978
* Note that this is not needed for INSERT because INSERT isn't inheritable.
977
979
*/
978
980
static List *
979
- adjust_inherited_tlist (List * tlist ,Oid new_relid )
981
+ adjust_inherited_tlist (List * tlist ,Oid old_relid , Oid new_relid )
980
982
{
981
983
bool changed_it = false;
982
984
List * tl ;
@@ -989,21 +991,26 @@ adjust_inherited_tlist(List *tlist, Oid new_relid)
989
991
{
990
992
TargetEntry * tle = (TargetEntry * )lfirst (tl );
991
993
Resdom * resdom = tle -> resdom ;
994
+ char * attname ;
992
995
993
996
if (resdom -> resjunk )
994
997
continue ;/* ignore junk items */
995
998
996
- attrno = get_attnum (new_relid ,resdom -> resname );
999
+ attname = get_relid_attribute_name (old_relid ,resdom -> resno );
1000
+ attrno = get_attnum (new_relid ,attname );
997
1001
if (attrno == InvalidAttrNumber )
998
1002
elog (ERROR ,"attribute \"%s\" of relation \"%s\" does not exist" ,
999
- resdom -> resname ,get_rel_name (new_relid ));
1003
+ attname ,get_rel_name (new_relid ));
1000
1004
if (resdom -> resno != attrno )
1001
1005
{
1002
1006
resdom = (Resdom * )copyObject ((Node * )resdom );
1003
1007
resdom -> resno = attrno ;
1008
+ resdom -> resname = attname ;
1004
1009
tle -> resdom = resdom ;
1005
1010
changed_it = true;
1006
1011
}
1012
+ else
1013
+ pfree (attname );
1007
1014
}
1008
1015
1009
1016
/*