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 1mYpSI-0007pL-Fh for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Oct 2021 12:58:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mYpSH-0000in-FV for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Oct 2021 12:58:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYpSH-0000if-2M for pgsql-hackers@lists.postgresql.org; Fri, 08 Oct 2021 12:58:29 +0000 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mYpSE-0006nN-Fh for pgsql-hackers@postgresql.org; Fri, 08 Oct 2021 12:58:28 +0000 Received: by mail-il1-x131.google.com with SMTP id b6so9981742ilv.0 for ; Fri, 08 Oct 2021 05:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=KSc/V+CiLodgnrLjiZwl8DlP4pWfFO2QGGHl7QPjj3w=; b=14i5RRCLjknjWXWD31wXoo0W3rwpZkN+AXWIgH5mPhtFX/Cex1ai8X9XHKESEYyJ+r c3gZcwjg24SsWnMDi6U1AFVHxuSVpxGJLDCSMgMRdZzYGZRRAXclRS6KbM6qbh01DtpO G9wdSB+IBaDfdOvAPBnkpYsTiSKtBdsvynUzNotjTiQLfPni7j3/j2FvVVB8OU/6GgvN /TCunwZJYBNCWN8mi38NapnStBeU8n76pW+atnqYBivMlWrJm1hIrIvUIdvsPkzqr+kQ w/Gg70TSIIQ7OQ11clEd5WCV1a1gqmPvEFmrfVPQcy2Gnf22hIhA0fNUiW4cXIeIRrzJ fnww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=KSc/V+CiLodgnrLjiZwl8DlP4pWfFO2QGGHl7QPjj3w=; b=fJRLdRN+GeK3ObDmOMT7x5t+4l4TVJM2Fzklog9BReUjNR8CrlC59OlV3vuqncvcEI W1f/yGFazbNYrp/6DMZNlf+4XztHA3qv5J72tXdZadb2Wc3wOCb1KJGfTkJ1Jrz4WOYK siejjKptPhBbJDv4ZDAR4NGf1B2kCNLhWPvh3qYGKKEIpaaKINz1V2W0lAPoAtcemvga fnMfWouiaxJ+vNd6wkbxFY49oge3TmurafhXKWjzbRz3dD8hWTyIga1FTLVCsVt65rJD Y1oTLG/Wl91+hgDntRK/AMw5/aIvBz2+Jg44exLm4KHgpFXsP0LrLvGhtqiqQKZBqjHw l03w== X-Gm-Message-State: AOAM530JYYgiI1nQPNhGdpma1rDXphHJeuRjeJ26n1M0NVFPoi7tEaxU qWBikbhB+mDiL0mmi7m9NEDmXw== X-Google-Smtp-Source: ABdhPJyp2Z0+fbfYN/KINaF7r1izt9Qm3799prE10cbinec3I60Uj/TKqBceB1RJtHLo+TO+JJlKJw== X-Received: by 2002:a05:6e02:c2f:: with SMTP id q15mr7792451ilg.255.1633697904368; Fri, 08 Oct 2021 05:58:24 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id w11sm984136ior.40.2021.10.08.05.58.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Oct 2021 05:58:23 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id E7236801BD4; Fri, 8 Oct 2021 07:58:22 -0500 (CDT) Date: Fri, 8 Oct 2021 07:58:22 -0500 From: Justin Pryzby To: =?iso-8859-1?Q?=C1lvaro?= Herrera Cc: yuzuko , pgsql-hackers@postgresql.org Subject: Re: document the need to analyze partitioned tables Message-ID: <20211008125822.GJ27491@telsasoft.com> References: <20210913035409.GA10647@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MZf7D3rAEoQgPanC" Content-Disposition: inline In-Reply-To: <20210913035409.GA10647@telsasoft.com> 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 --MZf7D3rAEoQgPanC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Cleaned up and attached as a .patch. The patch implementing autoanalyze on partitioned tables should revert relevant portions of this patch. --MZf7D3rAEoQgPanC Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-documentation-deficiencies-for-ANALYZE-of-partitione.patch" From cec31df3772ca51bbf14ebee207bcfd22e498073 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Thu, 22 Jul 2021 16:06:18 -0500 Subject: [PATCH] documentation deficiencies for ANALYZE of partitioned tables This is partially extracted from 1b5617eb844cd2470a334c1d2eec66cf9b39c41a, which was reverted. --- doc/src/sgml/maintenance.sgml | 27 ++++++++++++++++++++++++++ doc/src/sgml/perform.sgml | 2 ++ doc/src/sgml/ref/analyze.sgml | 36 ++++++++++++++++++++++------------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index 36f975b1e5..b7c806cc90 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -290,6 +290,14 @@ to meaningful statistical changes. + + Tuples changed in partitions and inheritance 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 is necessary to + periodically manual run ANALYZE on the parent table to + keep the statistics of its table hierarchy up to date. + + As with vacuuming for space recovery, frequent updates of statistics are more useful for heavily-updated tables than for seldom-updated @@ -347,6 +355,18 @@ ANALYZE commands on those tables on a suitable schedule. + + + + The autovacuum daemon does not issue ANALYZE commands for + partitioned tables. Inheritance parents will only be analyzed if the + parent itself is changed - changes to child tables do not trigger + autoanalyze on the parent table. It is necessary to periodically run a + manual ANALYZE to keep the statistics of the table + hierarchy up to date. + + + @@ -819,6 +839,13 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu since the last ANALYZE. + + Partitioned tables are not processed by autovacuum. Statistics + should be collected by running a manual ANALYZE when it is + first populated, and updated whenever the distribution of data in its + partitions changes significantly. + + Temporary tables cannot be accessed by autovacuum. Therefore, appropriate vacuum and analyze operations should be performed via diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml index 9cf8ebea80..caf703129d 100644 --- a/doc/src/sgml/perform.sgml +++ b/doc/src/sgml/perform.sgml @@ -1765,9 +1765,11 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse; Run <command>ANALYZE</command> Afterwards + Whenever you have significantly altered the distribution of data within a table, running ANALYZE is strongly recommended. This includes bulk loading large amounts of data into the table. Running + ANALYZE (or VACUUM ANALYZE) ensures that the planner has up-to-date statistics about the table. With no statistics or obsolete statistics, the planner might diff --git a/doc/src/sgml/ref/analyze.sgml b/doc/src/sgml/ref/analyze.sgml index c423aeeea5..9a904262df 100644 --- a/doc/src/sgml/ref/analyze.sgml +++ b/doc/src/sgml/ref/analyze.sgml @@ -250,22 +250,32 @@ ANALYZE [ VERBOSE ] [ table_and_columns - If the table being analyzed has one or more children, - ANALYZE will gather statistics 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 autovacuum daemon, however, will only consider inserts or - updates on 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. + If the table being analyzed is partitioned, ANALYZE + will gather statistics by sampling blocks randomly from its partitions; + in addition, it will recurse into each partition and update its statistics. + (However, in multi-level partitioning scenarios, each leaf partition + will only be analyzed once.) + By constrast, if the table being analyzed has inheritance children, + ANALYZE will gather statistics for it 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 child tables themselves are not individually + analyzed in this case. - If any of the child tables are foreign tables whose foreign data wrappers - do not support ANALYZE, those child tables are ignored while - gathering inheritance statistics. + The autovacuum daemon does not process partitioned tables, nor does it + process inheritance parents due to modifications to its child tables. + It is usually necessary to periodically run a manual + ANALYZE to keep the statistics of the table hierarchy + up to date. See... + + + + If any child tables or partitions are foreign tables whose foreign + data wrappers do not support ANALYZE, those tables are + ignored while gathering inheritance statistics. -- 2.17.0 --MZf7D3rAEoQgPanC--