beginner join optimization question - Mailing list pgsql-sql

From Peter Su
Subject beginner join optimization question
Date
Msg-id 002101bd9fa6$21f035e0$da9356cf@hugo.jprc.com
Whole thread Raw
List pgsql-sql
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.



pgsql-sql by date:

Previous
From: Marin D
Date:
Subject: Re: [SQL] foreign keys
Next
From: Mariana Travassos Aguiar da Silva
Date:
Subject: Help