Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D2D86133740B for ; Fri, 4 Feb 2011 11:41:16 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 80457-06 for ; Fri, 4 Feb 2011 15:41:09 +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 5A98A1336B42 for ; Fri, 4 Feb 2011 11:41:08 -0400 (AST) 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 p14Ff4Qh022837; Fri, 4 Feb 2011 10:41:05 -0500 (EST) To: Mark Mielke cc: Conor Walsh , jd@commandprompt.com, Robert Haas , "pgsql-performance@postgresql.org" Subject: Re: Does auto-analyze work on dirty writes? (was: Re: [HACKERS] Slow count(*) again...) In-reply-to: <4D4B7317.3070803@mark.mielke.cc> References: <201102012247.p11Ml6u02682@momjian.us> <4D48914B.4050403@dunslane.net> <4D489AD1.1010105@vmsinfo.com> <4D499E55.4020107@vmsinfo.com> <4D4A7B69.2020704@gmail.com> <1296786810.18411.102.camel@jd-desktop> <4D4B7317.3070803@mark.mielke.cc> Comments: In-reply-to Mark Mielke message dated "Thu, 03 Feb 2011 22:31:35 -0500" Date: Fri, 04 Feb 2011 10:41:04 -0500 Message-ID: <22836.1296834064@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/270 X-Sequence-Number: 42408 Mark Mielke writes: > My understanding is: > 1) Background daemon wakes up and checks whether a number of changes > have happened to the database, irrelevant of transaction boundaries. > 2) Background daemon analyzes a percentage of rows in the database for > statistical data, irrelevant of row visibility. > 3) Analyze is important for both visible rows and invisible rows, as > plan execution is impacted by invisible rows. As long as they are part > of the table, they may impact the queries performed against the table. > 4) It doesn't matter if the invisible rows are invisible because they > are not yet committed, or because they are not yet vacuumed. > Would somebody in the know please confirm the above understanding for my > own piece of mind? No. 1. Autovacuum fires when the stats collector's insert/update/delete counts have reached appropriate thresholds. Those counts are accumulated from messages sent by backends at transaction commit or rollback, so they take no account of what's been done by transactions still in progress. 2. Only live rows are included in the stats computed by ANALYZE. (IIRC it uses SnapshotNow to decide whether rows are live.) Although the stats collector does track an estimate of the number of dead rows for the benefit of autovacuum, this isn't used by planning. Table bloat is accounted for only in terms of growth of the physical size of the table in blocks. regards, tom lane