Commit a1a4459c authored by Robert Haas's avatar Robert Haas

doc: Improve documentation related to table partitioning feature.

Commit f0e44751 implemented table
partitioning, but failed to mention the "no row movement"
restriction in the documentation.  Fix that and a few other issues.

Amit Langote, with some additional wordsmithing by me.
parent 3856cf96
...@@ -715,7 +715,7 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> ...@@ -715,7 +715,7 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>ATTACH PARTITION</literal> <replaceable class="PARAMETER">partition_name</replaceable> <replaceable class="PARAMETER">partition_bound_spec</replaceable></term> <term><literal>ATTACH PARTITION</literal> <replaceable class="PARAMETER">partition_name</replaceable> FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable></term>
<listitem> <listitem>
<para> <para>
This form attaches an existing table (which might itself be partitioned) This form attaches an existing table (which might itself be partitioned)
...@@ -1332,7 +1332,7 @@ ALTER TABLE measurement ...@@ -1332,7 +1332,7 @@ ALTER TABLE measurement
Attach a partition to list partitioned table: Attach a partition to list partitioned table:
<programlisting> <programlisting>
ALTER TABLE cities ALTER TABLE cities
ATTACH PARTITION cities_west FOR VALUES IN ('Los Angeles', 'San Francisco'); ATTACH PARTITION cities_ab FOR VALUES IN ('a', 'b');
</programlisting></para> </programlisting></para>
<para> <para>
......
...@@ -248,7 +248,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI ...@@ -248,7 +248,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>PARTITION OF <replaceable class="PARAMETER">parent_table</replaceable></literal></term> <term><literal>PARTITION OF <replaceable class="PARAMETER">parent_table</replaceable></literal> FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable></term>
<listitem> <listitem>
<para> <para>
Creates the table as <firstterm>partition</firstterm> of the specified Creates the table as <firstterm>partition</firstterm> of the specified
...@@ -275,7 +275,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI ...@@ -275,7 +275,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
<para> <para>
Rows inserted into a partitioned table will be automatically routed to Rows inserted into a partitioned table will be automatically routed to
the correct partition. If no suitable partition exists, an error will the correct partition. If no suitable partition exists, an error will
occur. occur. Also, if updating a row in a given partition causes it to move
to another partition due to the new partition key, an error will occur.
</para> </para>
<para> <para>
...@@ -1477,7 +1478,6 @@ CREATE TABLE employees OF employee_type ( ...@@ -1477,7 +1478,6 @@ CREATE TABLE employees OF employee_type (
Create a range partitioned table: Create a range partitioned table:
<programlisting> <programlisting>
CREATE TABLE measurement ( CREATE TABLE measurement (
city_id int not null,
logdate date not null, logdate date not null,
peaktemp int, peaktemp int,
unitsales int unitsales int
...@@ -1488,9 +1488,10 @@ CREATE TABLE measurement ( ...@@ -1488,9 +1488,10 @@ CREATE TABLE measurement (
Create a list partitioned table: Create a list partitioned table:
<programlisting> <programlisting>
CREATE TABLE cities ( CREATE TABLE cities (
city_id bigserial not null,
name text not null, name text not null,
population int, population bigint,
) PARTITION BY LIST (initcap(name)); ) PARTITION BY LIST (left(lower(name), 1));
</programlisting></para> </programlisting></para>
<para> <para>
...@@ -1498,30 +1499,30 @@ CREATE TABLE cities ( ...@@ -1498,30 +1499,30 @@ CREATE TABLE cities (
<programlisting> <programlisting>
CREATE TABLE measurement_y2016m07 CREATE TABLE measurement_y2016m07
PARTITION OF measurement ( PARTITION OF measurement (
unitsales WITH OPTIONS DEFAULT 0 unitsales DEFAULT 0
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); ) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
</programlisting></para> </programlisting></para>
<para> <para>
Create partition of a list partitioned table: Create partition of a list partitioned table:
<programlisting> <programlisting>
CREATE TABLE cities_west CREATE TABLE cities_ab
PARTITION OF cities ( PARTITION OF cities (
CONSTRAINT city_id_nonzero CHECK (city_id != 0) CONSTRAINT city_id_nonzero CHECK (city_id != 0)
) FOR VALUES IN ('Los Angeles', 'San Francisco'); ) FOR VALUES IN ('a', 'b');
</programlisting></para> </programlisting></para>
<para> <para>
Create partition of a list partitioned table that is itself further Create partition of a list partitioned table that is itself further
partitioned and then add a partition to it: partitioned and then add a partition to it:
<programlisting> <programlisting>
CREATE TABLE cities_west CREATE TABLE cities_ab
PARTITION OF cities ( PARTITION OF cities (
CONSTRAINT city_id_nonzero CHECK (city_id != 0) CONSTRAINT city_id_nonzero CHECK (city_id != 0)
) FOR VALUES IN ('Los Angeles', 'San Francisco') PARTITION BY RANGE (population); ) FOR VALUES IN ('a', 'b') PARTITION BY RANGE (population);
CREATE TABLE cities_west_10000_to_100000 CREATE TABLE cities_ab_10000_to_100000
PARTITION OF cities_west FOR VALUES FROM (10000) TO (100000); PARTITION OF cities_ab FOR VALUES FROM (10000) TO (100000);
</programlisting></para> </programlisting></para>
</refsect1> </refsect1>
......
...@@ -526,6 +526,17 @@ INSERT <replaceable>oid</replaceable> <replaceable class="parameter">count</repl ...@@ -526,6 +526,17 @@ INSERT <replaceable>oid</replaceable> <replaceable class="parameter">count</repl
updated by the command. updated by the command.
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>Notes</title>
<para>
If the specified table is a partitioned table, each row is routed to
the appropriate partition and inserted into it. If the specified table
is a partition, an error will occur if one of the input rows violates
the partition constraint.
</para>
</refsect1>
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
......
...@@ -279,6 +279,14 @@ UPDATE <replaceable class="parameter">count</replaceable> ...@@ -279,6 +279,14 @@ UPDATE <replaceable class="parameter">count</replaceable>
sub-selects is safer, though often harder to read and slower than sub-selects is safer, though often harder to read and slower than
using a join. using a join.
</para> </para>
<para>
In the case of a partitioned table, updating a row might cause it to no
longer satisfy the partition constraint. Since there is no provision to
move the row to the partition appropriate to the new value of its
partitioning key, an error will occur in this case. This can also happen
when updating a partition directly.
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
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