Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/ref/analyze.sgml`
5b4987e95a01651c2bd7878662350a58b66cbbee737e2fb70000000100000f8c
 BY</literal> clauses of queries, since the planner will
   have no use for statistics on such columns.
  </para>

  <para>
   The largest statistics target among the columns being analyzed determines
   the number of table rows sampled to prepare the statistics.  Increasing
   the target causes a proportional increase in the time and space needed
   to do <command>ANALYZE</command>.
  </para>

  <para>
   One of the values estimated by <command>ANALYZE</command> is the number of
   distinct values that appear in each column.  Because only a subset of the
   rows are examined, this estimate can sometimes be quite inaccurate, even
   with the largest possible statistics target.  If this inaccuracy leads to
   bad query plans, a more accurate value can be determined manually and then
   installed with
   <link linkend="sql-altertable"><command>ALTER TABLE ... ALTER COLUMN ... SET (n_distinct = ...)</command></link>.
  </para>

  <para>
    If the table being analyzed has inheritance children,
    <command>ANALYZE</command> gathers two sets of statistics: one on the rows
    of the parent table only, and a second including rows of both the parent
    table and all of its children.  This second set of statistics is needed when
    planning queries that process the inheritance tree as a whole.  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
    <command>ANALYZE</command> manually.  By default,
    <command>ANALYZE</command> will also recursively collect and update the
    statistics for each inheritance child table.  The <literal>ONLY</literal>
    keyword may be used to disable this.
  </para>

  <para>
    For partitioned tables, <command>ANALYZE</command> gathers statistics by
    sampling rows from all partitions.  By default,
    <command>ANALYZE</command> will also recursively collect and update the
    statistics for each partition.  The <literal>ONLY</literal> keyword may be
    used to disable this.
  </para>

  <para>
    The autovacuum daemon does not process partitioned tables, nor does it
    process inheritance parents if only the children are ever modified.
    It is usually necessary to periodically run a manual
    <command>ANALYZE</command> to keep the statistics of the table hierarchy
    up to date.
  </para>

  <para>
    If any child tables or partitions are foreign tables whose foreign
    data wrappers do not support <command>ANALYZE</command>, those tables are
    ignored while gathering inheritance statistics.
  </para>

  <para>
    If the table being analyzed is completely empty, <command>ANALYZE</command>
    will not record new statistics for that table.  Any existing statistics
    will be retained.
  </para>

  <para>
    Each backend running <command>ANALYZE</command> will report its progress
    in the <structname>pg_stat_progress_analyze</structname> view. See
    <xref linkend="analyze-progress-reporting"/> for details.
  </para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   There is no <command>ANALYZE</command> statement in the SQL standard.
  </para>

  <para>
   The following syntax was used before <productname>PostgreSQL</productname>
   version 11 and is still supported:
<synopsis>
ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replaceable> [, ...] ]
</synopsis>
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-vacuum"/></member>
   <member><xref linkend="app-vacuumdb"/></member>
   <member><xref linkend="runtime-config-resource-vacuum-cost"/></member>
   <member><xref linkend="autovacuum"/></member>
   <member><xref linkend="analyze-progress-reporting"/></member>
  </simplelist>
 </refsect1>
</refentry>

Title: ANALYZE Behavior with Inheritance, Partitioned Tables, and Foreign Tables
Summary
This section details how ANALYZE handles tables with inheritance children and partitioned tables, including the collection of separate statistics for the parent table and its children, and sampling from all partitions. It also explains how ANALYZE interacts with foreign tables, empty tables, and progress reporting. It briefly mentions compatibility with older PostgreSQL versions and provides a list of related commands and resources.