mysql join on two indexes takes long time!!

Posted by Alaa on Stack Overflow See other posts from Stack Overflow or by Alaa
Published on 2011-01-03T12:38:31Z Indexed on 2011/01/03 12:53 UTC
Read the original article Hit count: 202

Filed under:
|
|

Hi All
I have a custom query in dripal, this query is:

select count(distinct B.src) 
from node A, url_alias B 
where concat('node/',A.nid)= B.src;

now, nid in node is primary key and i have made src as an index in url_alias table. after waiting for more than a minute i got this:

+-----------------------+  
| count(distinct B.src) |  
+-----------------------+  
|                325715 |  
+-----------------------+  
1 row in set (1 min 24.37 sec)  

now my question is: why did this query take this long, and how to optimize it??
Thanks for your help

© Stack Overflow or respective owner

Related posts about mysql

Related posts about drupal