pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Philip Warner <pjw@rhyme.com.au>
Cc: Chris Bitmead <chris@bitmead.com>
Cc: pgsql-hackers@postgreSQL.org
Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
Date: Tue, 25 Jan 2000 00:01:10 -0500
Message-ID: <11879.948776470@sss.pgh.pa.us> (raw)
In-Reply-To: <3.0.5.32.20000125150557.036121c0@mail.rhyme.com.au>
References: <2295.948765015@sss.pgh.pa.us>
	<3.0.5.32.20000125140349.035768d0@mail.rhyme.com.au>
	<3.0.5.32.20000125150557.036121c0@mail.rhyme.com.au>

Philip Warner <pjw@rhyme.com.au> writes:
> Just a thought, but would I be right in saying that this could be easily
> done with the addition of a new aggregate function 'FIRST', which simply
> returns the first value sent to it? Since the aggregates operate a row at
> a time, you are guaranteed a consistent set of values, I think.

No, because the system doesn't guarantee to deliver tuples to the
aggregate in any particular order.  The physical order of tuples
on the disk will depend on the order in which they were last updated
(plus random perturbations introduced by VACUUM); and the order in
which they are processed by a query will depend on the query plan
chosen by the planner (sequential scan vs. indexscan, etc).
SQL in general doesn't believe that tuple ordering has any semantic
significance --- you can ask for ORDER BY, but that's only honored
at the end stage of SELECT result delivery, not necessarily anywhere
in the bowels of a query.

Also, if you are going to use an aggregate, ISTM you might as well
use one like MIN() or MAX() and get a fully predictable result.
I suppose a FIRST() aggregate would save a few cycles by not running
comparisons, but I bet it'd be tough to notice any difference.

			regards, tom lane



view thread (36+ messages)  latest in thread

Message-ID: <11879.948776470@sss.pgh.pa.us>
Permalink:  ../11879.948776470@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11879.948776470@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, pjw@rhyme.com.au, chris@bitmead.com, pgsql-hackers@postgreSQL.org
  Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
  In-Reply-To: <11879.948776470@sss.pgh.pa.us>
  References: <2295.948765015@sss.pgh.pa.us> <3.0.5.32.20000125140349.035768d0@mail.rhyme.com.au> <3.0.5.32.20000125150557.036121c0@mail.rhyme.com.au> <11879.948776470@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