Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 80A44474E44 for ; Sat, 20 Jul 2002 16:55:03 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g6KKshVk014362; Sat, 20 Jul 2002 16:54:44 -0400 (EDT) To: jhood@hmcon.com (Jeffrey Hood) Cc: pgsql-general@postgresql.org Subject: Re: Query Performance... In-reply-to: References: Comments: In-reply-to jhood@hmcon.com (Jeffrey Hood) message dated "18 Jul 2002 08:43:45 -0700" Date: Sat, 20 Jul 2002 16:54:43 -0400 Message-ID: <14361.1027198483@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200207/1293 X-Sequence-Number: 27780 jhood@hmcon.com (Jeffrey Hood) writes: > explain > select r.dateissued, r.medication, p.lastname, p.dob > from rx r > inner join patient p on r.patientid = p.patientid > where r.dateissued between '7/13/02' and '7/14/02'; > Merge Join (cost=237899.24..250302.47 rows=24895698 width=64) > -> Sort (cost=8590.77..8590.77 rows=2515 width=32) > -> Index Scan using idx_rx_date_issued on rx r > (cost=0.00..8448.70 rows=2515 width=32) > -> Sort (cost=229308.47..229308.47 rows=989743 width=32) > -> Seq Scan on patient p (cost=0.00..35256.43 rows=989743 > width=32) > How does one get rid of the table scan on patient in the second...??? The only *possible* alternative to a seqscan on patient would be to use a nestloop with inner indexscan on patient.patientid, and I'm not at all clear that that'd be faster than the seqscan --- it would depend on how many rows are actually returned by the rx scan. Have you got an index on patientid? If you set enable_seqscan = off, does the plan change? regards, tom lane