Re: joining two tables slow due to sequential scan

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Tim Jones <TJones(at)optio(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: joining two tables slow due to sequential scan
Date: 2006-02-10 22:22:05
Message-ID: 1139610125.22740.145.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, 2006-02-10 at 16:06, Tim Jones wrote:
>
> I am trying to join two tables and keep getting a sequential scan in
> the plan even though there is an index on the columns I am joining
> on. Basically this the deal ... I have two tables with docid in them
> which is what I am using for the join.
>

SNIP

> select * from documentversions join clinicaldocuments on
> documentversions.documentidentifier
> = clinicaldocuments.dssdocumentidentifier where
> documentversions.documentstatus = 'AC';
>
> does index scan
> but if I change the order e.g
>
> select * from clinicaldocuments join documentversions on
> clinicaldocuments.dssdocumentidentifier
> = documentversions .documentidentifier where
> clinicaldocuments.patientidentifier= 123;

OK. I'm gonna make a couple of guesses here:

1: clinicaldocuments.patientidentifier is an int8 and you're running
7.4 or before.
2: There are more rows with clinicaldocuments.patientidentifier= 123
than with documentversions.documentstatus = 'AC'.
3: documentversions.documentidentifier and
clinicaldocuments.dssdocumentidentifier are not the same type.

Any of those things true?

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tim Jones 2006-02-10 22:35:50 Re: joining two tables slow due to sequential scan
Previous Message Dave Dutcher 2006-02-10 22:14:30 Re: joining two tables slow due to sequential scan