diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-06-26 18:38:51 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-06-26 18:38:51 -0400 |
commit | 55ed3defc966cf718fe1e8c0efe964580bb23351 (patch) | |
tree | ddc9c211ea304679726c72019f92494450779c04 /src/backend/tcop | |
parent | 65e6d42140c8d9918638b9f73528288ab980af82 (diff) | |
download | postgresql-55ed3defc966cf718fe1e8c0efe964580bb23351.tar.gz postgresql-55ed3defc966cf718fe1e8c0efe964580bb23351.zip |
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
Diffstat (limited to 'src/backend/tcop')
-rw-r--r-- | src/backend/tcop/utility.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 9578b5c7619..05ec7f3ac61 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -1347,10 +1347,16 @@ ProcessUtilitySlow(ParseState *pstate, if (relkind != RELKIND_RELATION && relkind != RELKIND_MATVIEW && - relkind != RELKIND_PARTITIONED_TABLE) + relkind != RELKIND_PARTITIONED_TABLE && + relkind != RELKIND_FOREIGN_TABLE) + elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"", + relkind, stmt->relation->relname); + + if (relkind == RELKIND_FOREIGN_TABLE && + (stmt->unique || stmt->primary)) ereport(ERROR, - (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), - errmsg("cannot create index on partitioned table \"%s\"", + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot create unique index on partitioned table \"%s\"", stmt->relation->relname), errdetail("Table \"%s\" contains partitions that are foreign tables.", stmt->relation->relname))); |