22
22
*
23
23
*
24
24
* IDENTIFICATION
25
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.160 2008/10/22 20:17:52 tgl Exp $
25
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.161 2008/11/11 18:13:32 tgl Exp $
26
26
*
27
27
*-------------------------------------------------------------------------
28
28
*/
@@ -91,11 +91,10 @@ static List *generate_append_tlist(List *colTypes, bool flag,
91
91
static List * generate_setop_grouplist (SetOperationStmt * op , List * targetlist );
92
92
static void expand_inherited_rtentry (PlannerInfo * root , RangeTblEntry * rte ,
93
93
Index rti );
94
- static void make_inh_translation_lists (Relation oldrelation ,
95
- Relation newrelation ,
96
- Index newvarno ,
97
- List * * col_mappings ,
98
- List * * translated_vars );
94
+ static void make_inh_translation_list (Relation oldrelation ,
95
+ Relation newrelation ,
96
+ Index newvarno ,
97
+ List * * translated_vars );
99
98
static Node * adjust_appendrel_attrs_mutator (Node * node ,
100
99
AppendRelInfo * context );
101
100
static Relids adjust_relid_set (Relids relids , Index oldrelid , Index newrelid );
@@ -1279,9 +1278,8 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
1279
1278
appinfo -> child_relid = childRTindex ;
1280
1279
appinfo -> parent_reltype = oldrelation -> rd_rel -> reltype ;
1281
1280
appinfo -> child_reltype = newrelation -> rd_rel -> reltype ;
1282
- make_inh_translation_lists (oldrelation , newrelation , childRTindex ,
1283
- & appinfo -> col_mappings ,
1284
- & appinfo -> translated_vars );
1281
+ make_inh_translation_list (oldrelation , newrelation , childRTindex ,
1282
+ & appinfo -> translated_vars );
1285
1283
appinfo -> parent_reloid = parentOID ;
1286
1284
appinfos = lappend (appinfos , appinfo );
1287
1285
@@ -1316,19 +1314,17 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
1316
1314
}
1317
1315
1318
1316
/*
1319
- * make_inh_translation_lists
1320
- * Build the lists of translations from parent Vars to child Vars for
1321
- * an inheritance child. We need both a column number mapping list
1322
- * and a list of Vars representing the child columns.
1317
+ * make_inh_translation_list
1318
+ * Build the list of translations from parent Vars to child Vars for
1319
+ * an inheritance child.
1323
1320
*
1324
1321
* For paranoia's sake, we match type as well as attribute name.
1325
1322
*/
1326
1323
static void
1327
- make_inh_translation_lists (Relation oldrelation , Relation newrelation ,
1328
- Index newvarno ,
1329
- List * * col_mappings , List * * translated_vars )
1324
+ make_inh_translation_list (Relation oldrelation , Relation newrelation ,
1325
+ Index newvarno ,
1326
+ List * * translated_vars )
1330
1327
{
1331
- List * numbers = NIL ;
1332
1328
List * vars = NIL ;
1333
1329
TupleDesc old_tupdesc = RelationGetDescr (oldrelation );
1334
1330
TupleDesc new_tupdesc = RelationGetDescr (newrelation );
@@ -1347,8 +1343,7 @@ make_inh_translation_lists(Relation oldrelation, Relation newrelation,
1347
1343
att = old_tupdesc -> attrs [old_attno ];
1348
1344
if (att -> attisdropped )
1349
1345
{
1350
- /* Just put 0/NULL into this list entry */
1351
- numbers = lappend_int (numbers , 0 );
1346
+ /* Just put NULL into this list entry */
1352
1347
vars = lappend (vars , NULL );
1353
1348
continue ;
1354
1349
}
@@ -1362,7 +1357,6 @@ make_inh_translation_lists(Relation oldrelation, Relation newrelation,
1362
1357
*/
1363
1358
if (oldrelation == newrelation )
1364
1359
{
1365
- numbers = lappend_int (numbers , old_attno + 1 );
1366
1360
vars = lappend (vars , makeVar (newvarno ,
1367
1361
(AttrNumber ) (old_attno + 1 ),
1368
1362
atttypid ,
@@ -1405,15 +1399,13 @@ make_inh_translation_lists(Relation oldrelation, Relation newrelation,
1405
1399
elog (ERROR , "attribute \"%s\" of relation \"%s\" does not match parent's type" ,
1406
1400
attname , RelationGetRelationName (newrelation ));
1407
1401
1408
- numbers = lappend_int (numbers , new_attno + 1 );
1409
1402
vars = lappend (vars , makeVar (newvarno ,
1410
1403
(AttrNumber ) (new_attno + 1 ),
1411
1404
atttypid ,
1412
1405
atttypmod ,
1413
1406
0 ));
1414
1407
}
1415
1408
1416
- * col_mappings = numbers ;
1417
1409
* translated_vars = vars ;
1418
1410
}
1419
1411
@@ -1682,70 +1674,6 @@ adjust_relid_set(Relids relids, Index oldrelid, Index newrelid)
1682
1674
return relids ;
1683
1675
}
1684
1676
1685
- /*
1686
- * adjust_appendrel_attr_needed
1687
- * Adjust an attr_needed[] array to reference a member rel instead of
1688
- * the original appendrel
1689
- *
1690
- * oldrel: source of data (we use the attr_needed, min_attr, max_attr fields)
1691
- * appinfo: supplies parent_relid, child_relid, col_mappings
1692
- * new_min_attr, new_max_attr: desired bounds of new attr_needed array
1693
- *
1694
- * The relid sets are adjusted by substituting child_relid for parent_relid.
1695
- * (NOTE: oldrel is not necessarily the parent_relid relation!) We are also
1696
- * careful to map attribute numbers within the array properly. User
1697
- * attributes have to be mapped through col_mappings, but system attributes
1698
- * and whole-row references always have the same attno.
1699
- *
1700
- * Returns a palloc'd array with the specified bounds
1701
- */
1702
- Relids *
1703
- adjust_appendrel_attr_needed (RelOptInfo * oldrel , AppendRelInfo * appinfo ,
1704
- AttrNumber new_min_attr , AttrNumber new_max_attr )
1705
- {
1706
- Relids * new_attr_needed ;
1707
- Index parent_relid = appinfo -> parent_relid ;
1708
- Index child_relid = appinfo -> child_relid ;
1709
- int parent_attr ;
1710
- ListCell * lm ;
1711
-
1712
- /* Create empty result array */
1713
- new_attr_needed = (Relids * )
1714
- palloc0 ((new_max_attr - new_min_attr + 1 ) * sizeof (Relids ));
1715
- /* Process user attributes, with appropriate attno mapping */
1716
- parent_attr = 1 ;
1717
- foreach (lm , appinfo -> col_mappings )
1718
- {
1719
- int child_attr = lfirst_int (lm );
1720
-
1721
- if (child_attr > 0 )
1722
- {
1723
- Relids attrneeded ;
1724
-
1725
- Assert (parent_attr <= oldrel -> max_attr );
1726
- Assert (child_attr <= new_max_attr );
1727
- attrneeded = oldrel -> attr_needed [parent_attr - oldrel -> min_attr ];
1728
- attrneeded = adjust_relid_set (attrneeded ,
1729
- parent_relid , child_relid );
1730
- new_attr_needed [child_attr - new_min_attr ] = attrneeded ;
1731
- }
1732
- parent_attr ++ ;
1733
- }
1734
- /* Process system attributes, including whole-row references */
1735
- Assert (new_min_attr <= oldrel -> min_attr );
1736
- for (parent_attr = oldrel -> min_attr ; parent_attr <= 0 ; parent_attr ++ )
1737
- {
1738
- Relids attrneeded ;
1739
-
1740
- attrneeded = oldrel -> attr_needed [parent_attr - oldrel -> min_attr ];
1741
- attrneeded = adjust_relid_set (attrneeded ,
1742
- parent_relid , child_relid );
1743
- new_attr_needed [parent_attr - new_min_attr ] = attrneeded ;
1744
- }
1745
-
1746
- return new_attr_needed ;
1747
- }
1748
-
1749
1677
/*
1750
1678
* Adjust the targetlist entries of an inherited UPDATE operation
1751
1679
*
@@ -1778,24 +1706,24 @@ adjust_inherited_tlist(List *tlist, AppendRelInfo *context)
1778
1706
foreach (tl , tlist )
1779
1707
{
1780
1708
TargetEntry * tle = (TargetEntry * ) lfirst (tl );
1781
- int newattno ;
1709
+ Var * childvar ;
1782
1710
1783
1711
if (tle -> resjunk )
1784
1712
continue ; /* ignore junk items */
1785
1713
1786
- /* Look up the translation of this column */
1714
+ /* Look up the translation of this column: it must be a Var */
1787
1715
if (tle -> resno <= 0 ||
1788
- tle -> resno > list_length (context -> col_mappings ))
1716
+ tle -> resno > list_length (context -> translated_vars ))
1789
1717
elog (ERROR , "attribute %d of relation \"%s\" does not exist" ,
1790
1718
tle -> resno , get_rel_name (context -> parent_reloid ));
1791
- newattno = list_nth_int ( context -> col_mappings , tle -> resno - 1 );
1792
- if (newattno <= 0 )
1719
+ childvar = ( Var * ) list_nth ( context -> translated_vars , tle -> resno - 1 );
1720
+ if (childvar == NULL || ! IsA ( childvar , Var ) )
1793
1721
elog (ERROR , "attribute %d of relation \"%s\" does not exist" ,
1794
1722
tle -> resno , get_rel_name (context -> parent_reloid ));
1795
1723
1796
- if (tle -> resno != newattno )
1724
+ if (tle -> resno != childvar -> varattno )
1797
1725
{
1798
- tle -> resno = newattno ;
1726
+ tle -> resno = childvar -> varattno ;
1799
1727
changed_it = true;
1800
1728
}
1801
1729
}
0 commit comments