From TJones@optio.com Fri Feb 10 22:06:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4FB7A9DC800 for ; Fri, 10 Feb 2006 18:06:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20038-05 for ; Fri, 10 Feb 2006 18:06:42 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E17A19DC855 for ; Fri, 10 Feb 2006 18:06:38 -0400 (AST) Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by svr4.postgresql.org (Postfix) with ESMTP id 68CF75AF864 for ; Fri, 10 Feb 2006 22:06:41 +0000 (GMT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C62E8E.437A3F6A" Subject: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 17:06:35 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D3131302@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: joining two tables slow due to sequential scan Thread-Index: AcYujkHN1/mQ5kzZQ2ib5koRLF6qWA== From: "Tim Jones" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.081 required=5 tests=[AWL=0.080, HTML_MESSAGE=0.001] X-Spam-Score: 0.081 X-Spam-Level: X-Archive-Number: 200602/112 X-Sequence-Number: 17098 This is a multi-part message in MIME format. ------_=_NextPart_001_01C62E8E.437A3F6A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable =20 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. =20 =20 ClinicalDocs ... (no primary key) though it does not help if I make docid primary key docid integer (index) patientid integer (index) visitid integer (index) ... =20 Documentversions docid integer (index) docversionnumber (index) docversionidentifier (primary key) =20 It seems to do an index scan if I put the primary key as docid. This is what occurs when I link on the patid from ClinicalDocs to patient table. However I can not make the docid primary key because it gets repeated depending on how may versions of a document I have. I have tried using a foreign key on documentversions with no sucess.=20 =20 In addition this query =20 select * from documentversions join clinicaldocuments on documentversions.documentidentifier =3D clinicaldocuments.dssdocumentidentifier where documentversions.documentstatus =3D 'AC';=20 =20 does index scan=20 but if I change the order e.g =20 select * from clinicaldocuments join documentversions on clinicaldocuments.dssdocumentidentifier =3D documentversions .documentidentifier where clinicaldocuments.patientidentifier=3D 123; =20 does sequential scan what I need is bottom query it is extremely slow ... Any ideas ? =20 Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 =20 ------_=_NextPart_001_01C62E8E.437A3F6A Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
 
I am = trying to join=20 two tables and keep getting a sequential scan in the plan even though = there is=20 an index on the columns I am joining on.  Basically this the = deal  ...=20 I have two tables with docid in them which is what I am using for the=20 join. 
 
ClinicalDocs ... (no=20 primary key) though it does not help if I make docid primary=20 key
docid = integer=20 (index)
patientid integer=20 (index)
visitid integer=20 (index)
 ...
 
Documentversions
docid = integer=20 (index)
docversionnumber=20 (index)
docversionidentifier=20 (primary key)
 
It = seems to do an=20 index scan if I put the primary key as docid.  This is what occurs = when I=20 link on the patid from ClinicalDocs to patient table.  However I = can not=20 make the docid primary key because it gets repeated depending on how may = versions of a document I have.  I have tried using a foreign key on = documentversions with no sucess.
 
In = addition this=20 query
 
select = * from=20 documentversions join clinicaldocuments on=20 documentversions.documentidentifier
=3D = clinicaldocuments.dssdocumentidentifier=20 where documentversions.documentstatus =3D 'AC';
 
does = index scan=20
but if = I change the=20 order e.g
 
select * from = clinicaldocuments=20 join documentversions on clinicaldocuments.dssdocumentidentifier
=3D=20 documentversions .documentidentifier where = clinicaldocuments.patientidentifier=3D=20 123;
 
does sequential scan what I need is = bottom=20 query
it is extremely slow ... Any ideas=20 ?
 
Tim Jones
Healthcare Project = Manager
Optio Software,=20 Inc.
(770) = 576-3555
 
------_=_NextPart_001_01C62E8E.437A3F6A-- From dave@tridecap.com Fri Feb 10 22:14:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DBA299DC95C for ; Fri, 10 Feb 2006 18:14:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23461-01 for ; Fri, 10 Feb 2006 18:14:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id 942A69DC855 for ; Fri, 10 Feb 2006 18:14:42 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [63.226.156.118] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 83442275; Fri, 10 Feb 2006 14:14:40 -0800 From: "Dave Dutcher" To: "'Tim Jones'" , Subject: Re: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 16:14:30 -0600 Message-ID: <001f01c62e8f$63551840$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0020_01C62E5D.18BAA840" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: <47668A1334CDBF46927C1A0DFEB223D3131302@mail.optiosoftware.com> Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.081 required=5 tests=[AWL=0.080, HTML_MESSAGE=0.001] X-Spam-Score: 0.081 X-Spam-Level: X-Archive-Number: 200602/113 X-Sequence-Number: 17099 This is a multi-part message in MIME format. ------=_NextPart_000_0020_01C62E5D.18BAA840 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit What version of postgres are you using? Can you post the output from EXPLAIN ANALYZE? -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tim Jones Sent: Friday, February 10, 2006 4:07 PM To: pgsql-performance@postgresql.org Subject: [PERFORM] joining two tables slow due to sequential scan 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. ClinicalDocs ... (no primary key) though it does not help if I make docid primary key docid integer (index) patientid integer (index) visitid integer (index) ... Documentversions docid integer (index) docversionnumber (index) docversionidentifier (primary key) It seems to do an index scan if I put the primary key as docid. This is what occurs when I link on the patid from ClinicalDocs to patient table. However I can not make the docid primary key because it gets repeated depending on how may versions of a document I have. I have tried using a foreign key on documentversions with no sucess. In addition this query 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; does sequential scan what I need is bottom query it is extremely slow ... Any ideas ? Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 ------=_NextPart_000_0020_01C62E5D.18BAA840 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

What version of postgres are you using?  Can you = post the output from EXPLAIN ANALYZE?

 

 

-----Original = Message-----
From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tim Jones
Sent: Friday, February = 10, 2006 4:07 PM
To: pgsql-performance@postgresql.org
Subject: [PERFORM] = joining two tables slow due to sequential scan

 

 

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.  =

 

ClinicalDocs ... (no = primary key) though it does not help if I make docid primary = key

docid integer = (index)

patientid integer = (index)

visitid integer = (index)

 ...=

 

Documentversions

docid integer = (index)

docversionnumber = (index)

docversionidentifier = (primary key)

 

It seems to do an index = scan if I put the primary key as docid.  This is what occurs when I link on = the patid from ClinicalDocs to patient table.  However I can not make = the docid primary key because it gets repeated depending on how may versions = of a document I have.  I have tried using a foreign key on = documentversions with no sucess.

 

In addition this = query

 

select * from = documentversions join clinicaldocuments on documentversions.documentidentifier
=3D clinicaldocuments.dssdocumentidentifier where = documentversions.documentstatus =3D 'AC';

 

does index scan =

but if I change the order = e.g

 

select * from = clinicaldocuments join documentversions on clinicaldocuments.dssdocumentidentifier
=3D documentversions .documentidentifier where clinicaldocuments.patientidentifier=3D 123;

 

does sequential = scan what I need is bottom query

it is extremely slow ... = Any ideas ?

 

Tim = Jones

Healthcare Project = Manager

Optio Software, = Inc.

(770) = 576-3555

 

------=_NextPart_000_0020_01C62E5D.18BAA840-- From smarlowe@g2switchworks.com Fri Feb 10 22:22:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2FAA19DC826 for ; Fri, 10 Feb 2006 18:22:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21565-08 for ; Fri, 10 Feb 2006 18:22:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id D237B9DC800 for ; Fri, 10 Feb 2006 18:22:06 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Fri, 10 Feb 2006 22:22:05 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 10 Feb 2006 16:22:05 -0600 Subject: Re: joining two tables slow due to sequential scan From: Scott Marlowe To: Tim Jones Cc: pgsql-performance@postgresql.org In-Reply-To: <47668A1334CDBF46927C1A0DFEB223D3131302@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D3131302@mail.optiosoftware.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1139610125.22740.145.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 10 Feb 2006 16:22:05 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.158 required=5 tests=[AWL=0.157, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.158 X-Spam-Level: X-Archive-Number: 200602/114 X-Sequence-Number: 17100 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? From TJones@optio.com Fri Feb 10 22:35:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 394019DCAA6 for ; Fri, 10 Feb 2006 18:35:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25182-04 for ; Fri, 10 Feb 2006 18:35:53 -0400 (AST) X-Greylist: delayed 00:29:11.528226 by SQLgrey- Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by postgresql.org (Postfix) with ESMTP id CB9709DC9E1 for ; Fri, 10 Feb 2006 18:35:48 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 17:35:50 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D3131315@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] joining two tables slow due to sequential scan Thread-Index: AcYukHEdLtCc4c6BRJuxo6jR64+RfAAAcx3w From: "Tim Jones" To: "Scott Marlowe" Cc: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.096 required=5 tests=[AWL=0.096] X-Spam-Score: 0.096 X-Spam-Level: X-Archive-Number: 200602/115 X-Sequence-Number: 17101 OK. I'm gonna make a couple of guesses here: 1: clinicaldocuments.patientidentifier is an int8 and you're running 7.4 or before. -- nope int4 and 8.1 2: There are more rows with clinicaldocuments.patientidentifier=3D 123 than with documentversions.documentstatus =3D 'AC'. -- nope generally speaking all statuses are 'AC' 3: documentversions.documentidentifier and clinicaldocuments.dssdocumentidentifier are not the same type. -- nope both int4 Any of those things true? From smarlowe@g2switchworks.com Fri Feb 10 22:36:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 197269DC855 for ; Fri, 10 Feb 2006 18:36:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24733-08 for ; Fri, 10 Feb 2006 18:36:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 7B7439DC826 for ; Fri, 10 Feb 2006 18:36:51 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Fri, 10 Feb 2006 22:36:52 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 10 Feb 2006 16:36:52 -0600 Subject: Re: joining two tables slow due to sequential scan From: Scott Marlowe To: Tim Jones Cc: pgsql-performance@postgresql.org In-Reply-To: <47668A1334CDBF46927C1A0DFEB223D3131315@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D3131315@mail.optiosoftware.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1139611012.22740.147.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 10 Feb 2006 16:36:52 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.158 required=5 tests=[AWL=0.157, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.158 X-Spam-Level: X-Archive-Number: 200602/116 X-Sequence-Number: 17102 On Fri, 2006-02-10 at 16:35, Tim Jones wrote: > OK. I'm gonna make a couple of guesses here: > > 1: clinicaldocuments.patientidentifier is an int8 and you're running > 7.4 or before. > > -- nope int4 and 8.1 > > 2: There are more rows with clinicaldocuments.patientidentifier= 123 > than with documentversions.documentstatus = 'AC'. > > -- nope generally speaking all statuses are 'AC' > > 3: documentversions.documentidentifier and > clinicaldocuments.dssdocumentidentifier are not the same type. > > -- nope both int4 OK then, I guess we'll need to see the explain analyze output of both of those queries. From TJones@optio.com Fri Feb 10 22:37:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C978D9DCD23 for ; Fri, 10 Feb 2006 18:37:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25580-03 for ; Fri, 10 Feb 2006 18:37:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by postgresql.org (Postfix) with ESMTP id 126D79DCAA6 for ; Fri, 10 Feb 2006 18:37:30 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 17:37:32 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D3131317@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] joining two tables slow due to sequential scan Thread-Index: AcYuj2fJETZfDwzXR6ibeZRXCfv5rQAAMd3g From: "Tim Jones" To: "Dave Dutcher" , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.103 required=5 tests=[AWL=0.103] X-Spam-Score: 0.103 X-Spam-Level: X-Archive-Number: 200602/117 X-Sequence-Number: 17103 for first query QUERY PLAN 'Limit (cost=3D4.69..88.47 rows=3D10 width=3D1350) (actual time=3D32.195..32.338 rows=3D10 loops=3D1)' ' -> Nested Loop (cost=3D4.69..4043.09 rows=3D482 width=3D1350) = (actual time=3D32.190..32.316 rows=3D10 loops=3D1)' ' -> Bitmap Heap Scan on documentversions (cost=3D4.69..1139.40 rows=3D482 width=3D996) (actual time=3D32.161..32.171 rows=3D10 = loops=3D1)' ' Recheck Cond: (documentstatus =3D ''AC''::bpchar)' ' -> Bitmap Index Scan on ix_docstatus (cost=3D0.00..4.69 rows=3D482 width=3D0) (actual time=3D31.467..31.467 rows=3D96368 = loops=3D1)' ' Index Cond: (documentstatus =3D ''AC''::bpchar)' ' -> Index Scan using ix_cdocdid on clinicaldocuments (cost=3D0.00..6.01 rows=3D1 width=3D354) (actual time=3D0.006..0.007 = rows=3D1 loops=3D10)' ' Index Cond: ("outer".documentidentifier =3D clinicaldocuments.dssdocumentidentifier)' =20 =20 for second query QUERY PLAN 'Hash Join (cost=3D899.83..4384.17 rows=3D482 width=3D1350)' ' Hash Cond: ("outer".documentidentifier =3D "inner".dssdocumentidentifier)' ' -> Seq Scan on documentversions (cost=3D0.00..2997.68 rows=3D96368 width=3D996)' ' -> Hash (cost=3D898.62..898.62 rows=3D482 width=3D354)' ' -> Bitmap Heap Scan on clinicaldocuments (cost=3D4.69..898.62 rows=3D482 width=3D354)' ' Recheck Cond: (patientidentifier =3D 123)' ' -> Bitmap Index Scan on ix_cdocpid (cost=3D0.00..4.69 rows=3D482 width=3D0)' ' Index Cond: (patientidentifier =3D 123)' thnx Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 =20 ________________________________ From: Dave Dutcher [mailto:dave@tridecap.com]=20 Sent: Friday, February 10, 2006 5:15 PM To: Tim Jones; pgsql-performance@postgresql.org Subject: RE: [PERFORM] joining two tables slow due to sequential scan What version of postgres are you using? Can you post the output from EXPLAIN ANALYZE? =20 =20 -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tim Jones Sent: Friday, February 10, 2006 4:07 PM To: pgsql-performance@postgresql.org Subject: [PERFORM] joining two tables slow due to sequential scan =20 =20 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. =20 =20 ClinicalDocs ... (no primary key) though it does not help if I make docid primary key docid integer (index) patientid integer (index) visitid integer (index) ... =20 Documentversions docid integer (index) docversionnumber (index) docversionidentifier (primary key) =20 It seems to do an index scan if I put the primary key as docid. This is what occurs when I link on the patid from ClinicalDocs to patient table. However I can not make the docid primary key because it gets repeated depending on how may versions of a document I have. I have tried using a foreign key on documentversions with no sucess.=20 =20 In addition this query =20 select * from documentversions join clinicaldocuments on documentversions.documentidentifier =3D clinicaldocuments.dssdocumentidentifier where documentversions.documentstatus =3D 'AC';=20 =20 does index scan=20 but if I change the order e.g =20 select * from clinicaldocuments join documentversions on clinicaldocuments.dssdocumentidentifier =3D documentversions .documentidentifier where clinicaldocuments.patientidentifier=3D 123; =20 does sequential scan what I need is bottom query it is extremely slow ... Any ideas ? =20 Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 =20 From smarlowe@g2switchworks.com Fri Feb 10 22:39:21 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4E4239DC826 for ; Fri, 10 Feb 2006 18:39:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25354-06 for ; Fri, 10 Feb 2006 18:39:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 78BB49DC800 for ; Fri, 10 Feb 2006 18:39:18 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Fri, 10 Feb 2006 22:39:19 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 10 Feb 2006 16:39:19 -0600 Subject: Re: joining two tables slow due to sequential scan From: Scott Marlowe To: Tim Jones Cc: Dave Dutcher , pgsql-performance@postgresql.org In-Reply-To: <47668A1334CDBF46927C1A0DFEB223D3131317@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D3131317@mail.optiosoftware.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1139611159.22740.149.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 10 Feb 2006 16:39:19 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.157 required=5 tests=[AWL=0.156, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.157 X-Spam-Level: X-Archive-Number: 200602/119 X-Sequence-Number: 17105 On Fri, 2006-02-10 at 16:37, Tim Jones wrote: > for first query > > QUERY PLAN > 'Limit (cost=4.69..88.47 rows=10 width=1350) (actual > time=32.195..32.338 rows=10 loops=1)' > ' -> Nested Loop (cost=4.69..4043.09 rows=482 width=1350) (actual > time=32.190..32.316 rows=10 loops=1)' > ' -> Bitmap Heap Scan on documentversions (cost=4.69..1139.40 > rows=482 width=996) (actual time=32.161..32.171 rows=10 loops=1)' > ' Recheck Cond: (documentstatus = ''AC''::bpchar)' > ' -> Bitmap Index Scan on ix_docstatus (cost=0.00..4.69 > rows=482 width=0) (actual time=31.467..31.467 rows=96368 loops=1)' > ' Index Cond: (documentstatus = ''AC''::bpchar)' > ' -> Index Scan using ix_cdocdid on clinicaldocuments > (cost=0.00..6.01 rows=1 width=354) (actual time=0.006..0.007 rows=1 > loops=10)' > ' Index Cond: ("outer".documentidentifier = > clinicaldocuments.dssdocumentidentifier)' > > > for second query > > QUERY PLAN > 'Hash Join (cost=899.83..4384.17 rows=482 width=1350)' > ' Hash Cond: ("outer".documentidentifier = > "inner".dssdocumentidentifier)' > ' -> Seq Scan on documentversions (cost=0.00..2997.68 rows=96368 > width=996)' > ' -> Hash (cost=898.62..898.62 rows=482 width=354)' > ' -> Bitmap Heap Scan on clinicaldocuments (cost=4.69..898.62 > rows=482 width=354)' > ' Recheck Cond: (patientidentifier = 123)' > ' -> Bitmap Index Scan on ix_cdocpid (cost=0.00..4.69 > rows=482 width=0)' > ' Index Cond: (patientidentifier = 123)' OK, the first one is explain analyze, but the second one is just plain explain... From TJones@optio.com Fri Feb 10 22:43:59 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3E4889DC826 for ; Fri, 10 Feb 2006 18:43:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25449-06 for ; Fri, 10 Feb 2006 18:44:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by postgresql.org (Postfix) with ESMTP id D196C9DC800 for ; Fri, 10 Feb 2006 18:43:56 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 17:43:58 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D313131D@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] joining two tables slow due to sequential scan Thread-Index: AcYuktoSqNJAD8cZSKOqTVIO5IZaoAAAE2Hw From: "Tim Jones" To: "Scott Marlowe" Cc: "Dave Dutcher" , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.107 required=5 tests=[AWL=0.107] X-Spam-Score: 0.107 X-Spam-Level: X-Archive-Number: 200602/121 X-Sequence-Number: 17107 oops QUERY PLAN 'Hash Join (cost=3D899.83..4384.17 rows=3D482 width=3D1350) (actual time=3D0.203..0.203 rows=3D0 loops=3D1)' ' Hash Cond: ("outer".documentidentifier =3D "inner".dssdocumentidentifier)' ' -> Seq Scan on documentversions (cost=3D0.00..2997.68 rows=3D96368 width=3D996) (actual time=3D0.007..0.007 rows=3D1 loops=3D1)' ' -> Hash (cost=3D898.62..898.62 rows=3D482 width=3D354) (actual time=3D0.161..0.161 rows=3D0 loops=3D1)' ' -> Bitmap Heap Scan on clinicaldocuments (cost=3D4.69..898.62 rows=3D482 width=3D354) (actual time=3D0.159..0.159 rows=3D0 loops=3D1)' ' Recheck Cond: (patientidentifier =3D 123)' ' -> Bitmap Index Scan on ix_cdocpid (cost=3D0.00..4.69 rows=3D482 width=3D0) (actual time=3D0.153..0.153 rows=3D0 loops=3D1)' ' Index Cond: (patientidentifier =3D 123)' 'Total runtime: 0.392 ms' note I have done these on a smaller db than what I am using but the plans are the same=20 Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 -----Original Message----- From: Scott Marlowe [mailto:smarlowe@g2switchworks.com]=20 Sent: Friday, February 10, 2006 5:39 PM To: Tim Jones Cc: Dave Dutcher; pgsql-performance@postgresql.org Subject: Re: [PERFORM] joining two tables slow due to sequential scan On Fri, 2006-02-10 at 16:37, Tim Jones wrote: > for first query >=20 > QUERY PLAN > 'Limit (cost=3D4.69..88.47 rows=3D10 width=3D1350) (actual > time=3D32.195..32.338 rows=3D10 loops=3D1)' > ' -> Nested Loop (cost=3D4.69..4043.09 rows=3D482 width=3D1350) = (actual > time=3D32.190..32.316 rows=3D10 loops=3D1)' > ' -> Bitmap Heap Scan on documentversions = (cost=3D4.69..1139.40 > rows=3D482 width=3D996) (actual time=3D32.161..32.171 rows=3D10 = loops=3D1)' > ' Recheck Cond: (documentstatus =3D ''AC''::bpchar)' > ' -> Bitmap Index Scan on ix_docstatus = (cost=3D0.00..4.69 > rows=3D482 width=3D0) (actual time=3D31.467..31.467 rows=3D96368 = loops=3D1)' > ' Index Cond: (documentstatus =3D ''AC''::bpchar)' > ' -> Index Scan using ix_cdocdid on clinicaldocuments > (cost=3D0.00..6.01 rows=3D1 width=3D354) (actual time=3D0.006..0.007 = rows=3D1=20 > loops=3D10)' > ' Index Cond: ("outer".documentidentifier =3D > clinicaldocuments.dssdocumentidentifier)' > =20 >=20 > for second query >=20 > QUERY PLAN > 'Hash Join (cost=3D899.83..4384.17 rows=3D482 width=3D1350)' > ' Hash Cond: ("outer".documentidentifier =3D=20 > "inner".dssdocumentidentifier)' > ' -> Seq Scan on documentversions (cost=3D0.00..2997.68 = rows=3D96368=20 > width=3D996)' > ' -> Hash (cost=3D898.62..898.62 rows=3D482 width=3D354)' > ' -> Bitmap Heap Scan on clinicaldocuments = (cost=3D4.69..898.62 > rows=3D482 width=3D354)' > ' Recheck Cond: (patientidentifier =3D 123)' > ' -> Bitmap Index Scan on ix_cdocpid (cost=3D0.00..4.69 > rows=3D482 width=3D0)' > ' Index Cond: (patientidentifier =3D 123)' OK, the first one is explain analyze, but the second one is just plain explain... From tgl@sss.pgh.pa.us Fri Feb 10 22:44:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 090DD9DC800 for ; Fri, 10 Feb 2006 18:44:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24469-10 for ; Fri, 10 Feb 2006 18:44:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id CB2179DC9E1 for ; Fri, 10 Feb 2006 18:44:07 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1AMi808002865; Fri, 10 Feb 2006 17:44:08 -0500 (EST) To: "Tim Jones" cc: "Dave Dutcher" , pgsql-performance@postgresql.org Subject: Re: joining two tables slow due to sequential scan In-reply-to: <47668A1334CDBF46927C1A0DFEB223D3131317@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D3131317@mail.optiosoftware.com> Comments: In-reply-to "Tim Jones" message dated "Fri, 10 Feb 2006 17:37:32 -0500" Date: Fri, 10 Feb 2006 17:44:08 -0500 Message-ID: <2864.1139611448@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.109 required=5 tests=[AWL=0.109] X-Spam-Score: 0.109 X-Spam-Level: X-Archive-Number: 200602/122 X-Sequence-Number: 17108 "Tim Jones" writes: > QUERY PLAN > 'Hash Join (cost=899.83..4384.17 rows=482 width=1350)' > ' Hash Cond: ("outer".documentidentifier = > "inner".dssdocumentidentifier)' This is not EXPLAIN ANALYZE output. Also, the rowcount estimates seem far enough off in the other query to make me wonder how long it's been since you ANALYZEd the tables... More generally, though, I don't see anything particularly wrong with this query plan. You're selecting enough of the table that an indexscan isn't necessarily a good plan. regards, tom lane From smarlowe@g2switchworks.com Fri Feb 10 22:46:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6E7E49DC800 for ; Fri, 10 Feb 2006 18:46:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26187-07 for ; Fri, 10 Feb 2006 18:46:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 50F0D9DC9E1 for ; Fri, 10 Feb 2006 18:46:13 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Fri, 10 Feb 2006 22:46:14 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 10 Feb 2006 16:46:14 -0600 Subject: Re: joining two tables slow due to sequential scan From: Scott Marlowe To: Tim Jones Cc: Dave Dutcher , pgsql-performance@postgresql.org In-Reply-To: <47668A1334CDBF46927C1A0DFEB223D313131D@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D313131D@mail.optiosoftware.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1139611574.22740.154.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 10 Feb 2006 16:46:14 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.156 required=5 tests=[AWL=0.155, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.156 X-Spam-Level: X-Archive-Number: 200602/123 X-Sequence-Number: 17109 On Fri, 2006-02-10 at 16:43, Tim Jones wrote: > oops > > QUERY PLAN > 'Hash Join (cost=899.83..4384.17 rows=482 width=1350) (actual > time=0.203..0.203 rows=0 loops=1)' > ' Hash Cond: ("outer".documentidentifier = > "inner".dssdocumentidentifier)' > ' -> Seq Scan on documentversions (cost=0.00..2997.68 rows=96368 > width=996) (actual time=0.007..0.007 rows=1 loops=1)' > ' -> Hash (cost=898.62..898.62 rows=482 width=354) (actual > time=0.161..0.161 rows=0 loops=1)' > ' -> Bitmap Heap Scan on clinicaldocuments (cost=4.69..898.62 > rows=482 width=354) (actual time=0.159..0.159 rows=0 loops=1)' > ' Recheck Cond: (patientidentifier = 123)' > ' -> Bitmap Index Scan on ix_cdocpid (cost=0.00..4.69 > rows=482 width=0) (actual time=0.153..0.153 rows=0 loops=1)' > ' Index Cond: (patientidentifier = 123)' > 'Total runtime: 0.392 ms' > > note I have done these on a smaller db than what I am using but the > plans are the same Hmmmm. We really need to see what's happening on the real database to see what's going wrong. i.e. if the real database thinks it'll get 30 rows and it gets back 5,000,000 that's a problem. The query planner in pgsql is cost based, so until you have real data underneath it, and analyze it, you can't really say how it will behave for you. I.e. small test sets don't work. From tgl@sss.pgh.pa.us Fri Feb 10 22:51:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B0F6C9DCD86 for ; Fri, 10 Feb 2006 18:51:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28617-03 for ; Fri, 10 Feb 2006 18:51:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8A6549DCB7A for ; Fri, 10 Feb 2006 18:51:55 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1AMpoE9002938; Fri, 10 Feb 2006 17:51:50 -0500 (EST) To: "Tim Jones" cc: "Scott Marlowe" , "Dave Dutcher" , pgsql-performance@postgresql.org Subject: Re: joining two tables slow due to sequential scan In-reply-to: <47668A1334CDBF46927C1A0DFEB223D313131D@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D313131D@mail.optiosoftware.com> Comments: In-reply-to "Tim Jones" message dated "Fri, 10 Feb 2006 17:43:58 -0500" Date: Fri, 10 Feb 2006 17:51:50 -0500 Message-ID: <2937.1139611910@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.109 required=5 tests=[AWL=0.109] X-Spam-Score: 0.109 X-Spam-Level: X-Archive-Number: 200602/124 X-Sequence-Number: 17110 "Tim Jones" writes: > QUERY PLAN > 'Hash Join (cost=899.83..4384.17 rows=482 width=1350) (actual > time=0.203..0.203 rows=0 loops=1)' > ... > 'Total runtime: 0.392 ms' Hardly seems like evidence of a performance problem ... regards, tom lane From TJones@optio.com Fri Feb 10 22:59:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 556929DCD92 for ; Fri, 10 Feb 2006 18:59:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28617-05 for ; Fri, 10 Feb 2006 18:59:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by postgresql.org (Postfix) with ESMTP id E9D369DCD86 for ; Fri, 10 Feb 2006 18:59:02 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 17:59:03 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D3131324@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] joining two tables slow due to sequential scan Thread-Index: AcYulJakTYfEeSl+RnqOOKcAiwGtCgAABsnw From: "Tim Jones" To: "Tom Lane" Cc: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.109 required=5 tests=[AWL=0.109] X-Spam-Score: 0.109 X-Spam-Level: X-Archive-Number: 200602/125 X-Sequence-Number: 17111 ok here is real db the first query I had seems to make no sense because it is only fast if I limit the rows since almost all rows have status =3D 'AC' second query tables both have about 10 million rows and it takes a long time as you can see but this person only has approx 160 total documents QUERY PLAN =20 ------------------------------------------------------------------------ ------------------------------------------------------------------- Hash Join (cost=3D84813.14..1510711.97 rows=3D48387 width=3D555) = (actual time=3D83266.854..91166.315 rows=3D3 loops=3D1) Hash Cond: ("outer".documentidentifier =3D "inner".dssdocumentidentifier) -> Seq Scan on documentversions (cost=3D0.00..269141.98 = rows=3D9677398 width=3D415) (actual time=3D0.056..49812.459 rows=3D9677398 loops=3D1) -> Hash (cost=3D83660.05..83660.05 rows=3D48036 width=3D140) = (actual time=3D10.833..10.833 rows=3D3 loops=3D1) -> Bitmap Heap Scan on clinicaldocuments (cost=3D301.13..83660.05 rows=3D48036 width=3D140) (actual = time=3D0.243..0.258 rows=3D3 loops=3D1) Recheck Cond: (patientidentifier =3D 690193) -> Bitmap Index Scan on ix_cdocpid (cost=3D0.00..301.13 rows=3D48036 width=3D0) (actual time=3D0.201..0.201 rows=3D3 loops=3D1) Index Cond: (patientidentifier =3D 690193) Total runtime: 91166.540 ms Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 Sent: Friday, February 10, 2006 5:52 PM To: Tim Jones Cc: Scott Marlowe; Dave Dutcher; pgsql-performance@postgresql.org Subject: Re: [PERFORM] joining two tables slow due to sequential scan=20 "Tim Jones" writes: > QUERY PLAN > 'Hash Join (cost=3D899.83..4384.17 rows=3D482 width=3D1350) (actual > time=3D0.203..0.203 rows=3D0 loops=3D1)' > ... > 'Total runtime: 0.392 ms' Hardly seems like evidence of a performance problem ... regards, tom lane From dave@tridecap.com Fri Feb 10 23:25:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 706D89DC81A for ; Fri, 10 Feb 2006 19:25:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32684-06 for ; Fri, 10 Feb 2006 19:25:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id 407779DC800 for ; Fri, 10 Feb 2006 19:25:19 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [63.226.156.118] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 83446776; Fri, 10 Feb 2006 15:25:22 -0800 From: "Dave Dutcher" To: "'Tim Jones'" Cc: Subject: Re: joining two tables slow due to sequential scan Date: Fri, 10 Feb 2006 17:25:20 -0600 Message-ID: <002601c62e99$434299b0$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: <47668A1334CDBF46927C1A0DFEB223D3131324@mail.optiosoftware.com> Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200602/126 X-Sequence-Number: 17112 OK, if I'm reading this correctly, it looks like the planner is choosing a sequential scan because it expects 48,000 rows for that patientidentifier, but its actually only getting 3. The planner has the number of rows right for the sequential scan, so it seems like the stats are up to date. I would try increasing the stats for the patientindentifier column with 'alter table set statistics...' or increasing the default_statistics_target for the whole DB. Once you have changed the stats I believe you need to run analyze again. -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tim Jones Sent: Friday, February 10, 2006 4:59 PM To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] joining two tables slow due to sequential scan ok here is real db the first query I had seems to make no sense because it is only fast if I limit the rows since almost all rows have status = 'AC' second query tables both have about 10 million rows and it takes a long time as you can see but this person only has approx 160 total documents QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------- Hash Join (cost=84813.14..1510711.97 rows=48387 width=555) (actual time=83266.854..91166.315 rows=3 loops=1) Hash Cond: ("outer".documentidentifier = "inner".dssdocumentidentifier) -> Seq Scan on documentversions (cost=0.00..269141.98 rows=9677398 width=415) (actual time=0.056..49812.459 rows=9677398 loops=1) -> Hash (cost=83660.05..83660.05 rows=48036 width=140) (actual time=10.833..10.833 rows=3 loops=1) -> Bitmap Heap Scan on clinicaldocuments (cost=301.13..83660.05 rows=48036 width=140) (actual time=0.243..0.258 rows=3 loops=1) Recheck Cond: (patientidentifier = 690193) -> Bitmap Index Scan on ix_cdocpid (cost=0.00..301.13 rows=48036 width=0) (actual time=0.201..0.201 rows=3 loops=1) Index Cond: (patientidentifier = 690193) Total runtime: 91166.540 ms Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us] Sent: Friday, February 10, 2006 5:52 PM To: Tim Jones Cc: Scott Marlowe; Dave Dutcher; pgsql-performance@postgresql.org Subject: Re: [PERFORM] joining two tables slow due to sequential scan "Tim Jones" writes: > QUERY PLAN > 'Hash Join (cost=899.83..4384.17 rows=482 width=1350) (actual > time=0.203..0.203 rows=0 loops=1)' > ... > 'Total runtime: 0.392 ms' Hardly seems like evidence of a performance problem ... regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings From TJones@optio.com Mon Feb 13 16:22:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3D2A39DCA77 for ; Mon, 13 Feb 2006 12:22:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52422-06 for ; Mon, 13 Feb 2006 12:22:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by postgresql.org (Postfix) with ESMTP id 7F0FB9DC99F for ; Mon, 13 Feb 2006 12:22:01 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: joining two tables slow due to sequential scan Date: Mon, 13 Feb 2006 11:21:58 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D3131457@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] joining two tables slow due to sequential scan Thread-Index: AcYumUTCGLv3XAabSGacxcKb3ISIkACIB5zw From: "Tim Jones" To: "Dave Dutcher" Cc: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200602/143 X-Sequence-Number: 17129 ok I am retarded :) Apparently I thought I had done analyze on these tables but I actually had not and that was all that was needed. but thanks for the help. Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 -----Original Message----- From: Dave Dutcher [mailto:dave@tridecap.com]=20 Sent: Friday, February 10, 2006 6:25 PM To: Tim Jones Cc: pgsql-performance@postgresql.org Subject: RE: [PERFORM] joining two tables slow due to sequential scan=20 OK, if I'm reading this correctly, it looks like the planner is choosing a sequential scan because it expects 48,000 rows for that patientidentifier, but its actually only getting 3. The planner has the number of rows right for the sequential scan, so it seems like the stats are up to date. I would try increasing the stats for the patientindentifier column with 'alter table set statistics...' or increasing the default_statistics_target for the whole DB. Once you have changed the stats I believe you need to run analyze again. -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tim Jones Sent: Friday, February 10, 2006 4:59 PM To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] joining two tables slow due to sequential scan=20 ok here is real db the first query I had seems to make no sense because it is only fast if I limit the rows since almost all rows have status =3D 'AC' second query tables both have about 10 million rows and it takes a long time as you can see but this person only has approx 160 total documents QUERY PLAN =20 ------------------------------------------------------------------------ ------------------------------------------------------------------- Hash Join (cost=3D84813.14..1510711.97 rows=3D48387 width=3D555) = (actual time=3D83266.854..91166.315 rows=3D3 loops=3D1) Hash Cond: ("outer".documentidentifier =3D "inner".dssdocumentidentifier) -> Seq Scan on documentversions (cost=3D0.00..269141.98 = rows=3D9677398 width=3D415) (actual time=3D0.056..49812.459 rows=3D9677398 loops=3D1) -> Hash (cost=3D83660.05..83660.05 rows=3D48036 width=3D140) = (actual time=3D10.833..10.833 rows=3D3 loops=3D1) -> Bitmap Heap Scan on clinicaldocuments (cost=3D301.13..83660.05 rows=3D48036 width=3D140) (actual = time=3D0.243..0.258 rows=3D3 loops=3D1) Recheck Cond: (patientidentifier =3D 690193) -> Bitmap Index Scan on ix_cdocpid (cost=3D0.00..301.13 rows=3D48036 width=3D0) (actual time=3D0.201..0.201 rows=3D3 loops=3D1) Index Cond: (patientidentifier =3D 690193) Total runtime: 91166.540 ms Tim Jones Healthcare Project Manager Optio Software, Inc. (770) 576-3555 -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us] Sent: Friday, February 10, 2006 5:52 PM To: Tim Jones Cc: Scott Marlowe; Dave Dutcher; pgsql-performance@postgresql.org Subject: Re: [PERFORM] joining two tables slow due to sequential scan=20 "Tim Jones" writes: > QUERY PLAN > 'Hash Join (cost=3D899.83..4384.17 rows=3D482 width=3D1350) (actual > time=3D0.203..0.203 rows=3D0 loops=3D1)' > ... > 'Total runtime: 0.392 ms' Hardly seems like evidence of a performance problem ... regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings