0

If I have a tables like...

tblResource
-----------
id
r_name


tblCategory
--------
id
c_name


tblTag
-------
id
t_name

tblResCatTag
------------
r_id
c_id
t_id

I have read only single indexes are read on tables, and the order of the values is important, so if I index tblResCatTag like...

ADD INDEX (rid, cid, t_id);

and have a query like...

SELECT r.r_name, c.c_name, t.t_name
FROM tblResource r
LEFT OUTER JOIN tblResCatTag rtc ON r.id = rtc.r_id
LEFT OUTER JOIN tblCategory c ON rtc.c_id = c.id
LEFT OUTER JOIN tblTag t ON rtc.t_id = t.id

Will the index get used in the last two joins, or will it be ignored since rid is the first item in the index?

2
  • Have you tried to EXPLAIN the query? Mar 9, 2012 at 16:39
  • 2
    Try using explain or looking at the execution plan. I've created a short fiddle for you here which will allow you to view the differences: sqlfiddle.com/#!2/6b543/1
    – RumpRanger
    Mar 9, 2012 at 16:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.