this driving me crazy, im trying hard make join 3 tables on mysql, want is, select suscriptors user suscribed to, , it, got tables
user(id, nombre) suscriptor(id, nombre) suscripcion(id, userid, suscriptorid) the query use one:
select u.nombre, sr.nombre, s.suscriptorid user u inner join suscripcion s on s.userid = u.id inner join suscriptor sr on sr.id = s.suscriptorid u.id = 1; and works fine, when use explain check query, when there's 1 result, mean, when user id = 1 suscribed 1 suscriptor fine me cause total rows scanned 1 * 1 * 1. problem when user suscribed more 1 suscriptors, cause displays:
row 1 , type const in table u(user)
row 1 , type ref in table s(suscripcion)
row 5(which total rows) , type in table sr(suscriptor)
i've tried these types of index combination:
- in table suscripcion: index ui(userid) , index si(suscriptorid)
and seems use 1 of index, , keeps scanning results in table suscriptor
- i've tried compound index : index usi(userid, suscriptorid) ignore second index again , scan rows in table suscriptor.
thanks in avanced.
if have 5 rows query planner won't use index because it's faster read 5 rows use index. try testing few hundred rows. suggest index see if it's eligible @ all
Comments
Post a Comment