From c457edc4d04ad3454d485362840264e02f4eea50 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 24 Jan 2017 14:22:34 +0900 Subject: [PATCH 2/2] Do not allocate storage for partitioned tables. Currently, it is not possible to insert any data into a partitioned table. So, they're empty at all times, which means it is wasteful to allocate relfilenode and related storage objects. --- src/backend/access/common/reloptions.c | 3 +-- src/backend/catalog/heap.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index 72e12532ab..d3b847e2e5 100644 --- a/src/backend/access/common/reloptions.c +++ b/src/backend/access/common/reloptions.c @@ -967,7 +967,6 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, case RELKIND_RELATION: case RELKIND_TOASTVALUE: case RELKIND_MATVIEW: - case RELKIND_PARTITIONED_TABLE: options = heap_reloptions(classForm->relkind, datum, false); break; case RELKIND_VIEW: @@ -977,6 +976,7 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, options = index_reloptions(amoptions, datum, false); break; case RELKIND_FOREIGN_TABLE: + case RELKIND_PARTITIONED_TABLE: options = NULL; break; default: @@ -1418,7 +1418,6 @@ heap_reloptions(char relkind, Datum reloptions, bool validate) return (bytea *) rdopts; case RELKIND_RELATION: case RELKIND_MATVIEW: - case RELKIND_PARTITIONED_TABLE: return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP); default: /* other relkinds are not supported */ diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 41c0056556..2f5090b183 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -291,6 +291,7 @@ heap_create(const char *relname, case RELKIND_VIEW: case RELKIND_COMPOSITE_TYPE: case RELKIND_FOREIGN_TABLE: + case RELKIND_PARTITIONED_TABLE: create_storage = false; /* @@ -1345,14 +1346,13 @@ heap_create_with_catalog(const char *relname, if (oncommit != ONCOMMIT_NOOP) register_on_commit_action(relid, oncommit); - if (relpersistence == RELPERSISTENCE_UNLOGGED) - { - Assert(relkind == RELKIND_RELATION || relkind == RELKIND_MATVIEW || - relkind == RELKIND_TOASTVALUE || - relkind == RELKIND_PARTITIONED_TABLE); - + /* + * We do not want to create any storage objects for a partitioned + * table, including the init fork. + */ + if (relpersistence == RELPERSISTENCE_UNLOGGED && + relkind != RELKIND_PARTITIONED_TABLE) heap_create_init_fork(new_rel_desc); - } /* * ok, the relation has been cataloged, so close our relations and return @@ -1376,6 +1376,9 @@ heap_create_with_catalog(const char *relname, void heap_create_init_fork(Relation rel) { + Assert(rel->rd_rel->relkind == RELKIND_RELATION || + rel->rd_rel->relkind == RELKIND_MATVIEW || + rel->rd_rel->relkind == RELKIND_TOASTVALUE); RelationOpenSmgr(rel); smgrcreate(rel->rd_smgr, INIT_FORKNUM, false); log_smgrcreate(&rel->rd_smgr->smgr_rnode.node, INIT_FORKNUM); -- 2.11.0