Re: min/max planner optimization - Mailing list pgsql-hackers

From Tom Lane
Subject Re: min/max planner optimization
Date
Msg-id 15642.1193492763@sss.pgh.pa.us
Whole thread Raw
In response to min/max planner optimization  (Gregory Stark <stark@enterprisedb.com>)
Responses Re: min/max planner optimization
List pgsql-hackers
Gregory Stark <stark@enterprisedb.com> writes:
> I don't understand why it wouldn't work to do it for any arbitrary path for
> any query at all as long as it has the correct ordering.

It might work, but the resulting plan would be uniformly inferior to the
regular aggregate code.  The only case where the optimization is a win
is where you have a zero-startup-cost subplan, and the only way to get
sorted output with zero startup cost is an indexscan.  Anything
involving a sort will be a loser, or at best break-even if the sort
figures out it can use top-N.

> I would have expected the way to do this would be to detect that the min/max
> optimization might be applicable early on, in which case we teach
> pathkeys_useful_for_ordering about the ordering which would be necessary for
> it.

Possibly.  I did it the way I did mostly to minimize the side-effects on
the rest of the planner.  But I think if we did it like that, we'd waste
cycles considering ordered-output paths that are really not of any value
in light of the comments above.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Proposal: real procedures again (8.4)
Next
From: Tom Lane
Date:
Subject: Re: Append nodes and orderings