Skip to content

Commit f5efc93

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 ee8b95f commit f5efc93

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

doc/src/sgml/ddl.sgml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,13 +3308,13 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
33083308
<para>
33093309
Before running the <command>ATTACH PARTITION</> command, it is
33103310
recommended to create a <literal>CHECK</> constraint on the table to
3311-
be attached describing the desired partition constraint. That way,
3311+
be attached matching the desired partition constraint. That way,
33123312
the system will be able to skip the scan to validate the implicit
3313-
partition constraint. Without such a constraint, the table will be
3314-
scanned to validate the partition constraint while holding an
3315-
<literal>ACCESS EXCLUSIVE</literal> lock on the parent table.
3316-
One may then drop the constraint after <command>ATTACH PARTITION</>
3317-
is finished, because it is no longer necessary.
3313+
partition constraint. Without the <literal>CHECK</> constraint,
3314+
the table will be scanned to validate the partition constraint while
3315+
holding an <literal>ACCESS EXCLUSIVE</literal> lock on the parent table.
3316+
It may be desired to drop the redundant <literal>CHECK</> constraint
3317+
after <command>ATTACH PARTITION</> is finished.
33183318
</para>
33193319
</sect3>
33203320

doc/src/sgml/ref/alter_table.sgml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -781,23 +781,24 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
781781
<literal>FOREIGN KEY</literal> constraints are not considered.
782782
If any of the <literal>CHECK</literal> constraints of the table being
783783
attached is marked <literal>NO INHERIT</literal>, the command will fail;
784-
such a constraint must be recreated without the <literal>NO INHERIT</literal>
785-
clause.
784+
such constraints must be recreated without the
785+
<literal>NO INHERIT</literal> clause.
786786
</para>
787787

788788
<para>
789789
If the new partition is a regular table, a full table scan is performed
790-
to check that no existing row in the table violates the partition
791-
constraint. It is possible to avoid this scan by adding a valid
792-
<literal>CHECK</literal> constraint to the table that would allow only
793-
the rows satisfying the desired partition constraint before running this
794-
command. It will be determined using such a constraint that the table
795-
need not be scanned to validate the partition constraint. This does not
796-
work, however, if any of the partition keys is an expression and the
797-
partition does not accept <literal>NULL</literal> values. If attaching
798-
a list partition that will not accept <literal>NULL</literal> values,
799-
also add <literal>NOT NULL</literal> constraint to the partition key
800-
column, unless it's an expression.
790+
to check that existing rows in the table do not violate the partition
791+
constraint. It is possible to avoid this scan by adding a valid
792+
<literal>CHECK</literal> constraint to the table that allows only
793+
rows satisfying the desired partition constraint before running this
794+
command. The <literal>CHECK</literal> constraint will be used to
795+
determine that the table need not be scanned to validate the partition
796+
constraint. This does not work, however, if any of the partition keys
797+
is an expression and the partition does not accept
798+
<literal>NULL</literal> values. If attaching a list partition that will
799+
not accept <literal>NULL</literal> values, also add
800+
<literal>NOT NULL</literal> constraint to the partition key column,
801+
unless it's an expression.
801802
</para>
802803

803804
<para>

0 commit comments

Comments
 (0)