diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 287addf429..d49e32d83f 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -67,6 +67,7 @@ #include "tcop/utility.h" #include "utils/acl.h" #include "utils/guc.h" +#include "utils/lsyscache.h" #include "utils/syscache.h" #include "utils/rel.h" @@ -1318,12 +1319,26 @@ ProcessUtilitySlow(ParseState *pstate, if (stmt->relation->inh) { Relation rel; + ListCell *lc; /* already locked by RangeVarGetRelidExtended */ rel = heap_open(relid, NoLock); if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) inheritors = find_all_inheritors(relid, lockmode, NULL); + foreach(lc, inheritors) + { + char relkind = get_rel_relkind(lfirst_oid(lc)); + + if (relkind != RELKIND_RELATION && + relkind != RELKIND_MATVIEW && + relkind != RELKIND_PARTITIONED_TABLE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot create index on partitioned table containing foreign partitions"))); + } + + list_free(inheritors); heap_close(rel, NoLock); } @@ -1353,8 +1368,6 @@ ProcessUtilitySlow(ParseState *pstate, parsetree); commandCollected = true; EventTriggerAlterTableEnd(); - - list_free(inheritors); } break;