1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Fix partitioned index creation with foreign partitions

When a partitioned tables contains foreign tables as partitions, it is
not possible to implement unique or primary key indexes -- but when
regular indexes are created, there is no reason to do anything other
than ignoring such partitions.  We were raising errors upon encountering
the foreign partitions, which is unfriendly and doesn't protect against
any actual problems.

Relax this restriction so that index creation is allowed on partitioned
tables containing foreign partitions, becoming a no-op on them.  (We may
later want to redefine this so that the FDW is told to create the
indexes on the foreign side.)  This applies to CREATE INDEX, as well as
ALTER TABLE / ATTACH PARTITION and CREATE TABLE / PARTITION OF.

Backpatch to 11, where indexes on partitioned tables were introduced.

Discussion: https://postgr.es/m/15724-d5a58fa9472eef4f@postgresql.org
Author: Álvaro Herrera
Reviewed-by: Amit Langote
This commit is contained in:
Alvaro Herrera
2019-06-26 18:38:51 -04:00
parent 0e08a3a1f5
commit 9653ca2197
7 changed files with 172 additions and 9 deletions

View File

@ -861,7 +861,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
Note that if the existing table is a foreign table, it is currently not
allowed to attach the table as a partition of the target table if there
are indexes on the target table. (See also
are <literal>UNIQUE</literal> indexes on the target table. (See also
<xref linkend="sql-createforeigntable"/>.)
</para>

View File

@ -169,8 +169,8 @@ CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ]
See the similar form of
<xref linkend="sql-createtable"/> for more details.
Note that it is currently not allowed to create the foreign table as a
partition of the parent table if there are indexes on the parent table.
(See also
partition of the parent table if there are <literal>UNIQUE</literal>
indexes on the parent table. (See also
<link linkend="sql-altertable"><command>ALTER TABLE ATTACH PARTITION</command></link>.)
</para>
</listitem>