Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id ACDD91337B96 for ; Tue, 10 May 2011 14:38:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 50214-02 for ; Tue, 10 May 2011 17:38:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com [209.85.214.46]) by mail.postgresql.org (Postfix) with ESMTP id 731D01337B80 for ; Tue, 10 May 2011 14:38:20 -0300 (ADT) Received: by bwz15 with SMTP id 15so5034472bwz.19 for ; Tue, 10 May 2011 10:38:19 -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 :content-transfer-encoding; bh=e61LQWMyE11V7vikk82722qgsLU3PkwEI1emYDKGVDc=; b=wcEGXOs3BT9whJqgOqxfeSEjqW8JmmF5vS+GI/ikSOcUhyXHCjLBcusp4Z5xzzDv6U phjSBe7nzGvmXX7KSRm+2eD22t09zxkCKJZj0z6+O/bUmE0KG3QRg93Ntey/qIlFqdnr RgcodCMmeC1wwhiWrvigIkKFNFSBa6UJqx1LY= 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:content-transfer-encoding; b=XgcksVE2DFM8MffLlczCo0VRS16sjbw4BibwuQu+sY/mLfWlWKBBkz+iZNnsbenUAs cDGwo/Oaf59YQc6s9JdHAOWDxFGOU0Y82DwlgmZ05yNYKNR/I3a41lweP2OxoA6NUXnW woDGA0j4Mxa5sfDX3+WnUFxWbwu1s6JYf6jUk= MIME-Version: 1.0 Received: by 10.204.57.135 with SMTP id c7mr3882787bkh.88.1305049097603; Tue, 10 May 2011 10:38:17 -0700 (PDT) Received: by 10.204.68.19 with HTTP; Tue, 10 May 2011 10:38:17 -0700 (PDT) In-Reply-To: <4D9B6CBA.2050609@nasa.gov> References: <4D9B6CBA.2050609@nasa.gov> Date: Tue, 10 May 2011 13:38:17 -0400 Message-ID: Subject: Re: help speeding up a query in postgres 8.4.5 From: Robert Haas To: Maria.L.Wilson-1@nasa.gov Cc: "pgsql-performance@postgresql.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201105/130 X-Sequence-Number: 43639 On Tue, Apr 5, 2011 at 3:25 PM, Maria L. Wilson wrote: > Would really appreciate someone taking a look at the query below....=A0 T= hanks > 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 =3D IV.GRANULE_ID, INVSENSO= R > INVS > where IV.INV_ID=3D'65' and GV.GRANULE_ID =3D INVS.granule_id and > INVS.sensor_id=3D'13' > > > "Aggregate=A0 (cost=3D736364.52..736364.53 rows=3D1 width=3D8) (actual > time=3D17532.930..17532.930 rows=3D1 loops=3D1)" > "=A0 ->=A0 Hash Join=A0 (cost=3D690287.33..734679.77 rows=3D336949 width= =3D8) (actual > time=3D13791.593..17323.080 rows=3D924675 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0 Hash Cond: (invs.granule_id =3D gv.granule_id)" > "=A0=A0=A0=A0=A0=A0=A0 ->=A0 Seq Scan on invsensor invs=A0 (cost=3D0.00..= 36189.41 rows=3D1288943 > width=3D4) (actual time=3D0.297..735.375 rows=3D1277121 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Filter: (sensor_id =3D 13)" > "=A0=A0=A0=A0=A0=A0=A0 ->=A0 Hash=A0 (cost=3D674401.52..674401.52 rows=3D= 1270865 width=3D16) (actual > time=3D13787.698..13787.698 rows=3D1270750 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ->=A0 Hash Join=A0 (cost=3D51354= 5.62..674401.52 rows=3D1270865 > width=3D16) (actual time=3D1998.702..13105.578 rows=3D1270750 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Hash Cond: (gv= .granule_id =3D iv.granule_id)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ->=A0 Seq Scan= on gran_ver gv=A0 (cost=3D0.00..75224.90 > rows=3D4861490 width=3D4) (actual time=3D0.008..1034.885 rows=3D4867542 l= oops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ->=A0 Hash=A0 = (cost=3D497659.81..497659.81 rows=3D1270865 > width=3D12) (actual time=3D1968.918..1968.918 rows=3D1270750 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 ->=A0 Bitmap Heap Scan on inventory iv > (cost=3D24050.00..497659.81 rows=3D1270865 width=3D12) (actual > time=3D253.542..1387.957 rows=3D1270750 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 Recheck Cond: (inv_id =3D 65)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 ->=A0 Bitmap Index Scan on inven_idx1 > (cost=3D0.00..23732.28 rows=3D1270865 width=3D0) (actual time=3D214.364..= 214.364 > rows=3D1270977 loops=3D1)" > "=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=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 > maintenance_work_mem =3D 512MB > wal_buffers =3D 6MB > > let me know if I've forgotten anything!=A0 thanks a bunch!! Late response here, but... Is there an index on invsensor (sensor_id, granule_id)? If not, that might be something to try. If so, you might want to try to figure out why it's not being used. Likewise, is there an index on gran_ver (granule_id)? --=20 Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company