RE: PHP/mySQL question about groups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I did some looking into performance issues many years ago at company that
developed and marketed another database server, comparing the query plan to
the actual code, and a query plan usually shows the processes that consume
the major amount of time, disk I/O, index or table searches and such, but
doesn't show time consumed comparing, discriminating, and totaling, mostly
because they are negligible.

On the other hand distinct depends on comparison of all columns and will
have no help in reducing row counts unless accompanied by an order by
clause, where as group by implys an orderby and can be faster if indexes are
available for use in row ordering, and while the same totaling occurs,
comparison is limited to the columns specified in the group by.

The biggest impact on one or the other would be a well placed index, but for
the most part they should be about the same.

Warren Vail

-----Original Message-----
From: Andrew Ballard [mailto:aballard@xxxxxxxxx] 
Sent: Wednesday, February 06, 2008 8:41 PM
To: PHP General list
Subject: Re:  PHP/mySQL question about groups

On Feb 6, 2008 11:20 PM, Nathan Nobbe <quickshiftin@xxxxxxxxx> wrote:
> On Feb 6, 2008 10:59 PM, Andrew Ballard <aballard@xxxxxxxxx> wrote:
>
> > Of course, in this case you could just avoid all the confusion with 
> > this statement as well:
> >
> > SELECT DISTINCT name, size
> > FROM    wine
>
> im not sure why, but i think distinct is typically way slower than group
by.
>
> -nathan
>

I can't really say for MySQL, but in my experience I'd say "it depends." It
seems to me that for this case they should be about the same, as it's always
been my thinking that GROUP BY did a DISTINCT implicitly. However, I don't
really know the internals of any DB platform so I can't confirm that. I ran
DESCRIBE on a couple different tables, and they both return the same plan. I
don't see any notable difference in the queries either. However, I'll leave
it to the OP to test and see if one is better for his question.

Andrew

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux