Skip site navigation (1) Skip section navigation (2)

Re: Why is a hash join being used?

From: Sergey Konoplev <sergey(dot)konoplev(at)postgresql-consulting(dot)com>
To: Tim Jacobs <tjacobs2(at)email(dot)unc(dot)edu>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Why is a hash join being used?
Date: 2012-06-20 13:36:20
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
On Wed, Jun 20, 2012 at 1:34 AM, Tim Jacobs <tjacobs2(at)email(dot)unc(dot)edu> wrote:
> The nested loop join performs very quickly, whereas the hash join is incredibly slow. If I disable the hash join temporarily then a nested loop join is used in the second case and is the query runs much more quickly. How can I change my configuration 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
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

> Alternatively, since I will be doing selections like this many times, what indexes can be put in place to expedite the query 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(at)postgresql(dot)org)
> To make changes to your subscription:

Sergey Konoplev

a database architect, software developer at

Jabber: gray(dot)ru(at)gmail(dot)com Skype: gray-hemp Phone: +79160686204

In response to

pgsql-performance by date

Next:From: Andy ColsonDate: 2012-06-20 13:43:01
Subject: Re: scale up (postgresql vs mssql)
Previous:From: Eyal WildeDate: 2012-06-20 06:01:13
Subject: Re: scale up (postgresql vs mssql)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group