Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 3F2646322B1 for ; Fri, 4 Jun 2010 05:13:36 -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 15293-09 for ; Fri, 4 Jun 2010 08:13:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from anastacia.gransy.com (anastacia.gransy.com [77.78.104.100]) by mail.postgresql.org (Postfix) with ESMTP id 9C6CC6321A7 for ; Fri, 4 Jun 2010 05:13:28 -0300 (ADT) Received: from sq.gransy.com (localhost [127.0.0.1]) by anastacia.gransy.com (Postfix) with ESMTP id 687C5AAC59E; Fri, 4 Jun 2010 10:13:23 +0200 (CEST) Received: from 85.160.40.238 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Fri, 4 Jun 2010 10:13:23 +0200 (CEST) Message-ID: <1097.85.160.40.238.1275639203.squirrel@sq.gransy.com> In-Reply-To: References: Date: Fri, 4 Jun 2010 10:13:23 +0200 (CEST) Subject: Re: slow query From: tv@fuzzy.cz To: "Anj Adu" Cc: pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.10a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-2 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201006/74 X-Sequence-Number: 38930 > I am reposting as my original query was mangled > > The link to the explain plan is here as it does not paste well into > the email body. > > http://explain.depesz.com/s/kHa > > > The machine is a 2 cpu quad core 5430 with 32G RAM and 6x450G 15K > single raid-10 array > > 1G work_mem > default_statistics_target=1000 > random_page_cost=1 Are you sure it's wise to set the work_mem to 1G? Do you really need it? Don't forget this is not a 'total' or 'per query' - each query may allocate multiple work areas (and occupy multiple GB). But I guess this does not cause the original problem. The last row 'random_page_cost=1' - this basically says that reading data by random is just as cheap as reading data sequentially. Which may result in poor performance due to bad plans. Why have you set this value? Sure, there are rare cases where 'random_page_cost=1' is OK. > > I am curious why the hash join takes so long. The main table > dev4_act_dy_fact_2010_05_t has 25 million rows. The table is > partitioned into 3 parts per month. Remaining tables are very small ( > < 1000 rows) Well, the real cause that makes your query slow is the 'index scan' part. Index Scan using dev4_act_dy_fact_2010_05_t3_thedate on dev4_act_dy_fact_2010_05_t3 a (cost=0.00..94041.89 rows=204276 width=60) (actual time=164533.725..164533.725 rows=0 loops=1) The first thing to note here is the difference in expected and actual number of rows - the planner expects 204276 but gets 0 rows. How large is this partition? Try to analyze it, set the random_page_cost to something reasonable (e.g. 4) and try to run the query again. Tomas