Re: Overhead of union versus union all

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, 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 17:47:35
Message-ID: 407d949e0907101047l39aff5d8h428c044a849da6d3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 10, 2009 at 6:37 PM, Jeff Davis<pgsql(at)j-davis(dot)com> wrote:
>
> -- foo has a primary key
> SELECT * FROM foo UNION SELECT * FROM foo;
>
> That's logically equivalent to:
>
> SELECT * FROM foo;
>
> But postgresql will add a sort anyway.

Well no, it's equivalent to SELECT DISTINCT * FROM foo;

--
greg
http://mit.edu/~gsstark/resume.pdf

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message artacus 2009-07-10 17:48:38 Re: XML import with DTD
Previous Message James B. Byrne 2009-07-10 17:38:57 How to trace client sql requests?