Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6EF6863225C for ; Tue, 3 Aug 2010 04:04:02 -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 02287-01 for ; Tue, 3 Aug 2010 07:03:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from serenity.inversion.ee (serenity.inversion.ee [194.204.33.112]) by mail.postgresql.org (Postfix) with ESMTP id 4D959632270 for ; Tue, 3 Aug 2010 04:03:52 -0300 (ADT) Received: by serenity.inversion.ee (Postfix, from userid 108) id 98FB51BB8469; Tue, 3 Aug 2010 08:45:06 +0300 (EEST) Received: from [IPv6:::1] (localhost [127.0.0.1]) by serenity.inversion.ee (Postfix) with ESMTP id 32F6C1BB8468; Tue, 3 Aug 2010 08:45:06 +0300 (EEST) Subject: Re: Questions on query planner, join types, and work_mem From: Hannu Krosing To: Peter Hussey Cc: Tom Lane , pgsql-performance In-Reply-To: References: <18551.1280275502@sss.pgh.pa.us> <25534.1280498632@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" Date: Tue, 03 Aug 2010 10:03:51 +0300 Message-ID: <1280819031.14579.38.camel@hvost> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201008/39 X-Sequence-Number: 39882 On Mon, 2010-08-02 at 14:23 -0700, Peter Hussey wrote: > I already had effective_cache_size set to 500MB. > > I experimented with lowering random_page_cost to 3 then 2. In case of fully cached database it is closer to 1. > 2) Why is the setting of work_mem something left to the admin and/or > developer? Couldn't the optimizer say how much it thinks it needs to > build a hash table based on size of the keys and estimated number of > rows? Yes, It can say how much it thinks it needs to build a hash table, the part it can't figure out is how much it can afford, based on things like number concurrent queries and how much work-mem these are using, and any work-mem used will be substracted from total memory pool, affecting also how much of the files the system caches. > It is difficult for a software development platform like ours to take > advantage of suggestions to set work_mem, or to change the cost > function, or turn on/off join strategies for individual queries. The > SQL we issue is formed by user interaction with the product and rarely > static. How would we know when to turn something on or off? That's > why I'm looking for a configuration solution that I can set on a > database-wide basis and have it work well for all queries. Keep trying. The close you get with your conf to real conditions, the better choices the optimiser can make ;) -- Hannu Krosing http://www.2ndQuadrant.com PostgreSQL Scalability and Availability Services, Consulting and Training