pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ang Chin Han <angch@pollcities.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Hash Join not using hashed index?
Date: Wed, 28 Jun 2000 15:20:57 +0800
Message-ID: <20000628152057.A30233@pollcities.com> (raw)
In-Reply-To: <14589.962175604@sss.pgh.pa.us>
References: <20000628132411.B29825@pollcities.com>
	<14589.962175604@sss.pgh.pa.us>

On Wed, Jun 28, 2000 at 03:00:04AM -0400, Tom Lane wrote:
> Hash joins don't have anything to do with hash indexes.

> A hash join is a join that makes use of a temporary hashtable
> built on-the-fly *in memory* for that join.

Oh, I see.

> The planner could choose to use an indexscan on a hash index
> as an input for the join, but it'd only be likely to do so
> if there is a restriction clause matching the index.  In your
> example you have only a join WHERE clause.

Well, in my original query, there was, but the plan's the same.
Probably the clause wasn't restrictive enough (" and region < n").

Original cost est:
Hash Join  (cost=8.85..16.76 rows=75 width=18)
  ->  Seq Scan on city  (cost=0.00..1.75 rows=75 width=16) 
  ->  Hash  (cost=5.53..5.53 rows=253 width=2)
        ->  Seq Scan on country  (cost=0.00..5.53 rows=253 width=2) 

I guess the problem is that country-city is a one-to-many relation,
BUT I've more countries than cities (note the # of rows above), thus
throwing the planner off...

OTOH, what's bugging me is that Postgresql could have used
pre-generated hash index rather rebuilding it on the fly again.

> Plain btree indexes on city.country_id and country.country_id
> might work better --- at least they'd offer the option of
> a merge join without doing explicit sort.

I tried, and it did worse.


Hmmm... I think I'm better off creating a temporary table
to store the results, since the table is seldom updated
but that query is run often. Rules to update that temp. table, too, 
of course.

(cost is now 1.75, if anyone cares)



view thread (6+ messages)  latest in thread

Message-ID: <20000628152057.A30233@pollcities.com>
Permalink:  ../20000628152057.A30233@pollcities.com/
Also on:    postgresql.org/message-id/20000628152057.A30233@pollcities.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-sql@postgresql.org
  Cc: angch@pollcities.com, tgl@sss.pgh.pa.us
  Subject: Re: Hash Join not using hashed index?
  In-Reply-To: <20000628152057.A30233@pollcities.com>
  References: <20000628132411.B29825@pollcities.com> <14589.962175604@sss.pgh.pa.us> <20000628152057.A30233@pollcities.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