Jonathan Vanasco <postgres@2xlp.com> writes:
> This is what I don't understand -- notice the two order_by calls.
> If i run this with an inner and outer order_by, I get ~305ms. (I don't think I need both, but I wasn't sure if
orderingis kept from a subselect )
> If i run this with only the inner, I get ~304ms.
> If I run this with only the outer, it's pushing over 10minutes again
> i'm wondering if anyone might know why that performance hit would be happening
The inner ORDER BY would prevent the planner from flattening the two
query levels into one; but as for why it gets a much worse plan after
flattening --- insufficient data.
https://wiki.postgresql.org/wiki/Slow_Query_Questions
regards, tom lane