NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: MySQL doubt

Ophir Prusak prusak at gmail.com
Sat Jan 15 00:23:43 EST 2005


Both queries have the same where clause.
Since the where clause is using a column which DOES have an index, I
would think the parser would be smart enough to realize that in both
queries you'll get the same answer, so why not execute them both in
the fastest way possible (using the index)?

I'm not sure what you mean by "asking" mysql to use an index.

Ophir

On Sat, 15 Jan 2005 00:09:15 -0500, Faber Fedor <faber at linuxnj.com> wrote:
> On 14/01/05 21:16 -0500, Ophir Prusak wrote:
> > As long as we're on the subject, could someone shed some light on this behavior?
> > It caused me a good amount of hair pulling until I realized what mysql
> > was doing.
> >
> > Why doesn't MySQL use the primary key in the second query?
> 
> I may be missing something here, but why would MySQL use the PK in the second
> query?  You didn't ask it to.
> 
> > I would think that count doesn't care what column I use, but obviously it does.
> 
> Why would you think that? count doesn't care what column you use, but
> the optimizer will use an index if it is available.  If an index is not
> available, it uses the raw data (read: column).
> 
> 
> --
> 
> Regards,
> 
> Faber
> 
> Linux New Jersey: Open Source Solutions for New Jersey
> http://www.linuxnj.com
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>



More information about the talk mailing list