On Wed, 18 Jan 2023 at 22:37, Richard Guo <guofengli...@gmail.com> wrote: > I'm still confused that when the same scenario happens with ORDER BY in > an aggregate function, like in query 1, the result is different in that > we would get an unsorted output. > > I wonder if we should avoid this inconsistent behavior.
It certainly seems pretty strange that aggregates with an ORDER BY behave differently from the query's ORDER BY. I'd have expected that to be the same. I've not looked to see why there's a difference, but suspect that we thought about how we want it to work for the query's ORDER BY and when ORDER BY aggregates were added, that behaviour was not considered. Likely finding the code or location where that code should be would help us understand if something was just forgotten in the aggregate's case. It's probably another question as to if we should be adjusting this behaviour now. David