Re: Is this proper UNION behavior??

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jules Bean <jules(at)jellybean(dot)co(dot)uk>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is this proper UNION behavior??
Date: 2000-11-14 16:03:05
Message-ID: 2604.974217785@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jules Bean <jules(at)jellybean(dot)co(dot)uk> writes:
> ObPG: I'm no suggesting that Pg change this, by the way, I'm just
> ranting pointlessly about one of SQL's stupidities. Maybe Pg ought to
> have an option for 'bette-than-SQL', though, which would, among other
> thigns, not permit duplicates in relations (and switch back on that
> optimisation).

Just to clarify: it was not really an optimization, at least not to
my mind. How many people are ever going to write "X union X" in real
queries? As an optimization attempt, it was a complete waste of time
to be looking for this case --- the savings on the once-in-a-blue-moon
silly query would never pay for the cycles burned to make the test on
every other query.

The reason that code was there in the first place is that the pre-7.1
implementation method for UNION/INTERSECT/EXCEPT could only cope with
query trees in which all the UNIONs were at the top. So what was
*really* being done was a transformation to disjunctive normal form,
eg,
(X union Y) intersect Z
becomes
(X intersect Z) union (Y intersect Z)
The simplication of cases like X union X was a byproduct of the DNF
transformation routine, which was an algorithm designed for boolean
expressions in which such a transformation is completely legitimate.

Now of course what will leap out at you here is that the transformed
query is likely to be considerably *more* work than the original.
So for real queries, this wasn't an optimization at all, but a
pessimization. I have no intention of putting it back regardless of
debates about better-than-SQL semantics ;-)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Anders R. Sveen 2000-11-14 16:04:45 Re: Encoding
Previous Message Hervé Piedvache 2000-11-14 16:01:22 Error with Vaccum Analyze !?