Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA37585 for ; Wed, 30 Jun 1999 10:45:13 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id KAA22125; Wed, 30 Jun 1999 10:43:55 -0400 (EDT) To: webmaster@tony.cz cc: pgsql-sql@postgreSQL.org Subject: Re: [SQL] Beginner's headache of joins In-reply-to: Your message of Wed, 30 Jun 1999 10:10:48 +0200 <99063010322700.00904@localhost.localdomain> Date: Wed, 30 Jun 1999 10:43:55 -0400 Message-ID: <22123.930753835@sss.pgh.pa.us> From: Tom Lane webmaster 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