Enforcing a query in MySql to use a specific index
Posted
by Hossein
on Stack Overflow
See other posts from Stack Overflow
or by Hossein
Published on 2010-05-13T21:50:43Z
Indexed on
2010/05/13
21:54 UTC
Read the original article
Hit count: 355
Hi, I have large table. consisting of only 3 columns (id(INT),bookmarkID(INT),tagID(INT)).I have two BTREE indexes one for each bookmarkID and tagID columns.This table has about 21 Million records. I am trying to run this query:
SELECT bookmarkID,COUNT(bookmarkID) AS count
FROM bookmark_tag_map
GROUP BY tagID,bookmarkID
HAVING tagID IN (-----"tagIDList"-----) AND count >= N
which takes ages to return the results.I read somewhere that if make an index in which it has tagID,bookmarkID together, i will get a much faster result. I created the index after some time. Tried the query again, but it seems that this query is not using the new index that I have made.I ran EXPLAIN and saw that it is actually true. My question now is that how I can enforce a query to use a specific index? also comments on other ways to make the query faster are welcome. Thanks
© Stack Overflow or respective owner