1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-21 00:42:43 +03:00

Get rid of adjust_appendrel_attr_needed(), which has been broken ever since

we extended the appendrel mechanism to support UNION ALL optimization.  The
reason nobody noticed was that we are not actually using attr_needed data for
appendrel children; hence it seems more reasonable to rip it out than fix it.
Back-patch to 8.2 because an Assert failure is possible in corner cases.
Per examination of an example from Jim Nasby.

In HEAD, also get rid of AppendRelInfo.col_mappings, which is quite inadequate
to represent UNION ALL situations; depend entirely on translated_vars instead.
This commit is contained in:
Tom Lane
2008-11-11 18:13:32 +00:00
parent ccc9073f26
commit 0436679969
8 changed files with 46 additions and 146 deletions

View File

@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.58 2008/10/22 20:17:52 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.59 2008/11/11 18:13:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,9 +54,8 @@ static Node *pull_up_simple_union_all(PlannerInfo *root, Node *jtnode,
static void pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root,
int parentRTindex, Query *setOpQuery,
int childRToffset);
static void make_setop_translation_lists(Query *query,
Index newvarno,
List **col_mappings, List **translated_vars);
static void make_setop_translation_list(Query *query, Index newvarno,
List **translated_vars);
static bool is_simple_subquery(Query *subquery);
static bool is_simple_union_all(Query *subquery);
static bool is_simple_union_all_recurse(Node *setOp, Query *setOpQuery,
@@ -839,9 +838,8 @@ pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex,
appinfo->child_relid = childRTindex;
appinfo->parent_reltype = InvalidOid;
appinfo->child_reltype = InvalidOid;
make_setop_translation_lists(setOpQuery, childRTindex,
&appinfo->col_mappings,
&appinfo->translated_vars);
make_setop_translation_list(setOpQuery, childRTindex,
&appinfo->translated_vars);
appinfo->parent_reloid = InvalidOid;
root->append_rel_list = lappend(root->append_rel_list, appinfo);
@@ -874,17 +872,16 @@ pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex,
}
/*
* make_setop_translation_lists
* Build the lists of translations from parent Vars to child Vars for
* a UNION ALL member. We need both a column number mapping list
* and a list of Vars representing the child columns.
* make_setop_translation_list
* Build the list of translations from parent Vars to child Vars for
* a UNION ALL member. (At this point it's just a simple list of
* referencing Vars, but if we succeed in pulling up the member
* subquery, the Vars will get replaced by pulled-up expressions.)
*/
static void
make_setop_translation_lists(Query *query,
Index newvarno,
List **col_mappings, List **translated_vars)
make_setop_translation_list(Query *query, Index newvarno,
List **translated_vars)
{
List *numbers = NIL;
List *vars = NIL;
ListCell *l;
@@ -895,7 +892,6 @@ make_setop_translation_lists(Query *query,
if (tle->resjunk)
continue;
numbers = lappend_int(numbers, tle->resno);
vars = lappend(vars, makeVar(newvarno,
tle->resno,
exprType((Node *) tle->expr),
@@ -903,7 +899,6 @@ make_setop_translation_lists(Query *query,
0));
}
*col_mappings = numbers;
*translated_vars = vars;
}