Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D5D961337B2F for ; Thu, 3 Feb 2011 18:36:00 -0400 (AST) 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 45361-01 for ; Thu, 3 Feb 2011 22:35:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.9]) by mail.postgresql.org (Postfix) with ESMTP id 11BC6133740B for ; Thu, 3 Feb 2011 18:35:52 -0400 (AST) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MXFZN-1Phb0e24tZ-00WnNp; Thu, 03 Feb 2011 23:35:15 +0100 Message-ID: <4D4B2DA0.3040601@2ndquadrant.com> Date: Thu, 03 Feb 2011 17:35:12 -0500 From: Greg Smith User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: david@lang.hm CC: Robert Haas , Vitalii Tymchyshyn , Jon Nelson , Mladen Gogala , Andrew Dunstan , Bruce Momjian , Tom Lane , Craig Ringer , "pgsql-performance@postgresql.org" Subject: Re: [HACKERS] Slow count(*) again... References: <201102012247.p11Ml6u02682@momjian.us> <4D48914B.4050403@dunslane.net> <4D489AD1.1010105@vmsinfo.com> <4D499E55.4020107@vmsinfo.com> <4D4A7B69.2020704@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:dkQxUVdFgPI6qAg/qUdpPPBvXORLzF6N9wj6Ln8Ol1Q 6yHDzT0n1wZKMHrFXtWSQIVBZmhZj1I9TVaivU00agxv0JhE4R Byh2FY6oTxut2cXoQu+eFOaFbtjG8qAeJcyhe5IYBme4+CoUHp en5E/C8h9AxOhAIDTyhsG1MgWS6oxB6zYV0DJzDa+g01nj/wTT ZMDa117s9pomQuDcGk3EdQKrdmeE4hFcsKmAEGOL/0= 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, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201102/120 X-Sequence-Number: 42258 david@lang.hm wrote: > I am making the assumption that an Analyze run only has to go over the > data once (a seqential scan of the table if it's >> ram for example) > and gathers stats as it goes. And that's the part there's some confusion about here. ANALYZE grabs a random set of samples from the table, the number of which is guided by the setting for default_statistics_target. The amount of time it takes is not proportional to the table size; it's only proportional to the sampling size. Adding a process whose overhead is proportional to the table size, such as the continuous analyze idea you're proposing, is quite likely to be a big step backwards relative to just running a single ANALYZE after the loading is finished. What people should be doing if concerned about multiple passes happening is something like this: CREATE TABLE t (s serial, i integer) WITH (autovacuum_enabled=off); [populate table] ANALYZE t; ALTER TABLE t SET (autovacuum_enabled=on); I'm not optimistic the database will ever get smart enough to recognize bulk loading and do this sort of thing automatically, but as the workaround is so simple it's hard to get motivated to work on trying. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books