Re: Append table - Mailing list pgsql-performance

From Gregory Stark
Subject Re: Append table
Date
Msg-id 87d50e5n5n.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: Append table  (Arjen van der Meijden <acmmailing@tweakers.net>)
List pgsql-performance
"Arjen van der Meijden" <acmmailing@tweakers.net> writes:

> There are two solutions:
...
> Or you can visually combine them without actually putting the records in a
> single table. That can be with a normal select-union statement or with a view,
> something like this:
> SELECT EmpId, EmpName FROM tabelA UNION EmpID, EmpName FROM tabelB;

If you're sure the two sets are distinct or you want to get any duplicates and
not eliminate them then if you went with this option you would want to use
"UNION ALL" not just a plain union.

In SQL UNION has to remove duplicates which often involves gathering all the
records and performing a big sort and lots of extra work. UNION ALL is much
faster and can start returning records right away.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com


pgsql-performance by date:

Previous
From: Arjen van der Meijden
Date:
Subject: Re: Append table
Next
From: Josh Berkus
Date:
Subject: Re: Postgres Benchmark Results