pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: webmaster@tony.cz
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Beginner's headache of joins
Date: Wed, 30 Jun 1999 10:43:55 -0400
Message-ID: <22123.930753835@sss.pgh.pa.us> (raw)
In-Reply-To: <99063010322700.00904@localhost.localdomain>

webmaster <webmaster@tony.cz> writes:
> explain select catnum.catnum, kat.ident, kat.nazev where
> catnum.catnum=kat.ident;

> resulting as:

> HASH JOIN ...
>   -> SEQ SCAN ON catnum ...
>   -> HASH ...
>     -> SEQ SCAN ON kat...

> So, I can see that it's performing two scans without using indexes. Why?

Looks like a perfectly reasonable plan to me.  The nice thing about a
hash join is that it doesn't need to examine the tables in sorted order,
so there's no need for the expense of an index scan.  The system tries
to estimate whether this will be cheaper than a merge join (which does
need to scan the tables in sorted order), and evidently it thinks so.

You haven't given us nearly enough info to tell whether that's a good
decision or not, however.  How big are the tables, and what are the data
types of the columns you're joining on?  It would help also to see the
*full* output from EXPLAIN, including all the numeric values.

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <22123.930753835@sss.pgh.pa.us>
Permalink:  ../22123.930753835@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22123.930753835@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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, webmaster@tony.cz
  Subject: Re: [SQL] Beginner's headache of joins
  In-Reply-To: <22123.930753835@sss.pgh.pa.us>
  References: <99063010322700.00904@localhost.localdomain> <22123.930753835@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