1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-09 22:41:56 +03:00

Doc: Improve description around ALTER TABLE ATTACH PARTITION

This clarifies more how to use and how to take advantage of constraints
when attaching a new partition.

Author: Justin Pryzby
Reviewed-by: Amit Langote, Álvaro Herrera, Michael Paquier
Discussion: https://postgr.es/m/20191028001207.GB23808@telsasoft.com
Backpatch-through: 10
This commit is contained in:
Michael Paquier
2019-11-05 10:18:05 +09:00
parent ee8b95f268
commit f5efc931c2
2 changed files with 20 additions and 19 deletions

View File

@ -3308,13 +3308,13 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
<para> <para>
Before running the <command>ATTACH PARTITION</> command, it is Before running the <command>ATTACH PARTITION</> command, it is
recommended to create a <literal>CHECK</> constraint on the table to recommended to create a <literal>CHECK</> constraint on the table to
be attached describing the desired partition constraint. That way, be attached matching the desired partition constraint. That way,
the system will be able to skip the scan to validate the implicit the system will be able to skip the scan to validate the implicit
partition constraint. Without such a constraint, the table will be partition constraint. Without the <literal>CHECK</> constraint,
scanned to validate the partition constraint while holding an the table will be scanned to validate the partition constraint while
<literal>ACCESS EXCLUSIVE</literal> lock on the parent table. holding an <literal>ACCESS EXCLUSIVE</literal> lock on the parent table.
One may then drop the constraint after <command>ATTACH PARTITION</> It may be desired to drop the redundant <literal>CHECK</> constraint
is finished, because it is no longer necessary. after <command>ATTACH PARTITION</> is finished.
</para> </para>
</sect3> </sect3>

View File

@ -781,23 +781,24 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
<literal>FOREIGN KEY</literal> constraints are not considered. <literal>FOREIGN KEY</literal> constraints are not considered.
If any of the <literal>CHECK</literal> constraints of the table being If any of the <literal>CHECK</literal> constraints of the table being
attached is marked <literal>NO INHERIT</literal>, the command will fail; attached is marked <literal>NO INHERIT</literal>, the command will fail;
such a constraint must be recreated without the <literal>NO INHERIT</literal> such constraints must be recreated without the
clause. <literal>NO INHERIT</literal> clause.
</para> </para>
<para> <para>
If the new partition is a regular table, a full table scan is performed If the new partition is a regular table, a full table scan is performed
to check that no existing row in the table violates the partition to check that existing rows in the table do not violate the partition
constraint. It is possible to avoid this scan by adding a valid constraint. It is possible to avoid this scan by adding a valid
<literal>CHECK</literal> constraint to the table that would allow only <literal>CHECK</literal> constraint to the table that allows only
the rows satisfying the desired partition constraint before running this rows satisfying the desired partition constraint before running this
command. It will be determined using such a constraint that the table command. The <literal>CHECK</literal> constraint will be used to
need not be scanned to validate the partition constraint. This does not determine that the table need not be scanned to validate the partition
work, however, if any of the partition keys is an expression and the constraint. This does not work, however, if any of the partition keys
partition does not accept <literal>NULL</literal> values. If attaching is an expression and the partition does not accept
a list partition that will not accept <literal>NULL</literal> values, <literal>NULL</literal> values. If attaching a list partition that will
also add <literal>NOT NULL</literal> constraint to the partition key not accept <literal>NULL</literal> values, also add
column, unless it's an expression. <literal>NOT NULL</literal> constraint to the partition key column,
unless it's an expression.
</para> </para>
<para> <para>