Re: wip: functions median and percentile
Hitoshi Harada <umi.tanuki@gmail.com>
From: Hitoshi Harada <umi.tanuki@gmail.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>, Greg Stark <gsstark@mit.edu>, Pavel Stehule <pavel.stehule@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, David Fetter <david@fetter.org>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2010-10-05T06:04:31Z
Lists: pgsql-hackers
2010/10/5 Dean Rasheed <dean.a.rasheed@gmail.com>: > On 4 October 2010 18:22, Robert Haas <robertmhaas@gmail.com> wrote: >> On Mon, Oct 4, 2010 at 2:58 AM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote: >>> That requires a new sort for each row. I generated this with a minor >>> tweak to Pavel's patch to just restart the tuplesort each time (the >>> "quick-fix" solution). The problem is that performance really sucks, >>> because it is an O(n^2 log(n)) algorithm. >> >> Maybe that's OK. If you're doing repeated median operations on large >> data sets, perhaps you should expect that to be slow. I bet that >> people who want to use this as a window function will want one median >> per group, not n medians per group; and it doesn't seem like a good >> idea to say - we're not going to let you use this as a window function >> AT ALL because you might decide to do something that will be really >> slow. You can always hit ^C if you get tired of waiting. This seems >> like it's very far from being the most important thing for us to >> optimize, though of course it's great if we can. >> > > Well FWIW, here's the quick-fix solution to make this median function > support window queries. Is this safe? It seems to me that the tuplesort_end isn't called in window aggregates at the last of a partition, which results in forgetting to close temp file if tuplesort is in state of tape. Regards, -- Hitoshi Harada