Re: [SQL] Beginner's headache of joins

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: webmaster(at)tony(dot)cz
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Beginner's headache of joins
Date: 1999-06-30 14:43:55
Message-ID: 22123.930753835@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

webmaster <webmaster(at)tony(dot)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

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Lockhart 1999-06-30 15:16:24 Re: [PORTS] Port Bug Report: parse error not detected onunterminated quote
Previous Message Kyle Bateman 1999-06-30 14:36:55 Re: [PORTS] Port Bug Report: parse error not detected onunterminated quote