I found a way that works, and is indeed quite a bit faster. It is even
uglier than what you proposed. The problem wasn't the "order by" in the
subquery, but the "order by" combined with the "union":
sorry, i always forget about the fact that union doesn't like internal order and limits. subquery is of course perfectly fine - i'm glad you found that :)
--
http://www.depesz.com/ - nowy, lepszy depesz