mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Allow UNIQUE indexes on partitioned tables
If we restrict unique constraints on partitioned tables so that they must always include the partition key, then our standard approach to unique indexes already works --- each unique key is forced to exist within a single partition, so enforcing the unique restriction in each index individually is enough to have it enforced globally. Therefore we can implement unique indexes on partitions by simply removing a few restrictions (and adding others.) Discussion: https://postgr.es/m/20171222212921.hi6hg6pem2w2t36z@alvherre.pgsql Discussion: https://postgr.es/m/20171229230607.3iib6b62fn3uaf47@alvherre.pgsql Reviewed-by: Simon Riggs, Jesper Pedersen, Peter Eisentraut, Jaime Casanova, Amit Langote
This commit is contained in:
@@ -546,8 +546,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Partitioned tables do not support <literal>UNIQUE</literal>,
|
||||
<literal>PRIMARY KEY</literal>, <literal>EXCLUDE</literal>, or
|
||||
Partitioned tables do not support <literal>EXCLUDE</literal> or
|
||||
<literal>FOREIGN KEY</literal> constraints; however, you can define
|
||||
these constraints on individual partitions.
|
||||
</para>
|
||||
@@ -786,6 +785,14 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
|
||||
primary key constraint defined for the table. (Otherwise it
|
||||
would just be the same constraint listed twice.)
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When used on partitioned tables, unique constraints must include all the
|
||||
columns of the partition key.
|
||||
If any partitions are in turn partitioned, all columns of each partition
|
||||
key are considered at each level below the <literal>UNIQUE</literal>
|
||||
constraint.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@@ -814,6 +821,13 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
|
||||
about the design of the schema, since a primary key implies that other
|
||||
tables can rely on this set of columns as a unique identifier for rows.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<literal>PRIMARY KEY</literal> constraints share the restrictions that
|
||||
<literal>UNIQUE</literal> constraints have when placed on partitioned
|
||||
tables.
|
||||
</para>
|
||||
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
Reference in New Issue
Block a user