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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Responses

Browse pgsql-performance by date

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