View Single Post

  #2 (permalink)  
Old 01-02-2008
Good Man
 
Posts: n/a
Default Re: Query running very very slow

gianpaolo <gianpaolo.pelloni@tin.it> wrote in news:df74318e-974f-4b75-97d5-
3c15ba82b5fa@y5g2000hsf.googlegroups.com:

> This is the query:
>
> SELECT DISTINCT A.id FROM B INNER JOIN A ON A.id=B.artist WHERE
> B.artist != 2444 AND B.artist != 92874 AND (A.surname LIKE 'james brown
> %' OR A.name LIKE 'james brown%') LIMIT 3;
>
> A: 230,848 rows
> B: 386,933 rows
>
> A has indexes on: id, name, surname
> B has indexes on: artist
>
> id: int 4
> name and surname: varchar 70
>
> Query execution time: 2.34 sec
>
> If i execute a query like this:
> SELECT DISTINCT A.id FROM B INNER JOIN A ON A.id=B.artist WHERE
> (A.surname LIKE 'james brown%' OR A.name LIKE 'james brown%') LIMIT 3;
> the execution time is: 0.00 sec
>
> I really don't understand. Anyone can help me please?
>


Try using EXPLAIN to see a little more of what is happening behind the
scenes....

Reply With Quote