pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jhood@hmcon.com
Cc: pgsql-general@postgresql.org
Subject: Re: Query Performance...
Date: Sat, 20 Jul 2002 16:54:43 -0400
Message-ID: <14361.1027198483@sss.pgh.pa.us> (raw)
In-Reply-To: <a2c11736.0207180743.5b1ef587@posting.google.com>
References: <a2c11736.0207171231.22cae5e6@posting.google.com>
	<a2c11736.0207180743.5b1ef587@posting.google.com>

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



view thread (47+ messages)  latest in thread

Message-ID: <14361.1027198483@sss.pgh.pa.us>
Permalink:  ../14361.1027198483@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14361.1027198483@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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jhood@hmcon.com
  Subject: Re: Query Performance...
  In-Reply-To: <14361.1027198483@sss.pgh.pa.us>
  References: <a2c11736.0207171231.22cae5e6@posting.google.com> <a2c11736.0207180743.5b1ef587@posting.google.com> <14361.1027198483@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