Home Explore Blog CI



postgresql

87th chunk of `doc/src/sgml/catalogs.sgml`
0331a8531dd414375181801e7883350d0f83dc439e91e3850000000100000fa4
 <replaceable>table</replaceable></literal>.
  </para>

  <para>
   <structname>pg_statistic</structname> also stores statistical data about
   the values of index expressions.  These are described as if they were
   actual data columns; in particular, <structfield>starelid</structfield>
   references the index.  No entry is made for an ordinary non-expression
   index column, however, since it would be redundant with the entry
   for the underlying table column.  Currently, entries for index expressions
   always have <structfield>stainherit</structfield> = <literal>false</literal>.
  </para>

  <para>
   Since different kinds of statistics might be appropriate for different
   kinds of data, <structname>pg_statistic</structname> is designed not
   to assume very much about what sort of statistics it stores.  Only
   extremely general statistics (such as nullness) are given dedicated
   columns in <structname>pg_statistic</structname>.  Everything else
   is stored in <quote>slots</quote>, which are groups of associated columns
   whose content is identified by a code number in one of the slot's columns.
   For more information see
   <filename>src/include/catalog/pg_statistic.h</filename>.
  </para>

  <para>
   <structname>pg_statistic</structname> should not be readable by the
   public, since even statistical information about a table's contents
   might be considered sensitive.  (Example: minimum and maximum values
   of a salary column might be quite interesting.)
   <link linkend="view-pg-stats"><structname>pg_stats</structname></link>
   is a publicly readable view on
   <structname>pg_statistic</structname> that only exposes information
   about those tables that are readable by the current user.
  </para>

  <table>
   <title><structname>pg_statistic</structname> Columns</title>
   <tgroup cols="1">
    <thead>
     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       Column Type
      </para>
      <para>
       Description
      </para></entry>
     </row>
    </thead>

    <tbody>
     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>starelid</structfield> <type>oid</type>
       (references <link linkend="catalog-pg-class"><structname>pg_class</structname></link>.<structfield>oid</structfield>)
      </para>
      <para>
       The table or index that the described column belongs to
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>staattnum</structfield> <type>int2</type>
       (references <link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.<structfield>attnum</structfield>)
      </para>
      <para>
       The number of the described column
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>stainherit</structfield> <type>bool</type>
      </para>
      <para>
       If true, the stats include values from child tables, not just the
       values in the specified relation
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>stanullfrac</structfield> <type>float4</type>
      </para>
      <para>
       The fraction of the column's entries that are null
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>stawidth</structfield> <type>int4</type>
      </para>
      <para>
       The average stored width, in bytes, of nonnull entries
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>stadistinct</structfield> <type>float4</type>
      </para>
      <para>
       The number of distinct nonnull data values in the column.
       A value greater than zero is the actual number of distinct

Title: pg_statistic Details, Slots, Security, and Columns
Summary
This section continues the explanation of the `pg_statistic` catalog, describing how it stores statistics for index expressions and its flexible design using 'slots' for various data types. It emphasizes that `pg_statistic` should not be publicly readable due to sensitive information. The publicly readable `pg_stats` view is introduced as a safer alternative. Finally, the columns of `pg_statistic` are detailed: `starelid` (table/index OID), `staattnum` (column number), `stainherit` (inheritance flag), `stanullfrac` (null fraction), `stawidth` (average width), and `stadistinct` (number of distinct values).