Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 537191337BD2 for ; Wed, 11 May 2011 11:31:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 77419-04 for ; Wed, 11 May 2011 14:31:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 70E0A1337B69 for ; Wed, 11 May 2011 11:31:37 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p4BEVaW5025612; Wed, 11 May 2011 10:31:36 -0400 (EDT) To: Scott Marlowe cc: Maria.L.Wilson-1@nasa.gov, "pgsql-performance@postgresql.org" Subject: Re: help speeding up a query in postgres 8.4.5 In-reply-to: References: <4D9B6CBA.2050609@nasa.gov> Comments: In-reply-to Scott Marlowe message dated "Wed, 11 May 2011 01:09:27 -0600" Date: Wed, 11 May 2011 10:31:36 -0400 Message-ID: <25611.1305124296@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.569 tagged_above=-10 required=5 tests=BAYES_00=-1.9, JOIN_MILLIONS=1.026, SARE_MILLIONSOF=0.315, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/150 X-Sequence-Number: 43659 Scott Marlowe writes: > On Tue, Apr 5, 2011 at 1:25 PM, Maria L. Wilson > wrote: > This bit: >> left outer join INVENTORY IV on GV.GRANULE_ID = IV.GRANULE_ID, INVSENSOR >> INVS > has both an explicit and an implicit join. This can constrain join > re-ordering in the planner. Can you change it to explicit joins only > and see if that helps? Since there's a WHERE constraint on IV, the outer join is going to be strength-reduced to an inner join (note the lack of any outer joins in the plan). So that isn't going to matter. AFAICS this is just plain an expensive query. The two filter constraints are not very selective, each passing more than a million rows up to the join. You can't expect to join millions of rows in no time flat. About all you can do is try to bump up work_mem enough that the join won't use temp files --- for something like this, that's likely to require a setting of hundreds of MB. I'm not sure whether Maria is using a version in which EXPLAIN ANALYZE will show whether a hash join was batched, but that's what I'd be looking at. regards, tom lane