DISTINCT ON: speak now or forever hold your peace

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org, pgsql-sql(at)postgreSQL(dot)org
Subject: DISTINCT ON: speak now or forever hold your peace
Date: 2000-01-25 01:50:15
Message-ID: 2295.948765015@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Lockhart 2000-01-25 01:57:53 Re: [HACKERS] Re: Doc updates for index cost estimator change
Previous Message The Hermit Hacker 2000-01-25 01:34:48 Re: [HACKERS] Well, then you keep your darn columns

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Donaldson 2000-01-25 01:54:51 JDK1.2 Driver to Postgresql 6.5.3 - connection problem
Previous Message Peter Eisentraut 2000-01-24 23:49:17 Re: [SQL] Blobs