Re: Merging large volumes of data

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Andreas Kostyrka" <andreas(at)kostyrka(dot)org>
Cc: "Ambrus Wagner \(IJ/ETH\)" <ambrus(dot)wagner(at)ericsson(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Merging large volumes of data
Date: 2007-05-07 14:24:23
Message-ID: 87lkg0yanc.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


"Andreas Kostyrka" <andreas(at)kostyrka(dot)org> writes:

>> (select a,b,c,d,e from table1 order by a,b) union all
>> (select a,b,c,d,e from table2 order by a,b) union all
>> etc...
>> (select a,b,c,d,e from tablen order by a,b) order by a,b;
>>
>> PostgreSQL does not seem to realise (maybe it should not be able to do this
>> trick anyway) that the last "order by" clause is merely a final merge step
>> on the ordered data sets.

There's no plan type in Postgres for merging pre-sorted data like this. The
only merge plan type is for joins which isn't going to be what you need.

But the queries as written here would be just as fast or faster to do one big
sort as they would be to do separate sorts and merge the results.

You might want to do it the way you describe if there were selective WHERE
clauses that you've left out that make the intermediate orderings come for
free.

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2007-05-07 15:09:28 Re: Merging large volumes of data
Previous Message Andreas Kostyrka 2007-05-07 13:44:34 Re: Merging large volumes of data