pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Postgres User <postgresuser@yahoo.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6668: hashjoin cost problem
Date: Thu, 31 May 2012 18:48:01 -0400
Message-ID: <23375.1338504481@sss.pgh.pa.us> (raw)
In-Reply-To: <1338443837.61025.YahooMailNeo@web121105.mail.ne1.yahoo.com>
References: <E1SZtC5-00028E-DI@wrigleys.postgresql.org>
	<28259.1338440604@sss.pgh.pa.us>
	<1338443837.61025.YahooMailNeo@web121105.mail.ne1.yahoo.com>

Postgres User <postgresuser@yahoo.com> writes:
> Why is cost_hashjoin estimating 50 billion tuple comparisons for 10K rows of output though?

Well, if it hashes the smaller table, there's 100 million rows on the
outside, and each of them will probe one hash chain in the hash table.
If you're unlucky, each of those probes will hit a populated hash chain
with at least 1000 entries, leading to 100 billion comparisons.  I think
it might derate that worst-case by a factor of 2.  Now if you're lucky,
a lot of the outer tuples hit unpopulated hash chains and so the number
of comparisons is a lot less --- but in non-artificial examples,
that's not a very good bet to make.  The conservative assumption is that
both sides of the join have similar key distributions, so that the more
populated hash chains are also more likely to be probed.  The cost
estimate is therefore designed to discriminate against using an inner
relation with a non-flat distribution.

			regards, tom lane



view thread (4+ messages)

Message-ID: <23375.1338504481@sss.pgh.pa.us>
Permalink:  ../23375.1338504481@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23375.1338504481@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, postgresuser@yahoo.com
  Subject: Re: BUG #6668: hashjoin cost problem
  In-Reply-To: <23375.1338504481@sss.pgh.pa.us>
  References: <E1SZtC5-00028E-DI@wrigleys.postgresql.org> <28259.1338440604@sss.pgh.pa.us> <1338443837.61025.YahooMailNeo@web121105.mail.ne1.yahoo.com> <23375.1338504481@sss.pgh.pa.us>

* 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