DISTINCT vs. GROUP BY - Mailing list pgsql-hackers

From Hans-Jürgen Schönig
Subject DISTINCT vs. GROUP BY
Date
Msg-id 432ECAE2.7070805@cybertec.at
Whole thread Raw
Responses Re: DISTINCT vs. GROUP BY
Re: DISTINCT vs. GROUP BY
List pgsql-hackers
I was wondering whether it is possible to teach the planner to handle 
DISTINCT in a more efficient way:

em=# explain select distinct lastname from import.testtest;                                   QUERY PLAN
-------------------------------------------------------------------------------- Unique  (cost=2647377.45..2709467.70
rows=1width=7)   ->  Sort  (cost=2647377.45..2678422.58 rows=12418051 width=7)         Sort Key: lastname         ->
SeqScan on testtest  (cost=0.00..370082.51 rows=12418051 
 
width=7)
(4 Zeilen)


Isn't it possible to perform the same operation using a HashAggregate?
We have seen that a GROUP BY workaround is usually a lot faster than 
sort->unique - at least when work_mem is large enough.
best regards,
    hans


-- 
Cybertec Geschwinde & Schönig GmbH
Schöngrabern 134; A-2020 Hollabrunn
Tel: +43/1/205 10 35 / 340
www.postgresql.at, www.cybertec.at


pgsql-hackers by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: New dot releases
Next
From: Neil Conway
Date:
Subject: Re: DISTINCT vs. GROUP BY