Double join on same table very slow
I have a Link table with `from_uid` and `to_uid` (both indexed individually and also together) and I want to filter out certain ids. So I do:
SELECT l.uid
FROM Link l
JOIN filter_ids t1 ON l.from_uid = t1.id
JOIN filter_ids t2 ON l.to_uid = t2.id
Now for some reason this is unexpectedly slow :( whereas each individual join is very fast. Can it not use the index right? The same happens if I join different table. For some reason it never uses the index for `from_uid` and `to_uid` :(
`EXPLAIN` tells me:
id select table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index Null PRIMARY 34 Null 12205 Using index
1 SIMPLE l ref from_uid,to_uid from_uid 96 func 6 Using where
1 SIMPLE t2 index Null PRIMARY 34 Null 12205 Using where; Using index; Using join buffer
Can I avoid creating temporary tables with a complicating two step join?
Subject
Views
Written By
Posted
Double join on same table very slow
2550
August 01, 2012 08:55AM
1032
August 01, 2012 09:42AM
1267
August 03, 2012 09:00AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.