From: Tom Lane Date: Tue, 11 Nov 2008 18:13:44 +0000 (+0000) Subject: Get rid of adjust_appendrel_attr_needed(), which has been broken ever since X-Git-Tag: REL8_3_6~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=213647b15870dc33a217b336dfe74ddf44972edd;p=postgresql 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. --- diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 0e5abc3493..8187ab37d5 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.168.2.2 2008/04/01 00:48:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.168.2.3 2008/11/11 18:13:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -351,14 +351,12 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, } /* - * Copy the parent's attr_needed data as well, with appropriate - * adjustment of relids and attribute numbers. + * Note: we could compute appropriate attr_needed data for the + * child's variables, by transforming the parent's attr_needed + * through the translated_vars mapping. However, currently there's + * no need because attr_needed is only examined for base relations + * not otherrels. So we just leave the child's attr_needed empty. */ - pfree(childrel->attr_needed); - childrel->attr_needed = - adjust_appendrel_attr_needed(rel, appinfo, - childrel->min_attr, - childrel->max_attr); /* * Compute the child's access paths, and add the cheapest one to the diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index 351d76d0fd..2779da74d0 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -22,7 +22,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.146 2008/01/01 19:45:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.146.2.1 2008/11/11 18:13:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1259,70 +1259,6 @@ adjust_relid_set(Relids relids, Index oldrelid, Index newrelid) return relids; } -/* - * adjust_appendrel_attr_needed - * Adjust an attr_needed[] array to reference a member rel instead of - * the original appendrel - * - * oldrel: source of data (we use the attr_needed, min_attr, max_attr fields) - * appinfo: supplies parent_relid, child_relid, col_mappings - * new_min_attr, new_max_attr: desired bounds of new attr_needed array - * - * The relid sets are adjusted by substituting child_relid for parent_relid. - * (NOTE: oldrel is not necessarily the parent_relid relation!) We are also - * careful to map attribute numbers within the array properly. User - * attributes have to be mapped through col_mappings, but system attributes - * and whole-row references always have the same attno. - * - * Returns a palloc'd array with the specified bounds - */ -Relids * -adjust_appendrel_attr_needed(RelOptInfo *oldrel, AppendRelInfo *appinfo, - AttrNumber new_min_attr, AttrNumber new_max_attr) -{ - Relids *new_attr_needed; - Index parent_relid = appinfo->parent_relid; - Index child_relid = appinfo->child_relid; - int parent_attr; - ListCell *lm; - - /* Create empty result array */ - new_attr_needed = (Relids *) - palloc0((new_max_attr - new_min_attr + 1) * sizeof(Relids)); - /* Process user attributes, with appropriate attno mapping */ - parent_attr = 1; - foreach(lm, appinfo->col_mappings) - { - int child_attr = lfirst_int(lm); - - if (child_attr > 0) - { - Relids attrneeded; - - Assert(parent_attr <= oldrel->max_attr); - Assert(child_attr <= new_max_attr); - attrneeded = oldrel->attr_needed[parent_attr - oldrel->min_attr]; - attrneeded = adjust_relid_set(attrneeded, - parent_relid, child_relid); - new_attr_needed[child_attr - new_min_attr] = attrneeded; - } - parent_attr++; - } - /* Process system attributes, including whole-row references */ - Assert(new_min_attr <= oldrel->min_attr); - for (parent_attr = oldrel->min_attr; parent_attr <= 0; parent_attr++) - { - Relids attrneeded; - - attrneeded = oldrel->attr_needed[parent_attr - oldrel->min_attr]; - attrneeded = adjust_relid_set(attrneeded, - parent_relid, child_relid); - new_attr_needed[parent_attr - new_min_attr] = attrneeded; - } - - return new_attr_needed; -} - /* * Adjust the targetlist entries of an inherited UPDATE operation * diff --git a/src/include/optimizer/prep.h b/src/include/optimizer/prep.h index b98040a498..29b0846308 100644 --- a/src/include/optimizer/prep.h +++ b/src/include/optimizer/prep.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/prep.h,v 1.59 2008/01/01 19:45:58 momjian Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/prep.h,v 1.59.2.1 2008/11/11 18:13:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -50,9 +50,4 @@ extern void expand_inherited_tables(PlannerInfo *root); extern Node *adjust_appendrel_attrs(Node *node, AppendRelInfo *appinfo); -extern Relids *adjust_appendrel_attr_needed(RelOptInfo *oldrel, - AppendRelInfo *appinfo, - AttrNumber new_min_attr, - AttrNumber new_max_attr); - #endif /* PREP_H */