Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lhKhp-00042U-4X for pgsql-hackers@arkaria.postgresql.org; Thu, 13 May 2021 23:25:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lhKho-00027o-18 for pgsql-hackers@arkaria.postgresql.org; Thu, 13 May 2021 23:25:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lhKhn-00027f-MV for pgsql-hackers@lists.postgresql.org; Thu, 13 May 2021 23:25:23 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lhKhk-0004rH-Bm for pgsql-hackers@lists.postgresql.org; Thu, 13 May 2021 23:25:22 +0000 Received: by mail-io1-xd36.google.com with SMTP id z24so26548169ioj.7 for ; Thu, 13 May 2021 16:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HqHVhHTH9yroYlIQ77r2wcHkSr2L/UsHw/2eJI9By4Q=; b=dBGgoJlmnstcpxgEZBPN7JxC04LFrVx/2LjUQhkfpnf2idvHM7vOkoG0QFOVP6LRVM ZjIgjy5fnIDyrU+r02o3gvJwScGX4AkMoAB4YY08c6b9V8a1yEb0s5Buqr2KT8+E06w5 2mxphEFa08QQzu0uyfNMCv1g3/Kc7jUrIVIotG85HVxsFppmi8g9D+idZ/qHrMoKjykU dgQxeR2oIWTTVo4hBPp/M/NGDj6mNJV8S+ULljnd/eWy1XDvcOmI5VSV9l4YsTlffMUU Q7vEu6trhvFxAjK5ngDcLJpULkEkbrt7LVvHVBo8FfNSmMt4WkqjEebFDWFdgAQBr7Lu kNEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HqHVhHTH9yroYlIQ77r2wcHkSr2L/UsHw/2eJI9By4Q=; b=oyddS5zMNTeGlaLLcIXG7KgNGasLL0IiYVg0Mk7XmNN+XLug58ctkZM7hWW6l+9Ckj OgjPeNkWFmNTAicElfrwgy7MHjFNgYKgp/1GOK+9nqE0H96oXyfcgn34LCqscueDF40F +C0OM2pAuRe83H0bTzrpmL6ql3inXU+nz6CHGPUjO+bgnJEYcg13OykXkOtsmG7+Io5/ +Y6l5pM7Juq2cdMSrBvCQbl5jgcMU2AY2D90Kt4bkZE6NuMHdo7RYCO8P3mX+ev+a9kq f6UWXVSBHO8iG4YIe/n2cwbvMWSDBS+agZObPoC4k3VDiiUZeOLlWuhCD9pw5+NCOXLS 8H+w== X-Gm-Message-State: AOAM531PTxvLSLHzcicyswE315wTlDBMi7d2GHVtArd4iyPx043iHewg rTEwgz27eyXVLB8sfQAQa2jKrQ== X-Google-Smtp-Source: ABdhPJwSzXHnYk0ABkTX3j15FRjemNfYPdqFUwXVrq3nRnN+F3ba85zIWChtdUlKZnSfBQx2jqdVFQ== X-Received: by 2002:a05:6638:2643:: with SMTP id n3mr39967298jat.104.1620948319384; Thu, 13 May 2021 16:25:19 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d16sm2032983ilo.12.2021.05.13.16.25.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 May 2021 16:25:19 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id CDAA6800BDB; Thu, 13 May 2021 18:25:17 -0500 (CDT) Date: Thu, 13 May 2021 18:25:17 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Robert Haas , Tom Lane , Zhihong Yu , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: autovacuum: handle analyze for partitioned tables Message-ID: <20210513232517.GO27406@telsasoft.com> References: <20210511215616.GA13282@alvherre.pgsql> <20210513213333.GA31073@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210513213333.GA31073@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, May 13, 2021 at 05:33:33PM -0400, Alvaro Herrera wrote: > +++ b/doc/src/sgml/maintenance.sgml > @@ -817,6 +817,11 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu > > is compared to the total number of tuples inserted, updated, or deleted > since the last ANALYZE. > + For partitioned tables, inserts and updates on partitions are counted > + towards this threshold; however partition meta-operations such as > + attachment, detachment or drop are not, so running a manual > + ANALYZE is recommended if the partition added or > + removed contains a statistically significant volume of data. I suggest: "Inserts, updates and deletes on partitions of a partitioned table are counted towards this threshold; however DDL operations such as ATTACH, DETACH and DROP are not, ... > + and in addition it will analyze each individual partition separately. remove "and" and say in addition COMMA Or: "it will also recursive into each partition and update its statistics." > + By constrast, if the table being analyzed has inheritance children, > + ANALYZE will gather statistics for that table twice: > + once on the rows of the parent table only, and a second time on the > + rows of the parent table with all of its children. This second set of > + statistics is needed when planning queries that traverse the entire > + inheritance tree. The children tables are not individually analyzed > + in this case. say "The child tables themselves.." > + > + For tables with inheritance children, the autovacuum daemon only > + counts inserts and deletes in the parent table itself when deciding > + whether to trigger an automatic analyze for that table. If that table > + is rarely inserted into or updated, the inheritance statistics will > + not be up to date unless you run ANALYZE manually. > + This should be emphasized: Tuples changed in inheritence children do not count towards analyze on the parent table. If the parent table is empty or rarely changed, it may never be processed by autovacuum. It's necesary to periodically run an manual ANALYZE to keep the statistics of the table hierarchy up to date. I don't know why it says "inserted or updated" but doesn't say "or deleted" - that seems like a back-patchable fix. > +++ b/doc/src/sgml/ref/pg_restore.sgml > @@ -922,8 +922,10 @@ CREATE DATABASE foo WITH TEMPLATE template0; > > > Once restored, it is wise to run ANALYZE on each > - restored table so the optimizer has useful statistics; see > - and > + restored table so the optimizer has useful statistics. > + If the table is a partition or an inheritance child, it may also be useful > + to analyze the parent table. > + See and > for more information. maybe say: "analyze the parent to update statistics for the table hierarchy".