pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Evgeny Shishkin <itparanoia@gmail.com>
To: Huan Ruan <huan.ruan.it@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: hash join vs nested loop join
Date: Wed, 12 Dec 2012 08:59:04 +0400
Message-ID: <3A5ED8C4-B611-4AF1-BFB1-AA05F9F594D8@gmail.com> (raw)
In-Reply-To: <8485F899-D139-41F9-B2E6-2D0F5B253367@gmail.com>
References: <CAGgcTZvrcmG-YoOi92b_YS-dchRPqa-kB7i_ZaEkJheqsSAADw@mail.gmail.com>
	<FF6456BC-134D-485E-8491-E651D00D7872@gmail.com>
	<CAD1stZukPPhrhZq7jSrM_0wh18nr7wbqJi=vrftAkz7p32guaQ@mail.gmail.com>
	<8485F899-D139-41F9-B2E6-2D0F5B253367@gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>


On Dec 12, 2012, at 8:57 AM, Evgeny Shishkin <itparanoia@gmail.com> wrote:

> 
> On Dec 12, 2012, at 8:44 AM, Huan Ruan <huan.ruan.it@gmail.com> wrote:
> 
>> 
>> On 12 December 2012 15:33, Evgeny Shishkin <itparanoia@gmail.com> wrote:
>> Optimiser thinks that nested loop is more expensive, because of point PK lookups, which a random io.
>> Can you set random_page_cost to 2 or 3 and try again?
>> 
>> Hi Evgeny
>> 
>> Thanks for the quick reply. Setting random_page_cost to 3 doesn't make a difference, but to 2 makes the optimiser to choose nested loop. However, with such a small penalty for random I/O, I'm worry about this setting will make other small queries incorrectly use index when it should be a sequential scan though. I understand random I/O is expensive, but in this case the optimiser already knows the big table is really big, should it consider a sequential scan will be slower than an index lookup? Scan 170 million records vs index lookup of 50,000 records. Any thoughts?
>> 
> 
> Yes, this is the most common issue for me. 
> Usually you just have to find the right combination of random and seq scan costs, shared_buffers and effective_cache_size.
> If some of the queries work well with another value of, say, random_page_cost, then, since it is per session parameter, you can SET it in your session before the query. But over time your table may change in size and distribution and everything brakes. No speaking about general ugliness from application standpoint.
> 
> May be somebody more experienced would help.
> 
> Also you can set different costs per tablespace.
> 
>> Thanks
>> Huan
> 

Added CC.

view thread (17+ messages)  latest in thread

Message-ID: <3A5ED8C4-B611-4AF1-BFB1-AA05F9F594D8@gmail.com>
Permalink:  ../3A5ED8C4-B611-4AF1-BFB1-AA05F9F594D8@gmail.com/
Also on:    postgresql.org/message-id/3A5ED8C4-B611-4AF1-BFB1-AA05F9F594D8@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: itparanoia@gmail.com, huan.ruan.it@gmail.com
  Subject: Re: hash join vs nested loop join
  In-Reply-To: <3A5ED8C4-B611-4AF1-BFB1-AA05F9F594D8@gmail.com>
  References: <CAGgcTZvrcmG-YoOi92b_YS-dchRPqa-kB7i_ZaEkJheqsSAADw@mail.gmail.com> <FF6456BC-134D-485E-8491-E651D00D7872@gmail.com> <CAD1stZukPPhrhZq7jSrM_0wh18nr7wbqJi=vrftAkz7p32guaQ@mail.gmail.com> <8485F899-D139-41F9-B2E6-2D0F5B253367@gmail.com> <3A5ED8C4-B611-4AF1-BFB1-AA05F9F594D8@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox