Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id EFE9F1337B43 for ; Wed, 6 Apr 2011 08:41:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 00109-07 for ; Wed, 6 Apr 2011 11:41:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com [209.85.216.46]) by mail.postgresql.org (Postfix) with ESMTP id AC0D3133655C for ; Wed, 6 Apr 2011 08:41:23 -0300 (ADT) Received: by qwk3 with SMTP id 3so792833qwk.19 for ; Wed, 06 Apr 2011 04:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=gOs8BWTasr+dNNz3uHTj3GnPO4izb3N/9Kq8EcbSN4I=; b=ViFF8Tvyye29BSYiM6tOcocME4sDtCHivYe6UX6zfzTcSgNYZ+y4rEuWjnbaftqk/t pYb/ZmA2K+LgkD7m389RSILe5h8+ufcMDhne8MZaiT6peinDoa+BArELsph995/LLCRA R9T4mBzHzVEQwI6Fs1EJkLG9N7y+B2n8oXJAI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=QwCoAmL7vM/SDdBqW7YW9g05KAERqdetfDirvpWyrAL0TAEKqHoP9UxRl1+573Ub/e snbDasVaWZwiHxuG0aW37EdoLrBQ6tEWCRx57yO+4y3d3mqB+PTz3T6ywd2bGhpOdX8L FXgmV6seN1cq/mXUUyxs1XAd3T42yiwWAg/9Y= MIME-Version: 1.0 Received: by 10.229.36.67 with SMTP id s3mr687492qcd.60.1302090083830; Wed, 06 Apr 2011 04:41:23 -0700 (PDT) Received: by 10.229.22.196 with HTTP; Wed, 6 Apr 2011 04:41:23 -0700 (PDT) In-Reply-To: <4D9B6CBA.2050609@nasa.gov> References: <4D9B6CBA.2050609@nasa.gov> Date: Wed, 6 Apr 2011 13:41:23 +0200 Message-ID: Subject: Re: help speeding up a query in postgres 8.4.5 From: Szymon Guz To: Maria.L.Wilson-1@nasa.gov Cc: "pgsql-performance@postgresql.org" Content-Type: multipart/alternative; boundary=0016e64eed26e98c6f04a03e78c4 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.888 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201104/44 X-Sequence-Number: 43106 --0016e64eed26e98c6f04a03e78c4 Content-Type: text/plain; charset=UTF-8 On 5 April 2011 21:25, Maria L. Wilson wrote: > Would really appreciate someone taking a look at the query below.... > Thanks in advance! > > > this is on a linux box... > Linux dsrvr201.larc.nasa.gov 2.6.18-164.9.1.el5 #1 SMP Wed Dec 9 03:27:37 > EST 2009 x86_64 x86_64 x86_64 GNU/Linux > > explain analyze > select MIN(IV.STRTDATE), MAX(IV.ENDDATE) > from GRAN_VER GV > left outer join INVENTORY IV on GV.GRANULE_ID = IV.GRANULE_ID, INVSENSOR > INVS > where IV.INV_ID='65' and GV.GRANULE_ID = INVS.granule_id and > INVS.sensor_id='13' > > > "Aggregate (cost=736364.52..736364.53 rows=1 width=8) (actual > time=17532.930..17532.930 rows=1 loops=1)" > " -> Hash Join (cost=690287.33..734679.77 rows=336949 width=8) (actual > time=13791.593..17323.080 rows=924675 loops=1)" > " Hash Cond: (invs.granule_id = gv.granule_id)" > " -> Seq Scan on invsensor invs (cost=0.00..36189.41 rows=1288943 > width=4) (actual time=0.297..735.375 rows=1277121 loops=1)" > " Filter: (sensor_id = 13)" > " -> Hash (cost=674401.52..674401.52 rows=1270865 width=16) > (actual time=13787.698..13787.698 rows=1270750 loops=1)" > " -> Hash Join (cost=513545.62..674401.52 rows=1270865 > width=16) (actual time=1998.702..13105.578 rows=1270750 loops=1)" > " Hash Cond: (gv.granule_id = iv.granule_id)" > " -> Seq Scan on gran_ver gv (cost=0.00..75224.90 > rows=4861490 width=4) (actual time=0.008..1034.885 rows=4867542 loops=1)" > " -> Hash (cost=497659.81..497659.81 rows=1270865 > width=12) (actual time=1968.918..1968.918 rows=1270750 loops=1)" > " -> Bitmap Heap Scan on inventory iv > (cost=24050.00..497659.81 rows=1270865 width=12) (actual > time=253.542..1387.957 rows=1270750 loops=1)" > " Recheck Cond: (inv_id = 65)" > " -> Bitmap Index Scan on inven_idx1 > (cost=0.00..23732.28 rows=1270865 width=0) (actual time=214.364..214.364 > rows=1270977 loops=1)" > " Index Cond: (inv_id = 65)" > "Total runtime: 17533.100 ms" > > some additional info..... > the table inventory is about 4481 MB and also has postgis types. > the table gran_ver is about 523 MB > the table INVSENSOR is about 217 MB > > the server itself has 32G RAM with the following set in the postgres conf > shared_buffers = 3GB > work_mem = 64MB > maintenance_work_mem = 512MB > wal_buffers = 6MB > > let me know if I've forgotten anything! thanks a bunch!! > > Maria Wilson > NASA/Langley Research Center > Hampton, Virginia > m.l.wilson@nasa.gov > > > Hi, could you show us indexes that you have on all tables from this query? Have you tried running vacuum analyze on those tables? Do you have autovacuum active? regards Szymon --0016e64eed26e98c6f04a03e78c4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On 5 April 2011 21:25, Maria L. Wilson <= span dir=3D"ltr"><Maria.L.W= ilson-1@nasa.gov> wrote:
=20 =20 =20
Would really appreciate someone taking a look at the query below....=C2=A0 Thanks in advance!


