David Rowley <dgrowleyml@gmail.com> writes:
> You're right that OFFSET 0 would have been a better choice. I just
> wasn't aware that we were considering changing the code so we pull up
> subqueries with an ORDER BY.
No such plan is in the offing AFAIK, but it doesn't seem entirely
out of the question either.
> In fact, I thought there were several
> good reasons we're not doing that. e.g. allow aggregation in outer
> query by some order specified by the subquery. But perhaps any changes
> we make in this area would be more conditional than just ignoring the
> fact that the subquery has an ORDER BY.
Yeah, we've historically honored subquery ORDER BY and I doubt we'd
want to stop. But I'm not sure that that that completely precludes
subquery flattening, especially for single-relation subqueries such
as these. You could imagine, for example, still doing the pull-up
and then only accepting paths for the rel that satisfy the ORDER BY.
This could still lead to better optimization of the outer query
than what happens now, I think.
Anyway, it's not something I expect to happen soon, but maybe
someday.
regards, tom lane