• Tom Lane's avatar
    Reimplement planner's handling of MIN/MAX aggregate optimization. · 034967bd
    Tom Lane authored
    Per my recent proposal, get rid of all the direct inspection of indexes
    and manual generation of paths in planagg.c.  Instead, set up
    EquivalenceClasses for the aggregate argument expressions, and let the
    regular path generation logic deal with creating paths that can satisfy
    those sort orders.  This makes planagg.c a bit more visible to the rest
    of the planner than it was originally, but the approach is basically a lot
    cleaner than before.  A major advantage of doing it this way is that we get
    MIN/MAX optimization on inheritance trees (using MergeAppend of indexscans)
    practically for free, whereas in the old way we'd have had to add a whole
    lot more duplicative logic.
    
    One small disadvantage of this approach is that MIN/MAX aggregates can no
    longer exploit partial indexes having an "x IS NOT NULL" predicate, unless
    that restriction or something that implies it is specified in the query.
    The previous implementation was able to use the added "x IS NOT NULL"
    condition as an extra predicate proof condition, but in this version we
    rely entirely on indexes that are considered usable by the main planning
    process.  That seems a fair tradeoff for the simplicity and functionality
    gained.
    034967bd
aggregates.out 30.9 KB