pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgreSQL.org
To: pgsql-sql@postgreSQL.org
Subject: DISTINCT ON: speak now or forever hold your peace
Date: Mon, 24 Jan 2000 20:50:15 -0500
Message-ID: <2295.948765015@sss.pgh.pa.us> (raw)

If I don't hear loud hollers very soon, I'm going to eliminate the
DISTINCT ON "feature" for 7.0.  As previously discussed, this feature
is not standard SQL and has no clear semantic interpretation.

I hadn't been planning to touch DISTINCT before 7.0, but changed my
mind when I noticed this little gem:

create table foo1 (f1 int, f2 int, f3 int);
insert into foo1 values(1,2,3);
insert into foo1 values(1,2,null);
insert into foo1 values(1,null,2);
insert into foo1 values(1,2,4);
insert into foo1 values(1,2,4);

select * from foo1;
 f1 | f2 | f3
----+----+----
  1 |  2 |  3
  1 |  2 |
  1 |    |  2
  1 |  2 |  4
  1 |  2 |  4
(5 rows)

select distinct * from foo1;
 f1 | f2 | f3
----+----+----
  1 |  2 |  3
  1 |  2 |  4
  1 |  2 |
(3 rows)

Didn't know that (NULL, 2) == (2, NULL), did you?  The problem here
is that nodeUnique is doing a bitwise comparison of the tuple contents
(which is bad enough --- not all datatypes think equality is bitwise),
and it's neglecting to include the null-field bitmap in what it
compares.  Rather than just band-aid the null-field problem, I'm
going to fix it right.  As long as I have to touch it, I'll deal
with DISTINCT ON too.

			regards, tom lane



view thread (36+ messages)  latest in thread

Message-ID: <2295.948765015@sss.pgh.pa.us>
Permalink:  ../2295.948765015@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2295.948765015@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, pgsql-hackers@postgreSQL.org
  Subject: Re: DISTINCT ON: speak now or forever hold your peace
  In-Reply-To: <2295.948765015@sss.pgh.pa.us>
  References: <2295.948765015@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