Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ea88133

Browse files
committed
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
1 parent 3534fa2 commit ea88133

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

doc/src/sgml/ddl.sgml

+6-6
Original file line numberDiff line numberDiff line change
@@ -3952,14 +3952,14 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
39523952
<para>
39533953
Before running the <command>ATTACH PARTITION</command> command, it is
39543954
recommended to create a <literal>CHECK</literal> constraint on the table to
3955-
be attached describing the desired partition constraint. That way,
3955+
be attached matching the desired partition constraint. That way,
39563956
the system will be able to skip the scan to validate the implicit
3957-
partition constraint. Without such a constraint, the table will be
3958-
scanned to validate the partition constraint while holding an
3959-
<literal>ACCESS EXCLUSIVE</literal> lock on that partition
3957+
partition constraint. Without the <literal>CHECK</literal> constraint,
3958+
the table will be scanned to validate the partition constraint while
3959+
holding an <literal>ACCESS EXCLUSIVE</literal> lock on that partition
39603960
and a <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the parent table.
3961-
One may then drop the constraint after <command>ATTACH PARTITION</command>
3962-
is finished, because it is no longer necessary.
3961+
It may be desired to drop the redundant <literal>CHECK</literal> constraint
3962+
after <command>ATTACH PARTITION</command> is finished.
39633963
</para>
39643964

39653965
<para>

doc/src/sgml/ref/alter_table.sgml

+15-14
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
841841
or as a default partition by using <literal>DEFAULT</literal>.
842842
For each index in the target table, a corresponding
843843
one will be created in the attached table; or, if an equivalent
844-
index already exists, will be attached to the target table's index,
844+
index already exists, it will be attached to the target table's index,
845845
as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
846846
Note that if the existing table is a foreign table, it is currently not
847847
allowed to attach the table as a partition of the target table if there
@@ -864,23 +864,24 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
864864
already exist.
865865
If any of the <literal>CHECK</literal> constraints of the table being
866866
attached is marked <literal>NO INHERIT</literal>, the command will fail;
867-
such a constraint must be recreated without the <literal>NO INHERIT</literal>
868-
clause.
867+
such constraints must be recreated without the
868+
<literal>NO INHERIT</literal> clause.
869869
</para>
870870

871871
<para>
872872
If the new partition is a regular table, a full table scan is performed
873-
to check that no existing row in the table violates the partition
874-
constraint. It is possible to avoid this scan by adding a valid
875-
<literal>CHECK</literal> constraint to the table that would allow only
876-
the rows satisfying the desired partition constraint before running this
877-
command. It will be determined using such a constraint that the table
878-
need not be scanned to validate the partition constraint. This does not
879-
work, however, if any of the partition keys is an expression and the
880-
partition does not accept <literal>NULL</literal> values. If attaching
881-
a list partition that will not accept <literal>NULL</literal> values,
882-
also add <literal>NOT NULL</literal> constraint to the partition key
883-
column, unless it's an expression.
873+
to check that existing rows in the table do not violate the partition
874+
constraint. It is possible to avoid this scan by adding a valid
875+
<literal>CHECK</literal> constraint to the table that allows only
876+
rows satisfying the desired partition constraint before running this
877+
command. The <literal>CHECK</literal> constraint will be used to
878+
determine that the table need not be scanned to validate the partition
879+
constraint. This does not work, however, if any of the partition keys
880+
is an expression and the partition does not accept
881+
<literal>NULL</literal> values. If attaching a list partition that will
882+
not accept <literal>NULL</literal> values, also add
883+
<literal>NOT NULL</literal> constraint to the partition key column,
884+
unless it's an expression.
884885
</para>
885886

886887
<para>

0 commit comments

Comments
 (0)