beginner join optimization question
beginner join optimization question
От:
"Peter Su" <psu@jprc.com>
Дата:
I have two tables, say, t1 (id, title) t2 (id, hash) I want to run a query of the form: select title from t1,t2 where t1.id=t2.id and t2.hash=15; I have indexes on all fields, but postgres insists on doing a nested loop join between t1 and t2 which takes a lot of time. If I do this select title into temp from t1,t2 where t1.id=t2.id; select * from temp where temp.hash=15; things go much much faster because now postgres uses a hash join. Is there any way to synthesize this behavior without using the temp. table? thanks, Pete p.s. t1 has, say, 10K records and t2 is somewhat smaller, less then a thousand records.