1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Replace ALTER TABLE ... SET STATISTICS DISTINCT with a more general mechanism.

Attributes can now have options, just as relations and tablespaces do, and
the reloptions code is used to parse, validate, and store them.  For
simplicity and because these options are not performance critical, we store
them in a separate cache rather than the main relcache.

Thanks to Alex Hunsaker for the review.
This commit is contained in:
Robert Haas
2010-01-22 16:40:19 +00:00
parent 9ca0989037
commit 76a47c0e74
19 changed files with 267 additions and 223 deletions

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.218 2010/01/17 22:56:21 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.219 2010/01/22 16:40:18 rhaas Exp $ -->
<!--
Documentation of the system catalogs, directed toward PostgreSQL developers
-->
@ -901,19 +901,6 @@
</entry>
</row>
<row>
<entry><structfield>attdistinct</structfield></entry>
<entry><type>float4</type></entry>
<entry></entry>
<entry>
<structfield>attdistinct</structfield>, if nonzero, is a user-specified
number-of-distinct-values figure to be used instead of estimating the
number of distinct values during <command>ANALYZE</>. Nonzero values
have the same meanings as for
<link linkend="catalog-pg-statistic"><structname>pg_statistic</></link>.<structfield>stadistinct</>
</entry>
</row>
<row>
<entry><structfield>attlen</structfield></entry>
<entry><type>int2</type></entry>
@ -1061,6 +1048,15 @@
</entry>
</row>
<row>
<entry><structfield>attoptions</structfield></entry>
<entry><type>text[]</type></entry>
<entry></entry>
<entry>
Attribute-level options, as <quote>keyword=value</> strings
</entry>
</row>
</tbody>
</tgroup>
</table>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.109 2009/09/18 05:00:41 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.110 2010/01/22 16:40:18 rhaas Exp $
PostgreSQL documentation
-->
@ -39,7 +39,8 @@ ALTER TABLE <replaceable class="PARAMETER">name</replaceable>
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> DROP DEFAULT
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> { SET | DROP } NOT NULL
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET STATISTICS <replaceable class="PARAMETER">integer</replaceable>
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET STATISTICS DISTINCT <replaceable class="PARAMETER">number</replaceable>
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET ( <replaceable class="PARAMETER">attribute_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> RESET ( <replaceable class="PARAMETER">attribute_option</replaceable> [, ... ] )
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
ADD <replaceable class="PARAMETER">table_constraint</replaceable>
DROP CONSTRAINT [ IF EXISTS ] <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
@ -158,14 +159,21 @@ ALTER TABLE <replaceable class="PARAMETER">name</replaceable>
</varlistentry>
<varlistentry>
<term><literal>SET STATISTICS DISTINCT</literal></term>
<term><literal>SET ( <replaceable class="PARAMETER">attribute_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )</term></literal>
<term><literal>RESET ( <replaceable class="PARAMETER">attribute_option</replaceable> [, ... ] )</literal>
<listitem>
<para>
This form overrides the number-of-distinct-values estimate made by
subsequent <xref linkend="sql-analyze" endterm="sql-analyze-title">
operations. When set to a positive value, <command>ANALYZE</> will
assume that the column contains exactly the specified number of distinct
nonnull values. When set to a negative value, which must be greater
This form sets or resets attribute-level options. Currently, the only
define attribute-level options are <literal>n_distinct</> and
<literal>n_distinct_inherited</>, which override the
number-of-distinct-values estimate made by subsequent
<xref linkend="sql-analyze" endterm="sql-analyze-title">
operations. <literal>n_distinct</> affects the statistics for the table
itself, while <literal>n_distinct_inherited</> affects the statistics
gathered for the table and its inheritance children. When set to a
positive value, <command>ANALYZE</> will assume that the column contains
exactly the specified number of distinct nonnull values. When set to a
negative value, which must be greater
than or equal to -1, <command>ANALYZE</> will assume that the number of
distinct nonnull values in the column is linear in the size of the
table; the exact count is to be computed by multiplying the estimated

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/analyze.sgml,v 1.27 2009/08/04 22:04:37 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/analyze.sgml,v 1.28 2010/01/22 16:40:18 rhaas Exp $
PostgreSQL documentation
-->
@ -173,7 +173,7 @@ ANALYZE [ VERBOSE ] [ <replaceable class="PARAMETER">table</replaceable> [ ( <re
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
<command>ALTER TABLE ... ALTER COLUMN ... SET STATISTICS DISTINCT</>
<command>ALTER TABLE ... ALTER COLUMN ... SET (n_distinct = ...)</>
(see <xref linkend="sql-altertable" endterm="sql-altertable-title">).
</para>
</refsect1>