RE: PHP/mySQL question about groups

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

 



You are correct, but that is what I meant by all columns (all those in the
query, and therefore subject to the distinct).  

At this point different database engines work differently, without an order
by, some will use the primary sequence, some will scan table space (in other
words, without an order by [or group by], some engines will give you a
performance hit).  It's always good practice to write your queries to help
your DB engine find an index.

Warren

> -----Original Message-----
> From: Andrew Ballard [mailto:aballard@xxxxxxxxx]
> Sent: Thursday, February 07, 2008 7:16 AM
> To: PHP General list
> Subject: Re:  PHP/mySQL question about groups
> 
> On Feb 7, 2008 1:20 AM, Warren Vail <warren@xxxxxxxxxxxx> wrote:
> > 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.
> 
> Does DISTINCT really compare all columns? I would think it would only
> compare the columns explicitly included in the SELECT clause.
> 
> 
> > 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
> >
> 
> I have seen discussions where in GROUP BY can be faster than DISTINCT
> depending on whether the query uses things like correlated subqueries,
> but this is not applicable in the current case. At any rate, I don't
> want to stray the conversation any further away than I already have.
> 
> 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