mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Allow a partitioned table to have a default partition.
Any tuples that don't route to any other partition will route to the default partition. Jeevan Ladhe, Beena Emerson, Ashutosh Bapat, Rahila Syed, and Robert Haas, with review and testing at various stages by (at least) Rushabh Lathia, Keith Fiske, Amit Langote, Amul Sul, Rajkumar Raghuanshi, Sven Kunze, Kyotaro Horiguchi, Thom Brown, Rafia Sabih, and Dilip Kumar. Discussion: http://postgr.es/m/CAH2L28tbN4SYyhS7YV1YBWcitkqbhSWfQCy0G=apRcC_PEO-bg@mail.gmail.com Discussion: http://postgr.es/m/CAOG9ApEYj34fWMcvBMBQ-YtqR9fTdXhdN82QEKG0SVZ6zeL1xg@mail.gmail.com
This commit is contained in:
@@ -49,7 +49,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
|
||||
{ <replaceable class="PARAMETER">column_name</replaceable> [ WITH OPTIONS ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
|
||||
| <replaceable>table_constraint</replaceable> }
|
||||
[, ... ]
|
||||
) ] FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable>
|
||||
) ] { FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable> | DEFAULT }
|
||||
[ PARTITION BY { RANGE | LIST } ( { <replaceable class="parameter">column_name</replaceable> | ( <replaceable class="parameter">expression</replaceable> ) } [ COLLATE <replaceable class="parameter">collation</replaceable> ] [ <replaceable class="parameter">opclass</replaceable> ] [, ... ] ) ]
|
||||
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
|
||||
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
|
||||
@@ -250,11 +250,13 @@ FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replace
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="SQL-CREATETABLE-PARTITION">
|
||||
<term><literal>PARTITION OF <replaceable class="PARAMETER">parent_table</replaceable> FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable></literal></term>
|
||||
<term><literal>PARTITION OF <replaceable class="PARAMETER">parent_table</replaceable> { FOR VALUES <replaceable class="PARAMETER">partition_bound_spec</replaceable> | DEFAULT }</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Creates the table as a <firstterm>partition</firstterm> of the specified
|
||||
parent table.
|
||||
parent table. The table can be created either as a partition for specific
|
||||
values using <literal>FOR VALUES</literal> or as a default partition
|
||||
using <literal>DEFAULT</literal>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -342,6 +344,26 @@ FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replace
|
||||
allows precisely one value to be stored — "infinity".
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If <literal>DEFAULT</literal> is specified, the table will be
|
||||
created as a default partition of the parent table. The parent can
|
||||
either be a list or range partitioned table. A partition key value
|
||||
not fitting into any other partition of the given parent will be
|
||||
routed to the default partition. There can be only one default
|
||||
partition for a given parent table.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When a table has an existing <literal>DEFAULT</literal> partition and
|
||||
a new partition is added to it, the existing default partition must
|
||||
be scanned to verify that it does not contain any rows which properly
|
||||
belong in the new partition. If the default partition contains a
|
||||
large number of rows, this may be slow. The scan will be skipped if
|
||||
the default partition is a foreign table or if it has a constraint which
|
||||
proves that it cannot contain rows which should be placed in the new
|
||||
partition.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
A partition must have the same column names and types as the partitioned
|
||||
table to which it belongs. If the parent is specified <literal>WITH
|
||||
@@ -1679,6 +1701,13 @@ CREATE TABLE cities_ab
|
||||
CREATE TABLE cities_ab_10000_to_100000
|
||||
PARTITION OF cities_ab FOR VALUES FROM (10000) TO (100000);
|
||||
</programlisting></para>
|
||||
|
||||
<para>
|
||||
Create a default partition:
|
||||
<programlisting>
|
||||
CREATE TABLE cities_partdef
|
||||
PARTITION OF cities DEFAULT;
|
||||
</programlisting></para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 id="SQL-CREATETABLE-compatibility">
|
||||
|
Reference in New Issue
Block a user