• Tom Lane's avatar
    Avoid inserting Result nodes that only compute identity projections. · 4387cf95
    Tom Lane authored
    The planner sometimes inserts Result nodes to perform column projections
    (ie, arbitrary scalar calculations) above plan nodes that lack projection
    logic of their own.  However, we did that even if the lower plan node was
    in fact producing the required column set already; which is a pretty common
    case given the popularity of "SELECT * FROM ...".  Measurements show that
    the useless plan node adds non-negligible overhead, especially when there
    are many columns in the result.  So add a check to avoid inserting a Result
    node unless there's something useful for it to do.
    
    There are a couple of remaining places where unnecessary Result nodes
    could get inserted, but they are (a) much less performance-critical,
    and (b) coded in such a way that it's hard to avoid inserting a Result,
    because the desired tlist is changed on-the-fly in subsequent logic.
    We'll leave those alone for now.
    
    Kyotaro Horiguchi; reviewed and further hacked on by Amit Kapila and
    Tom Lane.
    4387cf95
union.out 10 KB