• T
    Add an explicit representation of the output targetlist to Paths. · 19a54114
    Tom Lane 提交于
    Up to now, there's been an assumption that all Paths for a given relation
    compute the same output column set (targetlist).  However, there are good
    reasons to remove that assumption.  For example, an indexscan on an
    expression index might be able to return the value of an expensive function
    "for free".  While we have the ability to generate such a plan today in
    simple cases, we don't have a way to model that it's cheaper than a plan
    that computes the function from scratch, nor a way to create such a plan
    in join cases (where the function computation would normally happen at
    the topmost join node).  Also, we need this so that we can have Paths
    representing post-scan/join steps, where the targetlist may well change
    from one step to the next.  Therefore, invent a "struct PathTarget"
    representing the columns we expect a plan step to emit.  It's convenient
    to include the output tuple width and tlist evaluation cost in this struct,
    and there will likely be additional fields in future.
    
    While Path nodes that actually do have custom outputs will need their own
    PathTargets, it will still be true that most Paths for a given relation
    will compute the same tlist.  To reduce the overhead added by this patch,
    keep a "default PathTarget" in RelOptInfo, and allow Paths that compute
    that column set to just point to their parent RelOptInfo's reltarget.
    (In the patch as committed, actually every Path is like that, since we
    do not yet have any cases of custom PathTargets.)
    
    I took this opportunity to provide some more-honest costing of
    PlaceHolderVar evaluation.  Up to now, the assumption that "scan/join
    reltargetlists have cost zero" was applied not only to Vars, where it's
    reasonable, but also PlaceHolderVars where it isn't.  Now, we add the eval
    cost of a PlaceHolderVar's expression to the first plan level where it can
    be computed, by including it in the PathTarget cost field and adding that
    to the cost estimates for Paths.  This isn't perfect yet but it's much
    better than before, and there is a way forward to improve it more.  This
    costing change affects the join order chosen for a couple of the regression
    tests, changing expected row ordering.
    19a54114
planner.c 153.6 KB