Incidentally there are O(n) algorithms for finding the median (or any specific offset). It shouldn't be necessary to sort at all.
I'm not sure which path this argues for - perhaps Tom's position that we need more optimiser infrastructure so we can see how to accomplish this. Perhaps it means you should really implement median() with an internal selection alagorithm and not depend on the optimizer at all. -- greg -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers