Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Performance > Re: Group by mo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 14 Topic 4002 of 4355
Post > Topic >>

Re: Group by more efficient than distinct?

by lists@[EMAIL PROTECTED] (PFC) Apr 18, 2008 at 12:35 PM

On Fri, 18 Apr 2008 11:36:02 +0200, Gregory Stark <stark@[EMAIL PROTECTED]
>=
=20=20
wrote:

> "Francisco Reyes" <lists@[EMAIL PROTECTED]
> writes:
>
>> Is there any dissadvantage of using "group by" to obtain a unique list?
>>
>> On a small dataset the difference was about 20% percent.
>>
>> Group by
>> HashAggregate  (cost=3D369.61..381.12 rows=3D1151 width=3D8) (actual
>> time=3D76.641..85.167 rows=3D2890 loops=3D1)

	Basically :

	- If you process up to some percentage of your RAM worth of data,
ha****ng=
=20=20
is going to be a lot faster
	- If the size of the hash grows larger than your RAM, ha****ng will
fail=20=
=20
miserably and sorting will be much faster since PG's disksort is
really=20=
=20
good
	- GROUP BY knows this and acts accordingly
	- DISTINCT doesn't know this, it only knows sorting, so it sorts
	- If you need DISTINCT x ORDER BY x, sorting may be faster too
(depending=
=20=20
on the % of distinct rows)
	- If you need DISTINCT ON, well, you're stuck with the Sort
	- So, for the time being, you can replace DISTINCT with GROUP BY...

--=20
Sent via pgsql-performance mailing list (pgsql-performance@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
 




 14 Posts in Topic:
Group by more efficient than distinct?
lists@[EMAIL PROTECTED]   2008-04-17 23:46:08 
Re: Group by more efficient than distinct?
mlists@[EMAIL PROTECTED]   2008-04-18 09:25:04 
Re: Group by more efficient than distinct?
stark@[EMAIL PROTECTED]   2008-04-18 10:36:02 
Re: Group by more efficient than distinct?
lists@[EMAIL PROTECTED]   2008-04-18 12:35:04 
Re: Group by more efficient than distinct?
lists@[EMAIL PROTECTED]   2008-04-20 11:15:36 
Re: Group by more efficient than distinct?
lists@[EMAIL PROTECTED]   2008-04-22 01:34:40 
Re: Group by more efficient than distinct?
mark@[EMAIL PROTECTED] (  2008-04-21 19:50:22 
Re: Group by more efficient than distinct?
mark@[EMAIL PROTECTED] (  2008-04-21 21:39:15 
Re: Group by more efficient than distinct?
lists@[EMAIL PROTECTED]   2008-04-20 11:12:10 
Re: Group by more efficient than distinct?
llonergan@[EMAIL PROTECTE  2008-04-20 22:35:58 
Re: Group by more efficient than distinct?
matthew@[EMAIL PROTECTED]  2008-04-22 11:34:23 
Re: Group by more efficient than distinct?
mark@[EMAIL PROTECTED] (  2008-04-22 08:01:20 
Re: Group by more efficient than distinct?
matthew@[EMAIL PROTECTED]  2008-04-22 13:22:20 
Re: Group by more efficient than distinct?
mark@[EMAIL PROTECTED] (  2008-04-22 09:04:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 2:30:20 CDT 2008.