Commit eddcd492 authored by Neil Conway's avatar Neil Conway

Add some documentation for constraint exclusion and basic partitioning.

From Simon Riggs; cleanup and editorialization by Neil Conway.
parent b524cb36
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.33 2005/10/26 12:55:07 momjian Exp $ $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.34 2005/11/01 23:19:05 neilc Exp $
--> -->
<chapter Id="runtime-config"> <chapter Id="runtime-config">
<title>Server Configuration</title> <title>Server Configuration</title>
...@@ -1974,11 +1974,11 @@ archive_command = 'copy "%p" /mnt/server/archivedir/"%f"' # Windows ...@@ -1974,11 +1974,11 @@ archive_command = 'copy "%p" /mnt/server/archivedir/"%f"' # Windows
</para> </para>
<para> <para>
When this parameter is <literal>on</>, the planner compares query When this parameter is <literal>on</>, the planner compares
conditions with table CHECK constraints, and omits scanning tables query conditions with table <literal>CHECK</> constraints, and
where the conditions contradict the constraints. (Presently omits scanning tables where the conditions contradict the
this is done only for child tables of inheritance scans.) For constraints. (Presently this is done only for child tables of
example: inheritance scans.) For example:
<programlisting> <programlisting>
CREATE TABLE parent(key integer, ...); CREATE TABLE parent(key integer, ...);
...@@ -1988,23 +1988,30 @@ CREATE TABLE child2000(check (key between 2000 and 2999)) INHERITS(parent); ...@@ -1988,23 +1988,30 @@ CREATE TABLE child2000(check (key between 2000 and 2999)) INHERITS(parent);
SELECT * FROM parent WHERE key = 2400; SELECT * FROM parent WHERE key = 2400;
</programlisting> </programlisting>
With constraint exclusion enabled, this SELECT will not scan With constraint exclusion enabled, this <command>SELECT</>
<structname>child1000</> at all. This can improve performance when will not scan <structname>child1000</> at all. This can
inheritance is used to build partitioned tables. improve performance when inheritance is used to build
partitioned tables.
</para> </para>
<para> <para>
Currently, <varname>constraint_exclusion</> defaults to Currently, <varname>constraint_exclusion</> is disabled by
<literal>off</>, because it risks incorrect results if default because it risks incorrect results if query plans are
query plans are cached --- if a table constraint is changed or dropped, cached &mdash; if a table constraint is changed or dropped,
the previously generated plan might now be wrong, and there is no the previously generated plan might now be wrong, and there is
built-in mechanism to force re-planning. (This deficiency will no built-in mechanism to force re-planning. (This deficiency
probably be addressed in a future will probably be addressed in a future
<productname>PostgreSQL</productname> release.) Another reason <productname>PostgreSQL</> release.) Another reason for
for keeping it off is that the constraint checks are relatively keeping it off is that the constraint checks are relatively
expensive, and in many circumstances will yield no savings. expensive, and in many circumstances will yield no savings.
It is recommended to turn this on only if you are actually using It is recommended to turn this on only if you are actually
partitioned tables designed to take advantage of the feature. using partitioned tables designed to take advantage of the
feature.
</para>
<para>
Refer to <xref linkend="ce-partitioning"> for more information
on using constraint exclusion and partitioning.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment