Índice concatenado de MySQL al unir varias tablas

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?

preguntado el 09 de marzo de 12 a las 16:03

Has intentado EXPLAIN ¿la consulta? -

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 -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.