Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id C07EC9FB413 for ; Sat, 18 Aug 2007 00:04:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 29152-01 for ; Sat, 18 Aug 2007 00:04:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 457289FB3AF for ; Sat, 18 Aug 2007 00:03:59 -0300 (ADT) Received: from perhan.alvh.no-ip.org (201-221-221-172.bk12-dsl.surnet.cl [201.221.221.172]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l7I33t3v023719; Fri, 17 Aug 2007 20:03:56 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 589F547C5A; Fri, 17 Aug 2007 23:03:49 -0400 (CLT) Date: Fri, 17 Aug 2007 23:03:49 -0400 From: Alvaro Herrera To: Jozsef Szalay Cc: Bill Moran , Pavel Stehule , pgsql-performance@postgresql.org Subject: Re: Simple select hangs while CPU close to 100% - Analyze Message-ID: <20070818030349.GC13349@alvh.no-ip.org> References: <20070725162834.c18bd204.wmoran@collaborativefusion.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-11) X-Virus-Scanned: ClamAV 0.91.1/3967/Thu Aug 16 08:32:14 2007 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Fri, 17 Aug 2007 20:03:57 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/187 X-Sequence-Number: 26317 Jozsef Szalay escribió: > I don't know why ANALYZE would have any effect on a sequential scan of a > table but it does appear to impact both performance and memory usage > significantly. It doesn't. What it does is provide the query optimizer with the information that it needs to know that the table contains many different values, which makes it turn the initial hashed aggregation into a sort plus group aggregation. This allows the aggregation to use less memory. As an exercise, see an EXPLAIN of the query, both before and after the analyze, and study the difference. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.