diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/heap.c | 32 | ||||
-rw-r--r-- | src/backend/utils/cache/relcache.c | 4 |
2 files changed, 16 insertions, 20 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 694000798a7..472285d3913 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -324,35 +324,25 @@ heap_create(const char *relname, get_namespace_name(relnamespace), relname), errdetail("System catalog modifications are currently disallowed."))); - /* - * Decide if we need storage or not, and handle a couple other special - * cases for particular relkinds. - */ + /* Handle reltablespace for specific relkinds. */ switch (relkind) { case RELKIND_VIEW: case RELKIND_COMPOSITE_TYPE: case RELKIND_FOREIGN_TABLE: - create_storage = false; /* * Force reltablespace to zero if the relation has no physical * storage. This is mainly just for cleanliness' sake. + * + * Partitioned tables and indexes don't have physical storage + * either, but we want to keep their tablespace settings so that + * their children can inherit it. */ reltablespace = InvalidOid; break; - case RELKIND_PARTITIONED_TABLE: - case RELKIND_PARTITIONED_INDEX: - /* - * For partitioned tables and indexes, preserve tablespace so that - * it's used as the tablespace for future partitions. - */ - create_storage = false; - break; - case RELKIND_SEQUENCE: - create_storage = true; /* * Force reltablespace to zero for sequences, since we don't @@ -361,19 +351,21 @@ heap_create(const char *relname, reltablespace = InvalidOid; break; default: - create_storage = true; break; } /* - * Unless otherwise requested, the physical ID (relfilenode) is initially - * the same as the logical ID (OID). When the caller did specify a - * relfilenode, it already exists; do not attempt to create it. + * Decide whether to create storage. If caller passed a valid relfilenode, + * storage is already created, so don't do it here. Also don't create it + * for relkinds without physical storage. */ - if (OidIsValid(relfilenode)) + if (!RELKIND_HAS_STORAGE(relkind) || OidIsValid(relfilenode)) create_storage = false; else + { + create_storage = true; relfilenode = relid; + } /* * Never allow a pg_class entry to explicitly specify the database's diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index b5f5a224171..06503bc98b2 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1253,6 +1253,10 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) static void RelationInitPhysicalAddr(Relation relation) { + /* these relations kinds never have storage */ + if (!RELKIND_HAS_STORAGE(relation->rd_rel->relkind)) + return; + if (relation->rd_rel->reltablespace) relation->rd_node.spcNode = relation->rd_rel->reltablespace; else |