Stephen Frost <sfr...@snowman.net> writes: > Yeah, there certainly seems like a lot of opportunity for the ordering > to end up being volatile already and queries depending on it not > changing really shouldn't be making that assumption. I do think it was > probably a bad move on our part to say that ordering a subquery will > "usually" work in the documentation but having that slip-up in the > documentation mean that we actually *are* going to guarantee it'll > always work to use a subquery ordering to feed an aggregate is a pretty > big stretch (and is it even really true today anyway? the documentation > certainly doesn't seem to be clear on that...).
It's true as long as there's nothing in the outer query that would cause re-ordering of the subquery output. I'd be the first to agree that the wording is a bit sloppy, but I think there are lots of people depending on that behavior, not least because that was the only way to do it before we supported ORDER BY inside an aggregate call. Now, that doesn't directly bear on the argument at hand, because if you're aggregating over the result of an ORDER BY subquery then you aren't doing parallel aggregation anyway. (Perhaps there's parallelism inside the subquery, but that's irrelevant.) It is related in the sense that there are lots of people depending on things other than ORDER-BY-in-the- aggregate-call to get the results they expect. regards, tom lane