diff options
Diffstat (limited to 'src/backend/optimizer/path/costsize.c')
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 1b264a29e29..c853bd8dcb6 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -3238,14 +3238,14 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel, /* * Compute per-output-column width estimates by examining the subquery's * targetlist. For any output that is a plain Var, get the width estimate - * that was made while planning the subquery. Otherwise, fall back on a - * datatype-based estimate. + * that was made while planning the subquery. Otherwise, we leave it to + * set_rel_width to fill in a datatype-based default estimate. */ foreach(lc, subroot->parse->targetList) { TargetEntry *te = (TargetEntry *) lfirst(lc); Node *texpr = (Node *) te->expr; - int32 item_width; + int32 item_width = 0; Assert(IsA(te, TargetEntry)); /* junk columns aren't visible to upper query */ @@ -3256,8 +3256,14 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel, * XXX This currently doesn't work for subqueries containing set * operations, because the Vars in their tlists are bogus references * to the first leaf subquery, which wouldn't give the right answer - * even if we could still get to its PlannerInfo. So fall back on - * datatype in that case. + * even if we could still get to its PlannerInfo. + * + * Also, the subquery could be an appendrel for which all branches are + * known empty due to constraint exclusion, in which case + * set_append_rel_pathlist will have left the attr_widths set to zero. + * + * In either case, we just leave the width estimate zero until + * set_rel_width fixes it. */ if (IsA(texpr, Var) && subroot->parse->setOperations == NULL) @@ -3267,11 +3273,6 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel, item_width = subrel->attr_widths[var->varattno - subrel->min_attr]; } - else - { - item_width = get_typavgwidth(exprType(texpr), exprTypmod(texpr)); - } - Assert(item_width > 0); Assert(te->resno >= rel->min_attr && te->resno <= rel->max_attr); rel->attr_widths[te->resno - rel->min_attr] = item_width; } |