Re: Poor Performance with Distinct Subqueries with EXISTS and EXCEPT

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>, "PgSql General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Poor Performance with Distinct Subqueries with EXISTS and EXCEPT
Date: 2004-12-02 16:34:27
Message-ID: 08D972DD-4480-11D9-A917-000D93AE0944@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I wasn't sure whether EXCEPT would create a unique set from among the
results of both queries.

As in, if the first part of the query (before the EXCEPT clause),
without the DISTINCT, yielded

yahoo.com
yahoo.com

would the query reduce that to a single yahoo.com regardless of whether
it showed up in the EXCEPT clause?

-tfo

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005

On Dec 2, 2004, at 10:26 AM, Tom Lane wrote:

> =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=
> <lists(at)boutiquenumerique(dot)com> writes:
>> I may be mistaken, but you may be doing the same thing twice : you're
>> basically writing :
>
>> SELECT DISTINCT X WHERE Y EXCEPT SELECT DISTINCT X WHERE NOT Y
>> Is this not a way to get an empty result set ?
>
> No, because some X values may appear in rows where Y, and also in rows
> where NOT Y.
>
> The DISTINCTs are wastes of time, though, because EXCEPT implies
> elimination of duplicates.
>
> regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mario Weilguni 2004-12-02 16:36:36 Changing column type from oid to int4
Previous Message Tom Lane 2004-12-02 16:26:45 Re: Poor Performance with Distinct Subqueries with EXISTS and EXCEPT