Skip site navigation (1) Skip section navigation (2)

Re: UNION and bad performance

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: pasman pasmański <pasman(dot)p(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: UNION and bad performance
Date: 2010-12-20 18:57:09
Message-ID: AANLkTinC0ZcS1N54T-jmpj3VPWVnW15apmWVCKucgnD0@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
2010/12/12 pasman pasmański <pasman(dot)p(at)gmail(dot)com>:
>> UNION will remove all duplicates, so that the result additionally requires to
>> be sorted.
>
>>Right, to avoid the SORT and UNIQUE - operation you can use UNION ALL
>
>
> by the way maybe apply hashing to calculate UNION be better ?

The planner already considers such plans.

rhaas=# explain select a from generate_series(1,100) a union select a
from generate_series(1,100) a;
                                      QUERY PLAN
--------------------------------------------------------------------------------------
 HashAggregate  (cost=45.00..65.00 rows=2000 width=4)
   ->  Append  (cost=0.00..40.00 rows=2000 width=4)
         ->  Function Scan on generate_series a  (cost=0.00..10.00
rows=1000 width=4)
         ->  Function Scan on generate_series a  (cost=0.00..10.00
rows=1000 width=4)
(4 rows)

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

pgsql-performance by date

Next:From: tuanhoanganhDate: 2010-12-21 03:31:59
Subject: Re: PostgreSQL 9.0 x64 bit pgbench TPC very low question?
Previous:From: Scott MarloweDate: 2010-12-20 18:19:59
Subject: Re: postgres performance tunning

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group