NYCPHP Meetup

NYPHP.org

[nycphp-talk] Table Indexes

Michael B Allen ioplex at gmail.com
Sat Sep 27 20:54:10 EDT 2008


On Sat, Sep 27, 2008 at 8:32 PM, Daniel Convissor
<danielc at analysisandsolutions.com> wrote:
> Hi John:
>
> On Sun, Sep 07, 2008 at 02:31:48PM -0400, John Campbell wrote:
>>
>> With MySQL the fastest is often:
>> Primary(a,b)
>> index(b)
>
> I agree.
>
>
>> And in sometimes you even want:
>> Primary(a,b)
>> index(a)
>> index(b)
>
> The second index of "a" would duplicate the index of "a" in the primary
> key.

So is the first column of a primary key always also an index? I
thought I read somewhere that the columns are concatenated together to
form one index?

Something else of interest that I have learned is that MySQL can only
use one index per SELECT. So unfortunately OR-ing all the joins is
actually quite slow. If I use UNIONs instead, the query is a LOT
faster.

Currently I am using the second case above. I'll make a point of
dropping the INDEX(a) in the next iteration of the code and see how
that affects performance.

Mike

-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/



More information about the talk mailing list