Re: Warts with SELECT DISTINCT - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Warts with SELECT DISTINCT
Date
Msg-id 18946.1146719600@sss.pgh.pa.us
Whole thread Raw
In response to Re: Warts with SELECT DISTINCT  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: Warts with SELECT DISTINCT  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-hackers
Bruno Wolff III <bruno@wolff.to> writes:
> Greg Stark <gsstark@mit.edu> wrote [ baldly summarized ]
>> [ x > y implies upper(x) > upper(y) ]

> I don't think you can assume that that will be true for any locale.

Whether or not that may actually be true for upper() (I share Bruno's
skepticism, but maybe it's so), it really does not matter because the
planner doesn't have enough knowledge about the behavior of upper() to
make such an inference.

I think it's a fair point that we could allow "SELECT DISTINCT x ORDER BY
foo(x)" if foo() is stable, but that does not imply that sorting by x is
interchangeable with sorting by foo(x).  foo = abs is a trivial
counterexample.

As far as the original point goes: feel free to reimplement DISTINCT,
but don't break the documented behavior of DISTINCT ON + ORDER BY, or
you'll have a lot of unhappy villagers appear on your doorstep bearing
torches and pitchforks.  It might be mostly an implementation artifact,
but it's an awfully useful one ...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Warts with SELECT DISTINCT
Next
From: Christopher Kings-Lynne
Date:
Subject: Re: Rethinking locking for database create/drop vs connection