pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jan Wieck <JanWieck@yahoo.com>
Cc: omid omoomi <oomoomi@hotmail.com>
Cc: BKermani@illumina.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Median
Date: Tue, 18 Jul 2000 17:43:03 -0400
Message-ID: <19147.963956583@sss.pgh.pa.us> (raw)
In-Reply-To: <200007181935.VAA12101@hot.jw.home>
References: <200007181935.VAA12101@hot.jw.home>

JanWieck@t-online.de (Jan Wieck) writes:
>     I don't see any quick solution how to solve this problem with
>     an aggregate.  Aggregates get all selected values in unsorted
>     order, and don't know ahead how many  items  there  will  be.
>     Even if, all this wouldn't be of any use, because you need to
>     look at the entire sorted list of selected items.

Hmm.  It would be a pretty straightforward extension of the existing
support for DISTINCT aggregates to allow the agg function to receive
all the inputs in sorted order along with a count of how many there
are, whereupon a percentile aggregate would be trivial.

Slow, but trivial.

Probably a better way would be to skip evaluating the agg's transition
function as such, and instead call the agg's final function just once
with a pointer to the tuplesort object that contains the sorted input
data.  Then you reach in and pull out just the items you want, instead
of having to read 'em all.  Or you can scan 'em if you want.  We
might need to add a few features to the tuplesort API to allow access
to the N'th item in the sorted data, but it's surely doable.

Anyone care to work up a detailed proposal for something along this
line?  It seems like more work than it's worth to me, but if someone
else wants to do the legwork...

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <19147.963956583@sss.pgh.pa.us>
Permalink:  ../19147.963956583@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19147.963956583@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, JanWieck@yahoo.com, oomoomi@hotmail.com, BKermani@illumina.com
  Subject: Re: Median
  In-Reply-To: <19147.963956583@sss.pgh.pa.us>
  References: <200007181935.VAA12101@hot.jw.home> <19147.963956583@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox