• Tom Lane's avatar
    Fix overoptimistic assumptions in column width estimation for subqueries. · 43f0c208
    Tom Lane authored
    set_append_rel_pathlist supposed that, while computing per-column width
    estimates for the appendrel, it could ignore child rels for which the
    translated reltargetlist entry wasn't a Var.  This gave rise to completely
    silly estimates in some common cases, such as constant outputs from some or
    all of the arms of a UNION ALL.  Instead, fall back on get_typavgwidth to
    estimate from the value's datatype; which might be a poor estimate but at
    least it's not completely wacko.
    
    That problem was exposed by an Assert in set_subquery_size_estimates, which
    unfortunately was still overoptimistic even with that fix, since we don't
    compute attr_widths estimates for appendrels that are entirely excluded by
    constraints.  So remove the Assert; we'll just fall back on get_typavgwidth
    in such cases.
    
    Also, since set_subquery_size_estimates calls set_baserel_size_estimates
    which calls set_rel_width, there's no need for set_subquery_size_estimates
    to call get_typavgwidth; set_rel_width will handle it for us if we just
    leave the estimate set to zero.  Remove the unnecessary code.
    
    Per report from Erik Rijkers and subsequent investigation.
    43f0c208
costsize.c 114 KB