NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP array_unique vs. SQL DISTINCT

Adrian Noland anoland at indigente.net
Mon Jun 4 12:06:52 EDT 2007


On 6/3/07, David Krings <ramons at gmx.net> wrote:
>
> Adrian Noland wrote:
> > The key to speedy SQL is in the indexes. Without an index the SQL engine
> > iterates over every row. With an index it automagically grabs the
> > correct value.
>
> This is really an eyeopener. After indexing all those columns that come
> up in some selects running the same query that took over 30 minutes
> (that's when I hit the reset button) now takes 26 seconds.
>
> This is plain awesome! Thanks for making me less dumb.
>
> David
>
>
When it comes to choosing which columns to index, you want to pick something
with a high cardinality, or, for lack of a better term, "uniqueablity".
Gender wont have a high cardinality because there are only 2 choices for
many records. Last name on your personal family address book will have a low
cardinality because of family members sharing last name. A key of last name
+ first name will have a high cardinality and will make a good index.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070604/182f2bda/attachment.html>


More information about the talk mailing list