・・・っていうか、JOIN知らないんじゃないか?
select id from foo => 1000行くらいデータ取得
select * from bar where foo_id in (1000個くらいの値リスト)
とかやってるんじゃないだろうな。