Re: Overhead of union versus union all

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, Scott Bailey <artacus(at)comcast(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Overhead of union versus union all
Date: 2009-07-10 14:00:47
Message-ID: 1247234447.11347.598.camel@ebony.2ndQuadrant
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Fri, 2009-07-10 at 09:46 -0400, Bruce Momjian wrote:
> Simon Riggs wrote:
> > or a query like this
> >
> > Select '1', ...
> > ...
> > union
> > Select status, ...
> > ...
> > where status != '1';
> > ;
> >
> > then it is clear that we could automatically prove that the the distinct
> > step is redundant and so we could either hash or sort. This is the same
> > as replacing the UNION with UNION ALL.
>
> In the last example, how do you know that status != '1' produces unique
> output?

You don't. I was assuming that you could already prove that each
subquery was distinct in itself.

It's one for the TODO, that's all. I see it often, but I'm not planning
to work on the code for this myself.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hiroshi Saito 2009-07-10 14:26:32 Re: psql language
Previous Message Bruce Momjian 2009-07-10 13:46:23 Re: Overhead of union versus union all