Re: Why is a hash join being used? - Mailing list pgsql-performance

From Sergey Konoplev
Subject Re: Why is a hash join being used?
Date
Msg-id CAL_0b1vp2xpbJXpKdRydRNd4bKLai9rGe7F2L=9eZT0rH7A6rQ@mail.gmail.com
Whole thread Raw
In response to Why is a hash join being used?  (Tim Jacobs <tjacobs2@email.unc.edu>)
List pgsql-performance
On Wed, Jun 20, 2012 at 1:34 AM, Tim Jacobs <tjacobs2@email.unc.edu> wrote:
> The nested loop join performs very quickly, whereas the hash join is incredibly slow. If I disable the hash join
temporarilythen a nested loop join is used in the second case and is the query runs much more quickly. How can I change
myconfiguration to favor the nested join in this case? Is this a bad idea? 

First do ANALYZE the tables and try the tests again.

If it helped check your autovacuum configuration. Look at
http://www.postgresql.org/docs/9.1/static/routine-vacuuming.html#AUTOVACUUM
and the pg_stat_user_tables table (last_* and *_count fields).

If it still produces wrong plan then try to increase statistics
entries by ALTER TABLE SET STATISTICS (do not forget to ANALYZE after
doing it) or by the default_statistics_target configuration parameter.
Read more about it here
http://www.postgresql.org/docs/9.1/static/planner-stats.html.

> Alternatively, since I will be doing selections like this many times, what indexes can be put in place to expedite
thequery without mucking with the query optimizer? I've already created an index on the struct_id field of
residue_atom_coords(each unique struct_id should only have a small number of rows for the residue_atom_coords table). 

As I can see everything is okay with indexes.

>
> Thanks in advance,
> Tim
>
>
>
> --
> Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance



--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: gray.ru@gmail.com Skype: gray-hemp Phone: +79160686204

pgsql-performance by date:

Previous
From: "Strange, John W"
Date:
Subject: pgbouncer - massive overhead?
Next
From: Andy Colson
Date:
Subject: Re: scale up (postgresql vs mssql)