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

Re: Querying distinct values from a large table

From: Richard Huxton <dev(at)archonet(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Igor Lobanov <ilobanov(at)swsoft(dot)com>,pgsql-performance(at)postgresql(dot)org
Subject: Re: Querying distinct values from a large table
Date: 2007-01-30 14:11:48
Message-ID: 45BF5224.3070805@archonet.com (view raw or flat)
Thread:
Lists: pgsql-performance
Simon Riggs wrote:
> On Tue, 2007-01-30 at 15:33 +0600, Igor Lobanov wrote:
> 
>> explain analyze select distinct a, b from tbl
>>
>> EXPLAIN ANALYZE output is:
>>
>>   Unique  (cost=500327.32..525646.88 rows=1848 width=6) (actual 
>> time=52719.868..56126.356 rows=5390 loops=1)
>>     ->  Sort  (cost=500327.32..508767.17 rows=3375941 width=6) (actual 
>> time=52719.865..54919.989 rows=3378864 loops=1)
>>           Sort Key: a, b
>>           ->  Seq Scan on tbl  (cost=0.00..101216.41 rows=3375941 
>> width=6) (actual time=16.643..20652.610 rows=3378864 loops=1)
>>   Total runtime: 57307.394 ms
> 
> All your time is in the sort, not in the SeqScan.
> 
> Increase your work_mem.

Well, even if the sort was instant it's only going to get him down to 
20secs.

-- 
   Richard Huxton
   Archonet Ltd

In response to

pgsql-performance by date

Next:From: Chad WagnerDate: 2007-01-30 14:13:27
Subject: Re: Querying distinct values from a large table
Previous:From: Simon RiggsDate: 2007-01-30 14:04:15
Subject: Re: Querying distinct values from a large table

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