this is on a linux box...
Linux dsrvr= 201.larc.nasa.gov 2.6.18-164.9.1.el5 #1 SMP Wed Dec 9 03:27:37 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

explain analyze
select MIN(IV.STRTDATE), MAX(IV.ENDDATE)
from GRAN_VER GV
left outer join INVENTORY IV on GV.GRANULE_ID =3D IV.GRANULE_ID, INVSENSOR INVS
where IV.INV_ID=3D'65' and GV.GRANULE_ID =3D INVS.granule_id an= d INVS.sensor_id=3D'13'


"Aggregate=C2=A0 (cost=3D736364.52..736364.53 rows=3D1 width=3D8) = (actual time=3D17532.930..17532.930 rows=3D1 loops=3D1)"
"=C2=A0 ->=C2=A0 Hash Join=C2=A0 (cost=3D690287.33..734679.77 r= ows=3D336949 width=3D8) (actual time=3D13791.593..17323.080 rows=3D924675 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Hash Cond: (invs.granu= le_id =3D gv.granule_id)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Seq Scan o= n invsensor invs=C2=A0 (cost=3D0.00..36189.41 rows=3D1288943 width=3D4) (actual time=3D0.297..735.375 rows=3D1277121 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 Filter: (sensor_id =3D 13)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash=C2=A0= (cost=3D674401.52..674401.52 rows=3D1270865 width=3D16) (actual time=3D13787.698..13787.698 rows=3D1270750 loops=3D= 1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 ->=C2=A0 Hash Join=C2=A0 (cost=3D513545.62..674401.52 rows=3D1270865 width=3D16) (actual time=3D1998.702..13105.578 rows=3D12= 70750 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Hash Cond: (gv.granule_= id =3D iv.granule_id)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Seq Scan on= gran_ver gv=C2=A0 (cost=3D0.00..75224.90 rows=3D4861490 width=3D4) (actual time=3D0.008..1034.885 rows=3D4867542 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash=C2=A0 = (cost=3D497659.81..497659.81 rows=3D1270865 width=3D12) (actual time=3D1968.918..1968.918 rows=3D127= 0750 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 ->=C2=A0 Bitmap Heap Scan on inventory iv=C2=A0 (cost=3D24050.00..497659.81 rows=3D1270865 width=3D12) (actual time=3D253.542..1387.957 rows=3D1270750 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Recheck Cond: (inv_id =3D = 65)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Bitmap Index S= can on inven_idx1=C2=A0 (cost=3D0.00..23732.28 rows=3D1270865 width=3D0) (actu= al time=3D214.364..214.364 rows=3D1270977 loops=3D1)"
"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 Index Cond: (inv_id =3D 65)"
"Total runtime: 17533.100 ms"

some additional info.....
the table inventory is about 4481 MB and also has postgis types.
the table gran_ver is about 523 MB
the table INVSENSOR is about 217 MB

the server itself has 32G RAM with the following set in the postgres conf
shared_buffers =3D 3GB
work_mem =3D 64MB=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0
maintenance_work_mem =3D 512MB=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0
wal_buffers =3D 6MB

let me know if I've forgotten anything!=C2=A0 thanks a bunch!!

Maria Wilson
NASA/Langley Research Center
Hampton, Virginia
m.l.wilson@nas= a.gov



Hi,
could you = show us indexes that you have on all tables from this query? Have you tried= running vacuum analyze on those tables? Do you have autovacuum active?

regards
Szymon
--0016e64eed26e98c6f04a03e78c4--